Skip to content

Commit

Permalink
Remove pallet::getter usage from pallet-contracts-mock-network (#4417)
Browse files Browse the repository at this point in the history
A part of #3326 

Removes all #[pallet::getter] usage from the contracts mock network
pallet. As the storage values were pub(super), read-only visibility was
lost external to the crate upon the removal of the macros. I have
implemented custom getters as a replacement, keeping the api the same.

If we care very much about consistency of the
storagevalue::<T>::get() syntax, the other option would be to set
the storage values to pub. Though I find preserving data authority
better myself.

@muraca
  • Loading branch information
PolkadotDom authored May 10, 2024
1 parent a993513 commit 84d6437
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 13 additions & 0 deletions prdoc/pr_4417.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Removed `pallet::getter` usage from pallet-contracts-mock-network

doc:
- audience: Runtime Dev
description: |
This PR removed the `pallet::getter`s from `pallet-contracts-mock-network`s storage items.

crates:
- name: pallet-contracts-mock-network
bump: minor
14 changes: 10 additions & 4 deletions substrate/frame/contracts/mock-network/src/mocks/msg_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::storage]
#[pallet::getter(fn parachain_id)]
pub(super) type ParachainId<T: Config> = StorageValue<_, ParaId, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn received_dmp)]
/// A queue of received DMP messages
pub(super) type ReceivedDmp<T: Config> = StorageValue<_, Vec<Xcm<T::RuntimeCall>>, ValueQuery>;

impl<T: Config> Get<ParaId> for Pallet<T> {
fn get() -> ParaId {
Self::parachain_id()
ParachainId::<T>::get()
}
}

Expand Down Expand Up @@ -89,6 +87,14 @@ pub mod pallet {
ParachainId::<T>::put(para_id);
}

pub fn parachain_id() -> ParaId {
ParachainId::<T>::get()
}

pub fn received_dmp() -> Vec<Xcm<T::RuntimeCall>> {
ReceivedDmp::<T>::get()
}

fn handle_xcmp_message(
sender: ParaId,
_sent_at: RelayBlockNumber,
Expand Down Expand Up @@ -169,7 +175,7 @@ pub mod pallet {
limit,
Weight::zero(),
);
<ReceivedDmp<T>>::append(x);
ReceivedDmp::<T>::append(x);
Self::deposit_event(Event::ExecutedDownward(id, outcome));
},
},
Expand Down

0 comments on commit 84d6437

Please sign in to comment.