From a6439500ebc007e3806de48fd013212a7af1a648 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 27 Nov 2019 10:54:02 +0000 Subject: [PATCH] Update to latest substrate changes (#48) --- Cargo.toml | 4 ++-- src/rpc.rs | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a88b7213b..6988c13252 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,10 +28,10 @@ frame-system = { git = "https://github.com/paritytech/substrate/", package = "fr pallet-balances = { git = "https://github.com/paritytech/substrate/", package = "pallet-balances" } pallet-contracts = { git = "https://github.com/paritytech/substrate/", package = "pallet-contracts" } pallet-indices = { git = "https://github.com/paritytech/substrate/", package = "pallet-indices" } -substrate-rpc-api = { git = "https://github.com/paritytech/substrate/", package = "substrate-rpc-api" } +substrate-rpc-api = { git = "https://github.com/paritytech/substrate/", package = "sc-rpc-api" } substrate-rpc-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-rpc-primitives" } substrate-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-primitives" } -txpool = { git = "https://github.com/paritytech/substrate/", package = "substrate-transaction-graph" } +txpool = { git = "https://github.com/paritytech/substrate/", package = "sc-transaction-graph" } [dev-dependencies] env_logger = "0.7" diff --git a/src/rpc.rs b/src/rpc.rs index 9b0ec92e96..fbbfdd456e 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -61,7 +61,10 @@ use substrate_rpc_api::{ chain::ChainClient, state::StateClient, }; -use substrate_rpc_primitives::number::NumberOrHex; +use substrate_rpc_primitives::{ + list::ListOrValue, + number::NumberOrHex, +}; use txpool::watcher::Status; use crate::{ @@ -126,11 +129,14 @@ impl Rpc { pub fn genesis_hash(&self) -> impl Future { let block_zero = T::BlockNumber::min_value(); self.chain - .block_hash(Some(NumberOrHex::Number(block_zero))) + .block_hash(Some(ListOrValue::Value(NumberOrHex::Number(block_zero)))) .map_err(Into::into) - .and_then(|genesis_hash| { + .and_then(|list_or_value| { future::result( - genesis_hash.ok_or_else(|| "Genesis hash not found".into()), + match list_or_value { + ListOrValue::Value(genesis_hash) => genesis_hash.ok_or_else(|| "Genesis hash not found".into()), + ListOrValue::List(_) => Err("Expected a Value, got a List".into()), + } ) }) } @@ -149,9 +155,17 @@ impl Rpc { /// Get a block hash, returns hash of latest block by default pub fn block_hash( &self, - hash: Option>, + block_number: Option>, ) -> impl Future, Error = Error> { - self.chain.block_hash(hash).map_err(Into::into) + self.chain + .block_hash(block_number.map(|bn| ListOrValue::Value(bn))) + .map_err(Into::into) + .and_then(|list_or_value| { + match list_or_value { + ListOrValue::Value(hash) => Ok(hash), + ListOrValue::List(_) => Err("Expected a Value, got a List".into()), + } + }) } /// Get a Block