diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index ce71d06ea..12d48340a 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -157,23 +157,19 @@ pub mod pallet { /// All whitelisted chains and their respective transaction counts #[pallet::storage] - #[pallet::getter(fn chains)] pub type ChainNonces = StorageMap<_, Blake2_256, ChainId, DepositNonce>; /// Tracks current relayer set #[pallet::storage] - #[pallet::getter(fn relayers)] pub type Relayers = StorageMap<_, Blake2_256, T::AccountId, bool>; /// Utilized by the bridge software to map resource IDs to actual methods #[pallet::storage] - #[pallet::getter(fn resources)] pub type Resources = StorageMap<_, Blake2_256, ResourceId, Vec>; /// All known proposals. /// The key is the hash of the call and the deposit ID, to ensure it's unique #[pallet::storage] - #[pallet::getter(fn votes)] pub type Votes = StorageDoubleMap< _, Blake2_256, @@ -190,7 +186,6 @@ pub mod pallet { /// Number of votes required for a proposal to execute #[pallet::storage] - #[pallet::getter(fn relayer_threshold)] pub type RelayerThreshold = StorageValue>; @@ -201,7 +196,6 @@ pub mod pallet { /// Number of relayers in set #[pallet::storage] - #[pallet::getter(fn relayer_count)] pub type RelayerCount = StorageValue>; @@ -435,7 +429,7 @@ pub mod pallet { /// Checks if who is a relayer pub fn is_relayer(who: &T::AccountId) -> bool { - Self::relayers(who).unwrap_or(false) + Relayers::::get(who).unwrap_or(false) } /// Provides an AccountId for the pallet. @@ -446,18 +440,18 @@ pub mod pallet { /// Asserts if a resource is registered pub fn resource_exists(id: ResourceId) -> bool { - Self::resources(id).is_some() + Resources::::get(id).is_some() } /// Checks if a chain exists as a whitelisted destination pub fn chain_whitelisted(id: ChainId) -> bool { - Self::chains(id).is_some() + ChainNonces::::get(id).is_some() } /// Increments the deposit nonce for the specified chain ID fn bump_nonce(id: ChainId) -> DepositNonce { - let nonce = Self::chains(id).unwrap_or_default() + 1; - >::insert(id, nonce); + let nonce = ChainNonces::::get(id).unwrap_or_default() + 1; + ChainNonces::::insert(id, nonce); nonce } diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index bf873a1da..1ef98ae41 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -111,7 +111,7 @@ pub fn new_test_ext_initialized( t.execute_with(|| { // Set and check threshold assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD)); - assert_eq!(Bridge::relayer_threshold(), TEST_THRESHOLD); + assert_eq!(RelayerThreshold::::get(), TEST_THRESHOLD); // Add relayers assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index 3263718b3..8c48a0166 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -82,13 +82,13 @@ fn setup_resources() { let method2 = "Pallet.do_somethingElse".as_bytes().to_vec(); assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method.clone())); - assert_eq!(Bridge::resources(id), Some(method)); + assert_eq!(Resources::::get(id), Some(method)); assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), id, method2.clone())); - assert_eq!(Bridge::resources(id), Some(method2)); + assert_eq!(Resources::::get(id), Some(method2)); assert_ok!(Bridge::remove_resource(RuntimeOrigin::root(), id)); - assert_eq!(Bridge::resources(id), None); + assert_eq!(Resources::::get(id), None); }) } @@ -233,12 +233,12 @@ fn asset_transfer_invalid_chain() { fn add_remove_relayer() { new_test_ext().execute_with(|| { assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_eq!(Bridge::relayer_count(), 0); + assert_eq!(RelayerCount::::get(), 0); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_A)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_B)); assert_ok!(Bridge::add_relayer(RuntimeOrigin::root(), RELAYER_C)); - assert_eq!(Bridge::relayer_count(), 3); + assert_eq!(RelayerCount::::get(), 3); // Already exists assert_noop!( @@ -248,12 +248,12 @@ fn add_remove_relayer() { // Confirm removal assert_ok!(Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B)); - assert_eq!(Bridge::relayer_count(), 2); + assert_eq!(RelayerCount::::get(), 2); assert_noop!( Bridge::remove_relayer(RuntimeOrigin::root(), RELAYER_B), Error::::RelayerInvalid ); - assert_eq!(Bridge::relayer_count(), 2); + assert_eq!(RelayerCount::::get(), 2); assert_events(vec![ RuntimeEvent::Bridge(Event::RelayerAdded(RELAYER_A)), @@ -285,7 +285,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -302,7 +302,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -319,7 +319,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A, RELAYER_C], votes_against: vec![RELAYER_B], @@ -355,7 +355,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -372,7 +372,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -389,7 +389,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B, RELAYER_C], @@ -427,7 +427,7 @@ fn execute_after_threshold_change() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -447,7 +447,7 @@ fn execute_after_threshold_change() { Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -485,7 +485,7 @@ fn proposal_expires() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -510,7 +510,7 @@ fn proposal_expires() { ); // Proposal state should remain unchanged - let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -529,7 +529,7 @@ fn proposal_expires() { ), Error::::ProposalExpired ); - let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); + let prop = Votes::::get(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], diff --git a/pallets/ddc-clusters-gov/src/lib.rs b/pallets/ddc-clusters-gov/src/lib.rs index 788ee0656..a30f1e8e5 100644 --- a/pallets/ddc-clusters-gov/src/lib.rs +++ b/pallets/ddc-clusters-gov/src/lib.rs @@ -150,7 +150,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn proposal_of)] pub type ClusterProposal = StorageMap< _, Identity, @@ -161,13 +160,11 @@ pub mod pallet { /// Votes on a given cluster proposal, if it is ongoing. #[pallet::storage] - #[pallet::getter(fn voting)] pub type ClusterProposalVoting = StorageMap<_, Identity, ClusterId, Votes>, OptionQuery>; /// Public referendums initiated by clusters #[pallet::storage] - #[pallet::getter(fn submission_depositor)] pub type SubmissionDeposits = StorageMap<_, Identity, ReferendumIndex, SubmissionDeposit, OptionQuery>; @@ -534,7 +531,8 @@ pub mod pallet { cluster_id: ClusterId, approve: bool, ) -> Result { - let mut voting = Self::voting(cluster_id).ok_or(Error::::ProposalMissing)?; + let mut voting = + ClusterProposalVoting::::get(cluster_id).ok_or(Error::::ProposalMissing)?; let position_yes = voting.ayes.iter().position(|a| a == &voter_id); let position_no = voting.nays.iter().position(|a| a == &voter_id); @@ -579,7 +577,8 @@ pub mod pallet { /// Close a vote that is either approved, disapproved or whose voting period has ended. fn do_close(cluster_id: ClusterId, caller_id: T::AccountId) -> DispatchResultWithPostInfo { - let voting = Self::voting(cluster_id).ok_or(Error::::ProposalMissing)?; + let voting = + ClusterProposalVoting::::get(cluster_id).ok_or(Error::::ProposalMissing)?; let mut no_votes = voting.nays.len() as MemberCount; let mut yes_votes = voting.ayes.len() as MemberCount; diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index e9c1cd123..99a93fed0 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -138,12 +138,10 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn clusters)] pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; #[pallet::storage] - #[pallet::getter(fn clusters_protocol_params)] pub type ClustersGovParams = StorageMap< _, Twox64Concat, @@ -152,7 +150,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn clusters_nodes)] pub type ClustersNodes = StorageDoubleMap< _, Blake2_128Concat, @@ -164,7 +161,6 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn clusters_nodes_stats)] pub type ClustersNodesStats = StorageMap<_, Twox64Concat, ClusterId, ClusterNodesStats>; diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index c28301e24..0a71843eb 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -50,14 +50,13 @@ fn create_cluster_works() { cluster_protocol_params.clone() )); - let created_cluster = DdcClusters::clusters(cluster_id).unwrap(); + let created_cluster = Clusters::::get(cluster_id).unwrap(); assert_eq!(created_cluster.cluster_id, cluster_id); assert_eq!(created_cluster.manager_id, cluster_manager_id); assert_eq!(created_cluster.reserve_id, cluster_reserve_id); assert_eq!(created_cluster.props.node_provider_auth_contract, Some(auth_contract.clone())); - let created_cluster_protocol_params = - DdcClusters::clusters_protocol_params(cluster_id).unwrap(); + let created_cluster_protocol_params = ClustersGovParams::::get(cluster_id).unwrap(); assert_eq!( created_cluster_protocol_params.treasury_share, cluster_protocol_params.treasury_share @@ -482,7 +481,7 @@ fn set_cluster_params_works() { }, )); - let updated_cluster = DdcClusters::clusters(cluster_id).unwrap(); + let updated_cluster = Clusters::::get(cluster_id).unwrap(); assert_eq!(updated_cluster.props.node_provider_auth_contract, Some(auth_contract_2)); assert_eq!(updated_cluster.props.erasure_coding_required, 4); assert_eq!(updated_cluster.props.erasure_coding_total, 6); diff --git a/pallets/ddc-customers/src/benchmarking.rs b/pallets/ddc-customers/src/benchmarking.rs index 59585d476..32fbccd20 100644 --- a/pallets/ddc-customers/src/benchmarking.rs +++ b/pallets/ddc-customers/src/benchmarking.rs @@ -54,7 +54,7 @@ benchmarks! { whitelist_account!(user); }: _(RawOrigin::Signed(user), cluster_id, bucket_params) verify { - assert_eq!(Pallet::::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); } deposit { diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 35fbfb4e5..f263be5e2 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -159,7 +159,6 @@ pub mod pallet { /// Map from all (unlocked) "owner" accounts to the info regarding the staking. #[pallet::storage] - #[pallet::getter(fn ledger)] pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, AccountsLedger>; #[pallet::type_value] @@ -168,13 +167,11 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn buckets_count)] pub type BucketsCount = StorageValue>; /// Map from bucket ID to the bucket structure #[pallet::storage] - #[pallet::getter(fn buckets)] pub type Buckets = StorageMap<_, Twox64Concat, BucketId, Bucket, OptionQuery>; #[pallet::event] @@ -303,7 +300,7 @@ pub mod pallet { ) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = - Self::buckets_count().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; + BucketsCount::::get().checked_add(1).ok_or(Error::::ArithmeticOverflow)?; ensure!( >::cluster_exists(&cluster_id), @@ -385,7 +382,7 @@ pub mod pallet { #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -447,7 +444,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::withdraw_unlocked_deposit_kill())] pub fn withdraw_unlocked_deposit(origin: OriginFor) -> DispatchResultWithPostInfo { let owner = ensure_signed(origin)?; - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; let (owner, old_total) = (ledger.owner.clone(), ledger.total); let current_block = >::block_number(); ledger = ledger.consolidate_unlocked(current_block); @@ -507,7 +504,7 @@ pub mod pallet { bucket_params: BucketParams, ) -> DispatchResult { let owner = ensure_signed(origin)?; - let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; + let mut bucket = Buckets::::get(bucket_id).ok_or(Error::::NoBucketWithId)?; ensure!(bucket.owner_id == owner, Error::::NotBucketOwner); bucket.is_public = bucket_params.is_public; @@ -631,7 +628,7 @@ pub mod pallet { amount: u128, ) -> Result { let actually_charged: BalanceOf; - let mut ledger = Self::ledger(&content_owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&content_owner).ok_or(Error::::NotOwner)?; let amount_to_deduct = amount.saturated_into::>(); if ledger.active >= amount_to_deduct { @@ -713,7 +710,7 @@ pub mod pallet { fn deposit_extra(owner: T::AccountId, amount: u128) -> Result<(), DispatchError> { let max_additional = amount.saturated_into::>(); - let mut ledger = Self::ledger(&owner).ok_or(Error::::NotOwner)?; + let mut ledger = Ledger::::get(&owner).ok_or(Error::::NotOwner)?; let owner_balance = ::Currency::free_balance(&owner); let extra = owner_balance.min(max_additional); diff --git a/pallets/ddc-customers/src/migration.rs b/pallets/ddc-customers/src/migration.rs index cd2e9c6b0..5a66c8dd9 100644 --- a/pallets/ddc-customers/src/migration.rs +++ b/pallets/ddc-customers/src/migration.rs @@ -97,7 +97,7 @@ impl OnRuntimeUpgrade for MigrateToV1 { let (prev_bucket_id, prev_count): (u64, u64) = Decode::decode(&mut &prev_state[..]).expect("pre_upgrade provides a valid state; qed"); - let post_bucket_id = Pallet::::buckets_count(); + let post_bucket_id = BucketsCount::::get(); ensure!( prev_bucket_id == post_bucket_id, "the last bucket ID before and after the migration should be the same" diff --git a/pallets/ddc-customers/src/tests.rs b/pallets/ddc-customers/src/tests.rs index 86d1e0bf9..d9fcd2ad1 100644 --- a/pallets/ddc-customers/src/tests.rs +++ b/pallets/ddc-customers/src/tests.rs @@ -21,9 +21,9 @@ fn create_bucket_works() { )); // Check storage - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -66,9 +66,9 @@ fn create_two_buckets_works() { System::assert_last_event(Event::BucketCreated { bucket_id: 2u64 }.into()); // Check storage - assert_eq!(DdcCustomers::buckets_count(), 2); + assert_eq!(BucketsCount::::get(), 2); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -78,7 +78,7 @@ fn create_two_buckets_works() { }) ); assert_eq!( - DdcCustomers::buckets(2), + Buckets::::get(2), Some(Bucket { bucket_id: 2, owner_id: account_1, @@ -116,7 +116,7 @@ fn deposit_and_deposit_extra_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_1), + Ledger::::get(account_1), Some(AccountsLedger { owner: account_1, total: amount1, @@ -154,7 +154,7 @@ fn deposit_and_deposit_extra_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_1), + Ledger::::get(account_1), Some(AccountsLedger { owner: account_1, total: amount1 + extra_amount2, @@ -190,7 +190,7 @@ fn charge_content_owner_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit, @@ -218,7 +218,7 @@ fn charge_content_owner_works() { // Check storage assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit - charge1, @@ -236,7 +236,7 @@ fn charge_content_owner_works() { let charge2 = 100u128; let charge_result = DdcCustomers::charge_content_owner(account_3, vault, charge2).unwrap(); assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: 0, @@ -263,7 +263,7 @@ fn charge_content_owner_works() { assert_ok!(DdcCustomers::deposit_extra(RuntimeOrigin::signed(account_3), deposit)); assert_eq!( - DdcCustomers::ledger(account_3), + Ledger::::get(account_3), Some(AccountsLedger { owner: account_3, total: deposit, @@ -299,7 +299,7 @@ fn unlock_and_withdraw_deposit_works() { let unlocking_chunks = vec![UnlockChunk { value: 1, block: 11 }]; // Check storage assert_eq!( - DdcCustomers::ledger(1), + Ledger::::get(1), Some(AccountsLedger { owner: account_1, total: 35_u128, @@ -326,7 +326,7 @@ fn unlock_and_withdraw_deposit_works() { assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage assert_eq!( - DdcCustomers::ledger(1), + Ledger::::get(1), Some(AccountsLedger { owner: account_1, total: 3_u128, @@ -341,7 +341,7 @@ fn unlock_and_withdraw_deposit_works() { assert_ok!(DdcCustomers::withdraw_unlocked_deposit(RuntimeOrigin::signed(account_1))); // Check storage - assert_eq!(DdcCustomers::ledger(account_1), None); + assert_eq!(Ledger::::get(account_1), None); }) } @@ -373,9 +373,9 @@ fn set_bucket_params_works() { update_bucket_params.clone() )); - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id, owner_id: bucket_owner, @@ -466,9 +466,9 @@ fn remove_bucket_works() { ); // Check storage bucket is not removed - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -482,9 +482,9 @@ fn remove_bucket_works() { assert_ok!(DdcCustomers::remove_bucket(RuntimeOrigin::signed(account_1), bucket_id_1)); // Check storage bucket is removed - assert_eq!(DdcCustomers::buckets_count(), 1); + assert_eq!(BucketsCount::::get(), 1); assert_eq!( - DdcCustomers::buckets(1), + Buckets::::get(1), Some(Bucket { bucket_id: 1, owner_id: account_1, @@ -558,7 +558,7 @@ fn remove_bucket_checks_with_multiple_buckets_works() { // Verify whether bucket has been removed assert_eq!( - DdcCustomers::buckets(bucket_id_1), + Buckets::::get(bucket_id_1), Some(Bucket { bucket_id: bucket_id_1, owner_id: account_1, @@ -569,7 +569,7 @@ fn remove_bucket_checks_with_multiple_buckets_works() { ); assert_eq!( - DdcCustomers::buckets(bucket_id_2), + Buckets::::get(bucket_id_2), Some(Bucket { bucket_id: bucket_id_2, owner_id: account_2, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 83e7ee60b..9b0517182 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -86,7 +86,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn storage_nodes)] pub type StorageNodes = StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index 618a01c8e..b6545708f 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -66,7 +66,7 @@ fn create_storage_node_works() { NodeParams::StorageParams(storage_node_params.clone()) )); - let created_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let created_storage_node = StorageNodes::::get(&node_pub_key).unwrap(); let expected_host: BoundedVec = storage_node_params.clone().host.try_into().unwrap(); let expected_domain: BoundedVec = @@ -91,7 +91,7 @@ fn create_storage_node_works() { { assert_eq!(cluster_id, None); } - let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let storage_node = StorageNodes::::get(&node_pub_key).unwrap(); assert_eq!(storage_node.pub_key, node_pub_key); // Node already exists @@ -143,7 +143,7 @@ fn create_storage_node_with_node_creator() { { assert_eq!(cluster_id, None); } - let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let storage_node = StorageNodes::::get(&node_pub_key).unwrap(); assert_eq!(storage_node.pub_key, node_pub_key); }) } @@ -198,7 +198,7 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(updated_params.clone()) )); - let updated_storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + let updated_storage_node = StorageNodes::::get(&node_pub_key).unwrap(); let expected_host: BoundedVec = updated_params.host.try_into().unwrap(); let expected_domain: BoundedVec = updated_params.domain.try_into().unwrap(); diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index f543db269..34537f7a5 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -270,7 +270,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn active_billing_reports)] pub type ActiveBillingReports = StorageDoubleMap< _, Blake2_128Concat, @@ -281,16 +280,13 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::getter(fn authorised_caller)] pub type AuthorisedCaller = StorageValue<_, T::AccountId>; #[pallet::storage] - #[pallet::getter(fn debtor_customers)] pub type DebtorCustomers = StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; #[pallet::storage] - #[pallet::getter(fn owing_providers)] pub type OwingProviders = StorageDoubleMap<_, Blake2_128Concat, ClusterId, Blake2_128Concat, T::AccountId, u128>; @@ -371,7 +367,7 @@ pub mod pallet { end_era: i64, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( ActiveBillingReports::::try_get(cluster_id, era).is_err(), @@ -403,7 +399,7 @@ pub mod pallet { max_batch_index: BatchIndex, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); @@ -431,7 +427,7 @@ pub mod pallet { payers: Vec<(T::AccountId, CustomerUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( !payers.is_empty() && payers.len() <= MaxBatchSize::get() as usize, @@ -582,7 +578,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -683,7 +679,7 @@ pub mod pallet { total_node_usage: NodeUsage, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!(max_batch_index < MaxBatchesCount::get(), Error::::BatchIndexOverflow); @@ -715,7 +711,7 @@ pub mod pallet { payees: Vec<(T::AccountId, NodeUsage)>, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); ensure!( !payees.is_empty() && payees.len() <= MaxBatchSize::get() as usize, @@ -827,7 +823,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; @@ -878,7 +874,7 @@ pub mod pallet { era: DdcEra, ) -> DispatchResult { let caller = ensure_signed(origin)?; - ensure!(Self::authorised_caller() == Some(caller), Error::::Unauthorised); + ensure!(AuthorisedCaller::::get() == Some(caller), Error::::Unauthorised); let mut billing_report = ActiveBillingReports::::try_get(cluster_id, era) .map_err(|_| Error::::BillingReportDoesNotExist)?; diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 589e94740..e7629c0bd 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -27,7 +27,7 @@ fn set_authorised_caller_works() { Event::AuthorisedCaller { authorised_caller: dac_account }.into(), ); - assert_eq!(DdcPayouts::authorised_caller().unwrap(), dac_account); + assert_eq!(AuthorisedCaller::::get().unwrap(), dac_account); }) } @@ -98,7 +98,7 @@ fn begin_billing_report_works() { System::assert_last_event(Event::BillingReportInitialized { cluster_id, era }.into()); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_eq!(report.start_era, start_era); assert_eq!(report.end_era, end_era); @@ -182,7 +182,7 @@ fn begin_charging_customers_works() { System::assert_last_event(Event::ChargingStarted { cluster_id, era }.into()); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::ChargingCustomers); assert_eq!(report.charging_max_batch_index, max_batch_index); }) @@ -465,7 +465,7 @@ fn send_charging_customers_batch_works() { )); let usage4_charge = calculate_charge_for_month(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_month(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -477,7 +477,7 @@ fn send_charging_customers_batch_works() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_month(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -541,7 +541,7 @@ fn send_charging_customers_batch_works() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_month(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -561,7 +561,7 @@ fn send_charging_customers_batch_works() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -580,7 +580,7 @@ fn send_charging_customers_batch_works() { let user3_charge = calculate_charge_for_month(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_month(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -601,7 +601,7 @@ fn send_charging_customers_batch_works() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -687,7 +687,7 @@ fn end_charging_customers_works_small_usage_1_hour() { payers1, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let usage6_charge = calculate_charge_for_hour(cluster_id, usage6.clone()); let usage7_charge = calculate_charge_for_hour(cluster_id, usage7.clone()); let charge6 = calculate_charge_parts_for_hour(cluster_id, usage6); @@ -748,7 +748,7 @@ fn end_charging_customers_works_small_usage_1_hour() { )); System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let fees = get_fees(&cluster_id); @@ -898,7 +898,7 @@ fn send_charging_customers_batch_works_for_day() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -910,7 +910,7 @@ fn send_charging_customers_batch_works_for_day() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -974,7 +974,7 @@ fn send_charging_customers_batch_works_for_day() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -994,7 +994,7 @@ fn send_charging_customers_batch_works_for_day() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1013,7 +1013,7 @@ fn send_charging_customers_batch_works_for_day() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1034,7 +1034,7 @@ fn send_charging_customers_batch_works_for_day() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1141,7 +1141,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1153,7 +1153,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1217,7 +1217,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1237,7 +1237,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1256,7 +1256,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1277,7 +1277,7 @@ fn send_charging_customers_batch_works_for_day_free_storage() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1384,7 +1384,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1396,7 +1396,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1460,7 +1460,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1480,7 +1480,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1499,7 +1499,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1520,7 +1520,7 @@ fn send_charging_customers_batch_works_for_day_free_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1627,7 +1627,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1639,7 +1639,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1703,7 +1703,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1723,7 +1723,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1742,7 +1742,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -1763,7 +1763,7 @@ fn send_charging_customers_batch_works_for_day_free_get() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -1870,7 +1870,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -1882,7 +1882,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -1946,7 +1946,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -1966,7 +1966,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -1985,7 +1985,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -2006,7 +2006,7 @@ fn send_charging_customers_batch_works_for_day_free_put() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2113,7 +2113,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { )); let usage4_charge = calculate_charge_for_day(cluster_id, usage4.clone()); - let user2_debt = DdcPayouts::debtor_customers(cluster_id, user2_debtor).unwrap(); + let user2_debt = DebtorCustomers::::get(cluster_id, user2_debtor).unwrap(); let expected_charge2 = calculate_charge_for_day(cluster_id, usage2.clone()); let mut debt = expected_charge2 - USER2_BALANCE; assert_eq!(user2_debt, debt); @@ -2125,7 +2125,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { charge2.gets = ratio * charge2.gets; charge2.puts = ratio * charge2.puts; - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge4 = calculate_charge_parts_for_day(cluster_id, usage4); assert_eq!(charge2.puts + charge4.puts, report.total_customer_charge.puts); assert_eq!(charge2.gets + charge4.gets, report.total_customer_charge.gets); @@ -2189,7 +2189,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { .into(), ); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge1 = calculate_charge_parts_for_day(cluster_id, usage1); assert_eq!( charge1.puts + before_total_customer_charge.puts, @@ -2209,7 +2209,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { ); assert_eq!(report.state, State::ChargingCustomers); - let user1_debt = DdcPayouts::debtor_customers(cluster_id, user1); + let user1_debt = DebtorCustomers::::get(cluster_id, user1); assert_eq!(user1_debt, None); let balance_before = Balances::free_balance(DdcPayouts::account_id()); @@ -2228,7 +2228,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let user3_charge = calculate_charge_for_day(cluster_id, usage3.clone()); let charge3 = calculate_charge_parts_for_day(cluster_id, usage3); let ratio = Perquintill::from_rational(PARTIAL_CHARGE, user3_charge); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!( ratio * charge3.puts + before_total_customer_charge.puts, report.total_customer_charge.puts @@ -2249,7 +2249,7 @@ fn send_charging_customers_batch_works_for_day_free_storage_stream() { let balance = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance, balance_before + PARTIAL_CHARGE); - let user3_debt = DdcPayouts::debtor_customers(cluster_id, user3_debtor).unwrap(); + let user3_debt = DebtorCustomers::::get(cluster_id, user3_debtor).unwrap(); debt = user3_charge - PARTIAL_CHARGE; assert_eq!(user3_debt, debt); @@ -2321,7 +2321,7 @@ fn send_charging_customers_batch_works_zero_fees() { assert_eq!(System::events().len(), 3); // batch 1 - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); let before_total_customer_charge = report.total_customer_charge; let balance_before = Balances::free_balance(DdcPayouts::account_id()); assert_ok!(DdcPayouts::send_charging_customers_batch( @@ -2335,7 +2335,7 @@ fn send_charging_customers_batch_works_zero_fees() { let usage5_charge = calculate_charge_for_month(cluster_id, usage5.clone()); let charge5 = calculate_charge_parts_for_month(cluster_id, usage5); let balance = Balances::free_balance(DdcPayouts::account_id()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(balance, usage5_charge + balance_before); assert_eq!( charge5.puts + before_total_customer_charge.puts, @@ -2484,7 +2484,7 @@ fn end_charging_customers_works() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge = calculate_charge_for_month(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, batch_index, customer_id: user1, amount: charge } @@ -2522,7 +2522,7 @@ fn end_charging_customers_works() { let transfers = 3 + 3 + 3 + 3 * 3; // for Currency::transfer assert_eq!(System::events().len(), 5 + 1 + 3 + transfers); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let total_left_from_one = (get_fees(&cluster_id).treasury_share + @@ -2658,7 +2658,7 @@ fn end_charging_customers_works_zero_fees() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let charge = calculate_charge_for_month(cluster_id, usage1); System::assert_last_event( Event::Charged { cluster_id, era, customer_id: user1, batch_index, amount: charge } @@ -2678,7 +2678,7 @@ fn end_charging_customers_works_zero_fees() { System::assert_has_event(Event::ChargingFinished { cluster_id, era }.into()); assert_eq!(System::events().len(), 5 + 1); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report_after.state, State::CustomersChargedWithFees); let fees = get_fees(&cluster_id); @@ -2888,7 +2888,7 @@ fn begin_rewarding_providers_works() { end_era, )); - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -2922,7 +2922,7 @@ fn begin_rewarding_providers_works() { System::assert_last_event(Event::RewardingStarted { cluster_id, era }.into()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::RewardingProviders); }) } @@ -3175,14 +3175,14 @@ fn send_rewarding_providers_batch_works() { payers, )); - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_ok!(DdcPayouts::end_charging_customers( RuntimeOrigin::signed(dac_account), cluster_id, era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -3245,7 +3245,7 @@ fn send_rewarding_providers_batch_works() { let balance_node1 = Balances::free_balance(node1); assert_eq!(balance_node1, transfer_charge + storage_charge + puts_charge + gets_charge); - let mut report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report_reward = ActiveBillingReports::::get(cluster_id, era).unwrap(); System::assert_has_event( Event::ProviderRewarded { @@ -3336,7 +3336,7 @@ fn send_rewarding_providers_batch_works() { ); gets_charge = ratio3_gets * report_after.total_customer_charge.gets; - report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report_reward = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance_node3 = Balances::free_balance(node3); assert_eq!(balance_node3, transfer_charge + storage_charge + puts_charge + gets_charge); @@ -3533,7 +3533,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -3546,7 +3546,7 @@ fn send_rewarding_providers_batch_100_nodes_small_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -3807,7 +3807,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -3820,7 +3820,7 @@ fn send_rewarding_providers_batch_100_nodes_large_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4081,7 +4081,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -4094,7 +4094,7 @@ fn send_rewarding_providers_batch_100_nodes_small_large_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4314,7 +4314,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { batch_user_index += 1; } - let report_before = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_before = ActiveBillingReports::::get(cluster_id, era).unwrap(); let balance1 = Balances::free_balance(report_before.vault); let balance2 = Balances::free_balance(DdcPayouts::account_id()); assert_eq!(balance1, balance2); @@ -4327,7 +4327,7 @@ fn send_rewarding_providers_batch_100_nodes_random_usage_works() { era, )); - let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_after = ActiveBillingReports::::get(cluster_id, era).unwrap(); let total_left_from_one = (get_fees(&cluster_id).treasury_share + get_fees(&cluster_id).validators_share + get_fees(&cluster_id).cluster_reserve_share) @@ -4630,7 +4630,7 @@ fn end_rewarding_providers_works() { end_era, )); - let mut report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let mut report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -4678,7 +4678,7 @@ fn end_rewarding_providers_works() { System::assert_last_event(Event::RewardingFinished { cluster_id, era }.into()); - report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::ProvidersRewarded); }) } @@ -4858,7 +4858,7 @@ fn end_billing_report_works() { end_era, )); - let report = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert_eq!(report.state, State::Initialized); assert_ok!(DdcPayouts::begin_charging_customers( @@ -4912,7 +4912,7 @@ fn end_billing_report_works() { System::assert_last_event(Event::BillingReportFinalized { cluster_id, era }.into()); - let report_end = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); + let report_end = ActiveBillingReports::::get(cluster_id, era).unwrap(); assert!(report_end.rewarding_processed_batches.is_empty()); assert!(report_end.charging_processed_batches.is_empty()); assert_eq!(report_end.state, State::Finalized); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index ae4ae6d5f..4e8523908 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -190,44 +190,36 @@ pub mod pallet { /// Map from all locked "stash" accounts to the controller account. #[pallet::storage] - #[pallet::getter(fn bonded)] pub type Bonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; /// Map from all (unlocked) "controller" accounts to the info regarding the staking. #[pallet::storage] - #[pallet::getter(fn ledger)] pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; /// The map of (wannabe) Storage nodes participants stash keys to the DDC cluster ID they /// wish to participate into. #[pallet::storage] - #[pallet::getter(fn storages)] pub type Storages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// Map from DDC node ID to the node operator stash account. #[pallet::storage] - #[pallet::getter(fn nodes)] pub type Nodes = StorageMap<_, Twox64Concat, NodePubKey, T::AccountId>; /// Map from operator stash account to DDC node ID. #[pallet::storage] - #[pallet::getter(fn providers)] pub type Providers = StorageMap<_, Twox64Concat, T::AccountId, NodePubKey>; /// Map of Storage node provider stash accounts that aim to leave a cluster #[pallet::storage] - #[pallet::getter(fn leaving_storages)] pub type LeavingStorages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; /// Map from all clusters locked "stash" accounts to the controller account. #[pallet::storage] - #[pallet::getter(fn cluster_bonded)] pub type ClusterBonded = StorageMap<_, Twox64Concat, T::AccountId, T::AccountId>; /// Map of all clusters staking ledgers. #[pallet::storage] - #[pallet::getter(fn cluster_ledger)] pub type ClusterLedger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; @@ -470,7 +462,7 @@ pub mod pallet { #[pallet::compact] value: BalanceOf, ) -> DispatchResult { let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, @@ -490,7 +482,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let min_active_bond = if let Some(cluster_id) = Self::storages(&ledger.stash) { + let min_active_bond = if let Some(cluster_id) = Storages::::get(&ledger.stash) { let bond_size = T::ClusterProtocol::get_bond_size(&cluster_id, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; @@ -580,7 +572,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::withdraw_unbonded())] pub fn withdraw_unbonded(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; - let mut ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); let node_pub_key = >::get(stash.clone()).ok_or(Error::::BadState)?; @@ -639,7 +631,7 @@ pub mod pallet { Error::::NoCluster ); - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterProtocol::get_bond_size(&cluster_id, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; @@ -657,7 +649,7 @@ pub mod pallet { ); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::storages(stash) { + if let Some(current_cluster) = Storages::::get(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -695,11 +687,11 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; + let ledger = Ledger::::get(&controller).ok_or(Error::::NotController)?; let current_block = >::block_number(); // Extract delay from the cluster settings. - let (cluster, delay) = if let Some(cluster) = Self::storages(&ledger.stash) { + let (cluster, delay) = if let Some(cluster) = Storages::::get(&ledger.stash) { let chill_delay = T::ClusterProtocol::get_chill_delay(&cluster, NodeType::Storage) .map_err(|_| Error::::NoClusterGovParams)?; (cluster, chill_delay) @@ -749,7 +741,7 @@ pub mod pallet { controller: ::Source, ) -> DispatchResult { let stash = ensure_signed(origin)?; - let old_controller = Self::bonded(&stash).ok_or(Error::::NotStash)?; + let old_controller = Bonded::::get(&stash).ok_or(Error::::NotStash)?; let controller = T::Lookup::lookup(controller)?; if >::contains_key(&controller) { Err(Error::::AlreadyPaired)? @@ -877,7 +869,8 @@ pub mod pallet { ensure!(controller == cluster_controller, Error::::NotController); - let mut ledger = Self::cluster_ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = + ClusterLedger::::get(&controller).ok_or(Error::::NotController)?; ensure!( ledger.unlocking.len() < MaxUnlockingChunks::get() as usize, Error::::NoMoreChunks, @@ -923,7 +916,8 @@ pub mod pallet { let controller = T::ClusterManager::get_manager_account_id(&cluster_id)?; ensure!(controller == cluster_controller, Error::::NotController); - let mut ledger = Self::cluster_ledger(&controller).ok_or(Error::::NotController)?; + let mut ledger = + ClusterLedger::::get(&controller).ok_or(Error::::NotController)?; let (stash, old_total) = (ledger.stash.clone(), ledger.total); ledger = ledger.consolidate_unlocked(>::block_number()); diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 982e826ad..6007ce099 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -494,7 +494,7 @@ fn check_ledgers() { fn assert_ledger_consistent(controller: AccountId) { // ensures ledger.total == ledger.active + sum(ledger.unlocking). - let ledger = DdcStaking::ledger(controller.clone()).expect("Not a controller."); + let ledger = Ledger::::get(controller.clone()).expect("Not a controller."); let real_total: Balance = ledger.unlocking.iter().fold(ledger.active, |a, c| a + c.value); assert_eq!(real_total, ledger.total); assert!( diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index c48f89196..4952da4b8 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -8,7 +8,7 @@ use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; use pallet_ddc_clusters::{ cluster::{Cluster, ClusterProps}, - Error as ClustersError, + Clusters, Error as ClustersError, }; use super::{mock::*, *}; @@ -37,20 +37,20 @@ fn basic_setup_works() { ExtBuilder.build_and_execute(clusters, nodes, clusters_bonds, nodes_bondes, || { // Account 11 is stashed and locked, and account 10 is the controller assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); // Account 21 is stashed and locked, and account 20 is the controller assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_2)), + Bonded::::get(AccountId::from(NODE_STASH_2)), Some(AccountId::from(NODE_CONTROLLER_2)) ); // Account 1 is not a stashed - assert_eq!(DdcStaking::bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(Bonded::::get(AccountId::from(USER_KEY_1)), None); // Account 10 controls the stash from account 11, which is 100 units assert_eq!( - DdcStaking::ledger(AccountId::from(NODE_CONTROLLER_1)), + Ledger::::get(AccountId::from(NODE_CONTROLLER_1)), Some(StakingLedger { stash: AccountId::from(NODE_STASH_1), total: 100, @@ -61,7 +61,7 @@ fn basic_setup_works() { ); // Account 20 controls the stash from account 21, which is 100 units assert_eq!( - DdcStaking::ledger(AccountId::from(NODE_CONTROLLER_2)), + Ledger::::get(AccountId::from(NODE_CONTROLLER_2)), Some(StakingLedger { stash: AccountId::from(NODE_STASH_2), total: 100, @@ -71,7 +71,7 @@ fn basic_setup_works() { }) ); // Account 1 does not control any stash - assert_eq!(DdcStaking::ledger(AccountId::from(USER_KEY_1)), None); + assert_eq!(Ledger::::get(AccountId::from(USER_KEY_1)), None); }); } @@ -81,7 +81,7 @@ fn change_controller_works() { ExtBuilder.build_and_execute(clusters, nodes, clusters_bonds, nodes_bondes, || { // 10 and 11 are bonded as stash controller. assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); @@ -103,7 +103,7 @@ fn change_controller_works() { Error::::AlreadyPaired ); assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(USER_KEY_3)) ); @@ -250,7 +250,7 @@ fn set_node_works() { System::set_block_number(1); // 10 and 11 are bonded as stash controller. assert_eq!( - DdcStaking::bonded(AccountId::from(NODE_STASH_1)), + Bonded::::get(AccountId::from(NODE_STASH_1)), Some(AccountId::from(NODE_CONTROLLER_1)) ); @@ -427,11 +427,11 @@ fn staking_should_work() { // Account 4 controls the stash from account 3, which is 1500 units, 3 is a Storage // participant, 5 is a DDC node. assert_eq!( - DdcStaking::bonded(AccountId::from(USER_KEY_3)), + Bonded::::get(AccountId::from(USER_KEY_3)), Some(AccountId::from(USER_KEY_4)) ); assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -441,11 +441,11 @@ fn staking_should_work() { }) ); assert_eq!( - DdcStaking::storages(AccountId::from(USER_KEY_3)), + Storages::::get(AccountId::from(USER_KEY_3)), Some(ClusterId::from(CLUSTER_ID)) ); assert_eq!( - DdcStaking::nodes(NodePubKey::StoragePubKey(StorageNodePubKey::new(NODE_KEY_5))), + Nodes::::get(NodePubKey::StoragePubKey(StorageNodePubKey::new(NODE_KEY_5))), Some(AccountId::from(USER_KEY_3)) ); @@ -463,7 +463,7 @@ fn staking_should_work() { // TestClusterProtocol::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage) // .unwrap_or(10_u64); assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -499,7 +499,7 @@ fn staking_should_work() { // Ledger is not changed until we make another call to `chill`. assert_eq!( - DdcStaking::ledger(AccountId::from(USER_KEY_4)), + Ledger::::get(AccountId::from(USER_KEY_4)), Some(StakingLedger { stash: AccountId::from(USER_KEY_3), total: 1500, @@ -514,7 +514,7 @@ fn staking_should_work() { System::assert_last_event(Event::Chilled(AccountId::from(USER_KEY_3)).into()); // Account 3 is no longer a Storage participant. - assert_eq!(DdcStaking::storages(AccountId::from(USER_KEY_3)), None); + assert_eq!(Storages::::get(AccountId::from(USER_KEY_3)), None); }); } @@ -569,8 +569,8 @@ fn storage_full_unbonding_works() { )); System::assert_last_event(Event::Activated(provider_stash.clone()).into()); - assert_eq!(DdcStaking::storages(provider_stash.clone()), Some(cluster_id)); - assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash.clone())); + assert_eq!(Storages::::get(provider_stash.clone()), Some(cluster_id)); + assert_eq!(Nodes::::get(node_pub_key), Some(provider_stash.clone())); // Set block timestamp. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); @@ -593,7 +593,7 @@ fn storage_full_unbonding_works() { System::assert_last_event(Event::Chilled(provider_stash.clone()).into()); // Account is no longer a Storage participant. - assert_eq!(DdcStaking::storages(provider_stash.clone()), None); + assert_eq!(Storages::::get(provider_stash.clone()), None); // Start unbonding all tokens assert_ok!(DdcStaking::unbond( @@ -601,7 +601,7 @@ fn storage_full_unbonding_works() { storage_bond_size )); System::assert_has_event(Event::LeaveSoon(provider_stash.clone()).into()); - assert_eq!(DdcStaking::leaving_storages(provider_stash.clone()), Some(cluster_id)); + assert_eq!(LeavingStorages::::get(provider_stash.clone()), Some(cluster_id)); System::assert_last_event( Event::Unbonded(provider_stash.clone(), storage_bond_size).into(), ); @@ -619,7 +619,7 @@ fn storage_full_unbonding_works() { System::assert_has_event( Event::Withdrawn(provider_stash.clone(), storage_bond_size).into(), ); - assert_eq!(DdcStaking::leaving_storages(provider_stash.clone()), None); + assert_eq!(LeavingStorages::::get(provider_stash.clone()), None); System::assert_last_event(Event::Left(provider_stash).into()); }); } @@ -742,12 +742,12 @@ fn bond_cluster_works() { )); assert_eq!( - DdcStaking::cluster_bonded(AccountId::from(CLUSTER_STASH)), + ClusterBonded::::get(AccountId::from(CLUSTER_STASH)), Some(AccountId::from(CLUSTER_CONTROLLER)) ); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(CLUSTER_CONTROLLER)), + ClusterLedger::::get(AccountId::from(CLUSTER_CONTROLLER)), Some(StakingLedger { stash: AccountId::from(CLUSTER_STASH), total: 50, @@ -760,7 +760,7 @@ fn bond_cluster_works() { System::assert_has_event(Event::Bonded(AccountId::from(CLUSTER_STASH), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(CLUSTER_ID)), + Clusters::::get(ClusterId::from(CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(CLUSTER_ID), manager_id: AccountId::from(CLUSTER_CONTROLLER), @@ -896,7 +896,7 @@ fn unbond_bonded_cluster_works() { unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -909,7 +909,7 @@ fn unbond_bonded_cluster_works() { System::assert_has_event(Event::Unbonded(AccountId::from(USER_KEY_1), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(BONDED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(BONDED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(BONDED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -975,7 +975,7 @@ fn unbond_activated_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -988,7 +988,7 @@ fn unbond_activated_cluster_works() { System::assert_has_event(Event::Unbonded(AccountId::from(USER_KEY_1), 50).into()); assert_eq!( - DdcClusters::clusters(ClusterId::from(ACTIVATED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(ACTIVATED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(ACTIVATED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -1059,7 +1059,7 @@ fn withdraw_unbonded_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -1078,11 +1078,11 @@ fn withdraw_unbonded_cluster_works() { System::assert_last_event(Event::Withdrawn(AccountId::from(USER_KEY_1), 50).into()); - assert_eq!(DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), None); - assert_eq!(DdcStaking::cluster_bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); assert_eq!( - DdcClusters::clusters(ClusterId::from(BONDED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(BONDED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(BONDED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), @@ -1145,7 +1145,7 @@ fn withdraw_activated_cluster_works() { let chunk = UnlockChunk { value: 50u128, block: 3u64 }; unlocking.push(chunk); assert_eq!( - DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), + ClusterLedger::::get(AccountId::from(USER_KEY_1)), Some(StakingLedger { stash: AccountId::from(USER_KEY_1), total: 50, @@ -1164,11 +1164,11 @@ fn withdraw_activated_cluster_works() { System::assert_last_event(Event::Withdrawn(AccountId::from(USER_KEY_1), 50).into()); - assert_eq!(DdcStaking::cluster_ledger(AccountId::from(USER_KEY_1)), None); - assert_eq!(DdcStaking::cluster_bonded(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); + assert_eq!(ClusterBonded::::get(AccountId::from(USER_KEY_1)), None); assert_eq!( - DdcClusters::clusters(ClusterId::from(ACTIVATED_CLUSTER_ID)), + Clusters::::get(ClusterId::from(ACTIVATED_CLUSTER_ID)), Some(Cluster { cluster_id: ClusterId::from(ACTIVATED_CLUSTER_ID), manager_id: AccountId::from(USER_KEY_1), diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index 239251f12..da2d0ce4b 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -12,6 +12,7 @@ use frame_system::{ensure_signed, pallet_prelude::*}; pub use pallet::*; use pallet_chainbridge as bridge; use pallet_erc721 as erc721; +use pallet_erc721::Tokens; use sp_arithmetic::traits::SaturatedConversion; use sp_core::U256; use sp_std::prelude::*; @@ -121,7 +122,7 @@ pub mod pallet { ) -> DispatchResult { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - match >::tokens(token_id) { + match Tokens::::get(token_id) { Some(token) => { >::burn_token(source, token_id)?; let resource_id = T::Erc721Id::get(); diff --git a/pallets/erc20/src/tests.rs b/pallets/erc20/src/tests.rs index 5643698da..f892b8630 100644 --- a/pallets/erc20/src/tests.rs +++ b/pallets/erc20/src/tests.rs @@ -84,7 +84,7 @@ fn transfer_erc721() { // Create a token assert_ok!(Erc721::mint(Origin::root(), RELAYER_A, token_id, metadata.clone())); assert_eq!( - Erc721::tokens(token_id).unwrap(), + Tokens::::get(token_id).unwrap(), Erc721Token { id: token_id, metadata: metadata.clone() } ); @@ -107,7 +107,7 @@ fn transfer_erc721() { )); // Ensure token no longer exists - assert_eq!(Erc721::tokens(token_id), None); + assert_eq!(Tokens::::get(token_id), None); // Transfer should fail as token doesn't exist assert_noop!( @@ -198,7 +198,7 @@ fn mint_erc721() { let bridge_id: u64 = Bridge::account_id(); // Token doesn't yet exist - assert_eq!(Erc721::tokens(token_id), None); + assert_eq!(Tokens::::get(token_id), None); // Mint assert_ok!(Example::mint_erc721( Origin::signed(bridge_id), @@ -208,7 +208,7 @@ fn mint_erc721() { )); // Ensure token exists assert_eq!( - Erc721::tokens(token_id).unwrap(), + Tokens::::get(token_id).unwrap(), Erc721Token { id: token_id, metadata: metadata.clone() } ); // Cannot mint same token diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index 655277074..e71a2fc74 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -49,12 +49,10 @@ pub mod pallet { /// Maps tokenId to Erc721 object #[pallet::storage] - #[pallet::getter(fn tokens)] pub type Tokens = StorageMap<_, Blake2_256, TokenId, Erc721Token>; /// Maps tokenId to owner #[pallet::storage] - #[pallet::getter(fn owner_of)] pub type TokenOwner = StorageMap<_, Blake2_256, TokenId, T::AccountId>; #[pallet::type_value] @@ -63,7 +61,6 @@ pub mod pallet { } #[pallet::storage] - #[pallet::getter(fn token_count)] pub type TokenCount = StorageValue>; @@ -123,7 +120,7 @@ pub mod pallet { pub fn burn(origin: OriginFor, id: TokenId) -> DispatchResult { ensure_root(origin)?; - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; Self::burn_token(owner, id)?; @@ -151,7 +148,7 @@ pub mod pallet { /// Modifies ownership of a token pub fn transfer_from(from: T::AccountId, to: T::AccountId, id: TokenId) -> DispatchResult { // Check from is owner and token exists - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); // Update owner >::insert(id, to.clone()); @@ -163,7 +160,7 @@ pub mod pallet { /// Deletes a token from the system. pub fn burn_token(from: T::AccountId, id: TokenId) -> DispatchResult { - let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; + let owner = TokenOwner::::get(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); >::remove(id); diff --git a/pallets/erc721/src/tests.rs b/pallets/erc721/src/tests.rs index e4bfb0ca0..e881a6679 100644 --- a/pallets/erc721/src/tests.rs +++ b/pallets/erc721/src/tests.rs @@ -18,10 +18,10 @@ fn mint_burn_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); assert_eq!( - Erc721::tokens(id_a).unwrap(), + Tokens::::get(id_a).unwrap(), Erc721Token { id: id_a, metadata: metadata_a.clone() } ); - assert_eq!(Erc721::token_count(), 1.into()); + assert_eq!(TokenCount::::get(), 1.into()); assert_noop!( Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a), Error::::TokenAlreadyExists @@ -29,22 +29,22 @@ fn mint_burn_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); assert_eq!( - Erc721::tokens(id_b).unwrap(), + Tokens::::get(id_b).unwrap(), Erc721Token { id: id_b, metadata: metadata_b.clone() } ); - assert_eq!(Erc721::token_count(), 2.into()); + assert_eq!(TokenCount::::get(), 2.into()); assert_noop!( Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b), Error::::TokenAlreadyExists ); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a)); - assert_eq!(Erc721::token_count(), 1.into()); + assert_eq!(TokenCount::::get(), 1.into()); assert!(!>::contains_key(id_a)); assert!(!>::contains_key(id_a)); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b)); - assert_eq!(Erc721::token_count(), 0.into()); + assert_eq!(TokenCount::::get(), 0.into()); assert!(!>::contains_key(id_b)); assert!(!>::contains_key(id_b)); }) @@ -62,15 +62,15 @@ fn transfer_tokens() { assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b)); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); + assert_eq!(TokenOwner::::get(id_a).unwrap(), USER_B); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_C, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_C); + assert_eq!(TokenOwner::::get(id_b).unwrap(), USER_C); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_B), USER_A, id_a)); - assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_A); + assert_eq!(TokenOwner::::get(id_a).unwrap(), USER_A); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_C), USER_A, id_b)); - assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_A); + assert_eq!(TokenOwner::::get(id_b).unwrap(), USER_A); }) }