Skip to content

Commit 2dbeca6

Browse files
authored
Prep 0.13.0 release: separate Entry traits from core ones (#61)
* Prep 0.13.0 release: separate Entry traits from core ones * Remove unnecessary lifetime * remove list_storage_entries_any * Add to changelog
1 parent d49d35b commit 2dbeca6

15 files changed

+247
-190
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ The format is based on [Keep a Changelog].
44

55
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
66

7+
## 0.13.0 (2025-11-14)
8+
9+
- Separate the iterating over entries from the core `frame-decode` `*Info` traits; One only needs to implement `*Info` traits to work with `frame-decode`; the other traits are convenience traits.
10+
- Make `Entry` type generic so that it can potentially be used in more places, expose it, and expose concrete versions from each module.
11+
- Expose Kusama RC and AH types (though keep these hidden until the types are more complete).
12+
- Remove `helpers::list_storage_entries_any`: it was a bit of an anomaly to have this and not a version for any other thing. Better to keep this upstream for now.
13+
714
## 0.12.1 (2025-11-12)
815

916
- Add `map_ids()` functions to `RuntimeApiInfo`, `StorageInfo` and `ViewFunctionInfo` to make translating the `TypeId` parameter simpler.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "frame-decode"
3-
version = "0.12.1"
3+
version = "0.13.0"
44
edition = "2024"
55
description = "Decode extrinsics and storage from Substrate based chains"
66
license = "Apache-2.0"

src/lib.rs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ pub mod storage {
5252
//! from modern or historic runtimes.
5353
//! - See [`encode_storage_key_prefix`] to encode storage prefixes, and [`encode_storage_key`] to encode
5454
//! storage keys.
55-
//! - See [`StorageTypeInfo`] for the underlying trait which extracts the relevant information.
55+
//! - See [`StorageTypeInfo`] for the underlying trait which provides storage entry information.
56+
//! - See [`StorageEntryInfo`] for a underlying trait which provides information about the available
57+
//! storage entries.
5658
57-
pub use crate::methods::Entry;
5859
pub use crate::methods::storage_decoder::{
5960
StorageKey, StorageKeyDecodeError, StorageKeyPart, StorageKeyPartValue,
6061
StorageKeyValueDecodeError, StorageValueDecodeError,
@@ -68,7 +69,8 @@ pub mod storage {
6869
encode_storage_key_with_info, encode_storage_key_with_info_to,
6970
};
7071
pub use crate::methods::storage_type_info::{
71-
StorageHasher, StorageInfo, StorageInfoError, StorageKeyInfo, StorageTypeInfo,
72+
StorageEntry, StorageEntryInfo, StorageHasher, StorageInfo, StorageInfoError,
73+
StorageKeyInfo, StorageTypeInfo,
7274
};
7375
pub use crate::utils::{
7476
DecodableValues, EncodableValues, IntoDecodableValues, IntoEncodableValues,
@@ -81,13 +83,14 @@ pub mod constants {
8183
//! - See [`decode_constant`] and [`decode_constant_with_info`] to decode constants
8284
//! - See [`ConstantTypeInfo`] for the underlying trait which extracts constant
8385
//! information from metadata.
86+
//! - See [`ConstantEntryInfo`] for a underlying trait which provides information about the available
87+
//! constants.
8488
85-
pub use crate::methods::Entry;
8689
pub use crate::methods::constant_decoder::{
8790
ConstantDecodeError, decode_constant, decode_constant_with_info,
8891
};
8992
pub use crate::methods::constant_type_info::{
90-
ConstantInfo, ConstantInfoError, ConstantTypeInfo,
93+
ConstantEntry, ConstantEntryInfo, ConstantInfo, ConstantInfoError, ConstantTypeInfo,
9194
};
9295
}
9396

@@ -98,8 +101,9 @@ pub mod runtime_apis {
98101
//! the name and inputs to make a Runtime API call.
99102
//! - See [`decode_runtime_api_response`] to decode Runtime API responses.
100103
//! - See [`RuntimeApiTypeInfo`] for the underlying trait which extracts the relevant information.
104+
//! - See [`RuntimeApiEntryInfo`] for a underlying trait which provides information about the available
105+
//! Runtime APIs.
101106
102-
pub use crate::methods::Entry;
103107
pub use crate::methods::runtime_api_decoder::{
104108
RuntimeApiDecodeError, decode_runtime_api_response, decode_runtime_api_response_with_info,
105109
};
@@ -108,7 +112,8 @@ pub mod runtime_apis {
108112
encode_runtime_api_inputs_with_info_to, encode_runtime_api_name,
109113
};
110114
pub use crate::methods::runtime_api_type_info::{
111-
RuntimeApiInfo, RuntimeApiInfoError, RuntimeApiInput, RuntimeApiTypeInfo,
115+
RuntimeApiEntry, RuntimeApiEntryInfo, RuntimeApiInfo, RuntimeApiInfoError, RuntimeApiInput,
116+
RuntimeApiTypeInfo,
112117
};
113118
pub use crate::utils::{EncodableValues, IntoEncodableValues};
114119
}
@@ -120,8 +125,9 @@ pub mod view_functions {
120125
//! and the encoded input data required to call a given View Function.
121126
//! - See [`decode_view_function_response`] to decode View Function responses.
122127
//! - See [`ViewFunctionTypeInfo`] for the underlying trait which extracts the relevant information.
128+
//! - See [`ViewFunctionEntryInfo`] for a underlying trait which provides information about the available
129+
//! View Functions.
123130
124-
pub use crate::methods::Entry;
125131
pub use crate::methods::view_function_decoder::{
126132
ViewFunctionDecodeError, decode_view_function_response,
127133
decode_view_function_response_with_info,
@@ -131,7 +137,8 @@ pub mod view_functions {
131137
encode_view_function_inputs_to, encode_view_function_inputs_with_info_to,
132138
};
133139
pub use crate::methods::view_function_type_info::{
134-
ViewFunctionInfo, ViewFunctionInfoError, ViewFunctionInput, ViewFunctionTypeInfo,
140+
ViewFunctionEntry, ViewFunctionEntryInfo, ViewFunctionInfo, ViewFunctionInfoError,
141+
ViewFunctionInput, ViewFunctionTypeInfo,
135142
};
136143
pub use crate::utils::{EncodableValues, IntoEncodableValues};
137144
}
@@ -142,12 +149,15 @@ pub mod custom_values {
142149
//! - See [`decode_custom_value`] and [`decode_custom_value_with_info`] to decode custom values
143150
//! - See [`CustomValueTypeInfo`] for the underlying trait which extracts custom value
144151
//! information from metadata.
152+
//! - See [`CustomValueEntryInfo`] for a underlying trait which provides information about the available
153+
//! custom values.
145154
146155
pub use crate::methods::custom_value_decoder::{
147156
CustomValueDecodeError, decode_custom_value, decode_custom_value_with_info,
148157
};
149158
pub use crate::methods::custom_value_type_info::{
150-
CustomValue, CustomValueInfo, CustomValueInfoError, CustomValueTypeInfo,
159+
CustomValue, CustomValueEntryInfo, CustomValueInfo, CustomValueInfoError,
160+
CustomValueTypeInfo,
151161
};
152162
}
153163

@@ -162,8 +172,30 @@ pub mod legacy_types {
162172
pub fn relay_chain() -> scale_info_legacy::ChainTypeRegistry {
163173
// This is a convenience function to load the Polkadot relay chain types.
164174
// It is used in the examples in this crate.
165-
let bytes = include_bytes!("../types/polkadot_types.yaml");
166-
serde_yaml::from_slice(bytes).expect("Polkadot types are valid YAML")
175+
let bytes = include_bytes!("../types/polkadot_relay_types.yaml");
176+
serde_yaml::from_slice(bytes).expect("Polkadot RC types are valid YAML")
177+
}
178+
}
179+
180+
// Hidden until the types are ready.
181+
#[doc(hidden)]
182+
pub mod kusama {
183+
//! Legacy types for Kusama chains.
184+
185+
/// Legacy types for the Kusama Relay Chain.
186+
pub fn relay_chain() -> scale_info_legacy::ChainTypeRegistry {
187+
// This is a convenience function to load the Polkadot relay chain types.
188+
// It is used in the examples in this crate.
189+
let bytes = include_bytes!("../types/kusama_relay_types.yaml");
190+
serde_yaml::from_slice(bytes).expect("Kusama RC types are valid YAML")
191+
}
192+
193+
/// Legacy types for the Kusama Asset Hub.
194+
pub fn asset_hub() -> scale_info_legacy::ChainTypeRegistry {
195+
// This is a convenience function to load the Polkadot relay chain types.
196+
// It is used in the examples in this crate.
197+
let bytes = include_bytes!("../types/kusama_assethub_types.yaml");
198+
serde_yaml::from_slice(bytes).expect("Kusama AssetHub types are valid YAML")
167199
}
168200
}
169201
}
@@ -177,9 +209,11 @@ pub mod helpers {
177209
//! will use a tracing visitor (if the `error-tracing` feature is enabled) to provide more
178210
//! information in the event that decoding fails.
179211
212+
pub use crate::methods::Entry;
213+
180214
pub use crate::utils::{
181215
DecodableValues, DecodeErrorTrace, EncodableValues, IntoDecodableValues,
182-
IntoEncodableValues, decode_with_error_tracing, list_storage_entries_any,
216+
IntoEncodableValues, decode_with_error_tracing,
183217
};
184218
#[cfg(feature = "legacy")]
185219
pub use crate::utils::{type_registry_from_metadata, type_registry_from_metadata_any};
@@ -205,6 +239,8 @@ mod test {
205239
#[test]
206240
fn test_deserializing_legacy_types() {
207241
let _ = crate::legacy_types::polkadot::relay_chain();
242+
let _ = crate::legacy_types::kusama::relay_chain();
243+
let _ = crate::legacy_types::kusama::asset_hub();
208244
}
209245

210246
macro_rules! impls_trait {

src/methods/constant_type_info.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,25 @@ pub trait ConstantTypeInfo {
2828
pallet_name: &str,
2929
constant_name: &str,
3030
) -> Result<ConstantInfo<'_, Self::TypeId>, ConstantInfoError<'_>>;
31-
/// Iterate over all of the available Constants.
32-
fn constants(&self) -> impl Iterator<Item = Entry<'_>>;
31+
}
32+
33+
/// This can be implemented for anything capable of providing information about the available Constants
34+
pub trait ConstantEntryInfo {
35+
/// Iterate over all of the available Constants, returning [`Entry`] as we go.
36+
fn constant_entries(&self) -> impl Iterator<Item = ConstantEntry<'_>>;
37+
/// Iterate over all of the available Constants, returning a pair of `(pallet_name, constant_name)` as we go.
38+
fn constant_tuples(&self) -> impl Iterator<Item = (Cow<'_, str>, Cow<'_, str>)> {
39+
Entry::tuples_of(self.constant_entries())
40+
}
3341
/// Iterate over all of the available constants in a given pallet.
3442
fn constants_in_pallet(&self, pallet: &str) -> impl Iterator<Item = Cow<'_, str>> {
35-
Entry::entries_in(self.constants(), pallet)
43+
Entry::entries_in(self.constant_entries(), pallet)
3644
}
3745
}
3846

47+
/// An entry denoting a pallet or a constant name.
48+
pub type ConstantEntry<'a> = Entry<Cow<'a, str>, Cow<'a, str>>;
49+
3950
/// An error returned trying to access Constant information.
4051
#[non_exhaustive]
4152
#[allow(missing_docs)]
@@ -82,6 +93,7 @@ impl<'info> ConstantInfoError<'info> {
8293
}
8394

8495
/// Information about a Constant.
96+
#[derive(Debug, Clone, PartialEq, Eq)]
8597
pub struct ConstantInfo<'info, TypeId: Clone> {
8698
/// The bytes representing this constant.
8799
///
@@ -98,7 +110,6 @@ macro_rules! impl_constant_type_info_for_v14_to_v16 {
98110
use $path as path;
99111
impl ConstantTypeInfo for path::$name {
100112
type TypeId = u32;
101-
102113
fn constant_info(
103114
&self,
104115
pallet_name: &str,
@@ -128,17 +139,17 @@ macro_rules! impl_constant_type_info_for_v14_to_v16 {
128139
type_id: constant.ty.id,
129140
})
130141
}
131-
132-
fn constants(&self) -> impl Iterator<Item = Entry<'_>> {
142+
}
143+
impl ConstantEntryInfo for path::$name {
144+
fn constant_entries(&self) -> impl Iterator<Item = ConstantEntry<'_>> {
133145
self.pallets.iter().flat_map(|p| {
134-
core::iter::once(Entry::In(Cow::Borrowed(&p.name))).chain(
146+
core::iter::once(Entry::In(Cow::Borrowed(&*p.name))).chain(
135147
p.constants
136148
.iter()
137-
.map(|c| Entry::Name(Cow::Borrowed(&c.name))),
149+
.map(|c| Entry::Name(Cow::Borrowed(&*c.name))),
138150
)
139151
})
140152
}
141-
142153
fn constants_in_pallet(
143154
&self,
144155
pallet_name: &str,
@@ -175,7 +186,6 @@ mod legacy {
175186
use $path as path;
176187
impl ConstantTypeInfo for path::$name {
177188
type TypeId = LookupName;
178-
179189
fn constant_info(
180190
&self,
181191
pallet_name: &str,
@@ -209,21 +219,21 @@ mod legacy {
209219
type_id,
210220
})
211221
}
212-
213-
fn constants(&self) -> impl Iterator<Item = Entry<'_>> {
222+
}
223+
impl ConstantEntryInfo for path::$name {
224+
fn constant_entries(&self) -> impl Iterator<Item = ConstantEntry<'_>> {
214225
as_decoded(&self.modules).iter().flat_map(|module| {
215226
let pallet_name = as_decoded(&module.name);
216227
let constants = as_decoded(&module.constants);
217228

218-
core::iter::once(Entry::In(Cow::Borrowed(pallet_name))).chain(
229+
core::iter::once(Entry::In(Cow::Borrowed(&**pallet_name))).chain(
219230
constants.iter().map(|c| {
220231
let constant_name = as_decoded(&c.name);
221-
Entry::Name(Cow::Borrowed(constant_name))
232+
Entry::Name(Cow::Borrowed(&**constant_name))
222233
}),
223234
)
224235
})
225236
}
226-
227237
fn constants_in_pallet(
228238
&self,
229239
pallet_name: &str,

src/methods/custom_value_type_info.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ pub trait CustomValueTypeInfo {
2525
&self,
2626
name: &str,
2727
) -> Result<CustomValueInfo<'_, Self::TypeId>, CustomValueInfoError>;
28-
/// Iterate over all of the available Custom Values.
28+
}
29+
30+
/// This can be implemented for anything capable of providing information about the available Custom Values
31+
pub trait CustomValueEntryInfo {
32+
/// Iterate over all of the available Custom Values, returning [`CustomValue`] as we go.
2933
fn custom_values(&self) -> impl Iterator<Item = CustomValue<'_>>;
3034
}
3135

@@ -39,6 +43,7 @@ pub struct CustomValueInfoError {
3943
}
4044

4145
/// Information about a Custom Value.
46+
#[derive(Debug, Clone, PartialEq, Eq)]
4247
pub struct CustomValueInfo<'info, TypeId: Clone> {
4348
/// The bytes representing this custom value.
4449
///
@@ -52,7 +57,7 @@ pub struct CustomValueInfo<'info, TypeId: Clone> {
5257
}
5358

5459
/// The identifier for a single Custom Value.
55-
#[derive(Debug, Clone)]
60+
#[derive(Debug, Clone, PartialEq, Eq)]
5661
pub struct CustomValue<'info> {
5762
/// The name of this Custom Value.
5863
pub name: Cow<'info, str>,
@@ -64,7 +69,6 @@ macro_rules! impl_custom_value_type_info_for_v15_to_v16 {
6469
use $path as path;
6570
impl CustomValueTypeInfo for path::$name {
6671
type TypeId = u32;
67-
6872
fn custom_value_info(
6973
&self,
7074
name: &str,
@@ -82,7 +86,8 @@ macro_rules! impl_custom_value_type_info_for_v15_to_v16 {
8286
type_id: custom_value.ty.id,
8387
})
8488
}
85-
89+
}
90+
impl CustomValueEntryInfo for path::$name {
8691
fn custom_values(&self) -> impl Iterator<Item = CustomValue<'_>> {
8792
self.custom.map.iter().map(|(name, _)| CustomValue {
8893
name: Cow::Borrowed(name),

src/methods/extrinsic_type_info.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl ExtrinsicInfoError<'_> {
215215
}
216216

217217
/// An argument with a name and type ID.
218-
#[derive(Debug, Clone)]
218+
#[derive(Debug, Clone, PartialEq, Eq)]
219219
pub struct ExtrinsicInfoArg<'info, TypeId> {
220220
/// Argument name.
221221
pub name: Cow<'info, str>,
@@ -224,7 +224,7 @@ pub struct ExtrinsicInfoArg<'info, TypeId> {
224224
}
225225

226226
/// Extrinsic call data information.
227-
#[derive(Debug, Clone)]
227+
#[derive(Debug, Clone, PartialEq, Eq)]
228228
pub struct ExtrinsicCallInfo<'info, TypeId> {
229229
/// Name of the pallet.
230230
pub pallet_name: Cow<'info, str>,
@@ -235,7 +235,7 @@ pub struct ExtrinsicCallInfo<'info, TypeId> {
235235
}
236236

237237
/// Extrinsic signature information.
238-
#[derive(Debug, Clone)]
238+
#[derive(Debug, Clone, PartialEq, Eq)]
239239
pub struct ExtrinsicSignatureInfo<TypeId> {
240240
/// Type ID of the address.
241241
pub address_id: TypeId,
@@ -244,7 +244,7 @@ pub struct ExtrinsicSignatureInfo<TypeId> {
244244
}
245245

246246
/// Extrinsic extension information.
247-
#[derive(Debug, Clone)]
247+
#[derive(Debug, Clone, PartialEq, Eq)]
248248
pub struct ExtrinsicExtensionInfo<'info, TypeId> {
249249
/// Names and type IDs of the transaction extensions.
250250
pub extension_ids: Vec<ExtrinsicInfoArg<'info, TypeId>>,

0 commit comments

Comments
 (0)