expose module errors into metadata (#3752)

* expose module errors into metadata

* it checks

* Tests for error metadata

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* remove inherent errors from metadata

* bump version

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update srml/support/src/error.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Xiliang Chen
2019-10-08 22:30:16 +13:00
committed by Bastian Köcher
parent 38a61861b1
commit 2c77262c8f
5 changed files with 94 additions and 12 deletions
+28 -6
View File
@@ -179,7 +179,7 @@ pub struct OuterEventMetadata {
>,
}
/// All the metadata about a event.
/// All the metadata about an event.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct EventMetadata {
@@ -209,6 +209,25 @@ pub struct ModuleConstantMetadata {
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about a module error.
#[derive(Clone, PartialEq, Eq, Encode)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct ErrorMetadata {
pub name: DecodeDifferentStr,
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
}
/// All the metadata about errors in a module.
pub trait ModuleErrorMetadata {
fn metadata() -> &'static [ErrorMetadata];
}
impl ModuleErrorMetadata for &'static str {
fn metadata() -> &'static [ErrorMetadata] {
&[]
}
}
/// A technical trait to store lazy initiated vec value as static dyn pointer.
pub trait DefaultByte: Send + Sync {
fn default_byte(&self) -> Vec<u8>;
@@ -326,8 +345,10 @@ pub enum RuntimeMetadata {
V5(RuntimeMetadataDeprecated),
/// Version 6 for runtime metadata. No longer used.
V6(RuntimeMetadataDeprecated),
/// Version 7 for runtime metadata.
V7(RuntimeMetadataV7),
/// Version 7 for runtime metadata. No longer used.
V7(RuntimeMetadataDeprecated),
/// Version 8 for runtime metadata.
V8(RuntimeMetadataV8),
}
/// Enum that should fail.
@@ -351,12 +372,12 @@ impl Decode for RuntimeMetadataDeprecated {
/// The metadata of a runtime.
#[derive(Eq, Encode, PartialEq)]
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
pub struct RuntimeMetadataV7 {
pub struct RuntimeMetadataV8 {
pub modules: DecodeDifferentArray<ModuleMetadata>,
}
/// The latest version of the metadata.
pub type RuntimeMetadataLastVersion = RuntimeMetadataV7;
pub type RuntimeMetadataLastVersion = RuntimeMetadataV8;
/// All metadata about an runtime module.
#[derive(Clone, PartialEq, Eq, Encode)]
@@ -367,6 +388,7 @@ pub struct ModuleMetadata {
pub calls: ODFnA<FunctionMetadata>,
pub event: ODFnA<EventMetadata>,
pub constants: DFnA<ModuleConstantMetadata>,
pub errors: DFnA<ErrorMetadata>,
}
type ODFnA<T> = Option<DFnA<T>>;
@@ -380,6 +402,6 @@ impl Into<primitives::OpaqueMetadata> for RuntimeMetadataPrefixed {
impl Into<RuntimeMetadataPrefixed> for RuntimeMetadataLastVersion {
fn into(self) -> RuntimeMetadataPrefixed {
RuntimeMetadataPrefixed(META_RESERVED, RuntimeMetadata::V7(self))
RuntimeMetadataPrefixed(META_RESERVED, RuntimeMetadata::V8(self))
}
}