-
Notifications
You must be signed in to change notification settings - Fork 0
Fix/unsafe arithmetics #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
da3ce92
69418f7
e8244e8
0936cea
240f3f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2008,8 +2008,8 @@ impl<T: Config> Pallet<T> { | |
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Create revenue transaction id | ||
| let revenue_transaction_id = | ||
| (revenue_id, job_eligible_id, project_id, timestamp).using_encoded(blake2_256); | ||
|
|
||
| (revenue_id, revenue_amount, job_eligible_id, project_id, timestamp) | ||
| .using_encoded(blake2_256); | ||
| // Ensure revenue transaction id doesn't exist | ||
| ensure!( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por que se elimino este check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Estaba repetido, m{as abajo se vuelve a validar.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, movamos el ensure antes de crear el RevenueTransactionData por favor
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Falta este cambio |
||
| !RevenueTransactionsInfo::<T>::contains_key(revenue_transaction_id), | ||
|
|
@@ -2031,11 +2031,6 @@ impl<T: Config> Pallet<T> { | |
| }; | ||
|
|
||
| // Insert revenue transaction data into RevenueTransactionsInfo | ||
| // Ensure revenue transaction id doesn't exist | ||
| ensure!( | ||
| !RevenueTransactionsInfo::<T>::contains_key(revenue_transaction_id), | ||
| Error::<T>::RevenueTransactionIdAlreadyExists | ||
| ); | ||
| <RevenueTransactionsInfo<T>>::insert(revenue_transaction_id, revenue_transaction_data); | ||
|
|
||
| // Insert revenue transaction id into TransactionsByRevenue | ||
|
|
@@ -3125,6 +3120,14 @@ impl<T: Config> Pallet<T> { | |
| Ok(()) | ||
| } | ||
|
|
||
| fn safe_add( | ||
| a: u64, | ||
| b: u64 | ||
| ) -> Result<u64, DispatchError> { | ||
| let result = a.checked_add(b).ok_or_else(|| Error::<T>::ArithmeticOverflow)?; | ||
| Ok(result) | ||
| } | ||
|
|
||
| fn do_calculate_drawdown_total_amount( | ||
| project_id: [u8; 32], | ||
| drawdown_id: [u8; 32], | ||
|
|
@@ -3147,7 +3150,7 @@ impl<T: Config> Pallet<T> { | |
| .ok_or(Error::<T>::TransactionNotFound)?; | ||
|
|
||
| // Add transaction amount to drawdown total amount | ||
| drawdown_total_amount += transaction_data.amount; | ||
| drawdown_total_amount = Self::safe_add(drawdown_total_amount, transaction_data.amount)?; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -3299,7 +3302,7 @@ impl<T: Config> Pallet<T> { | |
| .ok_or(Error::<T>::RevenueTransactionNotFound)?; | ||
|
|
||
| // Add revenue transaction amount to revenue total amount | ||
| revenue_total_amount += revenue_transaction_data.amount; | ||
| revenue_total_amount = Self::safe_add(revenue_total_amount, revenue_transaction_data.amount)?; | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of 7539c1 - 15c838:
Error: couldn't generate summary