From 238b2af83b4711c998bbf09bc6a19a1726f23431 Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Mon, 17 Jun 2019 17:22:46 +0900 Subject: [PATCH 1/2] Add the spec of chain_getMetadataSeq --- spec/JSON-RPC.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/JSON-RPC.md b/spec/JSON-RPC.md index dd73077c4d..7fffa017d1 100644 --- a/spec/JSON-RPC.md +++ b/spec/JSON-RPC.md @@ -1467,6 +1467,35 @@ Errors: `Invalid Params` [Back to **List of methods**](#list-of-methods) +# chain_getMetadataSeq +Gets the sequence of metadata. +It returns null if the block number parameter is larger than the current best block. + +### Params + 1. block number - `number` | `null` + +### Returns +`number` | `null` + +### Request Example +``` + curl \ + -H 'Content-Type: application/json' \ + -d '{"jsonrpc": "2.0", "method": "chain_getMeatadataSeq", "params": [53], "id": 7}' \ + localhost:8080 +``` + +### Response Example +``` +{ + "jsonrpc":"2.0", + "result":43, + "id":7 +} +``` + +[Back to **List of methods**](#list-of-methods) + ## chain_executeTransaction Executes the transactions and returns whether the execution is successful. From 175bc6c84e254f00780c454307e42aac8bb3f99f Mon Sep 17 00:00:00 2001 From: Juhyung Park Date: Mon, 17 Jun 2019 17:45:28 +0900 Subject: [PATCH 2/2] Add `chain_getMetadataSeq` RPC --- core/src/client/client.rs | 10 ++++++++++ core/src/client/mod.rs | 1 + core/src/client/test_client.rs | 4 ++++ rpc/src/v1/impls/chain.rs | 5 +++++ rpc/src/v1/traits/chain.rs | 4 ++++ 5 files changed, 24 insertions(+) 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>>;