Update to latest substrate changes (#48)

# Conflicts:
#	Cargo.toml
#	src/rpc.rs
This commit is contained in:
Andrew Jones
2019-11-27 10:54:02 +00:00
parent 1087dc57b7
commit 1148141cf4
2 changed files with 41 additions and 25 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" }
url = "1.7"
[dev-dependencies]
+39 -23
View File
@@ -14,18 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use crate::{
error::Error,
events::{
EventsDecoder,
RuntimeEvent,
},
metadata::Metadata,
frame::{
balances::Balances,
system::System,
},
};
use futures::future::{
self,
Future,
@@ -55,7 +43,27 @@ use substrate_rpc_api::{
chain::ChainClient,
state::StateClient,
};
use substrate_rpc_primitives::number::NumberOrHex;
use substrate_rpc_primitives::{
list::ListOrValue,
number::NumberOrHex,
};
use crate::{
error::Error,
events::{
EventsDecoder,
RawEvent,
RuntimeEvent,
},
frame::{
balances::Balances,
system::{
System,
SystemEvent,
},
},
metadata::Metadata,
};
pub type ChainBlock<T> = SignedBlock<Block<<T as System>::Header, OpaqueExtrinsic>>;
pub type BlockNumber<T> = NumberOrHex<<T as System>::BlockNumber>;
@@ -102,10 +110,15 @@ 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| {
future::result(genesis_hash.ok_or("Genesis hash not found".into()))
.and_then(|list_or_value| {
future::result(
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()),
}
)
})
}
@@ -123,9 +136,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
@@ -158,11 +179,6 @@ use substrate_primitives::{
twox_128,
};
use txpool::watcher::Status;
use crate::{
events::RawEvent,
frame::system::SystemEvent,
};
use frame_system::Phase;
type MapClosure<T> = Box<dyn Fn(T) -> T + Send>;