Skip to content

Commit

Permalink
rename trait fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Oct 6, 2023
1 parent 824b5e0 commit 6b0fcf6
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion sdk/src/types/block/address/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/address/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types/block/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/address/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/src/types/block/output/feature/block_issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/feature/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/feature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand Down Expand Up @@ -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()
}
}

Expand Down
12 changes: 6 additions & 6 deletions sdk/src/types/block/output/foundry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
12 changes: 6 additions & 6 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>() 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),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/native_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/src/types/block/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/token_scheme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/token_scheme/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/block/output/unlock_condition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down
14 changes: 7 additions & 7 deletions sdk/src/types/block/rent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<T: StorageScore, const N: usize> 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()
}
}

0 comments on commit 6b0fcf6

Please sign in to comment.