mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Move inherent implementation into the modules (#924)
* Adds new `ProvideInherent` trait Also implements the new trait for `srml/consensus` and `srml/timestamp`. * Adds `impl_outer_inherent!` macro * Reexport macros from `alloc` * Introduce `RuntimeString` and fix `ProvideInherent` on `no_std` * Replace `VersionString` with `RuntimeString` * Improvements for `impl_outer_inherent!` * Make `construct_runtime!` support `impl_outer_inherent!` * Fixes after rebase * Whitespace
This commit is contained in:
+5
-5
@@ -91,7 +91,7 @@ pub struct Fork<Block: BlockT, T> {
|
||||
head: Entry<Block, T>,
|
||||
}
|
||||
|
||||
/// Outcome of Fork::try_append_or_fork.
|
||||
/// Outcome of Fork::try_append_or_fork.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
pub enum ForkAppendResult<Block: BlockT> {
|
||||
@@ -356,7 +356,7 @@ impl<Block: BlockT, T: CacheItemT, S: Storage<Block, T>> ListCache<Block, T, S>
|
||||
|
||||
// if there's an entry at this block:
|
||||
// - remove reference from this entry to the previous entry
|
||||
// - destroy fork starting with previous entry
|
||||
// - destroy fork starting with previous entry
|
||||
let current_entry = match self.storage.read_entry(&ancient_block)? {
|
||||
Some(current_entry) => current_entry,
|
||||
None => return Ok(()),
|
||||
@@ -583,12 +583,12 @@ fn read_forks<Block: BlockT, T: CacheItemT, S: Storage<Block, T>>(
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use runtime_primitives::testing::{Header, Block as RawBlock};
|
||||
use runtime_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
|
||||
use runtime_primitives::traits::Header as HeaderT;
|
||||
use cache::list_storage::tests::{DummyStorage, FaultyStorage, DummyTransaction};
|
||||
use super::*;
|
||||
|
||||
type Block = RawBlock<u64>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
pub fn test_id(number: u64) -> ComplexBlockId<Block> {
|
||||
ComplexBlockId::new(From::from(number), number)
|
||||
@@ -834,7 +834,7 @@ pub mod tests {
|
||||
// when trying to insert block @ finalized number
|
||||
assert!(ListCache::new(DummyStorage::new(), 1024, test_id(100))
|
||||
.on_block_insert(&mut DummyTransaction::new(), test_id(99), test_id(100), Some(100), false).unwrap().is_none());
|
||||
|
||||
|
||||
// when trying to insert non-final block AND it appends to the best block of unfinalized fork
|
||||
// AND new value is the same as in the fork' best block
|
||||
let mut cache = ListCache::new(
|
||||
|
||||
@@ -865,11 +865,11 @@ mod tests {
|
||||
use client::backend::Backend as BTrait;
|
||||
use client::backend::BlockImportOperation as Op;
|
||||
use client::blockchain::HeaderBackend as BlockchainHeaderBackend;
|
||||
use runtime_primitives::testing::{Header, Block as RawBlock};
|
||||
use runtime_primitives::testing::{Header, Block as RawBlock, ExtrinsicWrapper};
|
||||
use state_machine::{TrieMut, TrieDBMut, ChangesTrieRootsStorage, ChangesTrieStorage};
|
||||
use test_client;
|
||||
|
||||
type Block = RawBlock<u64>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
fn prepare_changes(changes: Vec<(Vec<u8>, Vec<u8>)>) -> (H256, MemoryDB<Blake2Hasher>) {
|
||||
let mut changes_root = H256::default();
|
||||
|
||||
@@ -402,10 +402,10 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use client::cht;
|
||||
use runtime_primitives::testing::{H256 as Hash, Header, Block as RawBlock};
|
||||
use runtime_primitives::testing::{H256 as Hash, Header, Block as RawBlock, ExtrinsicWrapper};
|
||||
use super::*;
|
||||
|
||||
type Block = RawBlock<u32>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<u32>>;
|
||||
|
||||
fn prepare_header(parent: &Hash, number: u64, extrinsics_root: Hash) -> Header {
|
||||
Header {
|
||||
|
||||
@@ -1126,12 +1126,12 @@ impl<B, E, Block> api::BlockBuilder<Block> for Client<B, E, Block> where
|
||||
self.call_api_at(at, "inherent_extrinsics", &(inherent))
|
||||
}
|
||||
|
||||
fn check_inherents<InherentData: Encode + Decode>(
|
||||
fn check_inherents<InherentData: Encode + Decode, InherentError: Encode + Decode>(
|
||||
&self,
|
||||
at: &BlockId<Block>,
|
||||
block: &Block,
|
||||
data: &InherentData
|
||||
) -> Result<Result<(), api::BlockBuilderError>, Self::Error> {
|
||||
) -> Result<Result<(), InherentError>, Self::Error> {
|
||||
self.call_api_at(at, "check_inherents", &(block, data))
|
||||
}
|
||||
|
||||
|
||||
@@ -179,11 +179,10 @@ impl<Block: BlockT> StorageNotifications<Block> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use runtime_primitives::testing::{H256 as Hash, Block as RawBlock};
|
||||
use runtime_primitives::testing::{H256 as Hash, Block as RawBlock, ExtrinsicWrapper};
|
||||
use super::*;
|
||||
use futures::Stream;
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
impl From<Vec<(StorageKey, Option<StorageData>)>> for StorageChangeSet {
|
||||
fn from(changes: Vec<(StorageKey, Option<StorageData>)>) -> Self {
|
||||
@@ -201,7 +200,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
type Block = RawBlock<Hash>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<Hash>>;
|
||||
|
||||
#[test]
|
||||
fn triggering_change_should_notify_wildcard_listeners() {
|
||||
|
||||
@@ -195,10 +195,10 @@ impl<B: BlockT> BlockCollection<B> {
|
||||
mod test {
|
||||
use super::{BlockCollection, BlockData, BlockRangeState};
|
||||
use message;
|
||||
use runtime_primitives::testing::Block as RawBlock;
|
||||
use runtime_primitives::testing::{Block as RawBlock, ExtrinsicWrapper};
|
||||
use primitives::H256;
|
||||
|
||||
type Block = RawBlock<u64>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
fn is_empty(bc: &BlockCollection<Block>) -> bool {
|
||||
bc.blocks.is_empty() &&
|
||||
|
||||
@@ -310,11 +310,11 @@ impl<Block: BlockT> Specialization<Block> for ConsensusGossip<Block> where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use runtime_primitives::testing::{H256, Block as RawBlock};
|
||||
use runtime_primitives::testing::{H256, Block as RawBlock, ExtrinsicWrapper};
|
||||
use std::time::Instant;
|
||||
use super::*;
|
||||
|
||||
type Block = RawBlock<u64>;
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
#[test]
|
||||
fn collects_garbage() {
|
||||
|
||||
@@ -5,7 +5,6 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
parity-codec = { version = "2.1", default-features = false }
|
||||
parity-codec-derive = { version = "2.1", default-features = false }
|
||||
sr-std = { path = "../sr-std", default-features = false }
|
||||
sr-primitives = { path = "../sr-primitives", default-features = false }
|
||||
sr-version = { path = "../sr-version", default-features = false }
|
||||
@@ -15,7 +14,6 @@ default = ["std"]
|
||||
std = [
|
||||
"sr-std/std",
|
||||
"parity-codec/std",
|
||||
"parity-codec-derive/std",
|
||||
"sr-primitives/std",
|
||||
"sr-version/std",
|
||||
]
|
||||
|
||||
@@ -22,8 +22,6 @@ extern crate sr_std as rstd;
|
||||
extern crate sr_primitives as primitives;
|
||||
#[doc(hidden)]
|
||||
pub extern crate parity_codec as codec;
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
extern crate sr_version as runtime_version;
|
||||
|
||||
#[doc(hidden)]
|
||||
@@ -429,17 +427,6 @@ macro_rules! decl_apis {
|
||||
};
|
||||
}
|
||||
|
||||
//TODO: Move into runtime!
|
||||
#[derive(Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Decode))]
|
||||
pub enum BlockBuilderError {
|
||||
#[cfg(not(feature = "std"))]
|
||||
Generic(&'static str),
|
||||
#[cfg(feature = "std")]
|
||||
Generic(String),
|
||||
TimestampInFuture(u64),
|
||||
}
|
||||
|
||||
decl_apis! {
|
||||
/// The `Core` api trait that is mandantory for each runtime.
|
||||
pub trait Core<Block: BlockT, AuthorityId> {
|
||||
@@ -482,7 +469,7 @@ decl_apis! {
|
||||
/// Generate inherent extrinsics.
|
||||
fn inherent_extrinsics<InherentExtrinsic, UncheckedExtrinsic>(inherent: InherentExtrinsic) -> Vec<UncheckedExtrinsic>;
|
||||
/// Check that the inherents are valid.
|
||||
fn check_inherents<InherentData>(block: Block, data: InherentData) -> Result<(), BlockBuilderError>;
|
||||
fn check_inherents<InherentData, Error>(block: Block, data: InherentData) -> Result<(), Error>;
|
||||
/// Generate a random seed.
|
||||
fn random_seed() -> <Block as BlockT>::Hash;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ parity-codec-derive = { version = "2.1", default-features = false }
|
||||
substrate-primitives = { path = "../primitives", default-features = false }
|
||||
sr-std = { path = "../sr-std", default-features = false }
|
||||
sr-io = { path = "../sr-io", default-features = false }
|
||||
sr-version = { path = "../sr-version", default-features = false }
|
||||
log = {version = "0.4", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
@@ -28,7 +27,6 @@ std = [
|
||||
"log",
|
||||
"sr-std/std",
|
||||
"sr-io/std",
|
||||
"sr-version/std",
|
||||
"parity-codec/std",
|
||||
"substrate-primitives/std",
|
||||
]
|
||||
|
||||
@@ -72,7 +72,7 @@ pub struct Block<Header, Extrinsic> {
|
||||
impl<Header, Extrinsic> traits::Block for Block<Header, Extrinsic>
|
||||
where
|
||||
Header: HeaderT,
|
||||
Extrinsic: Member + Codec,
|
||||
Extrinsic: Member + Codec + traits::Extrinsic,
|
||||
{
|
||||
type Extrinsic = Extrinsic;
|
||||
type Header = Header;
|
||||
@@ -102,4 +102,4 @@ pub struct SignedBlock<H, E> {
|
||||
pub block: Block<H, E>,
|
||||
/// Block justification.
|
||||
pub justification: Justification,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::fmt;
|
||||
use rstd::prelude::*;
|
||||
use codec::{Decode, Encode, Input};
|
||||
use traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup,
|
||||
Checkable};
|
||||
Checkable, Extrinsic};
|
||||
use super::{CheckedExtrinsic, Era};
|
||||
|
||||
const TRANSACTION_VERSION: u8 = 1;
|
||||
@@ -56,10 +56,11 @@ impl<Address, Index, Call, Signature> UncheckedMortalExtrinsic<Address, Index, C
|
||||
function,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `true` if there is a signature.
|
||||
pub fn is_signed(&self) -> bool {
|
||||
self.signature.is_some()
|
||||
impl<Address, Index, Call, Signature> Extrinsic for UncheckedMortalExtrinsic<Address, Index, Call, Signature> {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
Some(self.signature.is_some())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,49 +222,49 @@ mod tests {
|
||||
#[test]
|
||||
fn unsigned_check_should_work() {
|
||||
let ux = Ex::new_unsigned(DUMMY_FUNCTION);
|
||||
assert!(!ux.is_signed());
|
||||
assert!(!ux.is_signed().unwrap_or(false));
|
||||
assert!(<Ex as Checkable<TestContext>>::check(ux, &TestContext).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn badly_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, vec![0u8]), Era::immortal());
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn immortal_signed_check_should_work() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, DUMMY_FUNCTION, Era::immortal(), 0u64).encode()), Era::immortal());
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: DUMMY_FUNCTION }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mortal_signed_check_should_work() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, DUMMY_FUNCTION, Era::mortal(32, 42), 42u64).encode()), Era::mortal(32, 42));
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: DUMMY_FUNCTION }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn later_mortal_signed_check_should_work() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, DUMMY_FUNCTION, Era::mortal(32, 11), 11u64).encode()), Era::mortal(32, 11));
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: DUMMY_FUNCTION }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_late_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, DUMMY_FUNCTION, Era::mortal(32, 10), 10u64).encode()), Era::mortal(32, 10));
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_early_mortal_signed_check_should_fail() {
|
||||
let ux = Ex::new_signed(0, DUMMY_FUNCTION, DUMMY_ACCOUNTID, TestSig(DUMMY_ACCOUNTID, (DUMMY_ACCOUNTID, DUMMY_FUNCTION, Era::mortal(32, 43), 43u64).encode()), Era::mortal(32, 43));
|
||||
assert!(ux.is_signed());
|
||||
assert!(ux.is_signed().unwrap_or(false));
|
||||
assert_eq!(<Ex as Checkable<TestContext>>::check(ux, &TestContext), Err("bad signature in extrinsic"));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ extern crate num_traits;
|
||||
extern crate integer_sqrt;
|
||||
extern crate sr_std as rstd;
|
||||
extern crate sr_io as runtime_io;
|
||||
extern crate sr_version as runtime_version;
|
||||
#[doc(hidden)]
|
||||
pub extern crate parity_codec as codec;
|
||||
extern crate substrate_primitives;
|
||||
@@ -65,6 +64,12 @@ pub type Justification = Vec<u8>;
|
||||
|
||||
use traits::{Verify, Lazy};
|
||||
|
||||
/// A String that is a `&'static str` on `no_std` and a `String` on `std`.
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub type RuntimeString = &'static str;
|
||||
#[cfg(feature = "std")]
|
||||
pub type RuntimeString = ::std::borrow::Cow<'static, str>;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
//! Testing utilities.
|
||||
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::fmt::Debug;
|
||||
use std::{fmt::Debug, ops::Deref};
|
||||
use codec::Codec;
|
||||
use traits::{self, Checkable, Applyable, BlakeTwo256};
|
||||
use generic::DigestItem as GenDigestItem;
|
||||
@@ -93,13 +93,36 @@ impl traits::Header for Header {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
|
||||
pub struct ExtrinsicWrapper<Xt>(Xt);
|
||||
|
||||
impl<Xt> traits::Extrinsic for ExtrinsicWrapper<Xt> {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<Xt> From<Xt> for ExtrinsicWrapper<Xt> {
|
||||
fn from(xt: Xt) -> Self {
|
||||
ExtrinsicWrapper(xt)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Xt> Deref for ExtrinsicWrapper<Xt> {
|
||||
type Target = Xt;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize, Debug, Encode, Decode)]
|
||||
pub struct Block<Xt> {
|
||||
pub header: Header,
|
||||
pub extrinsics: Vec<Xt>,
|
||||
}
|
||||
|
||||
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug> traits::Block for Block<Xt> {
|
||||
impl<Xt: 'static + Codec + Sized + Send + Sync + Serialize + DeserializeOwned + Clone + Eq + Debug + traits::Extrinsic> traits::Block for Block<Xt> {
|
||||
type Extrinsic = Xt;
|
||||
type Header = Header;
|
||||
type Hash = <Header as traits::Header>::Hash;
|
||||
@@ -125,6 +148,11 @@ impl<Call: Codec + Sync + Send + Serialize, Context> Checkable<Context> for Test
|
||||
type Checked = Self;
|
||||
fn check(self, _: &Context) -> Result<Self::Checked, &'static str> { Ok(self) }
|
||||
}
|
||||
impl<Call: Codec + Sync + Send + Serialize> traits::Extrinsic for TestXt<Call> {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
}
|
||||
impl<Call> Applyable for TestXt<Call> where
|
||||
Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Serialize + DeserializeOwned,
|
||||
{
|
||||
|
||||
@@ -383,6 +383,17 @@ pub trait MaybeDisplay {}
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> MaybeDisplay for T {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub trait MaybeDecode: ::codec::Decode {}
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: ::codec::Decode> MaybeDecode for T {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub trait MaybeDecode {}
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> MaybeDecode for T {}
|
||||
|
||||
|
||||
pub trait Member: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + MaybeSerializeDebug + Eq + PartialEq + Clone + 'static> Member for T {}
|
||||
|
||||
@@ -430,7 +441,7 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'stat
|
||||
///
|
||||
/// You can get an iterator over each of the `extrinsics` and retrieve the `header`.
|
||||
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebug + 'static {
|
||||
type Extrinsic: Member + Codec;
|
||||
type Extrinsic: Member + Codec + Extrinsic;
|
||||
type Header: Header<Hash=Self::Hash>;
|
||||
type Hash: Member + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
|
||||
|
||||
@@ -532,3 +543,32 @@ pub trait DigestItem: Codec + Member {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Something that provides an inherent for a runtime.
|
||||
pub trait ProvideInherent {
|
||||
/// The inherent that is provided.
|
||||
type Inherent: Encode + MaybeDecode;
|
||||
/// The error used by this trait.
|
||||
type Error: Encode + MaybeDecode;
|
||||
/// The call for setting the inherent.
|
||||
type Call: Encode + MaybeDecode;
|
||||
|
||||
/// Create the inherent extrinsics.
|
||||
///
|
||||
/// # Return
|
||||
///
|
||||
/// Returns a vector with tuples containing the index for the extrinsic and the extrinsic itself.
|
||||
fn create_inherent_extrinsics(data: Self::Inherent) -> Vec<(u32, Self::Call)>;
|
||||
|
||||
/// Check that the given inherent is valid.
|
||||
fn check_inherent<Block: self::Block, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
|
||||
block: &Block, data: Self::Inherent, extract_function: &F
|
||||
) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
/// Something that acts like an `Extrinsic`.
|
||||
pub trait Extrinsic {
|
||||
/// Is this `Extrinsic` signed?
|
||||
/// If no information are available about signed/unsigned, `None` should be returned.
|
||||
fn is_signed(&self) -> Option<bool>;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
extern crate alloc;
|
||||
#[doc(hidden)]
|
||||
pub extern crate alloc;
|
||||
|
||||
extern "C" {
|
||||
fn ext_malloc(size: usize) -> *mut u8;
|
||||
|
||||
@@ -9,6 +9,7 @@ serde_derive = { version = "1.0", optional = true }
|
||||
parity-codec = { version = "2.1", default-features = false }
|
||||
parity-codec-derive = { version = "2.1", default-features = false }
|
||||
sr-std = { path = "../sr-std", default-features = false }
|
||||
sr-primitives = { path = "../sr-primitives", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
@@ -17,4 +18,5 @@ std = [
|
||||
"serde_derive",
|
||||
"parity-codec/std",
|
||||
"sr-std/std",
|
||||
"sr-primitives/std",
|
||||
]
|
||||
|
||||
@@ -29,15 +29,14 @@ extern crate sr_std as rstd;
|
||||
#[macro_use]
|
||||
extern crate parity_codec_derive;
|
||||
|
||||
extern crate sr_primitives as runtime_primitives;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::fmt;
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub type VersionString = ::std::borrow::Cow<'static, str>;
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub type VersionString = &'static str;
|
||||
use runtime_primitives::RuntimeString;
|
||||
|
||||
/// The identity of a particular API interface that the runtime might provide.
|
||||
pub type ApiId = [u8; 8];
|
||||
@@ -80,14 +79,14 @@ pub struct RuntimeVersion {
|
||||
/// Identifies the different Substrate runtimes. There'll be at least polkadot and node.
|
||||
/// A different on-chain spec_name to that of the native runtime would normally result
|
||||
/// in node not attempting to sync or author blocks.
|
||||
pub spec_name: VersionString,
|
||||
pub spec_name: RuntimeString,
|
||||
|
||||
/// Name of the implementation of the spec. This is of little consequence for the node
|
||||
/// and serves only to differentiate code of different implementation teams. For this
|
||||
/// codebase, it will be parity-polkadot. If there were a non-Rust implementation of the
|
||||
/// Polkadot runtime (e.g. C++), then it would identify itself with an accordingly different
|
||||
/// `impl_name`.
|
||||
pub impl_name: VersionString,
|
||||
pub impl_name: RuntimeString,
|
||||
|
||||
/// `authoring_version` is the version of the authorship interface. An authoring node
|
||||
/// will not attempt to author blocks unless this is equal to its native runtime.
|
||||
|
||||
@@ -54,7 +54,7 @@ use rstd::prelude::*;
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
use runtime_api::runtime::*;
|
||||
use runtime_primitives::traits::{BlindCheckable, BlakeTwo256, Block as BlockT};
|
||||
use runtime_primitives::traits::{BlindCheckable, BlakeTwo256, Block as BlockT, Extrinsic as ExtrinsicT};
|
||||
use runtime_primitives::{ApplyResult, Ed25519Signature, transaction_validity::TransactionValidity};
|
||||
use runtime_version::RuntimeVersion;
|
||||
pub use primitives::hash::H256;
|
||||
@@ -115,6 +115,12 @@ impl BlindCheckable for Extrinsic {
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtrinsicT for Extrinsic {
|
||||
fn is_signed(&self) -> Option<bool> {
|
||||
Some(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// An identifier for an account on this system.
|
||||
pub type AccountId = H256;
|
||||
/// A simple hash type for all our hashing.
|
||||
@@ -185,7 +191,7 @@ impl_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockBuilder<Block, u32, u32, u32> for Runtime {
|
||||
impl BlockBuilder<Block, u32, u32, u32, u32> for Runtime {
|
||||
fn initialise_block(header: <Block as BlockT>::Header) {
|
||||
system::initialise_block(header)
|
||||
}
|
||||
@@ -202,7 +208,7 @@ impl_apis! {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn check_inherents(_block: Block, _data: u32) -> Result<(), runtime_api::BlockBuilderError> {
|
||||
fn check_inherents(_block: Block, _data: u32) -> Result<(), u32> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -470,7 +470,6 @@ name = "sr-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"sr-version 0.1.0",
|
||||
@@ -503,7 +502,6 @@ dependencies = [
|
||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-io 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"sr-version 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
@@ -522,6 +520,7 @@ dependencies = [
|
||||
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user