From 3e2d949616107051e3383958c318454d3dd84217 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sat, 6 Jul 2024 23:16:23 +0530 Subject: [PATCH 01/12] remove getter from lib --- substrate/frame/treasury/src/lib.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index b437e5ef137e..5de68827af4d 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -276,12 +276,10 @@ pub mod pallet { /// Number of proposals that have been made. #[pallet::storage] - #[pallet::getter(fn proposal_count)] pub(crate) type ProposalCount = StorageValue<_, ProposalIndex, ValueQuery>; /// Proposals that have been made. #[pallet::storage] - #[pallet::getter(fn proposals)] pub type Proposals, I: 'static = ()> = StorageMap< _, Twox64Concat, @@ -297,7 +295,6 @@ pub mod pallet { /// Proposal indices that have been approved but not yet awarded. #[pallet::storage] - #[pallet::getter(fn approvals)] pub type Approvals, I: 'static = ()> = StorageValue<_, BoundedVec, ValueQuery>; From 28faa285447e90ce5b0653a883362e003fb4e25c Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sat, 6 Jul 2024 23:50:34 +0530 Subject: [PATCH 02/12] removed getter from pallet --- substrate/frame/treasury/src/benchmarking.rs | 2 +- substrate/frame/treasury/src/lib.rs | 4 ++-- substrate/frame/treasury/src/tests.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/substrate/frame/treasury/src/benchmarking.rs b/substrate/frame/treasury/src/benchmarking.rs index 63978c94e682..fdd684b3fc93 100644 --- a/substrate/frame/treasury/src/benchmarking.rs +++ b/substrate/frame/treasury/src/benchmarking.rs @@ -130,7 +130,7 @@ mod benchmarks { T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let (_, value, beneficiary_lookup) = setup_proposal::(SEED); Treasury::::spend_local(origin, value, beneficiary_lookup)?; - let proposal_id = Treasury::::proposal_count() - 1; + let proposal_id = ProposalCount::::get() - 1; let reject_origin = T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 5de68827af4d..8a382b1bf6b8 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -496,7 +496,7 @@ pub mod pallet { .unwrap_or(Ok(()))?; let beneficiary = T::Lookup::lookup(beneficiary)?; - let proposal_index = Self::proposal_count(); + let proposal_index = ProposalCount::::get(); Approvals::::try_append(proposal_index) .map_err(|_| Error::::TooManyApprovals)?; let proposal = Proposal { @@ -803,7 +803,7 @@ impl, I: 'static> Pallet { let proposals_approvals_len = v.len() as u32; v.retain(|&index| { // Should always be true, but shouldn't panic if false or we're screwed. - if let Some(p) = Self::proposals(index) { + if let Some(p) = Proposals::::get(index) { if p.value <= budget_remaining { budget_remaining -= p.value; >::remove(index); diff --git a/substrate/frame/treasury/src/tests.rs b/substrate/frame/treasury/src/tests.rs index 97b735928192..78c9d3fec925 100644 --- a/substrate/frame/treasury/src/tests.rs +++ b/substrate/frame/treasury/src/tests.rs @@ -219,7 +219,7 @@ fn get_payment_id(i: SpendIndex) -> Option { fn genesis_config_works() { ExtBuilder::default().build().execute_with(|| { assert_eq!(Treasury::pot(), 0); - assert_eq!(Treasury::proposal_count(), 0); + assert_eq!(ProposalCount::::get(), 0); }); } @@ -437,9 +437,9 @@ fn remove_already_removed_approval_fails() { assert_ok!(Treasury::spend_local(RuntimeOrigin::signed(14), 100, 3)); - assert_eq!(Treasury::approvals(), vec![0]); + assert_eq!(Approvals::::get(), vec![0]); assert_ok!(Treasury::remove_approval(RuntimeOrigin::root(), 0)); - assert_eq!(Treasury::approvals(), vec![]); + assert_eq!(Approvals::::get(), vec![]); assert_noop!( Treasury::remove_approval(RuntimeOrigin::root(), 0), From 36238528a997c84fdabbed3a628c2aae36d9e68c Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 00:14:10 +0530 Subject: [PATCH 03/12] removed turbofish --- substrate/frame/treasury/src/benchmarking.rs | 2 +- substrate/frame/treasury/src/lib.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/frame/treasury/src/benchmarking.rs b/substrate/frame/treasury/src/benchmarking.rs index fdd684b3fc93..e63febb5798b 100644 --- a/substrate/frame/treasury/src/benchmarking.rs +++ b/substrate/frame/treasury/src/benchmarking.rs @@ -78,7 +78,7 @@ fn create_approved_proposals, I: 'static>(n: u32) -> Result<(), &'s let (_, value, lookup) = setup_proposal::(i); Treasury::::spend_local(origin.clone(), value, lookup)?; } - ensure!(>::get().len() == n as usize, "Not all approved"); + ensure!(Approvals::::get().len() == n as usize, "Not all approved"); Ok(()) } diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 8a382b1bf6b8..9b2a5f8a38d5 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -330,7 +330,7 @@ pub mod pallet { impl, I: 'static> BuildGenesisConfig for GenesisConfig { fn build(&self) { // Create Treasury account - let account_id = >::account_id(); + let account_id = Pallet::::account_id(); let min = T::Currency::minimum_balance(); if T::Currency::free_balance(&account_id) < min { let _ = T::Currency::make_free_balance_be(&account_id, min); @@ -798,7 +798,7 @@ impl, I: 'static> Pallet { let account_id = Self::account_id(); let mut missed_any = false; - let mut imbalance = >::zero(); + let mut imbalance = PositiveImbalanceOf::::zero(); let proposals_len = Approvals::::mutate(|v| { let proposals_approvals_len = v.len() as u32; v.retain(|&index| { @@ -806,7 +806,7 @@ impl, I: 'static> Pallet { if let Some(p) = Proposals::::get(index) { if p.value <= budget_remaining { budget_remaining -= p.value; - >::remove(index); + Proposals::::remove(index); // return their deposit. let err_amount = T::Currency::unreserve(&p.proposer, p.bond); @@ -977,6 +977,6 @@ where { type Type = ::AccountId; fn get() -> Self::Type { - >::account_id() + crate::Pallet::::account_id() } } From 53ea9aba9065c1da07f1fb24660d03a6de5708f9 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 00:26:56 +0530 Subject: [PATCH 04/12] implemented public functions for storage --- substrate/frame/treasury/src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 9b2a5f8a38d5..7eac1788ea3e 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -98,7 +98,7 @@ use frame_support::{ ReservableCurrency, WithdrawReasons, }, weights::Weight, - PalletId, + BoundedVec, PalletId, }; pub use pallet::*; @@ -788,7 +788,18 @@ impl, I: 'static> Pallet { pub fn account_id() -> T::AccountId { T::PalletId::get().into_account_truncating() } - + /// Public function to proposals storage. + pub fn proposals(index: ProposalIndex) -> Option>> { + Proposals::::get(index) + } + /// Public function to proposal_count storage. + pub fn proposal_count() -> ProposalIndex { + ProposalCount::::get() + } + /// Public function to proposal_count storage. + pub fn approvals() -> BoundedVec { + Approvals::::get() + } /// Spend some money! returns number of approvals before spend. pub fn spend_funds() -> Weight { let mut total_weight = Weight::zero(); From 411a2083ef014322c9f65d3b5398319706226e53 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 00:32:21 +0530 Subject: [PATCH 05/12] refactored code --- substrate/frame/treasury/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 7eac1788ea3e..3ff9842692e0 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -788,18 +788,22 @@ impl, I: 'static> Pallet { pub fn account_id() -> T::AccountId { T::PalletId::get().into_account_truncating() } - /// Public function to proposals storage. - pub fn proposals(index: ProposalIndex) -> Option>> { - Proposals::::get(index) - } + /// Public function to proposal_count storage. pub fn proposal_count() -> ProposalIndex { ProposalCount::::get() } - /// Public function to proposal_count storage. + + /// Public function to proposals storage. + pub fn proposals(index: ProposalIndex) -> Option>> { + Proposals::::get(index) + } + + /// Public function to approvals storage. pub fn approvals() -> BoundedVec { Approvals::::get() } + /// Spend some money! returns number of approvals before spend. pub fn spend_funds() -> Weight { let mut total_weight = Weight::zero(); From 5be02f0a04eb10cfd1deb20539e709312e38fdf5 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 00:59:04 +0530 Subject: [PATCH 06/12] added prdoc --- prdoc/1.13.0/pr_4912.prdoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prdoc/1.13.0/pr_4912.prdoc diff --git a/prdoc/1.13.0/pr_4912.prdoc b/prdoc/1.13.0/pr_4912.prdoc new file mode 100644 index 000000000000..b50768222fb6 --- /dev/null +++ b/prdoc/1.13.0/pr_4912.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-treasury + +doc: + - audience: Runtime Dev + description: | + This PR removed `pallet::getter`s from `pallet-treasury`s storage items. + When accessed inside the pallet, use the syntax `StorageItem::::get()`. + +crates: + - name: pallet-treasury + bump: minor \ No newline at end of file From 5d7a5c679e3ffb30b629fb74ce92caad53971df7 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 01:08:23 +0530 Subject: [PATCH 07/12] updated prdoc --- prdoc/1.13.0/{pr_4912.prdoc => pr_4962.prdoc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/1.13.0/{pr_4912.prdoc => pr_4962.prdoc} (100%) diff --git a/prdoc/1.13.0/pr_4912.prdoc b/prdoc/1.13.0/pr_4962.prdoc similarity index 100% rename from prdoc/1.13.0/pr_4912.prdoc rename to prdoc/1.13.0/pr_4962.prdoc From d230c990adfe04c644ff8953549b7fb46f94e555 Mon Sep 17 00:00:00 2001 From: Polkaverse Date: Sun, 7 Jul 2024 01:14:25 +0530 Subject: [PATCH 08/12] updated prdoc --- prdoc/{1.13.0 => }/pr_4962.prdoc | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/{1.13.0 => }/pr_4962.prdoc (100%) diff --git a/prdoc/1.13.0/pr_4962.prdoc b/prdoc/pr_4962.prdoc similarity index 100% rename from prdoc/1.13.0/pr_4962.prdoc rename to prdoc/pr_4962.prdoc From 79875e2d6cd08c1c7038c0a972b7e638986fe7c7 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 29 Jul 2024 23:06:42 +0200 Subject: [PATCH 09/12] Update substrate/frame/treasury/src/lib.rs --- substrate/frame/treasury/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/treasury/src/lib.rs b/substrate/frame/treasury/src/lib.rs index 3ff9842692e0..223920edccec 100644 --- a/substrate/frame/treasury/src/lib.rs +++ b/substrate/frame/treasury/src/lib.rs @@ -276,7 +276,7 @@ pub mod pallet { /// Number of proposals that have been made. #[pallet::storage] - pub(crate) type ProposalCount = StorageValue<_, ProposalIndex, ValueQuery>; + pub type ProposalCount = StorageValue<_, ProposalIndex, ValueQuery>; /// Proposals that have been made. #[pallet::storage] From 7608a7a48b48a267c2840ec046a6a5625dc2fe89 Mon Sep 17 00:00:00 2001 From: Pankaj Date: Wed, 28 Aug 2024 14:56:01 +0530 Subject: [PATCH 10/12] Update prdoc/pr_4962.prdoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- prdoc/pr_4962.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4962.prdoc b/prdoc/pr_4962.prdoc index b50768222fb6..0957f85b6628 100644 --- a/prdoc/pr_4962.prdoc +++ b/prdoc/pr_4962.prdoc @@ -7,7 +7,7 @@ doc: - audience: Runtime Dev description: | This PR removed `pallet::getter`s from `pallet-treasury`s storage items. - When accessed inside the pallet, use the syntax `StorageItem::::get()`. + Instead use the syntax `StorageItem::::get()`. crates: - name: pallet-treasury From 38b5906664b522ed6419b72f25508858d24a2dd9 Mon Sep 17 00:00:00 2001 From: Pankaj Date: Wed, 28 Aug 2024 14:56:12 +0530 Subject: [PATCH 11/12] Update prdoc/pr_4962.prdoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- prdoc/pr_4962.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4962.prdoc b/prdoc/pr_4962.prdoc index 0957f85b6628..7a7ce0204fb5 100644 --- a/prdoc/pr_4962.prdoc +++ b/prdoc/pr_4962.prdoc @@ -11,4 +11,4 @@ doc: crates: - name: pallet-treasury - bump: minor \ No newline at end of file + bump: major \ No newline at end of file From 358d2758b96d96b9703bdf4d01ec7f36df0fd73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 28 Aug 2024 20:47:29 +0200 Subject: [PATCH 12/12] Update prdoc/pr_4962.prdoc --- prdoc/pr_4962.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4962.prdoc b/prdoc/pr_4962.prdoc index 7a7ce0204fb5..0957f85b6628 100644 --- a/prdoc/pr_4962.prdoc +++ b/prdoc/pr_4962.prdoc @@ -11,4 +11,4 @@ doc: crates: - name: pallet-treasury - bump: major \ No newline at end of file + bump: minor \ No newline at end of file