Skip to content

Commit

Permalink
Cleanup storage for empty account (#179)
Browse files Browse the repository at this point in the history
It's helpful to remove account from storage if the account balance is 0 and there are no allowance set to any escrow.
  • Loading branch information
Evgeny Kuzyakov authored Jun 5, 2020
1 parent e5295a3 commit 6ca4b34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Binary file modified examples/fungible-token/res/fungible_token.wasm
Binary file not shown.
6 changes: 5 additions & 1 deletion examples/fungible-token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ impl FungibleToken {
/// Helper method to set the account details for `owner_id` to the state.
fn set_account(&mut self, owner_id: &AccountId, account: &Account) {
let account_hash = env::sha256(owner_id.as_bytes());
self.accounts.insert(&account_hash, &account);
if account.balance > 0 || !account.allowances.is_empty() {
self.accounts.insert(&account_hash, &account);
} else {
self.accounts.remove(&account_hash);
}
}

fn refund_storage(&self, initial_storage: StorageUsage) {
Expand Down

0 comments on commit 6ca4b34

Please sign in to comment.