From 60849232ff11be10aa3afaa5085503a9c19028bd Mon Sep 17 00:00:00 2001
From: Deepak Chaudhary <54492415+Aideepakchaudhary@users.noreply.github.com>
Date: Thu, 4 Jul 2024 03:20:38 +0800
Subject: [PATCH] Remove pallet::getter usage from all pallet-tips (#4871)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

### ISSUE
Link to the issue:
https://github.com/paritytech/polkadot-sdk/issues/3326
cc @muraca

Deliverables
 - [Deprecation] remove pallet::getter usage from all pallet-tips


### Test Outcomes
___
Successful tests by running `cargo test -p pallet-tips --features
runtime-benchmarks`



running 26 tests
test tests::__construct_runtime_integrity_test::runtime_integrity_tests
... ok
test benchmarking::bench_retract_tip ... ok
test tests::equal_entries_invariant ... ok
test benchmarking::bench_tip ... ok
test tests::finders_fee_invariant ... ok
test tests::genesis_config_works ... ok
test tests::genesis_funding_works ... ok
test benchmarking::bench_slash_tip ... ok
test tests::reasons_invariant ... ok
test benchmarking::bench_report_awesome ... ok
test tests::close_tip_works ... ok
test tests::report_awesome_from_beneficiary_and_tip_works ... ok
test tests::test_genesis_config_builds ... ok
test tests::test_last_reward_migration ... ok
test benchmarking::bench_tip_new ... ok
test benchmarking::bench_close_tip ... ok
test tests::test_migration_v4 ... ok
test tests::slash_tip_works ... ok
test tests::report_awesome_and_tip_works_second_instance ... ok
test tests::report_awesome_and_tip_works ... ok
test tests::tip_changing_works ... ok
test tests::zero_base_deposit_prohibited - should panic ... ok
test tests::tip_median_calculation_works ... ok
test tests::tip_new_cannot_be_used_twice ... ok
test tests::tip_large_should_fail ... ok
test tests::retract_tip_works ... ok

test result: ok. 26 passed; 0 failed; 0 ignored; 0 measured; 0 filtered
out; finished in 0.02s

   Doc-tests pallet_tips

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered
out; finished in 0.00s

---

Polkadot Address: 16htXkeVhfroBhL6nuqiwknfXKcT6WadJPZqEi2jRf9z4XPY

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
---
 prdoc/pr_4871.prdoc             | 14 ++++++++++++++
 substrate/frame/tips/src/lib.rs | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 prdoc/pr_4871.prdoc

diff --git a/prdoc/pr_4871.prdoc b/prdoc/pr_4871.prdoc
new file mode 100644
index 00000000000..6ff36f59d70
--- /dev/null
+++ b/prdoc/pr_4871.prdoc
@@ -0,0 +1,14 @@
+# 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 the pallet-tips
+
+doc:
+  - audience: Runtime Dev
+    description: |
+      This PR removed `pallet::getter`s from `pallet-tips`s storage items.
+      When accessed inside the pallet, use the syntax `StorageItem::<T, I>::get()`.
+
+crates:
+  - name: pallet-tips
+    bump: minor
diff --git a/substrate/frame/tips/src/lib.rs b/substrate/frame/tips/src/lib.rs
index e16ee041fcd..a75aed89d0b 100644
--- a/substrate/frame/tips/src/lib.rs
+++ b/substrate/frame/tips/src/lib.rs
@@ -180,7 +180,6 @@ pub mod pallet {
 	/// This has the insecure enumerable hash function since the key itself is already
 	/// guaranteed to be a secure hash.
 	#[pallet::storage]
-	#[pallet::getter(fn tips)]
 	pub type Tips<T: Config<I>, I: 'static = ()> = StorageMap<
 		_,
 		Twox64Concat,
@@ -192,7 +191,6 @@ pub mod pallet {
 	/// Simple preimage lookup from the reason's hash to the original data. Again, has an
 	/// insecure enumerable hash since the key is guaranteed to be the result of a secure hash.
 	#[pallet::storage]
-	#[pallet::getter(fn reasons)]
 	pub type Reasons<T: Config<I>, I: 'static = ()> =
 		StorageMap<_, Identity, T::Hash, Vec<u8>, OptionQuery>;
 
@@ -492,6 +490,18 @@ pub mod pallet {
 impl<T: Config<I>, I: 'static> Pallet<T, I> {
 	// Add public immutables and private mutables.
 
+	/// Access tips storage from outside
+	pub fn tips(
+		hash: T::Hash,
+	) -> Option<OpenTip<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T>, T::Hash>> {
+		Tips::<T, I>::get(hash)
+	}
+
+	/// Access reasons storage from outside
+	pub fn reasons(hash: T::Hash) -> Option<Vec<u8>> {
+		Reasons::<T, I>::get(hash)
+	}
+
 	/// The account ID of the treasury pot.
 	///
 	/// This actually does computation. If you need to keep using it, then make sure you cache the
-- 
GitLab