Skip to content
Snippets Groups Projects
Commit d5e27aa8 authored by Wei Tang's avatar Wei Tang
Browse files

Update substrate version

parent aca0f739
Branches
No related merge requests found
This diff is collapsed.
......@@ -6,7 +6,6 @@ authors = ["Parity Team <admin@parity.io>"]
[workspace]
members = [
"runtime",
"api",
"executor",
"util/ssz",
"util/ssz-derive",
......
[package]
name = "shasper-api"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
error-chain = "0.12"
log = "0.3"
shasper-executor = { path = "../executor" }
shasper-runtime = { path = "../runtime" }
parity-codec = "1.0"
sr-io = { git = "https://github.com/paritytech/substrate" }
sr-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-client = { git = "https://github.com/paritytech/substrate" }
substrate-primitives = { git = "https://github.com/paritytech/substrate" }
substrate-executor = { git = "https://github.com/paritytech/substrate" }
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Strongly typed API for full Polkadot client.
use client::backend::LocalBackend;
use client::block_builder::BlockBuilder as ClientBlockBuilder;
use client::{Client, LocalCallExecutor};
use shasper_executor::Executor as LocalDispatch;
use substrate_executor::NativeExecutor;
use runtime::{Block, Extrinsic, InherentData, BlockId};
use substrate_primitives::{Blake2Hasher, RlpCodec};
use {BlockBuilder, ShasperApi, LocalShasperApi, ErrorKind, Result};
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> BlockBuilder for ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec> {
fn push_extrinsic(&mut self, extrinsic: Extrinsic) -> Result<()> {
self.push(extrinsic).map_err(Into::into)
}
/// Bake the block with provided extrinsics.
fn bake(self) -> Result<Block> {
ClientBlockBuilder::bake(self).map_err(Into::into)
}
}
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> ShasperApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block> {
type BlockBuilder = ClientBlockBuilder<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block, Blake2Hasher, RlpCodec>;
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool> {
let res: Result<()> = self.call_api_at(at, "execute_block", &block).map_err(From::from);
match res {
Ok(_) => Ok(true),
Err(err) => match err.kind() {
&ErrorKind::Execution(_) => Ok(false),
_ => Err(err)
}
}
}
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder> {
let mut block_builder = self.new_block_at(at)?;
for inherent in self.inherent_extrinsics(at, inherent_data)? {
block_builder.push(inherent)?;
}
Ok(block_builder)
}
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<Extrinsic>> {
let runtime_version = self.runtime_version_at(at)?;
Ok(self.call_api_at(at, "inherent_extrinsics", &(inherent_data, runtime_version.spec_version))?)
}
}
impl<B: LocalBackend<Block, Blake2Hasher, RlpCodec>> LocalShasperApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>, Block>
{}
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Strongly typed API for Polkadot based around the locally-compiled native
//! runtime.
extern crate shasper_executor;
extern crate shasper_runtime as runtime;
extern crate parity_codec as codec;
extern crate sr_io as runtime_io;
extern crate substrate_client as client;
extern crate substrate_executor as substrate_executor;
extern crate substrate_primitives;
extern crate sr_primitives as runtime_primitives;
#[macro_use]
extern crate error_chain;
extern crate log;
pub mod full;
pub mod light;
use runtime::{InherentData, Extrinsic, Block, BlockId};
error_chain! {
errors {
/// Unknown runtime code.
UnknownRuntime {
description("Unknown runtime code")
display("Unknown runtime code")
}
/// Unknown block ID.
UnknownBlock(b: String) {
description("Unknown block")
display("Unknown block {}", b)
}
/// Execution error.
Execution(e: String) {
description("Execution error")
display("Execution error: {}", e)
}
/// Some other error.
// TODO: allow to be specified as associated type of PolkadotApi
Other(e: Box<::std::error::Error + Send>) {
description("Other error")
display("Other error: {}", e.description())
}
}
}
impl From<client::error::Error> for Error {
fn from(e: client::error::Error) -> Error {
match e {
client::error::Error(client::error::ErrorKind::UnknownBlock(b), _) => Error::from_kind(ErrorKind::UnknownBlock(b)),
client::error::Error(client::error::ErrorKind::Execution(e), _) =>
Error::from_kind(ErrorKind::Execution(format!("{}", e))),
other => Error::from_kind(ErrorKind::Other(Box::new(other) as Box<_>)),
}
}
}
/// Build new blocks.
pub trait BlockBuilder {
/// Push an extrinsic onto the block. Fails if the extrinsic is invalid.
fn push_extrinsic(&mut self, extrinsic: Extrinsic) -> Result<()>;
/// Bake the block with provided extrinsics.
fn bake(self) -> Result<Block>;
}
/// Trait encapsulating the Shasper API.
///
/// All calls should fail when the exact runtime is unknown.
pub trait ShasperApi {
/// The block builder for this API type.
type BlockBuilder: BlockBuilder;
/// Evaluate a block. Returns true if the block is good, false if it is known to be bad,
/// and an error if we can't evaluate for some reason.
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool>;
/// Build a block on top of the given, with inherent extrinsics pre-pushed.
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder>;
/// Attempt to produce the (encoded) inherent extrinsics for a block being built upon the given.
/// This may vary by runtime and will fail if a runtime doesn't follow the same API.
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<Extrinsic>>;
}
/// Mark for all Shasper API implementations, that are making use of state data, stored locally.
pub trait LocalShasperApi: ShasperApi {}
/// Mark for all Shasper API implementations, that are fetching required state data from remote nodes.
pub trait RemoteShasperApi: ShasperApi {}
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Strongly typed API for light Polkadot client.
use std::sync::Arc;
use client::backend::{Backend, RemoteBackend};
use client::{Client, CallExecutor};
use runtime::{Block, Extrinsic, InherentData, BlockId};
use {ShasperApi, RemoteShasperApi, BlockBuilder, Result, ErrorKind};
use substrate_primitives::{Blake2Hasher, RlpCodec};
/// Light block builder. TODO: make this work (efficiently)
#[derive(Clone, Copy)]
pub struct LightBlockBuilder;
impl BlockBuilder for LightBlockBuilder {
fn push_extrinsic(&mut self, _xt: Extrinsic) -> Result<()> {
Err(ErrorKind::UnknownRuntime.into())
}
fn bake(self) -> Result<Block> {
Err(ErrorKind::UnknownRuntime.into())
}
}
/// Remote polkadot API implementation.
pub struct RemoteShasperApiWrapper<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>>(pub Arc<Client<B, E, Block>>);
impl<B: Backend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> ShasperApi for RemoteShasperApiWrapper<B, E> {
type BlockBuilder = LightBlockBuilder;
fn evaluate_block(&self, _at: &BlockId, _block: Block) -> Result<bool> {
Err(ErrorKind::UnknownRuntime.into())
}
fn build_block(&self, _at: &BlockId, _inherent: InherentData) -> Result<Self::BlockBuilder> {
Err(ErrorKind::UnknownRuntime.into())
}
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<Extrinsic>> {
Err(ErrorKind::UnknownRuntime.into())
}
}
impl<B: RemoteBackend<Block, Blake2Hasher, RlpCodec>, E: CallExecutor<Block, Blake2Hasher, RlpCodec>> RemoteShasperApi for RemoteShasperApiWrapper<B, E> {}
......@@ -4,4 +4,5 @@ extern crate substrate_primitives as primitives;
pub extern crate shasper_runtime as runtime;
native_executor_instance!(pub Executor, runtime::api::dispatch, runtime::VERSION, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/shasper_runtime.compact.wasm"));
pub use executor::NativeExecutor;
native_executor_instance!(pub Executor, runtime::api::dispatch, runtime::native_version, include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/shasper_runtime.compact.wasm"));
......@@ -8,8 +8,8 @@ blake2 = "0.7"
tiny-keccak = "1.4.2"
hashdb = { version = "0.2.1", default-features = false }
plain_hasher = { version = "0.2", default-features = false }
parity-codec = { version = "1.0", default-features = false }
parity-codec-derive = { version = "1.0", default-features = false }
parity-codec = { version = "2.0", default-features = false }
parity-codec-derive = { version = "2.0", default-features = false }
ssz = { path = "../util/ssz", default-features = false }
ssz-derive = { path = "../util/ssz-derive", default-features = false }
bls = { git = "https://github.com/sorpaas/bls", default-features = false }
......
......@@ -57,7 +57,7 @@ pub use bitfield::BitField;
use primitives::{H256, H160};
use rstd::prelude::*;
use runtime_version::RuntimeVersion;
use runtime_version::{RuntimeVersion, NativeVersion};
/// Shasper runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion {
......@@ -69,8 +69,12 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: apis_vec!([]),
};
fn version() -> RuntimeVersion {
VERSION
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion {
runtime_version: VERSION,
can_author_with: Default::default(),
}
}
pub type Hash = H256;
......@@ -91,6 +95,6 @@ pub mod api {
active_state_root => |()| system::active_state_root(),
crystallized_state_root => |()| system::crystallized_state_root(),
authorities => |()| system::authorities(),
version => |()| ::version()
version => |()| ::VERSION
);
}
......@@ -8,8 +8,8 @@ blake2 = "0.7"
tiny-keccak = "1.4.2"
hashdb = { version = "0.2.1", default-features = false }
plain_hasher = { version = "0.2", default-features = false }
parity-codec = { version = "1.0", default-features = false }
parity-codec-derive = { version = "1.0", default-features = false }
parity-codec = { version = "2.0", default-features = false }
parity-codec-derive = { version = "2.0", default-features = false }
ssz = { path = "../../util/ssz", default-features = false }
ssz-derive = { path = "../../util/ssz-derive", default-features = false }
bls = { git = "https://github.com/sorpaas/bls", default-features = false }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment