Skip to content
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

Require payments for storage increase and refund difference #173

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

evgenykuzyakov
Copy link
Contributor

Code fix for near/core-contracts#47
Requires Spec change to address this issue in the fungible token standard.
Fixes: near/core-contracts#56

Comment on lines +217 to +238
fn refund_storage(&self, initial_storage: StorageUsage) {
let current_storage = env::storage_usage();
let attached_deposit = env::attached_deposit();
let refund_amount = if current_storage > initial_storage {
let required_deposit =
Balance::from(current_storage - initial_storage) * STORAGE_PRICE_PER_BYTE;
assert!(
required_deposit <= attached_deposit,
"The required attached deposit is {}, but the given attached deposit is is {}",
required_deposit,
attached_deposit,
);
attached_deposit - required_deposit
} else {
attached_deposit
+ Balance::from(initial_storage - current_storage) * STORAGE_PRICE_PER_BYTE
};
if refund_amount > 0 {
env::log(format!("Refunding {} tokens for storage", refund_amount).as_bytes());
Promise::new(env::predecessor_account_id()).transfer(refund_amount);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Contributor

@lexfrl lexfrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@evgenykuzyakov
Copy link
Contributor Author

Ok. Let's merge this and I'll start working on the Spec update. We can include all changes in one update.

@evgenykuzyakov evgenykuzyakov merged commit c271c39 into master Jun 4, 2020
@evgenykuzyakov evgenykuzyakov deleted the add-storage-payments-to-fungible-token branch June 4, 2020 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflows Not Set to Panic
3 participants