-
Notifications
You must be signed in to change notification settings - Fork 3
feat: unlimited pending sign txs whitelist #31
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
base: omni-main
Are you sure you want to change the base?
Changes from 5 commits
7633d97
c96843b
32ca22e
31d5223
5e3f1ee
677420e
a4169de
371e6a9
bc5f39d
aef06f8
d84bb7b
cf7eecc
2ee80a2
3f977ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,19 +15,44 @@ pub struct OutstandingInfo { | |
| #[derive(Clone)] | ||
| #[cfg_attr(not(target_arch = "wasm32"), derive(Debug))] | ||
| pub struct Account { | ||
| pub account_id: AccountId, | ||
| pub btc_pending_sign_ids: HashSet<String>, | ||
| pub btc_pending_verify_list: HashSet<String>, | ||
| } | ||
|
|
||
| /// Old Account format (v0.7.5 and earlier) with single pending sign id. | ||
| #[near(serializers = [borsh])] | ||
| #[derive(Clone)] | ||
| pub struct AccountV0 { | ||
| pub account_id: AccountId, | ||
| pub btc_pending_sign_id: Option<String>, | ||
| pub btc_pending_verify_list: HashSet<String>, | ||
| } | ||
|
|
||
| impl From<AccountV0> for Account { | ||
| fn from(v: AccountV0) -> Self { | ||
| let mut btc_pending_sign_ids = HashSet::new(); | ||
| if let Some(id) = v.btc_pending_sign_id { | ||
| btc_pending_sign_ids.insert(id); | ||
| } | ||
| Self { | ||
| account_id: v.account_id, | ||
| btc_pending_sign_ids, | ||
| btc_pending_verify_list: v.btc_pending_verify_list, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[near(serializers = [borsh])] | ||
| pub enum VAccount { | ||
| V0(AccountV0), | ||
| Current(Account), | ||
| } | ||
|
|
||
| impl From<VAccount> for Account { | ||
| fn from(v: VAccount) -> Self { | ||
| match v { | ||
| VAccount::V0(c) => c.into(), | ||
| VAccount::Current(c) => c, | ||
| } | ||
| } | ||
|
|
@@ -36,23 +61,22 @@ impl From<VAccount> for Account { | |
| impl From<&VAccount> for Account { | ||
| fn from(v: &VAccount) -> Self { | ||
| match v { | ||
| VAccount::V0(c) => c.clone().into(), | ||
| VAccount::Current(c) => c.clone(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a mut VAccount> for &'a mut Account { | ||
| fn from(v: &'a mut VAccount) -> Self { | ||
| match v { | ||
| VAccount::Current(c) => c, | ||
| // Lazy migrate V0 -> Current on first mutable access | ||
| if let VAccount::V0(old) = v { | ||
| let migrated: Account = old.clone().into(); | ||
| *v = VAccount::Current(migrated); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a VAccount> for &'a Account { | ||
| fn from(v: &'a VAccount) -> Self { | ||
| match v { | ||
| VAccount::Current(c) => c, | ||
| _ => unreachable!(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -67,7 +91,7 @@ impl Account { | |
| pub fn new(account_id: &AccountId) -> Self { | ||
| Self { | ||
| account_id: account_id.clone(), | ||
| btc_pending_sign_id: None, | ||
| btc_pending_sign_ids: HashSet::new(), | ||
| btc_pending_verify_list: HashSet::new(), | ||
| } | ||
| } | ||
|
|
@@ -78,18 +102,14 @@ impl Contract { | |
| self.data().accounts.contains_key(account_id) | ||
| } | ||
|
|
||
| pub fn internal_get_account(&self, account_id: &AccountId) -> Option<&Account> { | ||
| self.data().accounts.get(account_id).map(Into::into) | ||
| pub fn internal_get_account(&self, account_id: &AccountId) -> Option<Account> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we return cloned version now?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just decided to implement a lazy account migration. If we request mut, we upgrade the account to the new version. If it’s view, we convert it locally. Because of this approach, we can’t return a reference, since a conversion happens. As an alternative, we could implement a separate migration function and migrate accounts in batches. But I kind of like the lazy approach more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be removed. there is get_account that can be used directly
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we'd need an unnecessary clone, since AccountId is taken by value in view method. So I'd leave it as is for now.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use ref in view methods as I know
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed: 3f977ef |
||
| self.data().accounts.get(account_id).map(Account::from) | ||
| } | ||
|
|
||
| pub fn internal_unwrap_account(&self, account_id: &AccountId) -> &Account { | ||
| self.data() | ||
| .accounts | ||
| .get(account_id) | ||
| .map(|o| o.into()) | ||
| .unwrap_or_else(|| { | ||
| env::panic_str(&format!("ERR_ACCOUNT_NOT_REGISTERED: {}", account_id)) | ||
| }) | ||
| pub fn internal_unwrap_account(&self, account_id: &AccountId) -> Account { | ||
|
karim-en marked this conversation as resolved.
Outdated
|
||
| self.internal_get_account(account_id).unwrap_or_else(|| { | ||
| env::panic_str(&format!("ERR_ACCOUNT_NOT_REGISTERED: {}", account_id)) | ||
| }) | ||
| } | ||
|
|
||
| pub fn internal_unwrap_mut_account(&mut self, account_id: &AccountId) -> &mut Account { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.