-
Notifications
You must be signed in to change notification settings - Fork 7
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
242 - unsafe integer cast for BalanceConversion
's StaticLookUp
implementation
#256
Conversation
a8ea7cc
to
0fb72a2
Compare
if the i64 value reaches negative, make it zero for u128
0fb72a2
to
5bdc044
Compare
primitives/src/lib.rs
Outdated
(stellar_stroops * CONVERSION_RATE as i64) as u128 | ||
let conversion_rate = i64::try_from(CONVERSION_RATE).unwrap_or(i64::MAX); | ||
|
||
let value = stellar_stroops * conversion_rate; |
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.
Maybe we should even use saturating_mul()
here, just to be safe
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.
@b-yap WDYT?
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.
done
…plementation (#256) * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371
…plementation (#256) * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371
* 242 removing unnecessary conversion of a vector (#247) * fix weight for mint tokens in redeem pallet (#259) * first iteration (#258) * TryFrom `CurrencyId` Implementations Contain Repeated Code (#249) * 242 - secret exposed in cli (#255) * first iteration * update the readme , for the `stellar_vault_secret_key_filepath`. * add the example secret key file * applying cargo fmt * update the readme * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * Revert "if conversion rate is too big for i64, set it to what its max is." This reverts commit 399f175. * since DOT is already at 20, 20 should not fail. changed it to 30. * 242 - unsafe integer cast for `BalanceConversion`'s `StaticLookUp` implementation (#256) * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371 * fix metadata-standalone.scale * updated metadata scala * TryFrom `CurrencyId` Implementations Contain Repeated Code (#249) * Update metadata-standalone.scale --------- Co-authored-by: B. Yap <2826165+b-yap@users.noreply.github.com> Co-authored-by: cr4pt0 <102041955+cr4pt0@users.noreply.github.com>
* 242 removing unnecessary conversion of a vector (#247) * fix weight for mint tokens in redeem pallet (#259) * first iteration (#258) * TryFrom `CurrencyId` Implementations Contain Repeated Code (#249) * 242 - secret exposed in cli (#255) * first iteration * update the readme , for the `stellar_vault_secret_key_filepath`. * add the example secret key file * applying cargo fmt * update the readme * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * Revert "if conversion rate is too big for i64, set it to what its max is." This reverts commit 399f175. * since DOT is already at 20, 20 should not fail. changed it to 30. * 242 - unsafe integer cast for `BalanceConversion`'s `StaticLookUp` implementation (#256) * if conversion rate is too big for i64, set it to what its max is. if the i64 value reaches negative, make it zero for u128 * https://github.com/pendulum-chain/spacewalk/pull/256/files#r1105566371 * fix metadata-standalone.scale * updated metadata scala * TryFrom `CurrencyId` Implementations Contain Repeated Code (#249) * Update metadata-standalone.scale --------- Co-authored-by: B. Yap <2826165+b-yap@users.noreply.github.com> Co-authored-by: cr4pt0 <102041955+cr4pt0@users.noreply.github.com>
This is item #5 of #242
if conversion rate is too big for i64, set it to what its max is.
if the i64 value reaches negative, make it zero for u128.
^ Unless that's the wrong approach?