mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 03:11:01 +00:00
Hex-encode block number. (#1389)
This commit is contained in:
@@ -33,6 +33,7 @@ use subscriptions::Subscriptions;
|
||||
mod error;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod number;
|
||||
|
||||
use self::error::Result;
|
||||
|
||||
@@ -56,7 +57,7 @@ build_rpc_trait! {
|
||||
///
|
||||
/// By default returns latest block hash.
|
||||
#[rpc(name = "chain_getBlockHash", alias = ["chain_getHead", ])]
|
||||
fn block_hash(&self, Trailing<Number>) -> Result<Option<Hash>>;
|
||||
fn block_hash(&self, Trailing<number::NumberOrHex<Number>>) -> Result<Option<Hash>>;
|
||||
|
||||
/// Get hash of the last finalised block in the canon chain.
|
||||
#[rpc(name = "chain_getFinalisedHead")]
|
||||
@@ -172,10 +173,11 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
|
||||
Ok(self.client.block(&BlockId::Hash(hash))?)
|
||||
}
|
||||
|
||||
fn block_hash(&self, number: Trailing<NumberFor<Block>>) -> Result<Option<Block::Hash>> {
|
||||
Ok(match number.into() {
|
||||
fn block_hash(&self, number: Trailing<number::NumberOrHex<NumberFor<Block>>>) -> Result<Option<Block::Hash>> {
|
||||
let number: Option<number::NumberOrHex<NumberFor<Block>>> = number.into();
|
||||
Ok(match number {
|
||||
None => Some(self.client.info()?.chain.best_hash),
|
||||
Some(number) => self.client.header(&BlockId::number(number))?.map(|h| h.hash()),
|
||||
Some(num_or_hex) => self.client.header(&BlockId::number(num_or_hex.to_number()?))?.map(|h| h.hash()),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user