Encode Metadata once instead of two times (#946)

This commit is contained in:
Bastian Köcher
2018-10-25 09:36:57 +02:00
committed by Gav Wood
parent 1ba73e0e88
commit 6244b6a3b9
6 changed files with 17 additions and 23 deletions
+1
View File
@@ -65,6 +65,7 @@ pub mod inherent;
pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType};
pub use self::metadata::RuntimeMetadata;
pub use runtime_io::print;
#[macro_export]
+8 -10
View File
@@ -33,14 +33,12 @@ macro_rules! impl_runtime_metadata {
$( $rest:tt )*
) => {
impl $runtime {
pub fn metadata() -> Vec<u8> {
$crate::codec::Encode::encode(
&$crate::metadata::RuntimeMetadata {
outer_event: Self::outer_event_metadata(),
modules: __runtime_modules_to_metadata!($runtime;; $( $rest )*),
outer_dispatch: Self::outer_dispatch_metadata(),
}
)
pub fn metadata() -> $crate::metadata::RuntimeMetadata {
$crate::metadata::RuntimeMetadata {
outer_event: Self::outer_event_metadata(),
modules: __runtime_modules_to_metadata!($runtime;; $( $rest )*),
outer_dispatch: Self::outer_dispatch_metadata(),
}
}
}
}
@@ -105,7 +103,7 @@ mod tests {
StorageFunctionModifier, StorageFunctionType, FunctionMetadata,
StorageMetadata, StorageFunctionMetadata, OuterDispatchMetadata, OuterDispatchCall
};
use codec::Decode;
use codec::{Decode, Encode};
mod system {
pub trait Trait {
@@ -352,7 +350,7 @@ mod tests {
#[test]
fn runtime_metadata() {
let metadata_encoded = TestRuntime::metadata();
let metadata_encoded = TestRuntime::metadata().encode();
let metadata_decoded = RuntimeMetadata::decode(&mut &metadata_encoded[..]);
assert_eq!(EXPECTED_METADATA, metadata_decoded.unwrap());