From 6b0fcf6c3d23fc1598918f411b381a686e461e20 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 6 Oct 2023 18:14:28 +0200 Subject: [PATCH] rename trait fn --- sdk/src/types/block/address/account.rs | 2 +- sdk/src/types/block/address/ed25519.rs | 2 +- sdk/src/types/block/address/mod.rs | 8 ++++---- sdk/src/types/block/address/nft.rs | 2 +- sdk/src/types/block/output/account.rs | 10 +++++----- sdk/src/types/block/output/basic.rs | 8 ++++---- sdk/src/types/block/output/delegation.rs | 4 ++-- sdk/src/types/block/output/feature/block_issuer.rs | 10 +++++----- sdk/src/types/block/output/feature/issuer.rs | 4 ++-- sdk/src/types/block/output/feature/mod.rs | 6 +++--- sdk/src/types/block/output/foundry.rs | 12 ++++++------ sdk/src/types/block/output/mod.rs | 12 ++++++------ sdk/src/types/block/output/native_token.rs | 6 +++--- sdk/src/types/block/output/nft.rs | 10 +++++----- sdk/src/types/block/output/token_scheme/mod.rs | 4 ++-- sdk/src/types/block/output/token_scheme/simple.rs | 2 +- sdk/src/types/block/output/unlock_condition/mod.rs | 6 +++--- sdk/src/types/block/rent.rs | 14 +++++++------- 18 files changed, 61 insertions(+), 61 deletions(-) diff --git a/sdk/src/types/block/address/account.rs b/sdk/src/types/block/address/account.rs index e8b5c35b0d..8ce13ce512 100644 --- a/sdk/src/types/block/address/account.rs +++ b/sdk/src/types/block/address/account.rs @@ -62,7 +62,7 @@ impl core::fmt::Debug for AccountAddress { } impl StorageScore for AccountAddress { - fn score(&self, _rent_struct: RentStructure) -> u64 { + fn storage_score(&self, _rent_struct: RentStructure) -> u64 { 0 } } diff --git a/sdk/src/types/block/address/ed25519.rs b/sdk/src/types/block/address/ed25519.rs index b63e070515..aa09608318 100644 --- a/sdk/src/types/block/address/ed25519.rs +++ b/sdk/src/types/block/address/ed25519.rs @@ -55,7 +55,7 @@ impl core::fmt::Debug for Ed25519Address { } impl StorageScore for Ed25519Address { - fn score(&self, _rent_struct: RentStructure) -> u64 { + fn storage_score(&self, _rent_struct: RentStructure) -> u64 { 0 } } diff --git a/sdk/src/types/block/address/mod.rs b/sdk/src/types/block/address/mod.rs index d82e23b60e..87d778c797 100644 --- a/sdk/src/types/block/address/mod.rs +++ b/sdk/src/types/block/address/mod.rs @@ -216,11 +216,11 @@ impl From<&Self> for Address { } impl StorageScore for Address { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { match self { - Self::Account(account) => account.score(rent_struct), - Self::Ed25519(ed25519) => ed25519.score(rent_struct), - Self::Nft(nft) => nft.score(rent_struct), + Self::Account(account) => account.storage_score(rent_struct), + Self::Ed25519(ed25519) => ed25519.storage_score(rent_struct), + Self::Nft(nft) => nft.storage_score(rent_struct), // TODO: other address types once merged } } diff --git a/sdk/src/types/block/address/nft.rs b/sdk/src/types/block/address/nft.rs index 10f622be7e..ab34a526e9 100644 --- a/sdk/src/types/block/address/nft.rs +++ b/sdk/src/types/block/address/nft.rs @@ -62,7 +62,7 @@ impl core::fmt::Debug for NftAddress { } impl StorageScore for NftAddress { - fn score(&self, _rent_struct: RentStructure) -> u64 { + fn storage_score(&self, _rent_struct: RentStructure) -> u64 { 0 } } diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index af3578f733..ff0dd9d436 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -745,13 +745,13 @@ impl Packable for AccountOutput { } impl StorageScore for AccountOutput { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { storage_score_offset_output(rent_struct) + self.packed_len() as u64 * rent_struct.storage_score_factor_data() as u64 - + self.native_tokens().score(rent_struct) - + self.unlock_conditions().score(rent_struct) - + self.features().score(rent_struct) - + self.immutable_features().score(rent_struct) + + self.native_tokens().storage_score(rent_struct) + + self.unlock_conditions().storage_score(rent_struct) + + self.features().storage_score(rent_struct) + + self.immutable_features().storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index ff8de7c29a..bf71b9bd44 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -334,12 +334,12 @@ impl BasicOutput { } impl StorageScore for BasicOutput { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { storage_score_offset_output(rent_struct) + self.packed_len() as u64 * rent_struct.storage_score_factor_data() as u64 - + self.native_tokens().score(rent_struct) - + self.unlock_conditions().score(rent_struct) - + self.features().score(rent_struct) + + self.native_tokens().storage_score(rent_struct) + + self.unlock_conditions().storage_score(rent_struct) + + self.features().storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index ae2d4f00c6..e928189178 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -458,11 +458,11 @@ impl Packable for DelegationOutput { } impl StorageScore for DelegationOutput { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { storage_score_offset_output(rent_struct) + rent_struct.storage_score_offset_delegation() + self.packed_len() as u64 * rent_struct.storage_score_factor_data() as u64 - + self.unlock_conditions().score(rent_struct) + + self.unlock_conditions().storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/feature/block_issuer.rs b/sdk/src/types/block/output/feature/block_issuer.rs index 3bb6e8dc0b..92c793cae3 100644 --- a/sdk/src/types/block/output/feature/block_issuer.rs +++ b/sdk/src/types/block/output/feature/block_issuer.rs @@ -62,9 +62,9 @@ impl BlockIssuerKey { } impl StorageScore for BlockIssuerKey { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { match self { - Self::Ed25519(key) => key.score(rent_struct), + Self::Ed25519(key) => key.storage_score(rent_struct), } } } @@ -118,7 +118,7 @@ impl Packable for Ed25519BlockIssuerKey { } impl StorageScore for Ed25519BlockIssuerKey { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { rent_struct.storage_score_offset_ed25519_block_issuer_key() } } @@ -206,8 +206,8 @@ impl BlockIssuerKeys { } impl StorageScore for BlockIssuerKeys { - fn score(&self, rent_struct: RentStructure) -> u64 { - (*self).iter().map(|key| key.score(rent_struct)).sum() + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + (*self).iter().map(|key| key.storage_score(rent_struct)).sum() } } diff --git a/sdk/src/types/block/output/feature/issuer.rs b/sdk/src/types/block/output/feature/issuer.rs index be5448177a..fc61921a45 100644 --- a/sdk/src/types/block/output/feature/issuer.rs +++ b/sdk/src/types/block/output/feature/issuer.rs @@ -30,8 +30,8 @@ impl IssuerFeature { } impl StorageScore for IssuerFeature { - fn score(&self, rent_struct: RentStructure) -> u64 { - self.0.score(rent_struct) + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + self.0.storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/feature/mod.rs b/sdk/src/types/block/output/feature/mod.rs index 2130daecfa..dcbe47e70a 100644 --- a/sdk/src/types/block/output/feature/mod.rs +++ b/sdk/src/types/block/output/feature/mod.rs @@ -202,7 +202,7 @@ impl Feature { } impl StorageScore for Feature { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { match self { Self::Sender(sender) => todo!(), Self::Issuer(issuer) => todo!(), @@ -331,8 +331,8 @@ impl Features { } impl StorageScore for Features { - fn score(&self, rent_struct: RentStructure) -> u64 { - self.0.iter().map(|f| f.score(rent_struct)).sum() + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + self.0.iter().map(|f| f.storage_score(rent_struct)).sum() } } diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index d13d641c86..12611dadc7 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -660,14 +660,14 @@ impl Packable for FoundryOutput { } impl StorageScore for FoundryOutput { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { storage_score_offset_output(rent_struct) + self.packed_len() as u64 * rent_struct.storage_score_factor_data() as u64 - + self.native_tokens().score(rent_struct) - + self.token_scheme().score(rent_struct) - + self.unlock_conditions().score(rent_struct) - + self.features().score(rent_struct) - + self.immutable_features().score(rent_struct) + + self.native_tokens().storage_score(rent_struct) + + self.token_scheme().storage_score(rent_struct) + + self.unlock_conditions().storage_score(rent_struct) + + self.features().storage_score(rent_struct) + + self.immutable_features().storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 3a5e3d1ab2..55dfd455f2 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -521,15 +521,15 @@ fn storage_score_offset_output(rent_struct: RentStructure) -> u64 { } impl StorageScore for Output { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { // +1 score for the output kind rent_struct.storage_score_factor_data() as u64 * size_of::() as u64 + match self { - Self::Basic(basic) => basic.score(rent_struct), - Self::Account(account) => account.score(rent_struct), - Self::Foundry(foundry) => foundry.score(rent_struct), - Self::Nft(nft) => nft.score(rent_struct), - Self::Delegation(delegation) => delegation.score(rent_struct), + Self::Basic(basic) => basic.storage_score(rent_struct), + Self::Account(account) => account.storage_score(rent_struct), + Self::Foundry(foundry) => foundry.storage_score(rent_struct), + Self::Nft(nft) => nft.storage_score(rent_struct), + Self::Delegation(delegation) => delegation.storage_score(rent_struct), } } } diff --git a/sdk/src/types/block/output/native_token.rs b/sdk/src/types/block/output/native_token.rs index 06bd001e86..10d2e750e9 100644 --- a/sdk/src/types/block/output/native_token.rs +++ b/sdk/src/types/block/output/native_token.rs @@ -78,7 +78,7 @@ impl Ord for NativeToken { } impl StorageScore for NativeToken { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { todo!("native token score") } } @@ -258,8 +258,8 @@ impl NativeTokens { } impl StorageScore for NativeTokens { - fn score(&self, rent_struct: RentStructure) -> u64 { - self.0.iter().map(|nt| nt.score(rent_struct)).sum() + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + self.0.iter().map(|nt| nt.storage_score(rent_struct)).sum() } } diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 1acd52c40b..330700b98c 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -523,13 +523,13 @@ impl Packable for NftOutput { } impl StorageScore for NftOutput { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { storage_score_offset_output(rent_struct) + self.packed_len() as u64 * rent_struct.storage_score_factor_data() as u64 - + self.native_tokens().score(rent_struct) - + self.unlock_conditions().score(rent_struct) - + self.features().score(rent_struct) - + self.immutable_features().score(rent_struct) + + self.native_tokens().storage_score(rent_struct) + + self.unlock_conditions().storage_score(rent_struct) + + self.features().storage_score(rent_struct) + + self.immutable_features().storage_score(rent_struct) } } diff --git a/sdk/src/types/block/output/token_scheme/mod.rs b/sdk/src/types/block/output/token_scheme/mod.rs index 4e63076c89..cd0aae9965 100644 --- a/sdk/src/types/block/output/token_scheme/mod.rs +++ b/sdk/src/types/block/output/token_scheme/mod.rs @@ -50,9 +50,9 @@ impl TokenScheme { } impl StorageScore for TokenScheme { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { match self { - Self::Simple(simple) => simple.score(rent_struct), + Self::Simple(simple) => simple.storage_score(rent_struct), } } } diff --git a/sdk/src/types/block/output/token_scheme/simple.rs b/sdk/src/types/block/output/token_scheme/simple.rs index e1250b93bb..9b62347ca8 100644 --- a/sdk/src/types/block/output/token_scheme/simple.rs +++ b/sdk/src/types/block/output/token_scheme/simple.rs @@ -107,7 +107,7 @@ impl Packable for SimpleTokenScheme { } impl StorageScore for SimpleTokenScheme { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { 0 } } diff --git a/sdk/src/types/block/output/unlock_condition/mod.rs b/sdk/src/types/block/output/unlock_condition/mod.rs index f6cc8d19a8..ee01e76101 100644 --- a/sdk/src/types/block/output/unlock_condition/mod.rs +++ b/sdk/src/types/block/output/unlock_condition/mod.rs @@ -84,7 +84,7 @@ impl core::fmt::Debug for UnlockCondition { } impl StorageScore for UnlockCondition { - fn score(&self, rent_struct: RentStructure) -> u64 { + fn storage_score(&self, rent_struct: RentStructure) -> u64 { todo!("unlock condition score") } } @@ -458,8 +458,8 @@ impl UnlockConditions { } impl StorageScore for UnlockConditions { - fn score(&self, rent_struct: RentStructure) -> u64 { - self.0.iter().map(|uc| uc.score(rent_struct)).sum() + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + self.0.iter().map(|uc| uc.storage_score(rent_struct)).sum() } } diff --git a/sdk/src/types/block/rent.rs b/sdk/src/types/block/rent.rs index f89c8e8c27..920f7b0db2 100644 --- a/sdk/src/types/block/rent.rs +++ b/sdk/src/types/block/rent.rs @@ -45,12 +45,12 @@ impl RentStructure { // set the storage score offset for implicit account creation addresses as // the difference between the storage score of the dummy account and the storage // score of the dummy basic output minus the storage score of the dummy address. - let dummy_basic_output_score = BasicOutput::dummy().score(rent_structure); - let dummy_address_score = Ed25519Address::dummy().score(rent_structure); + let dummy_basic_output_score = BasicOutput::dummy().storage_score(rent_structure); + let dummy_address_score = Ed25519Address::dummy().storage_score(rent_structure); let basic_score_without_address = dummy_basic_output_score .checked_sub(dummy_address_score) .expect("underflow"); - let dummy_account_output_score = AccountOutput::dummy().score(rent_structure); + let dummy_account_output_score = AccountOutput::dummy().storage_score(rent_structure); rent_structure.storage_score_offset_implicit_account_creation_address = dummy_account_output_score .checked_sub(basic_score_without_address) @@ -207,16 +207,16 @@ impl RentParameters { pub trait StorageScore { /// Computes the storage score given a [`RentStructure`]. Different fields in a type lead to different storage /// requirements for the ledger state. - fn score(&self, rent_struct: RentStructure) -> u64; + fn storage_score(&self, rent_struct: RentStructure) -> u64; /// Computes the rent cost given a [`RentStructure`]. fn rent_cost(&self, rent_struct: RentStructure) -> u64 { - rent_struct.storage_cost as u64 * self.score(rent_struct) + rent_struct.storage_cost as u64 * self.storage_score(rent_struct) } } impl StorageScore for [T; N] { - fn score(&self, rent_struct: RentStructure) -> u64 { - self.iter().map(|elem| elem.score(rent_struct)).sum() + fn storage_score(&self, rent_struct: RentStructure) -> u64 { + self.iter().map(|elem| elem.storage_score(rent_struct)).sum() } }