Skip to content

Commit b40f9ec

Browse files
committed
Add chain_getRawHeaderByNumber RPC
To create a light client we need raw bytes of a header. It will be included in the CreateClient datagram.
1 parent 94363b5 commit b40f9ec

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

rpc/src/v1/impls/chain.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ctypes::transaction::Action;
2626
use ctypes::{BlockHash, BlockNumber, ShardId, Tracker, TxHash};
2727
use jsonrpc_core::Result;
2828
use primitives::H256;
29+
use rustc_hex::ToHex;
2930
use std::convert::TryFrom;
3031
use std::sync::Arc;
3132

@@ -172,6 +173,11 @@ where
172173
}))
173174
}
174175

176+
fn get_raw_header_by_number(&self, block_number: u64) -> Result<Option<String>> {
177+
let id = BlockId::Number(block_number);
178+
Ok(self.client.block_header(&id).map(|header| header.into_inner().as_slice().to_hex()))
179+
}
180+
175181
fn get_block_transaction_count_by_hash(&self, block_hash: BlockHash) -> Result<Option<usize>> {
176182
Ok(self.client.block(&BlockId::Hash(block_hash)).map(|block| block.transactions_count()))
177183
}

rpc/src/v1/traits/chain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ pub trait Chain {
107107
#[rpc(name = "chain_getBlockTransactionCountByHash")]
108108
fn get_block_transaction_count_by_hash(&self, block_hash: BlockHash) -> Result<Option<usize>>;
109109

110+
///Gets the raw bytes of a header with given number.
111+
#[rpc(name = "chain_getRawHeaderByNumber")]
112+
fn get_raw_header_by_number(&self, block_number: u64) -> Result<Option<String>>;
113+
110114
///Gets the minimum transaction fee of the given name.
111115
#[rpc(name = "chain_getMinTransactionFee")]
112116
fn get_min_transaction_fee(&self, action_type: String, block_number: Option<u64>) -> Result<Option<u64>>;

0 commit comments

Comments
 (0)