Commit ef20c62f authored by Weiliang Li's avatar Weiliang Li Committed by Hero Bird

Fix erc20 transferring bug (#255)

* Update lib.rs

Fix #254

* Update lib.rs
parent 6689bb13
Pipeline #69742 passed with stages
in 26 minutes and 13 seconds
......@@ -129,11 +129,11 @@ contract! {
/// Transfers token from a specified AccountId to another AccountId.
fn transfer_impl(&mut self, env: &mut EnvHandler<ink_core::env::ContractEnv<DefaultSrmlTypes>>, from: AccountId, to: AccountId, value: Balance) -> bool {
let balance_from = self.balance_of_or_zero(&from);
let balance_to = self.balance_of_or_zero(&to);
if balance_from < value {
return false
}
self.balances.insert(from, balance_from - value);
let balance_to = self.balance_of_or_zero(&to);
self.balances.insert(to, balance_to + value);
env.emit(Transfer {
from: Some(from),
......
......@@ -119,8 +119,8 @@ mod erc20 {
if from_balance < value {
return false
}
let to_balance = self.balance_of_or_zero(&to);
self.balances.insert(from.clone(), from_balance - value);
let to_balance = self.balance_of_or_zero(&to);
self.balances.insert(to.clone(), to_balance + value);
self.env().emit_event(Transfer {
from: Some(from),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment