Update to latest substrate changes (#48)

This commit is contained in:
Andrew Jones
2019-11-27 10:54:02 +00:00
committed by GitHub
parent 02e4826662
commit a6439500eb
2 changed files with 22 additions and 8 deletions
+2 -2
View File
@@ -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"
+20 -6
View File
@@ -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<T: System> Rpc<T> {
pub fn genesis_hash(&self) -> impl Future<Item = T::Hash, Error = Error> {
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<T: System> Rpc<T> {
/// Get a block hash, returns hash of latest block by default
pub fn block_hash(
&self,
hash: Option<BlockNumber<T>>,
block_number: Option<BlockNumber<T>>,
) -> impl Future<Item = Option<T::Hash>, 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