From 367c58db0ee3e17c8f3bf9ba71f86e4830aeb7d8 Mon Sep 17 00:00:00 2001 From: Olga Kunyavskaya Date: Fri, 22 Nov 2024 18:11:09 +0200 Subject: [PATCH] fn for calc max_account key len --- near/nep141-locker/src/storage.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/near/nep141-locker/src/storage.rs b/near/nep141-locker/src/storage.rs index 61b51698..636cf926 100644 --- a/near/nep141-locker/src/storage.rs +++ b/near/nep141-locker/src/storage.rs @@ -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), @@ -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(); @@ -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 + } }