diff --git a/core/src/client/client.rs b/core/src/client/client.rs index 8aa8507662..a5016c5bfe 100644 --- a/core/src/client/client.rs +++ b/core/src/client/client.rs @@ -505,6 +505,16 @@ impl EngineInfo for Client { }) } + fn metadata_seq(&self, block_id: BlockId) -> Option { + self.state_info(block_id.into()).map(|state| { + state + .metadata() + .unwrap_or_else(|err| unreachable!("Unexpected failure. Maybe DB was corrupted: {:?}", err)) + .unwrap() + .seq() + }) + } + fn block_reward(&self, block_number: u64) -> u64 { self.engine().block_reward(block_number) } diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index 480d555aa8..66877e16df 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -88,6 +88,7 @@ pub trait BlockChainTrait { pub trait EngineInfo: Send + Sync { fn common_params(&self, block_id: BlockId) -> Option; + fn metadata_seq(&self, block_id: BlockId) -> Option; fn block_reward(&self, block_number: u64) -> u64; fn mining_reward(&self, block_number: u64) -> Option; fn recommended_confirmation(&self) -> u32; diff --git a/core/src/client/test_client.rs b/core/src/client/test_client.rs index 18dfa2c7ac..9fd640b1b9 100644 --- a/core/src/client/test_client.rs +++ b/core/src/client/test_client.rs @@ -589,6 +589,10 @@ impl EngineInfo for TestBlockChainClient { unimplemented!() } + fn metadata_seq(&self, _block_id: BlockId) -> Option { + unimplemented!() + } + fn block_reward(&self, _block_number: u64) -> u64 { unimplemented!() } diff --git a/rpc/src/v1/impls/chain.rs b/rpc/src/v1/impls/chain.rs index 0a870eeb22..a1b6db2645 100644 --- a/rpc/src/v1/impls/chain.rs +++ b/rpc/src/v1/impls/chain.rs @@ -316,6 +316,11 @@ where } } + fn get_metadata_seq(&self, block_number: Option) -> Result> { + let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest); + Ok(self.client.metadata_seq(block_id)) + } + fn get_possible_authors(&self, block_number: Option) -> Result>> { Ok(self.client.possible_authors(block_number).map_err(errors::core)?) } diff --git a/rpc/src/v1/traits/chain.rs b/rpc/src/v1/traits/chain.rs index 8c6f357260..db4a0620b4 100644 --- a/rpc/src/v1/traits/chain.rs +++ b/rpc/src/v1/traits/chain.rs @@ -145,6 +145,10 @@ build_rpc_trait! { #[rpc(name = "chain_getTermMetadata")] fn get_term_metadata(&self, Option) -> Result>; + /// Return the current metadata seq at given block number + #[rpc(name = "chain_getMetadataSeq")] + fn get_metadata_seq(&self, Option) -> Result>; + /// Return the valid block authors #[rpc(name = "chain_getPossibleAuthors")] fn get_possible_authors(&self, Option) -> Result>>;