File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
contract-sdk/specs/token/oas20/src Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -190,15 +190,16 @@ pub fn transfer<C: sdk::Context>(
190190 return Err ( Error :: ZeroAmount ) ;
191191 }
192192
193+ // Remove from account balance.
193194 let mut from_balance = balances. get ( ctx. public_store ( ) , from) . unwrap_or_default ( ) ;
194- let mut to_balance = balances. get ( ctx. public_store ( ) , to) . unwrap_or_default ( ) ;
195-
196195 from_balance = from_balance
197196 . checked_sub ( amount)
198197 . ok_or ( Error :: InsufficientFunds ) ?;
199- to_balance += amount;
200-
201198 balances. insert ( ctx. public_store ( ) , from, from_balance) ;
199+
200+ // Add to account balance. Shouldn't ever overflow.
201+ let mut to_balance = balances. get ( ctx. public_store ( ) , to) . unwrap_or_default ( ) ;
202+ to_balance = to_balance. checked_add ( amount) . unwrap ( ) ;
202203 balances. insert ( ctx. public_store ( ) , to, to_balance) ;
203204
204205 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments