From f24bcc1c522a080644196de5656301c0fbfebba2 Mon Sep 17 00:00:00 2001 From: Michael Birch Date: Thu, 17 Jun 2021 16:29:19 -0400 Subject: [PATCH 1/2] Return 0 balance when account is unknown --- src/fungible_token.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fungible_token.rs b/src/fungible_token.rs index c14220b12..1d037c5dc 100644 --- a/src/fungible_token.rs +++ b/src/fungible_token.rs @@ -39,7 +39,7 @@ impl FungibleToken { pub fn internal_unwrap_balance_of_eth_on_near(&self, account_id: &str) -> Balance { match self.accounts_get(account_id) { Some(balance) => u128::try_from_slice(&balance[..]).unwrap(), - None => sdk::panic_utf8(b"ERR_ACCOUNT_NOT_EXIST"), + None => 0, } } From be4c7bf72d8a1df2e3a9489e80f36d2c21799029 Mon Sep 17 00:00:00 2001 From: Michael Birch Date: Thu, 17 Jun 2021 17:14:52 -0400 Subject: [PATCH 2/2] in ft_transfer register the receiver account if it does not exit --- src/fungible_token.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fungible_token.rs b/src/fungible_token.rs index 1d037c5dc..4b18fd471 100644 --- a/src/fungible_token.rs +++ b/src/fungible_token.rs @@ -39,7 +39,7 @@ impl FungibleToken { pub fn internal_unwrap_balance_of_eth_on_near(&self, account_id: &str) -> Balance { match self.accounts_get(account_id) { Some(balance) => u128::try_from_slice(&balance[..]).unwrap(), - None => 0, + None => sdk::panic_utf8(b"ERR_ACCOUNT_NOT_EXIST"), } } @@ -144,6 +144,10 @@ impl FungibleToken { "Sender and receiver should be different" ); assert!(amount > 0, "The amount should be a positive number"); + if !self.accounts_contains_key(receiver_id) { + // TODO: how does this interact with the storage deposit concept? + self.internal_register_account(receiver_id) + } self.internal_withdraw_eth_from_near(sender_id, amount); self.internal_deposit_eth_to_near(receiver_id, amount); crate::log!(&format!(