Skip to content

Commit

Permalink
fn for calc max_account key len
Browse files Browse the repository at this point in the history
  • Loading branch information
olga24912 committed Nov 22, 2024
1 parent 8b4c4b0 commit 367c58d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions near/nep141-locker/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Contract {
}

pub fn required_balance_for_account(&self) -> NearToken {
let key_len = 64 + 4;
let key_len = Self::max_key_len_of_account_id();
let value_len = borsh::to_vec(&StorageBalance {
total: NearToken::from_yoctonear(0),
available: NearToken::from_yoctonear(0),
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Contract {
}

pub fn required_balance_for_deploy_token(&self) -> NearToken {
let key_len = 64 + 4;
let key_len = Self::max_key_len_of_account_id();
let deployed_tokens_required_balance =
env::storage_byte_cost().saturating_mul((Self::get_basic_storage() + key_len).into());
let bind_token_required_balance = self.required_balance_for_bind_token();
Expand All @@ -201,4 +201,9 @@ impl Contract {
const EXTRA_KEY_PREFIX_LEN: u64 = 1;
EXTRA_BYTES_RECORD + EXTRA_KEY_PREFIX_LEN
}

fn max_key_len_of_account_id() -> u64 {
let max_account_id: AccountId = "a".repeat(64).parse().sdk_expect("ERR_PARSE_ACCOUNT_ID");
borsh::to_vec(&max_account_id).sdk_expect("ERR_BORSH").len() as u64
}
}

0 comments on commit 367c58d

Please sign in to comment.