Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ impl EngineInfo for Client {
})
}

fn metadata_seq(&self, block_id: BlockId) -> Option<u64> {
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)
}
Expand Down
1 change: 1 addition & 0 deletions core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub trait BlockChainTrait {

pub trait EngineInfo: Send + Sync {
fn common_params(&self, block_id: BlockId) -> Option<CommonParams>;
fn metadata_seq(&self, block_id: BlockId) -> Option<u64>;
fn block_reward(&self, block_number: u64) -> u64;
fn mining_reward(&self, block_number: u64) -> Option<u64>;
fn recommended_confirmation(&self) -> u32;
Expand Down
4 changes: 4 additions & 0 deletions core/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ impl EngineInfo for TestBlockChainClient {
unimplemented!()
}

fn metadata_seq(&self, _block_id: BlockId) -> Option<u64> {
unimplemented!()
}

fn block_reward(&self, _block_number: u64) -> u64 {
unimplemented!()
}
Expand Down
5 changes: 5 additions & 0 deletions rpc/src/v1/impls/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ where
}
}

fn get_metadata_seq(&self, block_number: Option<u64>) -> Result<Option<u64>> {
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<u64>) -> Result<Option<Vec<PlatformAddress>>> {
Ok(self.client.possible_authors(block_number).map_err(errors::core)?)
}
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/v1/traits/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ build_rpc_trait! {
#[rpc(name = "chain_getTermMetadata")]
fn get_term_metadata(&self, Option<u64>) -> Result<Option<(u64, u64)>>;

/// Return the current metadata seq at given block number
#[rpc(name = "chain_getMetadataSeq")]
fn get_metadata_seq(&self, Option<u64>) -> Result<Option<u64>>;

/// Return the valid block authors
#[rpc(name = "chain_getPossibleAuthors")]
fn get_possible_authors(&self, Option<u64>) -> Result<Option<Vec<PlatformAddress>>>;
Expand Down
29 changes: 29 additions & 0 deletions spec/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down