mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Encode Metadata once instead of two times (#946)
This commit is contained in:
@@ -346,11 +346,6 @@ impl<B, E, Block> Client<B, E, Block> where
|
||||
&self.executor
|
||||
}
|
||||
|
||||
/// Returns the runtime metadata.
|
||||
pub fn metadata(&self, id: &BlockId<Block>) -> error::Result<Vec<u8>> {
|
||||
self.executor.call(id, "metadata",&[]).map(|v| v.return_data)
|
||||
}
|
||||
|
||||
/// Reads storage value at a given block + key, returning read proof.
|
||||
pub fn read_proof(&self, id: &BlockId<Block>, key: &[u8]) -> error::Result<Vec<Vec<u8>>> {
|
||||
self.state_at(id)
|
||||
@@ -1074,7 +1069,7 @@ impl<B, E, Block> api::Core<Block, AuthorityId> for Client<B, E, Block> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, E, Block> api::Metadata<Block> for Client<B, E, Block> where
|
||||
impl<B, E, Block> api::Metadata<Block, Vec<u8>> for Client<B, E, Block> where
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT,
|
||||
@@ -1082,7 +1077,7 @@ impl<B, E, Block> api::Metadata<Block> for Client<B, E, Block> where
|
||||
type Error = Error;
|
||||
|
||||
fn metadata(&self, at: &BlockId<Block>) -> Result<Vec<u8>, Self::Error> {
|
||||
self.call_api_at(at, "metadata", &())
|
||||
self.executor.call(at, "metadata",&[]).map(|v| v.return_data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use client::{self, Client, CallExecutor, BlockchainEvents};
|
||||
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
||||
use jsonrpc_macros::Trailing;
|
||||
use jsonrpc_macros::pubsub;
|
||||
use jsonrpc_pubsub::SubscriptionId;
|
||||
|
||||
@@ -436,8 +436,8 @@ decl_apis! {
|
||||
}
|
||||
|
||||
/// The `Metadata` api trait that returns metadata for the runtime.
|
||||
pub trait Metadata {
|
||||
fn metadata() -> Vec<u8>;
|
||||
pub trait Metadata<Data> {
|
||||
fn metadata() -> Data;
|
||||
}
|
||||
|
||||
/// The `OldTxQueue` api trait for interfering with the old transaction queue.
|
||||
|
||||
@@ -81,7 +81,7 @@ pub use timestamp::Call as TimestampCall;
|
||||
pub use balances::Call as BalancesCall;
|
||||
pub use runtime_primitives::{Permill, Perbill};
|
||||
pub use timestamp::BlockPeriod;
|
||||
pub use srml_support::StorageValue;
|
||||
pub use srml_support::{StorageValue, RuntimeMetadata};
|
||||
|
||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
||||
@@ -246,8 +246,8 @@ impl_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl Metadata for Runtime {
|
||||
fn metadata() -> Vec<u8> {
|
||||
impl Metadata<RuntimeMetadata> for Runtime {
|
||||
fn metadata() -> RuntimeMetadata {
|
||||
Runtime::metadata()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user