Open
Conversation
VladasZ
approved these changes
Dec 19, 2023
Comment on lines
+59
to
+68
| for index in lockup_indices.clone() { | ||
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | ||
| require!(lockup.is_adjustable, "Lockup is not adjustable"); | ||
|
|
||
| total_balance += lockup.schedule.total_balance(); | ||
|
|
||
| original_schedules.push((index, lockup.schedule)); | ||
| lockup.schedule = Schedule::new_unlocked(0); | ||
| self.lockups.replace(index as _, &lockup); | ||
| } |
There was a problem hiding this comment.
Suggested change
| for index in lockup_indices.clone() { | |
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | |
| require!(lockup.is_adjustable, "Lockup is not adjustable"); | |
| total_balance += lockup.schedule.total_balance(); | |
| original_schedules.push((index, lockup.schedule)); | |
| lockup.schedule = Schedule::new_unlocked(0); | |
| self.lockups.replace(index as _, &lockup); | |
| } | |
| for index in &lockup_indices { | |
| let mut lockup = self.lockups.get(*index as _).expect("Lockup not found"); | |
| require!(lockup.is_adjustable, "Lockup is not adjustable"); | |
| total_balance += lockup.schedule.total_balance(); | |
| original_schedules.push((*index, lockup.schedule)); | |
| lockup.schedule = Schedule::new_unlocked(0); | |
| self.lockups.replace(*index as _, &lockup); | |
| } |
Comment on lines
+99
to
+106
| fn after_lockup_adjustment(&mut self, lockup_index: LockupIndex, schedule: Schedule) { | ||
| if is_promise_success() { | ||
| return; | ||
| } | ||
|
|
||
| let mut lockup = self.lockups.get(lockup_index as _).expect("Lockup not found"); | ||
| lockup.schedule = schedule; | ||
| } |
There was a problem hiding this comment.
Does this code restore old schedule in case of failure? Maybe it is better to rename schedule variable here to something like schedule_before_adjustment?
Comment on lines
+108
to
+130
| fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) { | ||
| if is_promise_success() { | ||
| for (index, _) in original_schedules { | ||
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | ||
|
|
||
| let mut account_lockups = self | ||
| .account_lockups | ||
| .get(&lockup.account_id) | ||
| .expect("Account lockups not found"); | ||
| account_lockups.remove(&index); | ||
| self.account_lockups.insert(&lockup.account_id, &account_lockups); | ||
|
|
||
| lockup.account_id = env::current_account_id(); | ||
| self.lockups.replace(index as _, &lockup); | ||
| } | ||
| } else { | ||
| for (index, schedule) in original_schedules { | ||
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | ||
| lockup.schedule = schedule; | ||
| self.lockups.replace(index as _, &lockup); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
[nit]
I'm not sure if this improves the readability that much. You can ignore this if you don't like it)
Suggested change
| fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) { | |
| if is_promise_success() { | |
| for (index, _) in original_schedules { | |
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | |
| let mut account_lockups = self | |
| .account_lockups | |
| .get(&lockup.account_id) | |
| .expect("Account lockups not found"); | |
| account_lockups.remove(&index); | |
| self.account_lockups.insert(&lockup.account_id, &account_lockups); | |
| lockup.account_id = env::current_account_id(); | |
| self.lockups.replace(index as _, &lockup); | |
| } | |
| } else { | |
| for (index, schedule) in original_schedules { | |
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | |
| lockup.schedule = schedule; | |
| self.lockups.replace(index as _, &lockup); | |
| } | |
| } | |
| } | |
| fn after_lockups_revoke(&mut self, original_schedules: Vec<(LockupIndex, Schedule)>) { | |
| if !is_promise_success() { | |
| for (index, schedule) in original_schedules { | |
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | |
| lockup.schedule = schedule; | |
| self.lockups.replace(index as _, &lockup); | |
| } | |
| return; | |
| } | |
| for (index, _) in original_schedules { | |
| let mut lockup = self.lockups.get(index as _).expect("Lockup not found"); | |
| let mut account_lockups = self | |
| .account_lockups | |
| .get(&lockup.account_id) | |
| .expect("Account lockups not found"); | |
| account_lockups.remove(&index); | |
| self.account_lockups.insert(&lockup.account_id, &account_lockups); | |
| lockup.account_id = env::current_account_id(); | |
| self.lockups.replace(index as _, &lockup); | |
| } | |
| } |
Comment on lines
+71
to
+72
| // let holding_contract_init_result = context.utils().call("new").max_gas().transact().await?.into_result()?; | ||
| // println!("Initialized holding contract: {:?}", holding_contract_init_result); |
Comment on lines
+37
to
+49
| let result = self | ||
| .user_account() | ||
| .expect("User account is required") | ||
| .call(self.contract.id(), "terminate") | ||
| .args_json(json!({ | ||
| "lockup_index": lockup_index, | ||
| "hashed_schedule": hashed_schedule, | ||
| "termination_timestamp": termination_timestamp | ||
| })) | ||
| .max_gas() | ||
| .deposit(NearToken::from_yoctonear(1)) | ||
| .transact() | ||
| .await?; |
There was a problem hiding this comment.
I updated integration utils in this repo and you can use new interface for such calls. You can rebase to main and use them
3063e6f to
652fa96
Compare
This file contains hidden or 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
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.
No description provided.