From 84d64374613f3e2e263d45b0ef16e79b821e0f12 Mon Sep 17 00:00:00 2001
From: "polka.dom" <polkadotdom@gmail.com>
Date: Fri, 10 May 2024 16:59:00 -0400
Subject: [PATCH] Remove pallet::getter usage from
 pallet-contracts-mock-network (#4417)

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::&lt;T&gt;::get() syntax, the other option would be to set
the storage values to pub. Though I find preserving data authority
better myself.

@muraca
---
 prdoc/pr_4417.prdoc                                | 13 +++++++++++++
 .../contracts/mock-network/src/mocks/msg_queue.rs  | 14 ++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 prdoc/pr_4417.prdoc

diff --git a/prdoc/pr_4417.prdoc b/prdoc/pr_4417.prdoc
new file mode 100644
index 00000000000..5aa72edd066
--- /dev/null
+++ b/prdoc/pr_4417.prdoc
@@ -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
diff --git a/substrate/frame/contracts/mock-network/src/mocks/msg_queue.rs b/substrate/frame/contracts/mock-network/src/mocks/msg_queue.rs
index cc81b6bd636..bfdf6dd97ea 100644
--- a/substrate/frame/contracts/mock-network/src/mocks/msg_queue.rs
+++ b/substrate/frame/contracts/mock-network/src/mocks/msg_queue.rs
@@ -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()
 		}
 	}
 
@@ -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,
@@ -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));
 						},
 					},
-- 
GitLab