Skip to content

Commit 2271421

Browse files
authored
[AHM] Derive DecodeWithMemTracking and pub fields (#9067)
- Derive `DecodeWithMemTracking` on structs - Make some fields public --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]>
1 parent f1ba2a1 commit 2271421

File tree

8 files changed

+166
-24
lines changed

8 files changed

+166
-24
lines changed

prdoc/pr_9067.prdoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
title: '[AHM] Derive DecodeWithMemTracking and pub fields'
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
- Derive `DecodeWithMemTracking` on structs
6+
- Make some fields public
7+
crates:
8+
- name: pallet-balances
9+
bump: minor
10+
- name: pallet-bounties
11+
bump: minor
12+
- name: pallet-democracy
13+
bump: minor
14+
- name: pallet-proxy
15+
bump: minor
16+
- name: frame-support
17+
bump: minor
18+
- name: pallet-treasury
19+
bump: minor

substrate/frame/balances/src/types.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ pub struct BalanceLock<Balance> {
9191
}
9292

9393
/// Store named reserved balance.
94-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
94+
#[derive(
95+
Encode,
96+
Decode,
97+
DecodeWithMemTracking,
98+
Clone,
99+
PartialEq,
100+
Eq,
101+
RuntimeDebug,
102+
MaxEncodedLen,
103+
TypeInfo,
104+
)]
95105
pub struct ReserveData<ReserveIdentifier, Balance> {
96106
/// The identifier for the named reserve.
97107
pub id: ReserveIdentifier,
@@ -100,7 +110,18 @@ pub struct ReserveData<ReserveIdentifier, Balance> {
100110
}
101111

102112
/// All balance information for an account.
103-
#[derive(Encode, Decode, Clone, PartialEq, Eq, Default, RuntimeDebug, MaxEncodedLen, TypeInfo)]
113+
#[derive(
114+
Encode,
115+
Decode,
116+
DecodeWithMemTracking,
117+
Clone,
118+
PartialEq,
119+
Eq,
120+
Default,
121+
RuntimeDebug,
122+
MaxEncodedLen,
123+
TypeInfo,
124+
)]
104125
pub struct AccountData<Balance> {
105126
/// Non-reserved part of the balance which the account holder may be able to control.
106127
///
@@ -122,7 +143,17 @@ pub struct AccountData<Balance> {
122143

123144
const IS_NEW_LOGIC: u128 = 0x80000000_00000000_00000000_00000000u128;
124145

125-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
146+
#[derive(
147+
Encode,
148+
Decode,
149+
DecodeWithMemTracking,
150+
Clone,
151+
PartialEq,
152+
Eq,
153+
RuntimeDebug,
154+
MaxEncodedLen,
155+
TypeInfo,
156+
)]
126157
pub struct ExtraFlags(pub(crate) u128);
127158
impl Default for ExtraFlags {
128159
fn default() -> Self {

substrate/frame/bounties/src/lib.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ type BlockNumberFor<T, I = ()> =
127127
<<T as pallet_treasury::Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
128128

129129
/// A bounty proposal.
130-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
130+
#[derive(
131+
Encode,
132+
Decode,
133+
DecodeWithMemTracking,
134+
Clone,
135+
PartialEq,
136+
Eq,
137+
RuntimeDebug,
138+
TypeInfo,
139+
MaxEncodedLen,
140+
)]
131141
pub struct Bounty<AccountId, Balance, BlockNumber> {
132142
/// The account proposing it.
133143
proposer: AccountId,
@@ -153,7 +163,17 @@ impl<AccountId: PartialEq + Clone + Ord, Balance, BlockNumber: Clone>
153163
}
154164

155165
/// The status of a bounty proposal.
156-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
166+
#[derive(
167+
Encode,
168+
Decode,
169+
DecodeWithMemTracking,
170+
Clone,
171+
PartialEq,
172+
Eq,
173+
RuntimeDebug,
174+
TypeInfo,
175+
MaxEncodedLen,
176+
)]
157177
pub enum BountyStatus<AccountId, BlockNumber> {
158178
/// The bounty is proposed and waiting for approval.
159179
Proposed,

substrate/frame/democracy/src/types.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,17 @@ impl<
168168
}
169169

170170
/// Info regarding an ongoing referendum.
171-
#[derive(Encode, MaxEncodedLen, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
171+
#[derive(
172+
Encode,
173+
MaxEncodedLen,
174+
Decode,
175+
DecodeWithMemTracking,
176+
Clone,
177+
PartialEq,
178+
Eq,
179+
RuntimeDebug,
180+
TypeInfo,
181+
)]
172182
pub struct ReferendumStatus<BlockNumber, Proposal, Balance> {
173183
/// When voting on this referendum will end.
174184
pub end: BlockNumber,
@@ -183,7 +193,17 @@ pub struct ReferendumStatus<BlockNumber, Proposal, Balance> {
183193
}
184194

185195
/// Info regarding a referendum, present or past.
186-
#[derive(Encode, MaxEncodedLen, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
196+
#[derive(
197+
Encode,
198+
MaxEncodedLen,
199+
Decode,
200+
DecodeWithMemTracking,
201+
Clone,
202+
PartialEq,
203+
Eq,
204+
RuntimeDebug,
205+
TypeInfo,
206+
)]
187207
pub enum ReferendumInfo<BlockNumber, Proposal, Balance> {
188208
/// Referendum is happening, the arg is the block number at which it will end.
189209
Ongoing(ReferendumStatus<BlockNumber, Proposal, Balance>),

substrate/frame/proxy/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ pub struct ProxyDefinition<AccountId, ProxyType, BlockNumber> {
7979
}
8080

8181
/// Details surrounding a specific instance of an announcement to make a call.
82-
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
82+
#[derive(
83+
Encode,
84+
Decode,
85+
DecodeWithMemTracking,
86+
Clone,
87+
Copy,
88+
Eq,
89+
PartialEq,
90+
RuntimeDebug,
91+
MaxEncodedLen,
92+
TypeInfo,
93+
)]
8394
pub struct Announcement<AccountId, Hash, BlockNumber> {
8495
/// The account which made the announcement.
8596
real: AccountId,

substrate/frame/support/src/traits/tokens/fungible/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mod item_of;
160160
mod regular;
161161
mod union_of;
162162

163-
use codec::{Decode, Encode, MaxEncodedLen};
163+
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
164164
use core::marker::PhantomData;
165165
use frame_support_procedural::{CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound};
166166
use scale_info::TypeInfo;
@@ -265,6 +265,7 @@ impl<
265265
PartialEqNoBound,
266266
Encode,
267267
Decode,
268+
DecodeWithMemTracking,
268269
TypeInfo,
269270
MaxEncodedLen,
270271
RuntimeDebugNoBound,

substrate/frame/support/src/traits/tokens/misc.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,17 @@ impl<A, R, B, C: Convert<R, B>> GetSalary<R, A, B> for ConvertRank<C> {
387387
}
388388

389389
/// An identifier and balance.
390-
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
390+
#[derive(
391+
Encode,
392+
Decode,
393+
DecodeWithMemTracking,
394+
Clone,
395+
PartialEq,
396+
Eq,
397+
RuntimeDebug,
398+
MaxEncodedLen,
399+
TypeInfo,
400+
)]
391401
pub struct IdAmount<Id, Balance> {
392402
/// An identifier for this item.
393403
pub id: Id,

substrate/frame/treasury/src/lib.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub use benchmarking::ArgumentsFactory;
8484

8585
extern crate alloc;
8686

87-
use codec::{Decode, Encode, MaxEncodedLen};
87+
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
8888
use scale_info::TypeInfo;
8989

9090
use alloc::{boxed::Box, collections::btree_map::BTreeMap};
@@ -151,21 +151,41 @@ pub type ProposalIndex = u32;
151151

152152
/// A spending proposal.
153153
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
154-
#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
154+
#[derive(
155+
Encode,
156+
Decode,
157+
DecodeWithMemTracking,
158+
Clone,
159+
PartialEq,
160+
Eq,
161+
MaxEncodedLen,
162+
RuntimeDebug,
163+
TypeInfo,
164+
)]
155165
pub struct Proposal<AccountId, Balance> {
156166
/// The account proposing it.
157-
proposer: AccountId,
167+
pub proposer: AccountId,
158168
/// The (total) amount that should be paid if the proposal is accepted.
159-
value: Balance,
169+
pub value: Balance,
160170
/// The account to whom the payment should be made if the proposal is accepted.
161-
beneficiary: AccountId,
171+
pub beneficiary: AccountId,
162172
/// The amount held on deposit (reserved) for making this proposal.
163-
bond: Balance,
173+
pub bond: Balance,
164174
}
165175

166176
/// The state of the payment claim.
167177
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
168-
#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
178+
#[derive(
179+
Encode,
180+
Decode,
181+
DecodeWithMemTracking,
182+
Clone,
183+
PartialEq,
184+
Eq,
185+
MaxEncodedLen,
186+
RuntimeDebug,
187+
TypeInfo,
188+
)]
169189
pub enum PaymentState<Id> {
170190
/// Pending claim.
171191
Pending,
@@ -177,20 +197,30 @@ pub enum PaymentState<Id> {
177197

178198
/// Info regarding an approved treasury spend.
179199
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
180-
#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo)]
200+
#[derive(
201+
Encode,
202+
Decode,
203+
DecodeWithMemTracking,
204+
Clone,
205+
PartialEq,
206+
Eq,
207+
MaxEncodedLen,
208+
RuntimeDebug,
209+
TypeInfo,
210+
)]
181211
pub struct SpendStatus<AssetKind, AssetBalance, Beneficiary, BlockNumber, PaymentId> {
182212
// The kind of asset to be spent.
183-
asset_kind: AssetKind,
213+
pub asset_kind: AssetKind,
184214
/// The asset amount of the spend.
185-
amount: AssetBalance,
215+
pub amount: AssetBalance,
186216
/// The beneficiary of the spend.
187-
beneficiary: Beneficiary,
217+
pub beneficiary: Beneficiary,
188218
/// The block number from which the spend can be claimed.
189-
valid_from: BlockNumber,
219+
pub valid_from: BlockNumber,
190220
/// The block number by which the spend has to be claimed.
191-
expire_at: BlockNumber,
221+
pub expire_at: BlockNumber,
192222
/// The status of the payout/claim.
193-
status: PaymentState<PaymentId>,
223+
pub status: PaymentState<PaymentId>,
194224
}
195225

196226
/// Index of an approved treasury spend.

0 commit comments

Comments
 (0)