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

update after_token_burn #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions contracts/contract/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl Contract {

if let Some(mut lock_info) = account.locked_tokens.remove(&token_id) {
let amount = amount.unwrap_or(lock_info.locked_balance);
let unlock_time_sec = lock_info.unlock_time_sec;
lock_info.locked_balance = U128(
lock_info
.locked_balance
Expand All @@ -146,7 +147,7 @@ impl Contract {
account.locked_tokens.insert(token_id.clone(), lock_info);
}
self.internal_set_account(&account_id, account);
self.burn_token(&account_id, token_id.clone(), amount);
self.burn_token(&account_id, token_id.clone(), amount, unlock_time_sec);
Event::BurnStarted {
account_id: &account_id,
token_id: &token_id,
Expand Down Expand Up @@ -212,6 +213,7 @@ impl Contract {
account_id: AccountId,
token_id: String,
amount: U128,
unlock_time_sec: u32,
) -> bool {
let promise_success = is_promise_success();
if !promise_success {
Expand All @@ -223,7 +225,7 @@ impl Contract {
token_id.clone(),
LockInfo {
locked_balance: amount,
unlock_time_sec: nano_to_sec(env::block_timestamp()),
unlock_time_sec,
},
);
}
Expand Down Expand Up @@ -281,7 +283,7 @@ impl Contract {
};
}

pub fn burn_token(&self, account_id: &AccountId, token_id: String, amount: U128) {
pub fn burn_token(&self, account_id: &AccountId, token_id: String, amount: U128, unlock_time_sec: u32) {
let burn_account_id = self.data().burn_account_id.clone().expect("Missing burn_account_id");
let (contract_id, mft_token_id) = parse_token_id(&token_id);
if let Some(mft_token_id) = mft_token_id {
Expand All @@ -292,7 +294,7 @@ impl Contract {
.then(
Self::ext(env::current_account_id())
.with_static_gas(GAS_FOR_AFTER_TOKEN_BURN)
.after_token_burn(account_id.clone(), token_id.clone(), amount),
.after_token_burn(account_id.clone(), token_id.clone(), amount, unlock_time_sec),
)
} else {
ext_fungible_token::ext(contract_id.clone())
Expand All @@ -302,7 +304,7 @@ impl Contract {
.then(
Self::ext(env::current_account_id())
.with_static_gas(GAS_FOR_AFTER_TOKEN_BURN)
.after_token_burn(account_id.clone(), token_id.to_string(), amount),
.after_token_burn(account_id.clone(), token_id.to_string(), amount, unlock_time_sec),
)
};
}
Expand Down
2 changes: 1 addition & 1 deletion releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Version 0.2.0
```bash=
# codehash: 7yHXGgNxH7i1WNew378WVZPWRtZo4sFZi7MhZDjmPB62
# codehash: 53f1L7tJd4Pts1hxrnyvEhMiEChqfs2N7bBTKcUFU8gT
```
- add burn function.

Expand Down
Binary file modified releases/token_locker_release.wasm
Binary file not shown.