Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ jobs:
command: check
toolchain: stable
args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --features v14
- name: Checking all versions
- name: Checking all features
uses: actions-rs/cargo@master
with:
command: check
toolchain: stable
args: --manifest-path ./frame-metadata/Cargo.toml --no-default-features --features v12,v13,v14
args: --manifest-path ./frame-metadata/Cargo.toml --all-features


1 change: 1 addition & 0 deletions frame-metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde = { version = "1.0.101", optional = true, features = ["derive"] }

[features]
default = ["std", "v14"]
docs = ["scale-info/docs"]
v12 = []
v13 = []
v14 = ["scale-info"]
Expand Down
81 changes: 79 additions & 2 deletions frame-metadata/src/v14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct StorageEntryMetadata<T: Form = MetaForm> {
pub modifier: StorageEntryModifier,
pub ty: StorageEntryType<T>,
pub default: Vec<u8>,
pub docs: Vec<T::String>,
docs: Vec<T::String>,
}

impl IntoPortable for StorageEntryMetadata {
Expand All @@ -209,6 +209,48 @@ impl IntoPortable for StorageEntryMetadata {
}
}

impl StorageEntryMetadata<MetaForm> {
/// Create a new [`StorageEntryMetadata`].
pub fn new(
name: &'static str,
modifier: StorageEntryModifier,
ty: StorageEntryType<MetaForm>,
default: Vec<u8>,
) -> Self {
StorageEntryMetadata {
name,
modifier,
ty,
default,
docs: Vec::new(),
}
}

#[cfg(feature = "docs")]
/// Set the documentation.
pub fn with_docs(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}

#[cfg(not(feature = "docs"))]
#[inline]
/// Docs feature is not enabled so this is a no-op.
pub fn with_docs(self, _docs: &[&'static str]) -> Self {
self
}
}

impl<T> StorageEntryMetadata<T>
where
T: Form,
{
/// Get the documentation.
pub fn docs(&self) -> &[T::String] {
self.docs.as_slice()
}
}

/// A storage entry modifier.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
Expand Down Expand Up @@ -357,7 +399,7 @@ pub struct PalletConstantMetadata<T: Form = MetaForm> {
pub name: T::String,
pub ty: T::Type,
pub value: Vec<u8>,
pub docs: Vec<T::String>,
docs: Vec<T::String>,
}

impl IntoPortable for PalletConstantMetadata {
Expand All @@ -373,6 +415,41 @@ impl IntoPortable for PalletConstantMetadata {
}
}

impl PalletConstantMetadata {
pub fn new(name: &'static str, ty: MetaType, value: Vec<u8>) -> Self {
Self {
name,
ty,
value,
docs: Vec::new(),
}
}

#[cfg(feature = "docs")]
/// Set the documentation.
pub fn with_docs(mut self, docs: &[&'static str]) -> Self {
self.docs = docs.to_vec();
self
}

#[cfg(not(feature = "docs"))]
#[inline]
/// Docs feature is not enabled so this is a no-op.
pub fn with_docs(self, _docs: &[&'static str]) -> Self {
self
}
}

impl<T> PalletConstantMetadata<T>
where
T: Form,
{
/// Get the documentation.
pub fn docs(&self) -> &[T::String] {
self.docs.as_slice()
}
}

/// Metadata about a pallet error.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Serialize, Debug))]
Expand Down