-
Notifications
You must be signed in to change notification settings - Fork 249
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MaksymZavershynskyi
approved these changes
Jun 4, 2020
lexfrl
reviewed
Jun 4, 2020
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
lexfrl
approved these changes
Jun 4, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Ok. Let's merge this and I'll start working on the Spec update. We can include all changes in one update. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Code fix for near/core-contracts#47
Requires Spec change to address this issue in the fungible token standard.
Fixes: near/core-contracts#56