mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Runtime logging. (#3821)
* Implement Printable for tuples. * Add debugging function. * Add debug 1. * Implement for everything. * RuntimeDebug derive. * Introduce RuntimeDebug. * Add some dummy logging. * Replace RuntimeDebug with Debug. * Revert "Replace RuntimeDebug with Debug." This reverts commit bc47070a8cb30241b2b590b2fa29fd195088162f. * Working on Debug for all. * Fix bounds. * Add debug utils. * Implement runtime logging. * Add some docs and clean up. * Clean up derives. * Fix custom derive impl. * Bump runtime. * Fix long lines. * Fix doc test. * Use CARGO_CFG_STD. * Revert "Use CARGO_CFG_STD." This reverts commit ea429566de18ed0fa052571b359eb9826a64a9f4. * Use parse_macro_input * Update lockfile. * Apply review suggestions. * Remove stray re-export. * Add no-std impl. * Update lockfile.
This commit is contained in:
committed by
Bastian Köcher
parent
934d7aac1c
commit
20a3989785
Generated
+15
@@ -3852,6 +3852,7 @@ dependencies = [
|
||||
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-debug-derive 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3860,6 +3861,7 @@ version = "2.0.0"
|
||||
dependencies = [
|
||||
"hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libsecp256k1 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
@@ -4102,6 +4104,7 @@ version = "2.0.0"
|
||||
dependencies = [
|
||||
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-primitives 2.0.0",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-client 2.0.0",
|
||||
]
|
||||
@@ -4416,6 +4419,7 @@ version = "2.0.0"
|
||||
dependencies = [
|
||||
"bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"impl-trait-for-tuples 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"once_cell 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -5088,6 +5092,15 @@ dependencies = [
|
||||
"substrate-primitives 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-debug-derive"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-executor"
|
||||
version = "2.0.0"
|
||||
@@ -5367,6 +5380,7 @@ dependencies = [
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-bip39 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-debug-derive 2.0.0",
|
||||
"substrate-externalities 2.0.0",
|
||||
"substrate-primitives-storage 2.0.0",
|
||||
"substrate-serializer 2.0.0",
|
||||
@@ -5383,6 +5397,7 @@ dependencies = [
|
||||
"impl-serde 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-debug-derive 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use primitives::{self, crypto::{CryptoType, Public, Derive, IsWrappedBy, Wraps}};
|
||||
pub use primitives::{self, crypto::{CryptoType, Public, Derive, IsWrappedBy, Wraps}, RuntimeDebug};
|
||||
#[doc(hidden)]
|
||||
#[cfg(feature = "std")]
|
||||
pub use primitives::crypto::{SecretStringError, DeriveJunction, Ss58Codec, Pair};
|
||||
@@ -139,10 +139,12 @@ macro_rules! app_crypto {
|
||||
$crate::wrap!{
|
||||
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
|
||||
#[derive(
|
||||
Clone, Default, Eq, PartialEq, Ord, PartialOrd, $crate::codec::Encode,
|
||||
Clone, Default, Eq, PartialEq, Ord, PartialOrd,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub struct Public($public);
|
||||
}
|
||||
|
||||
@@ -239,8 +241,12 @@ macro_rules! app_crypto {
|
||||
|
||||
$crate::wrap! {
|
||||
/// A generic `AppPublic` wrapper type over $public crypto; this has no specific App.
|
||||
#[derive(Clone, Default, Eq, PartialEq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[derive(Clone, Default, Eq, PartialEq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub struct Signature($sig);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use primitives::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public};
|
||||
#[cfg(feature = "std")]
|
||||
use primitives::crypto::Pair;
|
||||
|
||||
use codec::Codec;
|
||||
use primitives::crypto::{KeyTypeId, CryptoType, IsWrappedBy, Public};
|
||||
use rstd::fmt::Debug;
|
||||
|
||||
/// An application-specific key.
|
||||
pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
|
||||
@@ -38,23 +40,25 @@ pub trait AppKey: 'static + Send + Sync + Sized + CryptoType + Clone {
|
||||
const ID: KeyTypeId;
|
||||
}
|
||||
|
||||
/// Type which implements Debug and Hash in std, not when no-std (std variant).
|
||||
/// Type which implements Hash in std, not when no-std (std variant).
|
||||
#[cfg(feature = "std")]
|
||||
pub trait MaybeDebugHash: std::fmt::Debug + std::hash::Hash {}
|
||||
pub trait MaybeHash: std::hash::Hash {}
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: std::fmt::Debug + std::hash::Hash> MaybeDebugHash for T {}
|
||||
impl<T: std::hash::Hash> MaybeHash for T {}
|
||||
|
||||
/// Type which implements Debug and Hash in std, not when no-std (no-std variant).
|
||||
/// Type which implements Hash in std, not when no-std (no-std variant).
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub trait MaybeDebugHash {}
|
||||
pub trait MaybeHash {}
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> MaybeDebugHash for T {}
|
||||
impl<T> MaybeHash for T {}
|
||||
|
||||
/// A application's public key.
|
||||
pub trait AppPublic: AppKey + Public + Ord + PartialOrd + Eq + PartialEq + MaybeDebugHash + codec::Codec {
|
||||
pub trait AppPublic:
|
||||
AppKey + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec
|
||||
{
|
||||
/// The wrapped type which is just a plain instance of `Public`.
|
||||
type Generic:
|
||||
IsWrappedBy<Self> + Public + Ord + PartialOrd + Eq + PartialEq + MaybeDebugHash + codec::Codec;
|
||||
IsWrappedBy<Self> + Public + Ord + PartialOrd + Eq + PartialEq + Debug + MaybeHash + codec::Codec;
|
||||
}
|
||||
|
||||
/// A application's key pair.
|
||||
@@ -65,15 +69,15 @@ pub trait AppPair: AppKey + Pair<Public=<Self as AppKey>::Public> {
|
||||
}
|
||||
|
||||
/// A application's signature.
|
||||
pub trait AppSignature: AppKey + Eq + PartialEq + MaybeDebugHash {
|
||||
pub trait AppSignature: AppKey + Eq + PartialEq + Debug + MaybeHash {
|
||||
/// The wrapped type which is just a plain instance of `Signature`.
|
||||
type Generic: IsWrappedBy<Self> + Eq + PartialEq + MaybeDebugHash;
|
||||
type Generic: IsWrappedBy<Self> + Eq + PartialEq + Debug + MaybeHash;
|
||||
}
|
||||
|
||||
/// A runtime interface for a public key.
|
||||
pub trait RuntimePublic: Sized {
|
||||
/// The signature that will be generated when signing with the corresponding private key.
|
||||
type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone;
|
||||
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone;
|
||||
|
||||
/// Returns all public keys for the given key type in the keystore.
|
||||
fn all(key_type: KeyTypeId) -> crate::Vec<Self>;
|
||||
@@ -101,7 +105,7 @@ pub trait RuntimeAppPublic: Sized {
|
||||
const ID: KeyTypeId;
|
||||
|
||||
/// The signature that will be generated when signing with the corresponding private key.
|
||||
type Signature: Codec + MaybeDebugHash + Eq + PartialEq + Clone;
|
||||
type Signature: Codec + Debug + MaybeHash + Eq + PartialEq + Clone;
|
||||
|
||||
/// Returns all public keys for this application in the keystore.
|
||||
fn all() -> crate::Vec<Self>;
|
||||
|
||||
@@ -20,12 +20,13 @@
|
||||
|
||||
use client::decl_runtime_apis;
|
||||
use rstd::vec::Vec;
|
||||
use sr_primitives::RuntimeDebug;
|
||||
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub struct Signature(pub Vec<u8>);
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub struct AuthorityId(pub Vec<u8>);
|
||||
|
||||
decl_runtime_apis! {
|
||||
|
||||
@@ -195,8 +195,7 @@ impl Decode for BabePreDigest {
|
||||
|
||||
/// Information about the next epoch. This is broadcast in the first block
|
||||
/// of the epoch.
|
||||
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(any(feature = "std", test), derive(Debug))]
|
||||
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
|
||||
pub struct NextEpochDescriptor {
|
||||
/// The authorities.
|
||||
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
|
||||
|
||||
@@ -23,7 +23,7 @@ mod digest;
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use rstd::vec::Vec;
|
||||
use sr_primitives::ConsensusEngineId;
|
||||
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
|
||||
use substrate_client::decl_runtime_apis;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -79,8 +79,7 @@ pub type BabeAuthorityWeight = u64;
|
||||
pub type BabeBlockWeight = u32;
|
||||
|
||||
/// BABE epoch information
|
||||
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(any(feature = "std", test), derive(Debug))]
|
||||
#[derive(Decode, Encode, Default, PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub struct Epoch {
|
||||
/// The epoch index
|
||||
pub epoch_index: u64,
|
||||
@@ -127,8 +126,7 @@ pub enum ConsensusLog {
|
||||
}
|
||||
|
||||
/// Configuration data used by the BABE consensus engine.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(any(feature = "std", test), derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct BabeConfiguration {
|
||||
/// The slot duration in milliseconds for BABE. Currently, only
|
||||
/// the value provided by this type at genesis will be used.
|
||||
|
||||
@@ -151,6 +151,22 @@ impl_wasm_host_interface! {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
ext_log(
|
||||
level: u32,
|
||||
target_data: Pointer<u8>,
|
||||
target_len: WordSize,
|
||||
message_data: Pointer<u8>,
|
||||
message_len: WordSize,
|
||||
) {
|
||||
let target = context.read_memory(target_data, target_len)
|
||||
.map_err(|_| "Invalid attempt to determine target in ext_log")?;
|
||||
let message = context.read_memory(message_data, message_len)
|
||||
.map_err(|_| "Invalid attempt to determine message in ext_log")?;
|
||||
|
||||
runtime_io::log(level.into(), &target, &message);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
ext_set_storage(
|
||||
key_data: Pointer<u8>,
|
||||
key_len: WordSize,
|
||||
|
||||
@@ -24,7 +24,7 @@ extern crate alloc;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::Serialize;
|
||||
use codec::{Encode, Decode, Codec};
|
||||
use sr_primitives::ConsensusEngineId;
|
||||
use sr_primitives::{ConsensusEngineId, RuntimeDebug};
|
||||
use client::decl_runtime_apis;
|
||||
use rstd::vec::Vec;
|
||||
|
||||
@@ -59,8 +59,8 @@ pub type SetId = u64;
|
||||
pub type RoundNumber = u64;
|
||||
|
||||
/// A scheduled change of authority set.
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct ScheduledChange<N> {
|
||||
/// The new authorities after the change, along with their respective weights.
|
||||
pub next_authorities: Vec<(AuthorityId, AuthorityWeight)>,
|
||||
@@ -69,8 +69,8 @@ pub struct ScheduledChange<N> {
|
||||
}
|
||||
|
||||
/// An consensus log item for GRANDPA.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Debug))]
|
||||
#[derive(Decode, Encode, PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
#[derive(Decode, Encode, PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub enum ConsensusLog<N: Codec> {
|
||||
/// Schedule an authority set change.
|
||||
///
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use rstd::{prelude::*, collections::btree_map::BTreeMap};
|
||||
use sr_primitives::RuntimeDebug;
|
||||
use sr_primitives::{helpers_128bit::multiply_by_rational, Perbill, Rational128};
|
||||
use sr_primitives::traits::{Zero, Convert, Member, SimpleArithmetic, Saturating, Bounded};
|
||||
|
||||
@@ -54,8 +55,7 @@ pub type ExtendedBalance = u128;
|
||||
const DEN: u128 = u128::max_value();
|
||||
|
||||
/// A candidate entity for phragmen election.
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
pub struct Candidate<AccountId> {
|
||||
/// Identifier.
|
||||
pub who: AccountId,
|
||||
@@ -68,8 +68,7 @@ pub struct Candidate<AccountId> {
|
||||
}
|
||||
|
||||
/// A voter entity.
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
pub struct Voter<AccountId> {
|
||||
/// Identifier.
|
||||
who: AccountId,
|
||||
@@ -82,8 +81,7 @@ pub struct Voter<AccountId> {
|
||||
}
|
||||
|
||||
/// A candidate being backed by a voter.
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Default, RuntimeDebug)]
|
||||
pub struct Edge<AccountId> {
|
||||
/// Identifier.
|
||||
who: AccountId,
|
||||
@@ -100,7 +98,7 @@ pub type PhragmenAssignment<AccountId> = (AccountId, Perbill);
|
||||
pub type PhragmenStakedAssignment<AccountId> = (AccountId, ExtendedBalance);
|
||||
|
||||
/// Final result of the phragmen election.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct PhragmenResult<AccountId> {
|
||||
/// Just winners zipped with their approval stake. Note that the approval stake is merely the
|
||||
/// sub of their received stake and could be used for very basic sorting and approval voting.
|
||||
@@ -117,8 +115,7 @@ pub struct PhragmenResult<AccountId> {
|
||||
///
|
||||
/// This, at the current version, resembles the `Exposure` defined in the staking SRML module, yet
|
||||
/// they do not necessarily have to be the same.
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Default, RuntimeDebug)]
|
||||
pub struct Support<AccountId> {
|
||||
/// The amount of support as the effect of self-vote.
|
||||
pub own: ExtendedBalance,
|
||||
|
||||
@@ -8,12 +8,12 @@ edition = "2018"
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
rustc-hex = { version = "2.0.1", default-features = false }
|
||||
log = { version = "0.4.8", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
twox-hash = { version = "1.5.0", optional = true }
|
||||
byteorder = { version = "1.3.2", default-features = false }
|
||||
primitive-types = { version = "0.5.1", default-features = false, features = ["codec"] }
|
||||
impl-serde = { version = "0.2.1", optional = true }
|
||||
log = { version = "0.4.8", optional = true }
|
||||
wasmi = { version = "0.5.1", optional = true }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
hash256-std-hasher = { version = "0.15.2", default-features = false }
|
||||
@@ -31,6 +31,7 @@ num-traits = { version = "0.2.8", default-features = false }
|
||||
zeroize = "0.10.1"
|
||||
lazy_static = { version = "1.4.0", optional = true }
|
||||
parking_lot = { version = "0.9.0", optional = true }
|
||||
substrate-debug-derive = { version = "2.0.0", path = "./debug-derive" }
|
||||
externalities = { package = "substrate-externalities", path = "../externalities", optional = true }
|
||||
primitives-storage = { package = "substrate-primitives-storage", path = "storage", default-features = false }
|
||||
|
||||
@@ -51,7 +52,7 @@ bench = false
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"log",
|
||||
"log/std",
|
||||
"wasmi",
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
@@ -81,6 +82,7 @@ std = [
|
||||
"schnorrkel",
|
||||
"regex",
|
||||
"num-traits/std",
|
||||
"substrate-debug-derive/std",
|
||||
"externalities",
|
||||
"primitives-storage/std",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "substrate-debug-derive"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0.2"
|
||||
syn = "1.0.5"
|
||||
proc-macro2 = "1.0"
|
||||
|
||||
[features]
|
||||
std = []
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use quote::quote;
|
||||
use proc_macro2::TokenStream;
|
||||
use syn::{Data, DeriveInput, parse_quote};
|
||||
|
||||
pub fn debug_derive(ast: DeriveInput) -> proc_macro::TokenStream {
|
||||
let name_str = ast.ident.to_string();
|
||||
let implementation = implementation::derive(&name_str, &ast.data);
|
||||
let name = &ast.ident;
|
||||
let mut generics = ast.generics.clone();
|
||||
let (impl_generics, ty_generics, where_clause) = {
|
||||
let wh = generics.make_where_clause();
|
||||
for t in ast.generics.type_params() {
|
||||
let name = &t.ident;
|
||||
wh.predicates.push(parse_quote!{ #name : core::fmt::Debug });
|
||||
}
|
||||
generics.split_for_impl()
|
||||
};
|
||||
let gen = quote!{
|
||||
impl #impl_generics core::fmt::Debug for #name #ty_generics #where_clause {
|
||||
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
#implementation
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
gen.into()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod implementation {
|
||||
use super::*;
|
||||
|
||||
/// Derive the inner implementation of `Debug::fmt` function.
|
||||
///
|
||||
/// Non-std environment. We do nothing to prevent bloating the size of runtime.
|
||||
/// Implement `Printable` if you need to print the details.
|
||||
pub fn derive(_name_str: &str, _data: &Data) -> TokenStream {
|
||||
quote! {
|
||||
fmt.write_str("<wasm:stripped>")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod implementation {
|
||||
use super::*;
|
||||
use proc_macro2::Span;
|
||||
use syn::{Ident, Index, token::SelfValue};
|
||||
|
||||
/// Derive the inner implementation of `Debug::fmt` function.
|
||||
pub fn derive(name_str: &str, data: &Data) -> TokenStream {
|
||||
match *data {
|
||||
Data::Struct(ref s) => derive_struct(&name_str, &s.fields),
|
||||
Data::Union(ref u) => derive_fields(&name_str, Fields::new(u.fields.named.iter(), None)),
|
||||
Data::Enum(ref e) => derive_enum(&name_str, &e),
|
||||
}
|
||||
}
|
||||
|
||||
enum Fields {
|
||||
Indexed {
|
||||
indices: Vec<Index>,
|
||||
},
|
||||
Unnamed {
|
||||
vars: Vec<Ident>,
|
||||
},
|
||||
Named {
|
||||
names: Vec<Ident>,
|
||||
this: Option<SelfValue>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Fields {
|
||||
fn new<'a>(fields: impl Iterator<Item=&'a syn::Field>, this: Option<SelfValue>) -> Self {
|
||||
let mut indices = vec![];
|
||||
let mut names = vec![];
|
||||
|
||||
for (i, f) in fields.enumerate() {
|
||||
if let Some(ident) = f.ident.clone() {
|
||||
names.push(ident);
|
||||
} else {
|
||||
indices.push(Index::from(i));
|
||||
}
|
||||
}
|
||||
|
||||
if names.is_empty() {
|
||||
Self::Indexed {
|
||||
indices,
|
||||
}
|
||||
} else {
|
||||
Self::Named {
|
||||
names,
|
||||
this,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_fields<'a>(
|
||||
name_str: &str,
|
||||
fields: Fields,
|
||||
) -> TokenStream {
|
||||
match fields {
|
||||
Fields::Named { names, this } => {
|
||||
let names_str: Vec<_> = names.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
|
||||
let fields = match this {
|
||||
None => quote! { #( .field(#names_str, #names) )* },
|
||||
Some(this) => quote! { #( .field(#names_str, &#this.#names) )* },
|
||||
};
|
||||
|
||||
quote! {
|
||||
fmt.debug_struct(#name_str)
|
||||
#fields
|
||||
.finish()
|
||||
}
|
||||
|
||||
},
|
||||
Fields::Indexed { indices } => {
|
||||
quote! {
|
||||
fmt.debug_tuple(#name_str)
|
||||
#( .field(&self.#indices) )*
|
||||
.finish()
|
||||
}
|
||||
},
|
||||
Fields::Unnamed { vars } => {
|
||||
quote! {
|
||||
fmt.debug_tuple(#name_str)
|
||||
#( .field(#vars) )*
|
||||
.finish()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_enum(
|
||||
name: &str,
|
||||
e: &syn::DataEnum,
|
||||
) -> TokenStream {
|
||||
let v = e.variants
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let name = format!("{}::{}", name, v.ident);
|
||||
let ident = &v.ident;
|
||||
match v.fields {
|
||||
syn::Fields::Named(ref f) => {
|
||||
let names: Vec<_> = f.named.iter().flat_map(|f| f.ident.clone()).collect();
|
||||
let fields_impl = derive_fields(&name, Fields::Named {
|
||||
names: names.clone(),
|
||||
this: None,
|
||||
});
|
||||
(ident, (quote!{ { #( ref #names ),* } }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unnamed(ref f) => {
|
||||
let names = f.unnamed.iter()
|
||||
.enumerate()
|
||||
.map(|(id, _)| Ident::new(&format!("a{}", id), Span::call_site()))
|
||||
.collect::<Vec<_>>();
|
||||
let fields_impl = derive_fields(&name, Fields::Unnamed { vars: names.clone() });
|
||||
(ident, (quote! { ( #( ref #names ),* ) }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unit => {
|
||||
let fields_impl = derive_fields(&name, Fields::Indexed { indices: vec![] });
|
||||
(ident, (quote! { }, fields_impl))
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
type Vecs<A, B> = (Vec<A>, Vec<B>);
|
||||
let (variants, others): Vecs<_, _> = v.unzip();
|
||||
let (match_fields, variants_impl): Vecs<_, _> = others.into_iter().unzip();
|
||||
|
||||
quote! {
|
||||
match self {
|
||||
#( Self::#variants #match_fields => #variants_impl, )*
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_struct(
|
||||
name_str: &str,
|
||||
fields: &syn::Fields,
|
||||
) -> TokenStream {
|
||||
match *fields {
|
||||
syn::Fields::Named(ref f) => derive_fields(
|
||||
name_str,
|
||||
Fields::new(f.named.iter(), Some(syn::Token!(self)(Span::call_site()))),
|
||||
),
|
||||
syn::Fields::Unnamed(ref f) => derive_fields(
|
||||
name_str,
|
||||
Fields::new(f.unnamed.iter(), None),
|
||||
),
|
||||
syn::Fields::Unit => derive_fields(
|
||||
name_str,
|
||||
Fields::Indexed { indices: vec![] },
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Macros to derive runtime debug implementation.
|
||||
//!
|
||||
//! This custom derive implements a `core::fmt::Debug` trait,
|
||||
//! but in case the `std` feature is enabled the implementation
|
||||
//! will actually print out the structure as regular `derive(Debug)`
|
||||
//! would do. If `std` is disabled the implementation will be empty.
|
||||
//!
|
||||
//! This behaviour is useful to prevent bloating the runtime WASM
|
||||
//! blob from unneeded code.
|
||||
//!
|
||||
//! ```rust
|
||||
//! #[derive(substrate_debug_derive::RuntimeDebug)]
|
||||
//! struct MyStruct;
|
||||
//!
|
||||
//! assert_eq!(format!("{:?}", MyStruct), "MyStruct");
|
||||
//! ```
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
mod impls;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro_derive(RuntimeDebug)]
|
||||
pub fn debug_derive(input: TokenStream) -> TokenStream {
|
||||
impls::debug_derive(syn::parse_macro_input!(input))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use substrate_debug_derive::RuntimeDebug;
|
||||
|
||||
#[derive(RuntimeDebug)]
|
||||
struct Unnamed(u64, String);
|
||||
|
||||
#[derive(RuntimeDebug)]
|
||||
struct Named {
|
||||
a: u64,
|
||||
b: String,
|
||||
}
|
||||
|
||||
#[derive(RuntimeDebug)]
|
||||
enum EnumLongName<A> {
|
||||
A,
|
||||
B(A, String),
|
||||
VariantLongName {
|
||||
a: A,
|
||||
b: String,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn should_display_proper_debug() {
|
||||
use self::EnumLongName as Enum;
|
||||
|
||||
assert_eq!(
|
||||
format!("{:?}", Unnamed(1, "abc".into())),
|
||||
"Unnamed(1, \"abc\")"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{:?}", Named { a: 1, b: "abc".into() }),
|
||||
"Named { a: 1, b: \"abc\" }"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{:?}", Enum::<u64>::A),
|
||||
"EnumLongName::A"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{:?}", Enum::B(1, "abc".into())),
|
||||
"EnumLongName::B(1, \"abc\")"
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{:?}", Enum::VariantLongName { a: 1, b: "abc".into() }),
|
||||
"EnumLongName::VariantLongName { a: 1, b: \"abc\" }"
|
||||
);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ pub const DEV_PHRASE: &str = "bottom drive obey lake curtain smoke basket hold r
|
||||
pub const DEV_ADDRESS: &str = "5DfhGyQdFobKM8NsWvEeAKk5EQQgYe9AydgJ7rMB6E1EqRzV";
|
||||
|
||||
/// The infallible type.
|
||||
#[derive(Debug)]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub enum Infallible {}
|
||||
|
||||
/// The length of the junction identifier. Note that this is also referred to as the
|
||||
@@ -743,7 +743,7 @@ pub trait CryptoType {
|
||||
/// Values whose first character is `_` are reserved for private use and won't conflict with any
|
||||
/// public modules.
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub struct KeyTypeId(pub [u8; 4]);
|
||||
|
||||
impl From<u32> for KeyTypeId {
|
||||
|
||||
@@ -130,12 +130,17 @@ impl std::fmt::Display for Public {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for Public {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl rstd::fmt::Debug for Public {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
let s = self.to_ss58check();
|
||||
write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -223,11 +228,16 @@ impl AsMut<[u8]> for Signature {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for Signature {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl rstd::fmt::Debug for Signature {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "{}", crate::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -24,8 +24,8 @@ impl<'a> HexDisplay<'a> {
|
||||
pub fn from<R: AsBytesRef>(d: &'a R) -> Self { HexDisplay(d.as_bytes_ref()) }
|
||||
}
|
||||
|
||||
impl<'a> ::core::fmt::Display for HexDisplay<'a> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
|
||||
impl<'a> rstd::fmt::Display for HexDisplay<'a> {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> Result<(), rstd::fmt::Error> {
|
||||
if self.0.len() < 1027 {
|
||||
for byte in self.0 {
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
@@ -43,8 +43,8 @@ impl<'a> ::core::fmt::Display for HexDisplay<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> core::fmt::Debug for HexDisplay<'a> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
|
||||
impl<'a> rstd::fmt::Debug for HexDisplay<'a> {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> Result<(), rstd::fmt::Error> {
|
||||
for byte in self.0 {
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ pub use serde;// << for macro
|
||||
#[doc(hidden)]
|
||||
pub use codec::{Encode, Decode};// << for macro
|
||||
|
||||
pub use substrate_debug_derive::RuntimeDebug;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use impl_serde::serialize as bytes;
|
||||
|
||||
@@ -116,8 +118,8 @@ impl ExecutionContext {
|
||||
}
|
||||
|
||||
/// Hex-serialized shim for `Vec<u8>`.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Hash, PartialOrd, Ord))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, PartialOrd, Ord))]
|
||||
pub struct Bytes(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
|
||||
|
||||
impl From<Vec<u8>> for Bytes {
|
||||
@@ -162,8 +164,8 @@ pub enum NativeOrEncoded<R> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<R: codec::Encode> ::std::fmt::Debug for NativeOrEncoded<R> {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
impl<R: codec::Encode> rstd::fmt::Debug for NativeOrEncoded<R> {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
hexdisplay::HexDisplay::from(&self.as_encoded().as_ref()).fmt(f)
|
||||
}
|
||||
}
|
||||
@@ -229,3 +231,58 @@ pub trait TypeId {
|
||||
/// Simple 4 byte identifier.
|
||||
const TYPE_ID: [u8; 4];
|
||||
}
|
||||
|
||||
/// A log level matching the one from `log` crate.
|
||||
///
|
||||
/// Used internally by `runtime_io::log` method.
|
||||
#[repr(u32)]
|
||||
pub enum LogLevel {
|
||||
/// `Error` log level.
|
||||
Error = 1,
|
||||
/// `Warn` log level.
|
||||
Warn = 2,
|
||||
/// `Info` log level.
|
||||
Info = 3,
|
||||
/// `Debug` log level.
|
||||
Debug = 4,
|
||||
/// `Trace` log level.
|
||||
Trace = 5,
|
||||
}
|
||||
|
||||
impl From<u32> for LogLevel {
|
||||
fn from(val: u32) -> Self {
|
||||
match val {
|
||||
x if x == LogLevel::Warn as u32 => LogLevel::Warn,
|
||||
x if x == LogLevel::Info as u32 => LogLevel::Info,
|
||||
x if x == LogLevel::Debug as u32 => LogLevel::Debug,
|
||||
x if x == LogLevel::Trace as u32 => LogLevel::Trace,
|
||||
_ => LogLevel::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<log::Level> for LogLevel {
|
||||
fn from(l: log::Level) -> Self {
|
||||
use log::Level::*;
|
||||
match l {
|
||||
Error => Self::Error,
|
||||
Warn => Self::Warn,
|
||||
Info => Self::Info,
|
||||
Debug => Self::Debug,
|
||||
Trace => Self::Trace,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LogLevel> for log::Level {
|
||||
fn from(l: LogLevel) -> Self {
|
||||
use self::LogLevel::*;
|
||||
match l {
|
||||
Error => Self::Error,
|
||||
Warn => Self::Warn,
|
||||
Info => Self::Info,
|
||||
Debug => Self::Debug,
|
||||
Trace => Self::Trace,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use rstd::{prelude::{Vec, Box}, convert::TryFrom};
|
||||
use crate::RuntimeDebug;
|
||||
|
||||
pub use crate::crypto::KeyTypeId;
|
||||
|
||||
/// A type of supported crypto.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
#[repr(C)]
|
||||
pub enum StorageKind {
|
||||
/// Persistent storage is non-revertible and not fork-aware. It means that any value
|
||||
@@ -59,8 +59,8 @@ impl From<StorageKind> for u32 {
|
||||
}
|
||||
|
||||
/// Opaque type for offchain http requests.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub struct HttpRequestId(pub u16);
|
||||
|
||||
impl From<HttpRequestId> for u32 {
|
||||
@@ -70,8 +70,7 @@ impl From<HttpRequestId> for u32 {
|
||||
}
|
||||
|
||||
/// An error enum returned by some http methods.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug)]
|
||||
#[repr(C)]
|
||||
pub enum HttpError {
|
||||
/// The requested action couldn't been completed within a deadline.
|
||||
@@ -102,8 +101,7 @@ impl From<HttpError> for u32 {
|
||||
}
|
||||
|
||||
/// Status of the HTTP request
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum HttpRequestStatus {
|
||||
/// Deadline was reached while we waited for this request to finish.
|
||||
///
|
||||
@@ -149,8 +147,7 @@ impl TryFrom<u32> for HttpRequestStatus {
|
||||
|
||||
/// A blob to hold information about the local node's network state
|
||||
/// without committing to its format.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct OpaqueNetworkState {
|
||||
/// PeerId of the local node.
|
||||
pub peer_id: OpaquePeerId,
|
||||
@@ -159,8 +156,7 @@ pub struct OpaqueNetworkState {
|
||||
}
|
||||
|
||||
/// Simple blob to hold a `PeerId` without committing to its format.
|
||||
#[derive(Default, Clone, Eq, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Default, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct OpaquePeerId(pub Vec<u8>);
|
||||
|
||||
impl OpaquePeerId {
|
||||
@@ -171,8 +167,7 @@ impl OpaquePeerId {
|
||||
}
|
||||
|
||||
/// Simple blob to hold a `Multiaddr` without committing to its format.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct OpaqueMultiaddr(pub Vec<u8>);
|
||||
|
||||
impl OpaqueMultiaddr {
|
||||
@@ -183,13 +178,11 @@ impl OpaqueMultiaddr {
|
||||
}
|
||||
|
||||
/// Opaque timestamp type
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default, RuntimeDebug)]
|
||||
pub struct Timestamp(u64);
|
||||
|
||||
/// Duration type
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default, RuntimeDebug)]
|
||||
pub struct Duration(u64);
|
||||
|
||||
impl Duration {
|
||||
|
||||
@@ -21,12 +21,12 @@ use rstd::vec::Vec;
|
||||
|
||||
/// Error error that can be returned from host function.
|
||||
#[derive(Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub struct HostError;
|
||||
|
||||
/// Representation of a typed wasm value.
|
||||
#[derive(Clone, Copy, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub enum TypedValue {
|
||||
/// Value of 32-bit signed or unsigned integer.
|
||||
#[codec(index = "1")]
|
||||
@@ -86,7 +86,7 @@ impl From<TypedValue> for ::wasmi::RuntimeValue {
|
||||
///
|
||||
/// Basically a `TypedValue` plus `Unit`, for functions which return nothing.
|
||||
#[derive(Clone, Copy, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub enum ReturnValue {
|
||||
/// For returning nothing.
|
||||
Unit,
|
||||
@@ -119,7 +119,7 @@ fn return_value_encoded_max_size() {
|
||||
|
||||
/// Describes an entity to define or import into the environment.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub enum ExternEntity {
|
||||
/// Function that is specified by an index in a default table of
|
||||
/// a module that creates the sandbox.
|
||||
@@ -137,7 +137,7 @@ pub enum ExternEntity {
|
||||
/// Each entry has a two-level name and description of an entity
|
||||
/// being defined.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub struct Entry {
|
||||
/// Module name of which corresponding entity being defined.
|
||||
pub module_name: Vec<u8>,
|
||||
@@ -149,7 +149,7 @@ pub struct Entry {
|
||||
|
||||
/// Definition of runtime that could be used by sandboxed code.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(crate::RuntimeDebug)]
|
||||
pub struct EnvironmentDefinition {
|
||||
/// Vector of all entries in the environment definition.
|
||||
pub entries: Vec<Entry>,
|
||||
|
||||
@@ -129,12 +129,20 @@ impl std::fmt::Display for Public {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for Public {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core as std;
|
||||
|
||||
impl rstd::fmt::Debug for Public {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
let s = self.to_ss58check();
|
||||
write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@@ -231,11 +239,16 @@ impl From<schnorrkel::Signature> for Signature {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for Signature {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
impl rstd::fmt::Debug for Signature {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "{}", crate::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -9,6 +9,7 @@ description = "Storage related primitives"
|
||||
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
impl-serde = { version = "0.2.1", optional = true }
|
||||
substrate-debug-derive = { version = "2.0.0", path = "../debug-derive" }
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
|
||||
@@ -20,27 +20,29 @@
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use substrate_debug_derive::RuntimeDebug;
|
||||
|
||||
use rstd::{vec::Vec, borrow::Cow};
|
||||
|
||||
/// Storage key.
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Hash, PartialOrd, Ord, Clone))]
|
||||
#[derive(PartialEq, Eq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, PartialOrd, Ord, Clone))]
|
||||
pub struct StorageKey(
|
||||
#[cfg_attr(feature = "std", serde(with="impl_serde::serialize"))]
|
||||
pub Vec<u8>,
|
||||
);
|
||||
|
||||
/// Storage data associated to a [`StorageKey`].
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Hash, PartialOrd, Ord, Clone))]
|
||||
#[derive(PartialEq, Eq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, PartialOrd, Ord, Clone))]
|
||||
pub struct StorageData(
|
||||
#[cfg_attr(feature = "std", serde(with="impl_serde::serialize"))]
|
||||
pub Vec<u8>,
|
||||
);
|
||||
|
||||
/// Storage change set
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, PartialEq, Eq))]
|
||||
#[derive(RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, PartialEq, Eq))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
pub struct StorageChangeSet<Hash> {
|
||||
/// Block hash
|
||||
|
||||
@@ -5,11 +5,12 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
num-traits = { version = "0.2.8", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
integer-sqrt = "0.1.2"
|
||||
num-traits = { version = "0.2.8", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
substrate-debug-derive = { path = "../primitives/debug-derive", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
primitive-types = "0.6.0"
|
||||
@@ -19,8 +20,9 @@ rand = "0.7.2"
|
||||
bench = []
|
||||
default = ["std"]
|
||||
std = [
|
||||
"serde",
|
||||
"codec/std",
|
||||
"num-traits/std",
|
||||
"rstd/std",
|
||||
"codec/std",
|
||||
"serde",
|
||||
"substrate-debug-derive/std",
|
||||
]
|
||||
|
||||
@@ -427,8 +427,8 @@ impl BigUint {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl rstd::fmt::Debug for BigUint {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
@@ -437,6 +437,12 @@ impl rstd::fmt::Debug for BigUint {
|
||||
u128::try_from(self.clone()).unwrap_or(0),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl PartialEq for BigUint {
|
||||
|
||||
@@ -144,11 +144,16 @@ impl CheckedAdd for Fixed64 {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl rstd::fmt::Debug for Fixed64 {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "Fixed64({},{})", self.0 / DIV, (self.0 % DIV) / 1000)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -20,14 +20,15 @@ use serde::{Serialize, Deserialize};
|
||||
use rstd::{ops, prelude::*, convert::TryInto};
|
||||
use codec::{Encode, Decode, CompactAs};
|
||||
use crate::traits::{SaturatedConversion, UniqueSaturatedInto, Saturating};
|
||||
use substrate_debug_derive::RuntimeDebug;
|
||||
|
||||
macro_rules! implement_per_thing {
|
||||
($name:ident, $test_mod:ident, [$($test_units:tt),+], $max:tt, $type:ty, $upper_type:ty, $title:expr $(,)?) => {
|
||||
/// A fixed point representation of a number between in the range [0, 1].
|
||||
///
|
||||
#[doc = $title]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Ord, PartialOrd))]
|
||||
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, CompactAs)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Ord, PartialOrd))]
|
||||
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, RuntimeDebug, CompactAs)]
|
||||
pub struct $name($type);
|
||||
|
||||
impl $name {
|
||||
@@ -189,7 +190,7 @@ macro_rules! implement_per_thing {
|
||||
#[cfg(test)]
|
||||
mod $test_mod {
|
||||
use codec::{Encode, Decode};
|
||||
use super::{$name, Saturating};
|
||||
use super::{$name, Saturating, RuntimeDebug};
|
||||
use crate::traits::Zero;
|
||||
|
||||
|
||||
@@ -208,7 +209,7 @@ macro_rules! implement_per_thing {
|
||||
assert!(<$upper_type>::from($max).checked_mul($max.into()).is_some());
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, PartialEq, Eq, Debug)]
|
||||
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
struct WithCompact<T: codec::HasCompact> {
|
||||
data: T,
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
use rstd::{cmp::Ordering, prelude::*};
|
||||
use crate::helpers_128bit;
|
||||
use num_traits::Zero;
|
||||
use substrate_debug_derive::RuntimeDebug;
|
||||
|
||||
/// A wrapper for any rational number with a 128 bit numerator and denominator.
|
||||
#[derive(Clone, Copy, Default, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, Default, Eq, RuntimeDebug)]
|
||||
pub struct Rational128(u128, u128);
|
||||
|
||||
impl Rational128 {
|
||||
|
||||
@@ -9,15 +9,16 @@ edition = "2018"
|
||||
rustc_version = "0.2.3"
|
||||
|
||||
[dependencies]
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
libsecp256k1 = { version = "0.3.0", optional = true }
|
||||
tiny-keccak = { version = "1.5.0", optional = true }
|
||||
substrate-state-machine = { path = "../state-machine", optional = true }
|
||||
trie = { package = "substrate-trie", path = "../trie", optional = true }
|
||||
externalities = { package = "substrate-externalities", path = "../externalities", optional = true }
|
||||
log = { version = "0.4.8", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
@@ -31,6 +32,7 @@ std = [
|
||||
"libsecp256k1",
|
||||
"tiny-keccak",
|
||||
"externalities",
|
||||
"log",
|
||||
]
|
||||
nightly = []
|
||||
strict = []
|
||||
|
||||
@@ -33,6 +33,7 @@ use primitives::{
|
||||
offchain::{
|
||||
Timestamp, HttpRequestId, HttpRequestStatus, HttpError, StorageKind, OpaqueNetworkState,
|
||||
},
|
||||
LogLevel,
|
||||
};
|
||||
|
||||
/// Error verifying ECDSA signature
|
||||
@@ -158,6 +159,20 @@ export_api! {
|
||||
fn print_utf8(utf8: &[u8]);
|
||||
/// Print any `u8` slice as hex.
|
||||
fn print_hex(data: &[u8]);
|
||||
|
||||
/// Request to print a log message (stderr) on the host.
|
||||
///
|
||||
/// Note that this will be only displayed if the host
|
||||
/// is enabed to display log messages with given
|
||||
/// level and target.
|
||||
///
|
||||
/// Instead of using directly, prefer setting up `RuntimeLogger`
|
||||
/// and using `log` macros.
|
||||
fn log(
|
||||
level: LogLevel,
|
||||
target: &[u8],
|
||||
message: &[u8]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,22 @@ impl OtherApi for () {
|
||||
fn print_hex(data: &[u8]) {
|
||||
println!("{}", HexDisplay::from(&data));
|
||||
}
|
||||
|
||||
fn log(
|
||||
level: LogLevel,
|
||||
target: &[u8],
|
||||
message: &[u8],
|
||||
) {
|
||||
let target = std::str::from_utf8(target).unwrap_or("invalid utf8");
|
||||
let msg = std::str::from_utf8(message).unwrap_or("invalid utf8");
|
||||
|
||||
log::log!(
|
||||
target: target,
|
||||
log::Level::from(level),
|
||||
"{}",
|
||||
msg,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl CryptoApi for () {
|
||||
|
||||
@@ -160,6 +160,14 @@ pub mod ext {
|
||||
fn ext_print_hex(data: *const u8, len: u32);
|
||||
/// Print a number
|
||||
fn ext_print_num(value: u64);
|
||||
/// Print a log line if logging for given level and target is enabled.
|
||||
fn ext_log(
|
||||
level: u32,
|
||||
target_data: *const u8,
|
||||
target_len: u32,
|
||||
message_data: *const u8,
|
||||
message_len: u32,
|
||||
);
|
||||
|
||||
/// Set value for key in storage.
|
||||
fn ext_set_storage(key_data: *const u8, key_len: u32, value_data: *const u8, value_len: u32);
|
||||
@@ -780,6 +788,22 @@ impl OtherApi for () {
|
||||
ext_print_hex.get()(data.as_ptr(), data.len() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
fn log(
|
||||
level: LogLevel,
|
||||
target: &[u8],
|
||||
message: &[u8]
|
||||
) {
|
||||
unsafe {
|
||||
ext_log.get()(
|
||||
level as u32,
|
||||
target.as_ptr(),
|
||||
target.len() as u32,
|
||||
message.as_ptr(),
|
||||
message.len() as u32,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HashingApi for () {
|
||||
|
||||
@@ -26,13 +26,13 @@ substrate-offchain = { path = "../offchain" }
|
||||
bench = []
|
||||
default = ["std"]
|
||||
std = [
|
||||
"serde",
|
||||
"log",
|
||||
"rstd/std",
|
||||
"runtime_io/std",
|
||||
"codec/std",
|
||||
"primitives/std",
|
||||
"app-crypto/std",
|
||||
"arithmetic/std",
|
||||
"codec/std",
|
||||
"log",
|
||||
"primitives/std",
|
||||
"rand",
|
||||
"rstd/std",
|
||||
"runtime_io/std",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@@ -20,8 +20,7 @@ use crate::{Perbill, traits::{SimpleArithmetic, SaturatedConversion}};
|
||||
use core::ops::Sub;
|
||||
|
||||
/// Piecewise Linear function in [0, 1] -> [0, 1].
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[derive(PartialEq, Eq, primitives::RuntimeDebug)]
|
||||
pub struct PiecewiseLinear<'a> {
|
||||
/// Array of points. Must be in order from the lowest abscissas to the highest.
|
||||
pub points: &'a [(Perbill, Perbill)]
|
||||
|
||||
@@ -23,13 +23,14 @@ use std::fmt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use rstd::prelude::*;
|
||||
use primitives::RuntimeDebug;
|
||||
use crate::codec::{Codec, Encode, Decode};
|
||||
use crate::traits::{self, Member, Block as BlockT, Header as HeaderT, MaybeSerialize};
|
||||
use crate::Justification;
|
||||
|
||||
/// Something to identify a block.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "std", serde(deny_unknown_fields))]
|
||||
pub enum BlockId<Block: BlockT> {
|
||||
@@ -61,8 +62,8 @@ impl<Block: BlockT> fmt::Display for BlockId<Block> {
|
||||
}
|
||||
|
||||
/// Abstraction over a substrate block.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "std", serde(deny_unknown_fields))]
|
||||
pub struct Block<Header, Extrinsic: MaybeSerialize> {
|
||||
@@ -99,8 +100,8 @@ where
|
||||
}
|
||||
|
||||
/// Abstraction over a substrate block and justification.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "std", serde(deny_unknown_fields))]
|
||||
pub struct SignedBlock<Block> {
|
||||
|
||||
@@ -26,8 +26,7 @@ use crate::transaction_validity::TransactionValidity;
|
||||
/// Definition of something that the external world might want to say; its
|
||||
/// existence implies that it has been checked and is good, particularly with
|
||||
/// regards to the signature.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, primitives::RuntimeDebug)]
|
||||
pub struct CheckedExtrinsic<AccountId, Call, Extra> {
|
||||
/// Who this purports to be from and the number of extrinsics have come before
|
||||
/// from the same signer, if anyone (note this is not a signature).
|
||||
|
||||
@@ -23,10 +23,11 @@ use rstd::prelude::*;
|
||||
|
||||
use crate::ConsensusEngineId;
|
||||
use crate::codec::{Decode, Encode, Input, Error};
|
||||
use primitives::RuntimeDebug;
|
||||
|
||||
/// Generic header digest.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Digest<Hash: Encode + Decode> {
|
||||
/// A list of logs in the digest.
|
||||
pub logs: Vec<DigestItem<Hash>>,
|
||||
@@ -72,8 +73,7 @@ impl<Hash: Encode + Decode> Digest<Hash> {
|
||||
|
||||
/// Digest item that is able to encode/decode 'system' digest items and
|
||||
/// provide opaque access to other items.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub enum DigestItem<Hash> {
|
||||
/// System digest item that contains the root of changes trie at given
|
||||
/// block. It is created for every block iff runtime supports changes
|
||||
@@ -123,8 +123,7 @@ impl<'a, Hash: Decode> serde::Deserialize<'a> for DigestItem<Hash> {
|
||||
|
||||
/// A 'referencing view' for digest item. Does not own its contents. Used by
|
||||
/// final runtime implementations for encoding/decoding its log items.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub enum DigestItemRef<'a, Hash: 'a> {
|
||||
/// Reference to `DigestItem::ChangesTrieRoot`.
|
||||
ChangesTrieRoot(&'a Hash),
|
||||
|
||||
@@ -28,8 +28,8 @@ pub type Period = u64;
|
||||
pub type Phase = u64;
|
||||
|
||||
/// An era to describe the longevity of a transaction.
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Copy, primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum Era {
|
||||
/// The transaction is valid forever. The genesis hash must be present in the signed content.
|
||||
Immortal,
|
||||
|
||||
@@ -18,20 +18,21 @@
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cfg(feature = "std")]
|
||||
use log::debug;
|
||||
use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef, Error};
|
||||
use crate::traits::{
|
||||
self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay, Hash as HashT, MaybeSerializeDebug,
|
||||
MaybeSerializeDebugButNotDeserialize
|
||||
self, Member, SimpleArithmetic, SimpleBitOps, Hash as HashT,
|
||||
MaybeSerializeDeserialize, MaybeSerialize, MaybeDisplay,
|
||||
};
|
||||
use crate::generic::Digest;
|
||||
use primitives::U256;
|
||||
use core::convert::TryFrom;
|
||||
use rstd::{
|
||||
convert::TryFrom,
|
||||
fmt::Debug,
|
||||
};
|
||||
|
||||
/// Abstraction over a block header for a substrate chain.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(PartialEq, Eq, Clone, primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
#[cfg_attr(feature = "std", serde(deny_unknown_fields))]
|
||||
pub struct Header<Number: Copy + Into<U256> + TryFrom<U256>, Hash: HashT> {
|
||||
@@ -103,11 +104,11 @@ impl<Number, Hash> codec::EncodeLike for Header<Number, Hash> where
|
||||
{}
|
||||
|
||||
impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
Number: Member + MaybeSerializeDebug + rstd::hash::Hash + MaybeDisplay +
|
||||
Number: Member + MaybeSerializeDeserialize + Debug + rstd::hash::Hash + MaybeDisplay +
|
||||
SimpleArithmetic + Codec + Copy + Into<U256> + TryFrom<U256>,
|
||||
Hash: HashT,
|
||||
Hash::Output: Default + rstd::hash::Hash + Copy + Member +
|
||||
MaybeSerializeDebugButNotDeserialize + MaybeDisplay + SimpleBitOps + Codec,
|
||||
MaybeSerialize + Debug + MaybeDisplay + SimpleBitOps + Codec,
|
||||
{
|
||||
type Number = Number;
|
||||
type Hash = <Hash as HashT>::Output;
|
||||
@@ -127,15 +128,12 @@ impl<Number, Hash> traits::Header for Header<Number, Hash> where
|
||||
|
||||
fn digest(&self) -> &Digest<Self::Hash> { &self.digest }
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn digest_mut(&mut self) -> &mut Digest<Self::Hash> {
|
||||
debug!(target: "header", "Retrieving mutable reference to digest");
|
||||
#[cfg(feature = "std")]
|
||||
log::debug!(target: "header", "Retrieving mutable reference to digest");
|
||||
&mut self.digest
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn digest_mut(&mut self) -> &mut Digest<Self::Hash> { &mut self.digest }
|
||||
|
||||
fn new(
|
||||
number: Self::Number,
|
||||
extrinsics_root: Self::Hash,
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
//! Generic implementation of an unchecked (pre-verification) extrinsic.
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::fmt;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::fmt;
|
||||
use runtime_io::blake2_256;
|
||||
use codec::{Decode, Encode, EncodeLike, Input, Error};
|
||||
use crate::{
|
||||
@@ -264,7 +262,6 @@ impl<Address: Encode, Signature: Encode, Call: Encode, Extra: SignedExtension> s
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<Address, Call, Signature, Extra> fmt::Debug
|
||||
for UncheckedExtrinsic<Address, Call, Signature, Extra>
|
||||
where
|
||||
|
||||
@@ -62,6 +62,9 @@ pub use generic::{DigestItem, Digest};
|
||||
pub use primitives::{TypeId, crypto::{key_types, KeyTypeId, CryptoType}};
|
||||
pub use app_crypto::RuntimeAppPublic;
|
||||
|
||||
/// Re-export `RuntimeDebug`, to avoid dependency clutter.
|
||||
pub use primitives::RuntimeDebug;
|
||||
|
||||
/// Re-export top-level arithmetic stuff.
|
||||
pub use arithmetic::{
|
||||
Perquintill, Perbill, Permill, Percent,
|
||||
@@ -166,8 +169,7 @@ impl BuildStorage for (StorageOverlay, ChildrenStorageOverlay) {
|
||||
pub type ConsensusEngineId = [u8; 4];
|
||||
|
||||
/// Signature verify that can work with any known signature types..
|
||||
#[derive(Eq, PartialEq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Eq, PartialEq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub enum MultiSignature {
|
||||
/// An Ed25519 signature.
|
||||
Ed25519(ed25519::Signature),
|
||||
@@ -194,8 +196,8 @@ impl Default for MultiSignature {
|
||||
}
|
||||
|
||||
/// Public key for any known crypto algorithm.
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum MultiSigner {
|
||||
/// An Ed25519 identity.
|
||||
Ed25519(ed25519::Public),
|
||||
@@ -260,8 +262,8 @@ impl Verify for MultiSignature {
|
||||
}
|
||||
|
||||
/// Signature verify that can work with any known signature types..
|
||||
#[derive(Eq, PartialEq, Clone, Default, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(Eq, PartialEq, Clone, Default, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct AnySignature(H512);
|
||||
|
||||
impl Verify for AnySignature {
|
||||
@@ -289,8 +291,8 @@ impl From<ed25519::Signature> for AnySignature {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Decode, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Decode, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
/// Reason why an extrinsic couldn't be applied (i.e. invalid extrinsic).
|
||||
pub enum ApplyError {
|
||||
/// General error to do with the permissions of the sender.
|
||||
@@ -341,8 +343,8 @@ impl From<DispatchError> for ApplyOutcome {
|
||||
/// Result from attempt to apply an extrinsic.
|
||||
pub type ApplyResult = Result<ApplyOutcome, ApplyError>;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
/// Reason why a dispatch call failed
|
||||
pub struct DispatchError {
|
||||
/// Module index, matching the metadata module index
|
||||
@@ -564,13 +566,19 @@ macro_rules! assert_eq_error_rate {
|
||||
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
|
||||
pub struct OpaqueExtrinsic(pub Vec<u8>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for OpaqueExtrinsic {
|
||||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl rstd::fmt::Debug for OpaqueExtrinsic {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, fmt: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(fmt, "{}", primitives::hexdisplay::HexDisplay::from(&self.0))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _fmt: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl ::serde::Serialize for OpaqueExtrinsic {
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: ::serde::Serializer {
|
||||
|
||||
@@ -51,6 +51,7 @@ use rstd::str;
|
||||
use rstd::prelude::Vec;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use rstd::prelude::vec;
|
||||
use primitives::RuntimeDebug;
|
||||
use primitives::offchain::{
|
||||
Timestamp,
|
||||
HttpRequestId as RequestId,
|
||||
@@ -59,8 +60,7 @@ use primitives::offchain::{
|
||||
};
|
||||
|
||||
/// Request method (HTTP verb)
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum Method {
|
||||
/// GET request
|
||||
Get,
|
||||
@@ -93,8 +93,7 @@ mod header {
|
||||
use super::*;
|
||||
|
||||
/// A header type.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct Header {
|
||||
name: Vec<u8>,
|
||||
value: Vec<u8>,
|
||||
@@ -128,8 +127,7 @@ mod header {
|
||||
}
|
||||
|
||||
/// An HTTP request builder.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct Request<'a, T = Vec<&'static [u8]>> {
|
||||
/// Request method
|
||||
pub method: Method,
|
||||
@@ -249,8 +247,7 @@ impl<'a, I: AsRef<[u8]>, T: IntoIterator<Item=I>> Request<'a, T> {
|
||||
}
|
||||
|
||||
/// A request error
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum Error {
|
||||
/// Deadline has been reached.
|
||||
DeadlineReached,
|
||||
@@ -261,8 +258,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
/// A struct representing an uncompleted http request.
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct PendingRequest {
|
||||
/// Request ID
|
||||
pub id: RequestId,
|
||||
@@ -323,7 +319,7 @@ impl PendingRequest {
|
||||
}
|
||||
|
||||
/// A HTTP response.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct Response {
|
||||
/// Request id
|
||||
pub id: RequestId,
|
||||
@@ -452,8 +448,7 @@ impl Iterator for ResponseBody {
|
||||
}
|
||||
|
||||
/// A collection of Headers in the response.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct Headers {
|
||||
/// Raw headers
|
||||
pub raw: Vec<(Vec<u8>, Vec<u8>)>,
|
||||
@@ -483,8 +478,7 @@ impl Headers {
|
||||
}
|
||||
|
||||
/// A custom iterator traversing all the headers.
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, RuntimeDebug)]
|
||||
pub struct HeadersIterator<'a> {
|
||||
collection: &'a [(Vec<u8>, Vec<u8>)],
|
||||
index: Option<usize>,
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
//! Primitives for the runtime modules.
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::{self, result, marker::PhantomData, convert::{TryFrom, TryInto}};
|
||||
use rstd::{self, result, marker::PhantomData, convert::{TryFrom, TryInto}, fmt::Debug};
|
||||
use runtime_io;
|
||||
#[cfg(feature = "std")]
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::fmt::Display;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize, de::DeserializeOwned};
|
||||
use primitives::{self, Hasher, Blake2Hasher, TypeId};
|
||||
@@ -147,7 +147,7 @@ pub trait Lookup {
|
||||
/// context.
|
||||
pub trait StaticLookup {
|
||||
/// Type to lookup from.
|
||||
type Source: Codec + Clone + PartialEq + MaybeDebug;
|
||||
type Source: Codec + Clone + PartialEq + Debug;
|
||||
/// Type to lookup into.
|
||||
type Target;
|
||||
/// Attempt a lookup.
|
||||
@@ -159,7 +159,7 @@ pub trait StaticLookup {
|
||||
/// A lookup implementation returning the input value.
|
||||
#[derive(Default)]
|
||||
pub struct IdentityLookup<T>(PhantomData<T>);
|
||||
impl<T: Codec + Clone + PartialEq + MaybeDebug> StaticLookup for IdentityLookup<T> {
|
||||
impl<T: Codec + Clone + PartialEq + Debug> StaticLookup for IdentityLookup<T> {
|
||||
type Source = T;
|
||||
type Target = T;
|
||||
fn lookup(x: T) -> Result<T, LookupError> { Ok(x) }
|
||||
@@ -323,10 +323,10 @@ pub trait OffchainWorker<BlockNumber> {
|
||||
/// Abstraction around hashing
|
||||
// Stupid bug in the Rust compiler believes derived
|
||||
// traits must be fulfilled by all type parameters.
|
||||
pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq {
|
||||
pub trait Hash: 'static + MaybeSerializeDeserialize + Debug + Clone + Eq + PartialEq {
|
||||
/// The hash type produced.
|
||||
type Output: Member + MaybeSerializeDebug + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]> + Copy
|
||||
+ Default + Encode + Decode;
|
||||
type Output: Member + MaybeSerializeDeserialize + Debug + rstd::hash::Hash
|
||||
+ AsRef<[u8]> + AsMut<[u8]> + Copy + Default + Encode + Decode;
|
||||
|
||||
/// The associated hash_db Hasher type.
|
||||
type Hasher: Hasher<Out=Self::Output>;
|
||||
@@ -353,8 +353,8 @@ pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq {
|
||||
}
|
||||
|
||||
/// Blake2-256 Hash implementation.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(PartialEq, Eq, Clone, primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct BlakeTwo256;
|
||||
|
||||
impl Hash for BlakeTwo256 {
|
||||
@@ -410,7 +410,7 @@ impl CheckEqual for primitives::H256 {
|
||||
}
|
||||
}
|
||||
|
||||
impl<H: PartialEq + Eq + MaybeDebug> CheckEqual for super::generic::DigestItem<H> where H: Encode {
|
||||
impl<H: PartialEq + Eq + Debug> CheckEqual for super::generic::DigestItem<H> where H: Encode {
|
||||
#[cfg(feature = "std")]
|
||||
fn check_equal(&self, other: &Self) {
|
||||
if self != other {
|
||||
@@ -447,23 +447,17 @@ macro_rules! impl_maybe_marker {
|
||||
}
|
||||
|
||||
impl_maybe_marker!(
|
||||
/// A type that implements Debug when in std environment.
|
||||
MaybeDebug: Debug;
|
||||
|
||||
/// A type that implements Display when in std environment.
|
||||
MaybeDisplay: Display;
|
||||
|
||||
/// A type that implements Hash when in std environment.
|
||||
MaybeHash: ::rstd::hash::Hash;
|
||||
MaybeHash: rstd::hash::Hash;
|
||||
|
||||
/// A type that implements Serialize when in std environment.
|
||||
MaybeSerialize: Serialize;
|
||||
|
||||
/// A type that implements Serialize, DeserializeOwned and Debug when in std environment.
|
||||
MaybeSerializeDebug: Debug, DeserializeOwned, Serialize;
|
||||
|
||||
/// A type that implements Serialize and Debug when in std environment.
|
||||
MaybeSerializeDebugButNotDeserialize: Debug, Serialize
|
||||
MaybeSerializeDeserialize: DeserializeOwned, Serialize
|
||||
);
|
||||
|
||||
/// A type that provides a randomness beacon.
|
||||
@@ -483,8 +477,8 @@ pub trait RandomnessBeacon {
|
||||
}
|
||||
|
||||
/// A type that can be used in runtime structures.
|
||||
pub trait Member: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + MaybeDebug + Eq + PartialEq + Clone + 'static> Member for T {}
|
||||
pub trait Member: Send + Sync + Sized + Debug + Eq + PartialEq + Clone + 'static {}
|
||||
impl<T: Send + Sync + Sized + Debug + Eq + PartialEq + Clone + 'static> Member for T {}
|
||||
|
||||
/// Determine if a `MemberId` is a valid member.
|
||||
pub trait IsMember<MemberId> {
|
||||
@@ -497,11 +491,13 @@ pub trait IsMember<MemberId> {
|
||||
/// `parent_hash`, as well as a `digest` and a block `number`.
|
||||
///
|
||||
/// You can also create a `new` one from those fields.
|
||||
pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDeserialize + 'static {
|
||||
pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerialize + Debug + 'static {
|
||||
/// Header number.
|
||||
type Number: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + SimpleArithmetic + Codec;
|
||||
type Number: Member + MaybeSerializeDeserialize + Debug + rstd::hash::Hash
|
||||
+ Copy + MaybeDisplay + SimpleArithmetic + Codec;
|
||||
/// Header hash type
|
||||
type Hash: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
|
||||
type Hash: Member + MaybeSerializeDeserialize + Debug + rstd::hash::Hash
|
||||
+ Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
|
||||
/// Hashing algorithm
|
||||
type Hashing: Hash<Output = Self::Hash>;
|
||||
|
||||
@@ -549,13 +545,14 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDe
|
||||
/// `Extrinsic` piece of information as well as a `Header`.
|
||||
///
|
||||
/// You can get an iterator over each of the `extrinsics` and retrieve the `header`.
|
||||
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDeserialize + 'static {
|
||||
pub trait Block: Clone + Send + Sync + Codec + Eq + MaybeSerialize + Debug + 'static {
|
||||
/// Type of extrinsics.
|
||||
type Extrinsic: Member + Codec + Extrinsic + MaybeSerialize;
|
||||
/// Header type.
|
||||
type Header: Header<Hash=Self::Hash>;
|
||||
/// Block hash type.
|
||||
type Hash: Member + MaybeSerializeDebug + ::rstd::hash::Hash + Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
|
||||
type Hash: Member + MaybeSerializeDeserialize + Debug + rstd::hash::Hash
|
||||
+ Copy + MaybeDisplay + Default + SimpleBitOps + Codec + AsRef<[u8]> + AsMut<[u8]>;
|
||||
|
||||
/// Returns a reference to the header.
|
||||
fn header(&self) -> &Self::Header;
|
||||
@@ -661,7 +658,7 @@ pub trait Dispatchable {
|
||||
|
||||
/// Means by which a transaction may be extended. This type embodies both the data and the logic
|
||||
/// that should be additionally associated with the transaction. It should be plain old data.
|
||||
pub trait SignedExtension: Codec + MaybeDebug + Sync + Send + Clone + Eq + PartialEq {
|
||||
pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq {
|
||||
/// The type which encodes the sender identity.
|
||||
type AccountId;
|
||||
|
||||
@@ -1080,8 +1077,13 @@ macro_rules! impl_opaque_keys {
|
||||
)*
|
||||
}
|
||||
) => {
|
||||
#[derive(Default, Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, $crate::serde::Serialize, $crate::serde::Deserialize))]
|
||||
#[derive(
|
||||
Default, Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug
|
||||
)]
|
||||
#[cfg_attr(feature = "std", derive($crate::serde::Serialize, $crate::serde::Deserialize))]
|
||||
pub struct $name {
|
||||
$(
|
||||
pub $field: $type,
|
||||
@@ -1131,7 +1133,25 @@ pub trait Printable {
|
||||
|
||||
impl Printable for u8 {
|
||||
fn print(&self) {
|
||||
u64::from(*self).print()
|
||||
(*self as u64).print()
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for u32 {
|
||||
fn print(&self) {
|
||||
(*self as u64).print()
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for usize {
|
||||
fn print(&self) {
|
||||
(*self as u64).print()
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for u64 {
|
||||
fn print(&self) {
|
||||
runtime_io::print_num(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1147,9 +1167,10 @@ impl Printable for &str {
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for u64 {
|
||||
#[impl_for_tuples(1, 12)]
|
||||
impl Printable for Tuple {
|
||||
fn print(&self) {
|
||||
runtime_io::print_num(*self);
|
||||
for_tuples!( #( Tuple.print(); )* )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use crate::codec::{Encode, Decode};
|
||||
use crate::RuntimeDebug;
|
||||
|
||||
/// Priority for a transaction. Additive. Higher is better.
|
||||
pub type TransactionPriority = u64;
|
||||
@@ -30,8 +31,8 @@ pub type TransactionLongevity = u64;
|
||||
pub type TransactionTag = Vec<u8>;
|
||||
|
||||
/// An invalid transaction validity.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, serde::Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize))]
|
||||
pub enum InvalidTransaction {
|
||||
/// The call of the transaction is not expected.
|
||||
Call,
|
||||
@@ -81,8 +82,8 @@ impl From<InvalidTransaction> for &'static str {
|
||||
}
|
||||
|
||||
/// An unknown transaction validity.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, serde::Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize))]
|
||||
pub enum UnknownTransaction {
|
||||
/// Could not lookup some information that is required to validate the transaction.
|
||||
CannotLookup,
|
||||
@@ -105,8 +106,8 @@ impl From<UnknownTransaction> for &'static str {
|
||||
}
|
||||
|
||||
/// Errors that can occur while checking the validity of a transaction.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, serde::Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, Copy, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize))]
|
||||
pub enum TransactionValidityError {
|
||||
/// The transaction is invalid.
|
||||
Invalid(InvalidTransaction),
|
||||
@@ -173,8 +174,7 @@ impl Into<TransactionValidity> for UnknownTransaction {
|
||||
}
|
||||
|
||||
/// Information concerning a valid transaction.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct ValidTransaction {
|
||||
/// Priority of the transaction.
|
||||
///
|
||||
|
||||
@@ -23,16 +23,17 @@
|
||||
//! Note that the decl_module macro _cannot_ enforce this and will simply fail if an invalid struct
|
||||
//! (something that does not implement `Weighable`) is passed in.
|
||||
|
||||
pub use crate::transaction_validity::TransactionPriority;
|
||||
use arithmetic::traits::Bounded;
|
||||
use crate::RuntimeDebug;
|
||||
|
||||
pub use crate::transaction_validity::TransactionPriority;
|
||||
|
||||
/// Numeric range of a transaction weight.
|
||||
pub type Weight = u32;
|
||||
|
||||
/// A generalized group of dispatch types. This is only distinguishing normal, user-triggered transactions
|
||||
/// (`Normal`) and anything beyond which serves a higher purpose to the system (`Operational`).
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
#[derive(PartialEq, Eq, Clone, Copy, RuntimeDebug)]
|
||||
pub enum DispatchClass {
|
||||
/// A normal dispatch.
|
||||
Normal,
|
||||
@@ -61,8 +62,8 @@ impl From<SimpleDispatchInfo> for DispatchClass {
|
||||
}
|
||||
|
||||
/// A bundle of static information collected from the `#[weight = $x]` attributes.
|
||||
#[cfg_attr(feature = "std", derive(PartialEq, Eq, Debug))]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
#[cfg_attr(feature = "std", derive(PartialEq, Eq))]
|
||||
#[derive(Clone, Copy, Default, RuntimeDebug)]
|
||||
pub struct DispatchInfo {
|
||||
/// Weight of this transaction.
|
||||
pub weight: Weight,
|
||||
|
||||
@@ -51,7 +51,7 @@ mod imp {
|
||||
}
|
||||
|
||||
/// Error that can occur while using this crate.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(primitives::RuntimeDebug)]
|
||||
pub enum Error {
|
||||
/// Module is not valid, couldn't be instantiated.
|
||||
Module,
|
||||
|
||||
@@ -131,8 +131,7 @@ impl<Reporter, Offender> OnOffenceHandler<Reporter, Offender> for () {
|
||||
}
|
||||
|
||||
/// A details about an offending authority for a particular kind of offence.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, sr_primitives::RuntimeDebug)]
|
||||
pub struct OffenceDetails<Reporter, Offender> {
|
||||
/// The offending authority id
|
||||
pub offender: Offender,
|
||||
|
||||
@@ -53,6 +53,7 @@ pub use core::clone;
|
||||
pub use core::cmp;
|
||||
pub use core::convert;
|
||||
pub use core::default;
|
||||
pub use core::fmt;
|
||||
pub use core::hash;
|
||||
pub use core::intrinsics;
|
||||
pub use core::iter;
|
||||
|
||||
@@ -62,8 +62,8 @@ macro_rules! create_apis_vec {
|
||||
/// This triplet have different semantics and mis-interpretation could cause problems.
|
||||
/// In particular: bug fixes should result in an increment of `spec_version` and possibly `authoring_version`,
|
||||
/// absolutely not `impl_version` since they change the semantics of the runtime.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize, Decode))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Default, sr_primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Decode))]
|
||||
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
|
||||
pub struct RuntimeVersion {
|
||||
/// Identifies the different Substrate runtimes. There'll be at least polkadot and node.
|
||||
@@ -147,7 +147,7 @@ impl RuntimeVersion {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Debug)]
|
||||
pub struct NativeVersion {
|
||||
/// Basic runtime version info.
|
||||
pub runtime_version: RuntimeVersion,
|
||||
|
||||
@@ -28,6 +28,7 @@ use codec::{Encode, Decode, Input, Error};
|
||||
use primitives::{
|
||||
Blake2Hasher,
|
||||
OpaqueMetadata,
|
||||
RuntimeDebug,
|
||||
testing::{
|
||||
ED25519,
|
||||
SR25519,
|
||||
@@ -93,8 +94,7 @@ pub fn native_version() -> NativeVersion {
|
||||
}
|
||||
|
||||
/// Calls in transactions.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
pub struct Transfer {
|
||||
pub from: AccountId,
|
||||
pub to: AccountId,
|
||||
@@ -113,8 +113,7 @@ impl Transfer {
|
||||
}
|
||||
|
||||
/// Extrinsic for test-runtime.
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
pub enum Extrinsic {
|
||||
AuthoritiesChange(Vec<AuthorityId>),
|
||||
Transfer(Transfer, AccountSignature),
|
||||
@@ -353,8 +352,7 @@ impl_outer_origin!{
|
||||
pub enum Origin for Runtime where system = srml_system {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Encode, Decode, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug)]
|
||||
pub struct Event;
|
||||
|
||||
impl From<srml_system::Event> for Event {
|
||||
|
||||
@@ -22,7 +22,7 @@ use rstd::iter::once;
|
||||
|
||||
/// A node header
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(primitives::RuntimeDebug)]
|
||||
pub(crate) enum NodeHeader {
|
||||
Null,
|
||||
Branch(bool, usize),
|
||||
|
||||
@@ -66,4 +66,3 @@ pub type BlockId = generic::BlockId<Block>;
|
||||
|
||||
/// Opaque, encoded, unchecked extrinsic.
|
||||
pub type UncheckedExtrinsic = OpaqueExtrinsic;
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 181,
|
||||
impl_version: 181,
|
||||
impl_version: 182,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
@@ -195,8 +195,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode)]
|
||||
#[cfg_attr(any(feature = "std", test), derive(PartialEq, Debug))]
|
||||
#[derive(Encode, Decode, sr_primitives::RuntimeDebug)]
|
||||
#[cfg_attr(any(feature = "std", test), derive(PartialEq))]
|
||||
enum UncleEntryItem<BlockNumber, Hash, Author> {
|
||||
InclusionHeight(BlockNumber),
|
||||
Uncle(Hash, Option<Author>),
|
||||
|
||||
@@ -148,7 +148,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::{cmp, result, mem};
|
||||
use rstd::{cmp, result, mem, fmt::Debug};
|
||||
use codec::{Codec, Encode, Decode};
|
||||
use support::{
|
||||
StorageValue, Parameter, decl_event, decl_storage, decl_module,
|
||||
@@ -160,8 +160,9 @@ use support::{
|
||||
dispatch::Result,
|
||||
};
|
||||
use sr_primitives::{
|
||||
RuntimeDebug,
|
||||
traits::{
|
||||
Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDebug,
|
||||
Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDeserialize,
|
||||
Saturating, Bounded,
|
||||
},
|
||||
weights::SimpleDispatchInfo,
|
||||
@@ -176,7 +177,7 @@ pub use self::imbalances::{PositiveImbalance, NegativeImbalance};
|
||||
pub trait Subtrait<I: Instance = DefaultInstance>: system::Trait {
|
||||
/// The balance of an account.
|
||||
type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy +
|
||||
MaybeSerializeDebug + From<Self::BlockNumber>;
|
||||
MaybeSerializeDeserialize + Debug + From<Self::BlockNumber>;
|
||||
|
||||
/// A function that is invoked when the free-balance has fallen below the existential deposit and
|
||||
/// has been reduced to zero.
|
||||
@@ -200,7 +201,7 @@ pub trait Subtrait<I: Instance = DefaultInstance>: system::Trait {
|
||||
pub trait Trait<I: Instance = DefaultInstance>: system::Trait {
|
||||
/// The balance of an account.
|
||||
type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy +
|
||||
MaybeSerializeDebug + From<Self::BlockNumber>;
|
||||
MaybeSerializeDeserialize + Debug + From<Self::BlockNumber>;
|
||||
|
||||
/// A function that is invoked when the free-balance has fallen below the existential deposit and
|
||||
/// has been reduced to zero.
|
||||
@@ -255,8 +256,7 @@ decl_event!(
|
||||
);
|
||||
|
||||
/// Struct to encode the vesting schedule of an individual account.
|
||||
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct VestingSchedule<Balance, BlockNumber> {
|
||||
/// Locked amount at genesis.
|
||||
pub locked: Balance,
|
||||
@@ -283,8 +283,7 @@ impl<Balance: SimpleArithmetic + Copy, BlockNumber: SimpleArithmetic + Copy> Ves
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct BalanceLock<Balance, BlockNumber> {
|
||||
pub id: LockIdentifier,
|
||||
pub amount: Balance,
|
||||
@@ -772,7 +771,7 @@ impl<T: Subtrait<I>, I: Instance> Trait<I> for ElevatedTrait<T, I> {
|
||||
|
||||
impl<T: Trait<I>, I: Instance> Currency<T::AccountId> for Module<T, I>
|
||||
where
|
||||
T::Balance: MaybeSerializeDebug
|
||||
T::Balance: MaybeSerializeDeserialize + Debug
|
||||
{
|
||||
type Balance = T::Balance;
|
||||
type PositiveImbalance = PositiveImbalance<T, I>;
|
||||
@@ -1009,7 +1008,7 @@ where
|
||||
|
||||
impl<T: Trait<I>, I: Instance> ReservableCurrency<T::AccountId> for Module<T, I>
|
||||
where
|
||||
T::Balance: MaybeSerializeDebug
|
||||
T::Balance: MaybeSerializeDeserialize + Debug
|
||||
{
|
||||
fn can_reserve(who: &T::AccountId, value: Self::Balance) -> bool {
|
||||
Self::free_balance(who)
|
||||
@@ -1072,7 +1071,7 @@ where
|
||||
|
||||
impl<T: Trait<I>, I: Instance> LockableCurrency<T::AccountId> for Module<T, I>
|
||||
where
|
||||
T::Balance: MaybeSerializeDebug
|
||||
T::Balance: MaybeSerializeDeserialize + Debug
|
||||
{
|
||||
type Moment = T::BlockNumber;
|
||||
|
||||
@@ -1146,7 +1145,7 @@ where
|
||||
|
||||
impl<T: Trait<I>, I: Instance> IsDeadAccount<T::AccountId> for Module<T, I>
|
||||
where
|
||||
T::Balance: MaybeSerializeDebug
|
||||
T::Balance: MaybeSerializeDeserialize + Debug
|
||||
{
|
||||
fn is_dead_account(who: &T::AccountId) -> bool {
|
||||
Self::total_balance(who).is_zero()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
use rstd::{prelude::*, result};
|
||||
use primitives::u32_trait::Value as U32;
|
||||
use sr_primitives::RuntimeDebug;
|
||||
use sr_primitives::traits::{Hash, EnsureOrigin};
|
||||
use sr_primitives::weights::SimpleDispatchInfo;
|
||||
use support::{
|
||||
@@ -55,8 +56,7 @@ pub trait Trait<I=DefaultInstance>: system::Trait {
|
||||
}
|
||||
|
||||
/// Origin for the collective module.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub enum RawOrigin<AccountId, I> {
|
||||
/// It has been condoned by a given number of members of the collective from a given total.
|
||||
Members(MemberCount, MemberCount),
|
||||
@@ -69,8 +69,7 @@ pub enum RawOrigin<AccountId, I> {
|
||||
/// Origin for the collective module.
|
||||
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as system::Trait>::AccountId, I>;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
/// Info for keeping track of a motion being voted on.
|
||||
pub struct Votes<AccountId> {
|
||||
/// The proposal's unique index.
|
||||
|
||||
@@ -9,6 +9,7 @@ client = { package = "substrate-client", path = "../../../../core/client", defau
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
|
||||
rstd = { package = "sr-std", path = "../../../../core/sr-std", default-features = false }
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
sr-primitives = { path = "../../../../core/sr-primitives", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
@@ -17,4 +18,5 @@ std = [
|
||||
"codec/std",
|
||||
"rstd/std",
|
||||
"serde",
|
||||
"sr-primitives/std",
|
||||
]
|
||||
|
||||
@@ -24,10 +24,11 @@
|
||||
|
||||
use rstd::vec::Vec;
|
||||
use codec::{Encode, Decode, Codec};
|
||||
use sr_primitives::RuntimeDebug;
|
||||
|
||||
/// A result of execution of a contract.
|
||||
#[derive(Eq, PartialEq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum ContractExecResult {
|
||||
/// The contract returned successfully.
|
||||
///
|
||||
|
||||
@@ -60,7 +60,7 @@ impl ExecReturnValue {
|
||||
/// VM-specific errors during execution (eg. division by 0, OOB access, failure to satisfy some
|
||||
/// precondition of a system call, etc.) or errors with the orchestration (eg. out-of-gas errors, a
|
||||
/// non-existent destination contract, etc.).
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
#[cfg_attr(test, derive(sr_primitives::RuntimeDebug))]
|
||||
pub struct ExecError {
|
||||
pub reason: &'static str,
|
||||
/// This is an allocated buffer that may be reused. The buffer must be cleared explicitly
|
||||
@@ -231,7 +231,8 @@ impl<T: Trait> Token<T> for ExecFeeToken {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(any(feature = "std", test), derive(Debug, PartialEq, Eq, Clone))]
|
||||
#[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq, Clone))]
|
||||
#[derive(sr_primitives::RuntimeDebug)]
|
||||
pub enum DeferredAction<T: Trait> {
|
||||
DepositEvent {
|
||||
/// A list of topics this event will be deposited with.
|
||||
|
||||
@@ -109,15 +109,16 @@ pub use crate::exec::{ExecResult, ExecReturnValue, ExecError, StatusCode};
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use primitives::crypto::UncheckedFrom;
|
||||
use rstd::{prelude::*, marker::PhantomData};
|
||||
use rstd::{prelude::*, marker::PhantomData, fmt::Debug};
|
||||
use codec::{Codec, Encode, Decode};
|
||||
use runtime_io::blake2_256;
|
||||
use sr_primitives::{
|
||||
traits::{Hash, StaticLookup, Zero, MaybeSerializeDebug, Member, SignedExtension},
|
||||
traits::{Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension},
|
||||
weights::DispatchInfo,
|
||||
transaction_validity::{
|
||||
ValidTransaction, InvalidTransaction, TransactionValidity, TransactionValidityError,
|
||||
},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use support::dispatch::{Result, Dispatchable};
|
||||
use support::{
|
||||
@@ -143,8 +144,7 @@ pub trait ComputeDispatchFee<Call, Balance> {
|
||||
|
||||
/// Information for managing an acocunt and its sub trie abstraction.
|
||||
/// This is the required info to cache for an account
|
||||
#[derive(Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, RuntimeDebug)]
|
||||
pub enum ContractInfo<T: Trait> {
|
||||
Alive(AliveContractInfo<T>),
|
||||
Tombstone(TombstoneContractInfo<T>),
|
||||
@@ -207,9 +207,7 @@ pub type AliveContractInfo<T> =
|
||||
|
||||
/// Information for managing an account and its sub trie abstraction.
|
||||
/// This is the required info to cache for an account.
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct RawAliveContractInfo<CodeHash, Balance, BlockNumber> {
|
||||
/// Unique ID for the subtree encoded as a bytes vector.
|
||||
pub trie_id: TrieId,
|
||||
@@ -228,15 +226,14 @@ pub struct RawAliveContractInfo<CodeHash, Balance, BlockNumber> {
|
||||
pub type TombstoneContractInfo<T> =
|
||||
RawTombstoneContractInfo<<T as system::Trait>::Hash, <T as system::Trait>::Hashing>;
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Encode, Decode, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct RawTombstoneContractInfo<H, Hasher>(H, PhantomData<Hasher>);
|
||||
|
||||
impl<H, Hasher> RawTombstoneContractInfo<H, Hasher>
|
||||
where
|
||||
H: Member + MaybeSerializeDebug + AsRef<[u8]> + AsMut<[u8]> + Copy + Default + rstd::hash::Hash
|
||||
+ Codec,
|
||||
H: Member + MaybeSerializeDeserialize+ Debug
|
||||
+ AsRef<[u8]> + AsMut<[u8]> + Copy + Default
|
||||
+ rstd::hash::Hash + Codec,
|
||||
Hasher: Hash<Output=H>,
|
||||
{
|
||||
fn new(storage_root: &[u8], code_hash: H) -> Self {
|
||||
@@ -891,8 +888,8 @@ impl<T: Trait> Config<T> {
|
||||
}
|
||||
|
||||
/// Definition of the cost schedule and other parameterizations for wasm vm.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct Schedule {
|
||||
/// Version of the schedule.
|
||||
pub version: u32,
|
||||
@@ -988,9 +985,14 @@ impl<T: Trait + Send + Sync> Default for CheckBlockGasLimit<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> std::fmt::Debug for CheckBlockGasLimit<T> {
|
||||
fn fmt(&self, _: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckBlockGasLimit<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "CheckBlockGasLimit")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
use rstd::prelude::*;
|
||||
use rstd::{result, convert::TryFrom};
|
||||
use sr_primitives::{
|
||||
RuntimeDebug,
|
||||
traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash, Dispatchable},
|
||||
weights::SimpleDispatchInfo,
|
||||
};
|
||||
@@ -48,8 +49,7 @@ pub type PropIndex = u32;
|
||||
pub type ReferendumIndex = u32;
|
||||
|
||||
/// A value denoting the strength of conviction of a vote.
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug)]
|
||||
pub enum Conviction {
|
||||
/// 0.1x votes, unlocked.
|
||||
None,
|
||||
@@ -148,8 +148,7 @@ impl Bounded for Conviction {
|
||||
const MAX_RECURSION_LIMIT: u32 = 16;
|
||||
|
||||
/// A number of lock periods, plus a vote, one way or the other.
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Default, RuntimeDebug)]
|
||||
pub struct Vote {
|
||||
pub aye: bool,
|
||||
pub conviction: Conviction,
|
||||
@@ -231,8 +230,7 @@ pub trait Trait: system::Trait + Sized {
|
||||
}
|
||||
|
||||
/// Info regarding an ongoing referendum.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct ReferendumInfo<BlockNumber: Parameter, Proposal: Parameter> {
|
||||
/// When voting on this referendum will end.
|
||||
end: BlockNumber,
|
||||
|
||||
@@ -23,8 +23,8 @@ use sr_primitives::traits::{Zero, IntegerSquareRoot};
|
||||
use rstd::ops::{Add, Mul, Div, Rem};
|
||||
|
||||
/// A means of determining if a vote is past pass threshold.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, sr_primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum VoteThreshold {
|
||||
/// A supermajority of approvals is needed to pass this vote.
|
||||
SuperMajorityApprove,
|
||||
|
||||
@@ -25,7 +25,10 @@
|
||||
|
||||
use rstd::prelude::*;
|
||||
use sr_primitives::{
|
||||
print, traits::{Zero, One, StaticLookup, Bounded, Saturating}, weights::SimpleDispatchInfo,
|
||||
RuntimeDebug,
|
||||
print,
|
||||
traits::{Zero, One, StaticLookup, Bounded, Saturating},
|
||||
weights::SimpleDispatchInfo,
|
||||
};
|
||||
use support::{
|
||||
dispatch::Result, decl_storage, decl_event, ensure, decl_module,
|
||||
@@ -98,8 +101,7 @@ mod tests;
|
||||
// entries before they increase the capacity.
|
||||
|
||||
/// The activity status of a voter.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Default, RuntimeDebug)]
|
||||
pub struct VoterInfo<Balance> {
|
||||
/// Last VoteIndex in which this voter assigned (or initialized) approvals.
|
||||
last_active: VoteIndex,
|
||||
@@ -114,8 +116,7 @@ pub struct VoterInfo<Balance> {
|
||||
}
|
||||
|
||||
/// Used to demonstrate the status of a particular index in the global voter list.
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum CellStatus {
|
||||
/// Any out of bound index. Means a push a must happen to the chunk pointed by `NextVoterSet<T>`.
|
||||
/// Voting fee is applied in case a new chunk is created.
|
||||
|
||||
@@ -584,10 +584,9 @@ impl<T: Trait> Module<T> {
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct WatchDummy<T: Trait + Send + Sync>(PhantomData<T>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for WatchDummy<T> {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "WatchDummy<T>")
|
||||
write!(f, "WatchDummy")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,12 +153,13 @@
|
||||
|
||||
use codec::{Decode, Encode, HasCompact, Input, Output, Error};
|
||||
|
||||
use sr_primitives::RuntimeDebug;
|
||||
use sr_primitives::traits::{
|
||||
CheckedAdd, CheckedSub, MaybeSerializeDebug, Member, One, Saturating, SimpleArithmetic, Zero, Bounded
|
||||
CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Member, One, Saturating, SimpleArithmetic, Zero, Bounded
|
||||
};
|
||||
|
||||
use rstd::prelude::*;
|
||||
use rstd::{cmp, result};
|
||||
use rstd::{cmp, result, fmt::Debug};
|
||||
use support::dispatch::Result;
|
||||
use support::{
|
||||
decl_event, decl_module, decl_storage, ensure,
|
||||
@@ -181,7 +182,8 @@ pub trait Trait: system::Trait {
|
||||
+ SimpleArithmetic
|
||||
+ Default
|
||||
+ Copy
|
||||
+ MaybeSerializeDebug;
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug;
|
||||
type AssetId: Parameter + Member + SimpleArithmetic + Default + Copy;
|
||||
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
||||
}
|
||||
@@ -192,7 +194,8 @@ pub trait Subtrait: system::Trait {
|
||||
+ SimpleArithmetic
|
||||
+ Default
|
||||
+ Copy
|
||||
+ MaybeSerializeDebug;
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug;
|
||||
type AssetId: Parameter + Member + SimpleArithmetic + Default + Copy;
|
||||
}
|
||||
|
||||
@@ -202,8 +205,7 @@ impl<T: Trait> Subtrait for T {
|
||||
}
|
||||
|
||||
/// Asset creation options.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct AssetOptions<Balance: HasCompact, AccountId> {
|
||||
/// Initial issuance of this asset. All deposit to the creater of the asset.
|
||||
#[codec(compact)]
|
||||
@@ -213,8 +215,7 @@ pub struct AssetOptions<Balance: HasCompact, AccountId> {
|
||||
}
|
||||
|
||||
/// Owner of an asset.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum Owner<AccountId> {
|
||||
/// No owner.
|
||||
None,
|
||||
@@ -229,8 +230,7 @@ impl<AccountId> Default for Owner<AccountId> {
|
||||
}
|
||||
|
||||
/// Asset permissions
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct PermissionsV1<AccountId> {
|
||||
/// Who have permission to update asset permission
|
||||
pub update: Owner<AccountId>,
|
||||
@@ -240,16 +240,14 @@ pub struct PermissionsV1<AccountId> {
|
||||
pub burn: Owner<AccountId>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
|
||||
#[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)]
|
||||
#[repr(u8)]
|
||||
enum PermissionVersionNumber {
|
||||
V1 = 0,
|
||||
}
|
||||
|
||||
/// Versioned asset permission
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub enum PermissionVersions<AccountId> {
|
||||
V1(PermissionsV1<AccountId>),
|
||||
}
|
||||
@@ -435,8 +433,7 @@ decl_module! {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct BalanceLock<Balance, BlockNumber> {
|
||||
pub id: LockIdentifier,
|
||||
pub amount: Balance,
|
||||
@@ -1065,8 +1062,7 @@ impl<T: Subtrait> Trait for ElevatedTrait<T> {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct AssetCurrency<T, U>(rstd::marker::PhantomData<T>, rstd::marker::PhantomData<U>);
|
||||
|
||||
impl<T, U> Currency<T::AccountId> for AssetCurrency<T, U>
|
||||
@@ -1200,7 +1196,9 @@ where
|
||||
Self::free_balance(who)
|
||||
.checked_sub(&value)
|
||||
.map_or(false, |new_balance|
|
||||
<Module<T>>::ensure_can_withdraw(&U::asset_id(), who, value, WithdrawReason::Reserve, new_balance).is_ok()
|
||||
<Module<T>>::ensure_can_withdraw(
|
||||
&U::asset_id(), who, value, WithdrawReason::Reserve, new_balance
|
||||
).is_ok()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1254,7 +1252,7 @@ impl<T: Trait> AssetIdProvider for SpendingAssetIdProvider<T> {
|
||||
impl<T> LockableCurrency<T::AccountId> for AssetCurrency<T, StakingAssetIdProvider<T>>
|
||||
where
|
||||
T: Trait,
|
||||
T::Balance: MaybeSerializeDebug,
|
||||
T::Balance: MaybeSerializeDeserialize + Debug,
|
||||
{
|
||||
type Moment = T::BlockNumber;
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ use primitives::offchain::{OpaqueNetworkState, StorageKind};
|
||||
use rstd::prelude::*;
|
||||
use session::historical::IdentificationTuple;
|
||||
use sr_primitives::{
|
||||
RuntimeDebug,
|
||||
traits::{Convert, Member, Printable, Saturating}, Perbill,
|
||||
transaction_validity::{
|
||||
TransactionValidity, TransactionLongevity, ValidTransaction, InvalidTransaction,
|
||||
@@ -86,7 +87,7 @@ use sr_staking_primitives::{
|
||||
offence::{ReportOffence, Offence, Kind},
|
||||
};
|
||||
use support::{
|
||||
decl_module, decl_event, decl_storage, print, ensure, Parameter
|
||||
decl_module, decl_event, decl_storage, print, ensure, Parameter, debug
|
||||
};
|
||||
use system::ensure_none;
|
||||
use system::offchain::SubmitUnsignedTransaction;
|
||||
@@ -146,15 +147,14 @@ const DB_KEY: &[u8] = b"srml/im-online-worker-status";
|
||||
/// finishing it. With every execution of the off-chain worker we check
|
||||
/// if we need to recover and resume gossipping or if there is already
|
||||
/// another off-chain worker in the process of gossipping.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
struct WorkerStatus<BlockNumber> {
|
||||
done: bool,
|
||||
gossipping_at: BlockNumber,
|
||||
}
|
||||
|
||||
/// Error which may occur while executing the off-chain code.
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(RuntimeDebug)]
|
||||
enum OffchainErr {
|
||||
DecodeWorkerStatus,
|
||||
FailedSigning,
|
||||
@@ -176,8 +176,7 @@ impl Printable for OffchainErr {
|
||||
pub type AuthIndex = u32;
|
||||
|
||||
/// Heartbeat which is sent/received.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
|
||||
pub struct Heartbeat<BlockNumber>
|
||||
where BlockNumber: PartialEq + Eq + Decode + Encode,
|
||||
{
|
||||
@@ -280,6 +279,8 @@ decl_module! {
|
||||
|
||||
// Runs after every block.
|
||||
fn offchain_worker(now: T::BlockNumber) {
|
||||
debug::RuntimeLogger::init();
|
||||
|
||||
// Only send messages if we are a potential validator.
|
||||
if runtime_io::is_validator() {
|
||||
Self::offchain(now);
|
||||
@@ -319,6 +320,14 @@ impl<T: Trait> Module<T> {
|
||||
Ok(_) => {},
|
||||
Err(err) => print(err),
|
||||
}
|
||||
} else {
|
||||
debug::native::trace!(
|
||||
target: "imonline",
|
||||
"Skipping gossip at: {:?} >= {:?} || {:?}",
|
||||
next_gossip,
|
||||
now,
|
||||
if not_yet_gossipped { "not gossipped" } else { "gossipped" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,6 +355,13 @@ impl<T: Trait> Module<T> {
|
||||
|
||||
let signature = key.sign(&heartbeat_data.encode()).ok_or(OffchainErr::FailedSigning)?;
|
||||
let call = Call::heartbeat(heartbeat_data, signature);
|
||||
|
||||
debug::info!(
|
||||
target: "imonline",
|
||||
"[index: {:?}] Reporting im-online at block: {:?}",
|
||||
authority_index,
|
||||
block_number
|
||||
);
|
||||
T::SubmitTransaction::submit_unsigned(call)
|
||||
.map_err(|_| OffchainErr::SubmitTransaction)?;
|
||||
|
||||
@@ -538,7 +554,8 @@ impl<T: Trait> support::unsigned::ValidateUnsigned for Module<T> {
|
||||
}
|
||||
|
||||
/// An offence that is filed if a validator didn't send a heartbeat message.
|
||||
#[cfg_attr(feature = "std", derive(Clone, Debug, PartialEq, Eq))]
|
||||
#[derive(RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
|
||||
pub struct UnresponsivenessOffence<Offender> {
|
||||
/// The current session index in which we report the unresponsive validators.
|
||||
///
|
||||
|
||||
@@ -24,8 +24,8 @@ use codec::{Encode, Decode, Input, Output, Error};
|
||||
|
||||
/// An indices-aware address, which can be either a direct `AccountId` or
|
||||
/// an index.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Hash))]
|
||||
#[derive(PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Hash))]
|
||||
pub enum Address<AccountId, AccountIndex> where
|
||||
AccountId: Member,
|
||||
AccountIndex: Member,
|
||||
|
||||
@@ -28,6 +28,7 @@ use serde::Serialize;
|
||||
use codec::{Decode, Input, Error};
|
||||
use codec::{Encode, Output};
|
||||
use rstd::vec::Vec;
|
||||
use primitives::RuntimeDebug;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
type StringBuf = String;
|
||||
@@ -84,13 +85,12 @@ impl<B, O> Eq for DecodeDifferent<B, O>
|
||||
where B: Encode + Eq + PartialEq + 'static, O: Encode + Eq + PartialEq + 'static
|
||||
{}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<B, O> std::fmt::Debug for DecodeDifferent<B, O>
|
||||
impl<B, O> rstd::fmt::Debug for DecodeDifferent<B, O>
|
||||
where
|
||||
B: std::fmt::Debug + Eq + 'static,
|
||||
O: std::fmt::Debug + Eq + 'static,
|
||||
B: rstd::fmt::Debug + Eq + 'static,
|
||||
O: rstd::fmt::Debug + Eq + 'static,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
match self {
|
||||
DecodeDifferent::Encode(b) => b.fmt(f),
|
||||
DecodeDifferent::Decoded(o) => o.fmt(f),
|
||||
@@ -114,14 +114,11 @@ impl<B, O> serde::Serialize for DecodeDifferent<B, O>
|
||||
|
||||
pub type DecodeDifferentArray<B, O=B> = DecodeDifferent<&'static [B], Vec<O>>;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>;
|
||||
#[cfg(not(feature = "std"))]
|
||||
type DecodeDifferentStr = DecodeDifferent<&'static str, StringBuf>;
|
||||
|
||||
/// All the metadata about a function.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct FunctionMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub arguments: DecodeDifferentArray<FunctionArgumentMetadata>,
|
||||
@@ -129,8 +126,8 @@ pub struct FunctionMetadata {
|
||||
}
|
||||
|
||||
/// All the metadata about a function argument.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct FunctionArgumentMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub ty: DecodeDifferentStr,
|
||||
@@ -154,9 +151,8 @@ impl<E: Encode + PartialEq> PartialEq for FnEncode<E> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<E: Encode + ::std::fmt::Debug> std::fmt::Debug for FnEncode<E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl<E: Encode + rstd::fmt::Debug> rstd::fmt::Debug for FnEncode<E> {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
self.0().fmt(f)
|
||||
}
|
||||
}
|
||||
@@ -169,8 +165,8 @@ impl<E: Encode + serde::Serialize> serde::Serialize for FnEncode<E> {
|
||||
}
|
||||
|
||||
/// All the metadata about an outer event.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct OuterEventMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub events: DecodeDifferentArray<
|
||||
@@ -180,8 +176,8 @@ pub struct OuterEventMetadata {
|
||||
}
|
||||
|
||||
/// All the metadata about an event.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct EventMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub arguments: DecodeDifferentArray<&'static str, StringBuf>,
|
||||
@@ -189,8 +185,8 @@ pub struct EventMetadata {
|
||||
}
|
||||
|
||||
/// All the metadata about one storage entry.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct StorageEntryMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub modifier: StorageEntryModifier,
|
||||
@@ -200,8 +196,8 @@ pub struct StorageEntryMetadata {
|
||||
}
|
||||
|
||||
/// All the metadata about one module constant.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct ModuleConstantMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub ty: DecodeDifferentStr,
|
||||
@@ -210,8 +206,8 @@ pub struct ModuleConstantMetadata {
|
||||
}
|
||||
|
||||
/// All the metadata about a module error.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct ErrorMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub documentation: DecodeDifferentArray<&'static str, StringBuf>,
|
||||
@@ -265,16 +261,15 @@ impl serde::Serialize for DefaultByteGetter {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl std::fmt::Debug for DefaultByteGetter {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl rstd::fmt::Debug for DefaultByteGetter {
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
self.0.default_byte().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Hasher used by storage maps
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub enum StorageHasher {
|
||||
Blake2_128,
|
||||
Blake2_256,
|
||||
@@ -284,8 +279,8 @@ pub enum StorageHasher {
|
||||
}
|
||||
|
||||
/// A storage entry type.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub enum StorageEntryType {
|
||||
Plain(DecodeDifferentStr),
|
||||
Map {
|
||||
@@ -304,32 +299,32 @@ pub enum StorageEntryType {
|
||||
}
|
||||
|
||||
/// A storage entry modifier.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub enum StorageEntryModifier {
|
||||
Optional,
|
||||
Default,
|
||||
}
|
||||
|
||||
/// All metadata of the storage.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct StorageMetadata {
|
||||
/// The common prefix used by all storage entries.
|
||||
pub prefix: DecodeDifferent<&'static str, StringBuf>,
|
||||
pub entries: DecodeDifferent<&'static [StorageEntryMetadata], Vec<StorageEntryMetadata>>,
|
||||
}
|
||||
|
||||
#[derive(Eq, Encode, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Eq, Encode, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
/// Metadata prefixed by a u32 for reserved usage
|
||||
pub struct RuntimeMetadataPrefixed(pub u32, pub RuntimeMetadata);
|
||||
|
||||
/// The metadata of a runtime.
|
||||
/// The version ID encoded/decoded through
|
||||
/// the enum nature of `RuntimeMetadata`.
|
||||
#[derive(Eq, Encode, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Eq, Encode, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub enum RuntimeMetadata {
|
||||
/// Unused; enum filler.
|
||||
V0(RuntimeMetadataDeprecated),
|
||||
@@ -352,8 +347,8 @@ pub enum RuntimeMetadata {
|
||||
}
|
||||
|
||||
/// Enum that should fail.
|
||||
#[derive(Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize))]
|
||||
#[derive(Eq, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize))]
|
||||
pub enum RuntimeMetadataDeprecated { }
|
||||
|
||||
impl Encode for RuntimeMetadataDeprecated {
|
||||
@@ -370,8 +365,8 @@ impl Decode for RuntimeMetadataDeprecated {
|
||||
}
|
||||
|
||||
/// The metadata of a runtime.
|
||||
#[derive(Eq, Encode, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Eq, Encode, PartialEq, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct RuntimeMetadataV8 {
|
||||
pub modules: DecodeDifferentArray<ModuleMetadata>,
|
||||
}
|
||||
@@ -380,8 +375,8 @@ pub struct RuntimeMetadataV8 {
|
||||
pub type RuntimeMetadataLastVersion = RuntimeMetadataV8;
|
||||
|
||||
/// All metadata about an runtime module.
|
||||
#[derive(Clone, PartialEq, Eq, Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))]
|
||||
#[derive(Clone, PartialEq, Eq, Encode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode, Serialize))]
|
||||
pub struct ModuleMetadata {
|
||||
pub name: DecodeDifferentStr,
|
||||
pub storage: Option<DecodeDifferent<FnEncode<StorageMetadata>, StorageMetadata>>,
|
||||
|
||||
@@ -89,14 +89,17 @@ mod mock;
|
||||
mod tests;
|
||||
|
||||
use codec::FullCodec;
|
||||
use rstd::prelude::*;
|
||||
use rstd::{
|
||||
fmt::Debug,
|
||||
prelude::*,
|
||||
};
|
||||
use support::{
|
||||
decl_module, decl_storage, decl_event, ensure,
|
||||
traits::{ChangeMembers, InitializeMembers, Currency, Get, ReservableCurrency},
|
||||
};
|
||||
use system::{self, ensure_root, ensure_signed};
|
||||
use sr_primitives::{
|
||||
traits::{EnsureOrigin, SimpleArithmetic, MaybeSerializeDebug, Zero, StaticLookup},
|
||||
traits::{EnsureOrigin, SimpleArithmetic, MaybeSerializeDeserialize, Zero, StaticLookup},
|
||||
};
|
||||
|
||||
type BalanceOf<T, I> = <<T as Trait<I>>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
@@ -117,7 +120,8 @@ pub trait Trait<I=DefaultInstance>: system::Trait {
|
||||
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
|
||||
|
||||
/// The score attributed to a member or candidate.
|
||||
type Score: SimpleArithmetic + Clone + Copy + Default + FullCodec + MaybeSerializeDebug;
|
||||
type Score:
|
||||
SimpleArithmetic + Clone + Copy + Default + FullCodec + MaybeSerializeDeserialize + Debug;
|
||||
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
|
||||
|
||||
@@ -263,6 +263,7 @@ use support::{
|
||||
use session::{historical::OnSessionEnding, SelectInitialValidators};
|
||||
use sr_primitives::{
|
||||
Perbill,
|
||||
RuntimeDebug,
|
||||
curve::PiecewiseLinear,
|
||||
weights::SimpleDispatchInfo,
|
||||
traits::{
|
||||
@@ -313,7 +314,8 @@ impl EraPoints {
|
||||
}
|
||||
|
||||
/// Indicates the initial status of the staker.
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum StakerStatus<AccountId> {
|
||||
/// Chilling.
|
||||
Idle,
|
||||
@@ -324,8 +326,7 @@ pub enum StakerStatus<AccountId> {
|
||||
}
|
||||
|
||||
/// A destination account for payment.
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub enum RewardDestination {
|
||||
/// Pay into the stash account, increasing the amount at stake accordingly.
|
||||
Staked,
|
||||
@@ -342,8 +343,7 @@ impl Default for RewardDestination {
|
||||
}
|
||||
|
||||
/// Preference of what happens on a slash event.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub struct ValidatorPrefs<Balance: HasCompact> {
|
||||
/// Reward that validator takes up-front; only the rest is split between themselves and
|
||||
/// nominators.
|
||||
@@ -360,8 +360,7 @@ impl<B: Default + HasCompact + Copy> Default for ValidatorPrefs<B> {
|
||||
}
|
||||
|
||||
/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub struct UnlockChunk<Balance: HasCompact> {
|
||||
/// Amount of funds to be unlocked.
|
||||
#[codec(compact)]
|
||||
@@ -372,8 +371,7 @@ pub struct UnlockChunk<Balance: HasCompact> {
|
||||
}
|
||||
|
||||
/// The ledger of a (bonded) stash.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub struct StakingLedger<AccountId, Balance: HasCompact> {
|
||||
/// The stash account whose balance is actually locked and at stake.
|
||||
pub stash: AccountId,
|
||||
@@ -411,8 +409,7 @@ impl<
|
||||
}
|
||||
|
||||
/// The amount of exposure (to slashing) than an individual nominator has.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, RuntimeDebug)]
|
||||
pub struct IndividualExposure<AccountId, Balance: HasCompact> {
|
||||
/// The stash account of the nominator in question.
|
||||
who: AccountId,
|
||||
@@ -422,8 +419,7 @@ pub struct IndividualExposure<AccountId, Balance: HasCompact> {
|
||||
}
|
||||
|
||||
/// A snapshot of the stake backing a single validator in the system.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default, RuntimeDebug)]
|
||||
pub struct Exposure<AccountId, Balance: HasCompact> {
|
||||
/// The total balance backing this validator.
|
||||
#[codec(compact)]
|
||||
@@ -436,8 +432,7 @@ pub struct Exposure<AccountId, Balance: HasCompact> {
|
||||
}
|
||||
|
||||
/// A slashing event occurred, slashing a validator for a given amount of balance.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default, RuntimeDebug)]
|
||||
pub struct SlashJournalEntry<AccountId, Balance: HasCompact> {
|
||||
who: AccountId,
|
||||
amount: Balance,
|
||||
@@ -532,8 +527,8 @@ pub trait Trait: system::Trait {
|
||||
}
|
||||
|
||||
/// Mode of era-forcing.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub enum Forcing {
|
||||
/// Not forcing anything - just let whatever happen.
|
||||
NotForcing,
|
||||
|
||||
@@ -5,6 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
serde = { version = "1.0.101", optional = true, features = ["derive"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] }
|
||||
srml-metadata = { path = "../metadata", default-features = false }
|
||||
|
||||
@@ -184,8 +184,12 @@ fn create_and_impl_instance_struct(
|
||||
|
||||
quote! {
|
||||
// Those trait are derived because of wrong bounds for generics
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Eq, PartialEq, #scrate::codec::Encode, #scrate::codec::Decode)]
|
||||
#[derive(
|
||||
Clone, Eq, PartialEq,
|
||||
#scrate::codec::Encode,
|
||||
#scrate::codec::Decode,
|
||||
#scrate::RuntimeDebug,
|
||||
)]
|
||||
#doc
|
||||
pub struct #instance_struct;
|
||||
impl #instance_trait for #instance_struct {
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Runtime debugging and logging utilities.
|
||||
//!
|
||||
//! This module contains macros and functions that will allow
|
||||
//! you to print logs out of the runtime code.
|
||||
//!
|
||||
//! First and foremost be aware that adding regular logging code to
|
||||
//! your runtime will have a negative effect on the performance
|
||||
//! and size of the blob. Luckily there are some ways to mitigate
|
||||
//! this that are described below.
|
||||
//!
|
||||
//! First component to utilize debug-printing and loggin is actually
|
||||
//! located in `primitives` crate: `primitives::RuntimeDebug`.
|
||||
//! This custom-derive generates `core::fmt::Debug` implementation,
|
||||
//! just like regular `derive(Debug)`, however it does not generate
|
||||
//! any code when the code is compiled to WASM. This means that
|
||||
//! you can safely sprinkle `RuntimeDebug` in your runtime codebase,
|
||||
//! without affecting the size. This also allows you to print/log
|
||||
//! both when the code is running natively or in WASM, but note
|
||||
//! that WASM debug formatting of structs will be empty.
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use srml_support::debug;
|
||||
//!
|
||||
//! #[derive(primitives::RuntimeDebug)]
|
||||
//! struct MyStruct {
|
||||
//! a: u64,
|
||||
//! }
|
||||
//!
|
||||
//! // First initialize the logger.
|
||||
//! //
|
||||
//! // This is only required when you want the logs to be printed
|
||||
//! // also during non-native run.
|
||||
//! // Note that enabling the logger has performance impact on
|
||||
//! // WASM runtime execution and should be used sparingly.
|
||||
//! debug::RuntimeLogger::init();
|
||||
//!
|
||||
//! let x = MyStruct { a: 5 };
|
||||
//! // will log an info line `"My struct: MyStruct{a:5}"` when running
|
||||
//! // natively, but will only print `"My struct: "` when running WASM.
|
||||
//! debug::info!("My struct: {:?}", x);
|
||||
//!
|
||||
//! // same output here, although this will print to stdout
|
||||
//! // (and without log format)
|
||||
//! debug::print!("My struct: {:?}", x);
|
||||
//! ```
|
||||
//!
|
||||
//! If you want to avoid extra overhead in WASM, but still be able
|
||||
//! to print / log when the code is executed natively you can use
|
||||
//! macros coming from `native` sub-module. This module enables
|
||||
//! logs conditionally and strips out logs in WASM.
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use srml_support::debug::native;
|
||||
//!
|
||||
//! #[derive(primitives::RuntimeDebug)]
|
||||
//! struct MyStruct {
|
||||
//! a: u64,
|
||||
//! }
|
||||
//!
|
||||
//! // We don't initialize the logger, since
|
||||
//! // we are not printing anything out in WASM.
|
||||
//! // debug::RuntimeLogger::init();
|
||||
//!
|
||||
//! let x = MyStruct { a: 5 };
|
||||
//!
|
||||
//! // Displays an info log when running natively, nothing when WASM.
|
||||
//! native::info!("My struct: {:?}", x);
|
||||
//!
|
||||
//! // same output to stdout, no overhead on WASM.
|
||||
//! native::print!("My struct: {:?}", x);
|
||||
//! ```
|
||||
|
||||
use rstd::vec::Vec;
|
||||
use rstd::fmt::{self, Debug};
|
||||
|
||||
pub use log::{info, debug, error, trace, warn};
|
||||
pub use crate::runtime_print as print;
|
||||
|
||||
/// Native-only logging.
|
||||
///
|
||||
/// Using any functions from this module will have any effect
|
||||
/// only if the runtime is running natively (i.e. not via WASM)
|
||||
#[cfg(feature = "std")]
|
||||
pub mod native {
|
||||
pub use super::{info, debug, error, trace, warn, print};
|
||||
}
|
||||
|
||||
/// Native-only logging.
|
||||
///
|
||||
/// Using any functions from this module will have any effect
|
||||
/// only if the runtime is running natively (i.e. not via WASM)
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub mod native {
|
||||
#[macro_export]
|
||||
macro_rules! noop {
|
||||
($($arg:tt)+) => {}
|
||||
}
|
||||
pub use noop as info;
|
||||
pub use noop as debug;
|
||||
pub use noop as error;
|
||||
pub use noop as trace;
|
||||
pub use noop as warn;
|
||||
pub use noop as print;
|
||||
}
|
||||
|
||||
/// Print out a formatted message.
|
||||
#[macro_export]
|
||||
macro_rules! runtime_print {
|
||||
($($arg:tt)+) => {
|
||||
use core::fmt::Write;
|
||||
let mut w = $crate::debug::Writer::default();
|
||||
let _ = core::write!(&mut w, $($arg)+);
|
||||
w.print();
|
||||
}
|
||||
}
|
||||
|
||||
/// Print out the debuggable type.
|
||||
pub fn debug(data: &impl Debug) {
|
||||
runtime_print!("{:?}", data);
|
||||
}
|
||||
|
||||
/// A target for `core::write!` macro - constructs a string in memory.
|
||||
#[derive(Default)]
|
||||
pub struct Writer(Vec<u8>);
|
||||
|
||||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
self.0.extend(s.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Writer {
|
||||
/// Print the content of this `Writer` out.
|
||||
pub fn print(&self) {
|
||||
runtime_io::print_utf8(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Runtime logger implementation - `log` crate backend.
|
||||
///
|
||||
/// The logger should be initialized if you want to display
|
||||
/// logs inside the runtime that is not necessarily running natively.
|
||||
///
|
||||
/// When runtime is executed natively any log statements are displayed
|
||||
/// even if this logger is NOT initialized.
|
||||
///
|
||||
/// Note that even though the logs are not displayed in WASM, they
|
||||
/// may still affect the size and performance of the generated runtime.
|
||||
/// To lower the footprint make sure to only use macros from `native`
|
||||
/// sub-module.
|
||||
pub struct RuntimeLogger;
|
||||
|
||||
impl RuntimeLogger {
|
||||
/// Initialize the logger.
|
||||
///
|
||||
/// This is a no-op when running natively (`std`).
|
||||
#[cfg(feature = "std")]
|
||||
pub fn init() {}
|
||||
|
||||
/// Initialize the logger.
|
||||
///
|
||||
/// This is a no-op when running natively (`std`).
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub fn init() {
|
||||
static LOGGER: RuntimeLogger = RuntimeLogger;;
|
||||
let _ = log::set_logger(&LOGGER);
|
||||
}
|
||||
}
|
||||
|
||||
impl log::Log for RuntimeLogger {
|
||||
fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
||||
// to avoid calling to host twice, we pass everything
|
||||
// and let the host decide what to print.
|
||||
// If someone is initializing the logger they should
|
||||
// know what they are doing.
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
use fmt::Write;
|
||||
let mut w = Writer::default();
|
||||
let _ = core::write!(&mut w, "{}", record.args());
|
||||
|
||||
runtime_io::log(
|
||||
record.level().into(),
|
||||
record.target().as_bytes(),
|
||||
&w.0,
|
||||
);
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
@@ -17,9 +17,7 @@
|
||||
//! Dispatch system. Contains a macro for defining runtime modules and
|
||||
//! generating values representing lazy module function calls.
|
||||
|
||||
pub use crate::rstd::{result, prelude::{Vec, Clone, Eq, PartialEq}, marker};
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::fmt;
|
||||
pub use crate::rstd::{result, fmt, prelude::{Vec, Clone, Eq, PartialEq}, marker};
|
||||
pub use crate::codec::{Codec, EncodeLike, Decode, Encode, Input, Output, HasCompact, EncodeAsRef};
|
||||
pub use srml_metadata::{
|
||||
FunctionMetadata, DecodeDifferent, DecodeDifferentArray, FunctionArgumentMetadata,
|
||||
@@ -29,7 +27,9 @@ pub use sr_primitives::{
|
||||
weights::{
|
||||
SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch,
|
||||
TransactionPriority
|
||||
}, traits::{Dispatchable, DispatchResult, ModuleDispatchError}, DispatchError
|
||||
},
|
||||
traits::{Dispatchable, DispatchResult, ModuleDispatchError},
|
||||
DispatchError,
|
||||
};
|
||||
|
||||
/// A type that cannot be instantiated.
|
||||
@@ -48,18 +48,9 @@ pub trait Callable<T> {
|
||||
// https://github.com/rust-lang/rust/issues/51331
|
||||
pub type CallableCallFor<A, T> = <A as Callable<T>>::Call;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub trait Parameter: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq + fmt::Debug {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub trait Parameter: Codec + EncodeLike + Clone + Eq {}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
impl<T> Parameter for T where T: Codec + EncodeLike + Clone + Eq {}
|
||||
|
||||
/// Declares a `Module` struct and a `Call` enum, which implements the dispatch logic.
|
||||
///
|
||||
/// ## Declaration
|
||||
@@ -1071,8 +1062,7 @@ macro_rules! decl_module {
|
||||
$crate::__check_reserved_fn_name! { $( $fn_name )* }
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, $crate::RuntimeDebug)]
|
||||
pub struct $mod_type<
|
||||
$trait_instance: $trait_name
|
||||
$(<I>, $instance: $instantiable $( = $module_default_instance)?)?
|
||||
@@ -1223,7 +1213,6 @@ macro_rules! decl_module {
|
||||
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<$trait_instance: $trait_name $(<I>, $instance: $instantiable)?> $crate::dispatch::fmt::Debug
|
||||
for $call_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )*
|
||||
{
|
||||
@@ -1325,8 +1314,12 @@ macro_rules! impl_outer_dispatch {
|
||||
}
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
pub enum $call_type {
|
||||
$(
|
||||
$camelcase ( $crate::dispatch::CallableCallFor<$camelcase, $runtime> )
|
||||
|
||||
@@ -56,8 +56,7 @@ macro_rules! decl_error {
|
||||
$(,)?
|
||||
}
|
||||
) => {
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, $crate::RuntimeDebug)]
|
||||
$(#[$attr])*
|
||||
pub enum $error {
|
||||
Other(&'static str),
|
||||
|
||||
@@ -121,8 +121,12 @@ macro_rules! decl_event {
|
||||
}
|
||||
) => {
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
/// Events for this module.
|
||||
///
|
||||
$(#[$attr])*
|
||||
@@ -260,9 +264,12 @@ macro_rules! __decl_generic_event {
|
||||
/// [`Trait`]: trait.Trait.html
|
||||
pub type Event<$event_generic_param $(, $instance $( = $event_default_instance)? )?> = RawEvent<$( $generic_type ),* $(, $instance)? >;
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
/// Events for this module.
|
||||
///
|
||||
$(#[$attr])*
|
||||
@@ -452,8 +459,12 @@ macro_rules! impl_outer_event {
|
||||
$( $module_name:ident::Event $( <$generic_param:ident> )? $( { $generic_instance:ident } )?, )*;
|
||||
) => {
|
||||
$crate::paste::item! {
|
||||
#[derive(Clone, PartialEq, Eq, $crate::codec::Encode, $crate::codec::Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::RuntimeDebug,
|
||||
)]
|
||||
$(#[$attr])*
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum $name {
|
||||
|
||||
@@ -40,7 +40,11 @@ pub use paste;
|
||||
pub use runtime_io::with_storage;
|
||||
#[doc(hidden)]
|
||||
pub use runtime_io::storage_root;
|
||||
#[doc(hidden)]
|
||||
pub use sr_primitives::RuntimeDebug;
|
||||
|
||||
#[macro_use]
|
||||
pub mod debug;
|
||||
#[macro_use]
|
||||
pub mod dispatch;
|
||||
#[macro_use]
|
||||
@@ -224,8 +228,7 @@ macro_rules! __assert_eq_uvec {
|
||||
|
||||
/// The void type - it cannot exist.
|
||||
// Oh rust, you crack me up...
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Eq, PartialEq, RuntimeDebug)]
|
||||
pub enum Void {}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -151,9 +151,7 @@ macro_rules! impl_outer_origin {
|
||||
$( $module:ident $( < $generic:ident > )? $( { $generic_instance:ident } )? ,)*
|
||||
) => {
|
||||
$crate::paste::item! {
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, PartialEq, Eq, $crate::RuntimeDebug)]
|
||||
$(#[$attr])*
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum $name {
|
||||
|
||||
@@ -191,8 +191,7 @@ macro_rules! construct_runtime {
|
||||
)*
|
||||
};
|
||||
) => {
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, $crate::RuntimeDebug)]
|
||||
pub struct $runtime;
|
||||
impl $crate::sr_primitives::traits::GetNodeBlockType for $runtime {
|
||||
type NodeBlock = $node_block;
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
//!
|
||||
//! NOTE: If you're looking for `parameter_types`, it has moved in to the top-level module.
|
||||
|
||||
use rstd::{prelude::*, result, marker::PhantomData, ops::Div};
|
||||
use rstd::{prelude::*, result, marker::PhantomData, ops::Div, fmt::Debug};
|
||||
use codec::{FullCodec, Codec, Encode, Decode};
|
||||
use primitives::u32_trait::Value as U32;
|
||||
use sr_primitives::{
|
||||
ConsensusEngineId,
|
||||
traits::{MaybeSerializeDebug, SimpleArithmetic, Saturating},
|
||||
traits::{MaybeSerializeDeserialize, SimpleArithmetic, Saturating},
|
||||
};
|
||||
|
||||
/// Anything that can have a `::len()` method.
|
||||
@@ -257,7 +257,7 @@ pub enum SignedImbalance<B, P: Imbalance<B>>{
|
||||
impl<
|
||||
P: Imbalance<B, Opposite=N>,
|
||||
N: Imbalance<B, Opposite=P>,
|
||||
B: SimpleArithmetic + FullCodec + Copy + MaybeSerializeDebug + Default,
|
||||
B: SimpleArithmetic + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default,
|
||||
> SignedImbalance<B, P> {
|
||||
pub fn zero() -> Self {
|
||||
SignedImbalance::Positive(P::zero())
|
||||
@@ -320,7 +320,7 @@ impl<
|
||||
/// Abstraction over a fungible assets system.
|
||||
pub trait Currency<AccountId> {
|
||||
/// The balance of an account.
|
||||
type Balance: SimpleArithmetic + FullCodec + Copy + MaybeSerializeDebug + Default;
|
||||
type Balance: SimpleArithmetic + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
|
||||
|
||||
/// The opaque token type for an imbalance. This is returned by unbalanced operations
|
||||
/// and must be dealt with. It may be dropped but cannot be cloned.
|
||||
|
||||
@@ -87,8 +87,7 @@ mod module1 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
|
||||
pub enum Origin<T: Trait<I>, I> where T::BlockNumber: From<u32> {
|
||||
Members(u32),
|
||||
_Phantom(std::marker::PhantomData<(T, I)>),
|
||||
@@ -150,8 +149,7 @@ mod module2 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
|
||||
pub enum Origin<T: Trait<I>, I=DefaultInstance> {
|
||||
Members(u32),
|
||||
_Phantom(std::marker::PhantomData<(T, I)>),
|
||||
|
||||
@@ -38,8 +38,7 @@ support::decl_error! {
|
||||
}
|
||||
|
||||
/// Origin for the system module.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, sr_primitives::RuntimeDebug)]
|
||||
pub enum RawOrigin<AccountId> {
|
||||
Root,
|
||||
Signed(AccountId),
|
||||
|
||||
@@ -94,8 +94,10 @@ use rstd::prelude::*;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use rstd::map;
|
||||
use rstd::marker::PhantomData;
|
||||
use rstd::fmt::Debug;
|
||||
use sr_version::RuntimeVersion;
|
||||
use sr_primitives::{
|
||||
RuntimeDebug,
|
||||
generic::{self, Era}, Perbill, ApplyError, ApplyOutcome, DispatchError,
|
||||
weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo},
|
||||
transaction_validity::{
|
||||
@@ -105,7 +107,7 @@ use sr_primitives::{
|
||||
traits::{
|
||||
self, CheckEqual, SimpleArithmetic, Zero, SignedExtension, Lookup, LookupError,
|
||||
SimpleBitOps, Hash, Member, MaybeDisplay, EnsureOrigin, SaturatedConversion,
|
||||
MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup, One, Bounded,
|
||||
MaybeSerialize, MaybeSerializeDeserialize, StaticLookup, One, Bounded,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -158,28 +160,28 @@ pub trait Trait: 'static + Eq + Clone {
|
||||
type Origin: Into<Result<RawOrigin<Self::AccountId>, Self::Origin>> + From<RawOrigin<Self::AccountId>>;
|
||||
|
||||
/// The aggregated `Call` type.
|
||||
type Call;
|
||||
type Call: Debug;
|
||||
|
||||
/// Account index (aka nonce) type. This stores the number of previous transactions associated with a sender
|
||||
/// account.
|
||||
type Index:
|
||||
Parameter + Member + MaybeSerializeDebugButNotDeserialize + Default + MaybeDisplay + SimpleArithmetic + Copy;
|
||||
Parameter + Member + MaybeSerialize + Debug + Default + MaybeDisplay + SimpleArithmetic + Copy;
|
||||
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber:
|
||||
Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleArithmetic + Default + Bounded + Copy
|
||||
+ rstd::hash::Hash;
|
||||
Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + SimpleArithmetic
|
||||
+ Default + Bounded + Copy + rstd::hash::Hash;
|
||||
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash:
|
||||
Parameter + Member + MaybeSerializeDebug + MaybeDisplay + SimpleBitOps + Default + Copy + CheckEqual
|
||||
+ rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]>;
|
||||
Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + SimpleBitOps
|
||||
+ Default + Copy + CheckEqual + rstd::hash::Hash + AsRef<[u8]> + AsMut<[u8]>;
|
||||
|
||||
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
|
||||
type Hashing: Hash<Output = Self::Hash>;
|
||||
|
||||
/// The user account identifier type for the runtime.
|
||||
type AccountId: Parameter + Member + MaybeSerializeDebug + MaybeDisplay + Ord + Default;
|
||||
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default;
|
||||
|
||||
/// Converting trait to take a source type and convert to `AccountId`.
|
||||
///
|
||||
@@ -195,7 +197,7 @@ pub trait Trait: 'static + Eq + Clone {
|
||||
>;
|
||||
|
||||
/// The aggregated event type of the runtime.
|
||||
type Event: Parameter + Member + From<Event>;
|
||||
type Event: Parameter + Member + From<Event> + Debug;
|
||||
|
||||
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
|
||||
type BlockHashCount: Get<Self::BlockNumber>;
|
||||
@@ -280,8 +282,8 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// A phase of a block's execution.
|
||||
#[derive(Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone, Debug))]
|
||||
#[derive(Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone))]
|
||||
pub enum Phase {
|
||||
/// Applying an extrinsic.
|
||||
ApplyExtrinsic(u32),
|
||||
@@ -290,8 +292,8 @@ pub enum Phase {
|
||||
}
|
||||
|
||||
/// Record of an event happening.
|
||||
#[derive(Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone, Debug))]
|
||||
#[derive(Encode, Decode, RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, PartialEq, Eq, Clone))]
|
||||
pub struct EventRecord<E: Parameter + Member, T> {
|
||||
/// The phase of the block it happened in.
|
||||
pub phase: Phase,
|
||||
@@ -323,8 +325,7 @@ decl_error! {
|
||||
}
|
||||
|
||||
/// Origin for the System module.
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
||||
pub enum RawOrigin<AccountId> {
|
||||
/// The system itself ordained this dispatch to happen: this is the highest privilege level.
|
||||
Root,
|
||||
@@ -855,10 +856,15 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckWeight<T> {
|
||||
impl<T: Trait + Send + Sync> Debug for CheckWeight<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "CheckWeight<T>")
|
||||
write!(f, "CheckWeight")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -873,11 +879,16 @@ impl<T: Trait> CheckNonce<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait> rstd::fmt::Debug for CheckNonce<T> {
|
||||
impl<T: Trait> Debug for CheckNonce<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> SignedExtension for CheckNonce<T> {
|
||||
@@ -951,11 +962,16 @@ impl<T: Trait + Send + Sync> CheckEra<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckEra<T> {
|
||||
impl<T: Trait + Send + Sync> Debug for CheckEra<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
|
||||
@@ -994,9 +1010,14 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> {
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckGenesis<T: Trait + Send + Sync>(rstd::marker::PhantomData<T>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckGenesis<T> {
|
||||
fn fmt(&self, _f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
impl<T: Trait + Send + Sync> Debug for CheckGenesis<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "CheckGenesis")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1023,9 +1044,14 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> {
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
|
||||
pub struct CheckVersion<T: Trait + Send + Sync>(rstd::marker::PhantomData<T>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for CheckVersion<T> {
|
||||
fn fmt(&self, _f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
impl<T: Trait + Send + Sync> Debug for CheckVersion<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "CheckVersion")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +111,8 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"timstap0";
|
||||
pub type InherentType = u64;
|
||||
|
||||
/// Errors that can occur while checking the timestamp inherent.
|
||||
#[derive(Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug, Decode))]
|
||||
#[derive(Encode, sr_primitives::RuntimeDebug)]
|
||||
#[cfg_attr(feature = "std", derive(Decode))]
|
||||
pub enum InherentError {
|
||||
/// The timestamp is valid in the future.
|
||||
/// This is a non-fatal-error and will not stop checking the inherents.
|
||||
|
||||
@@ -145,11 +145,15 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Trait + Send + Sync> rstd::fmt::Debug for ChargeTransactionPayment<T> {
|
||||
#[cfg(feature = "std")]
|
||||
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
write!(f, "ChargeTransactionPayment<{:?}>", self.0)
|
||||
}
|
||||
#[cfg(not(feature = "std"))]
|
||||
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T>
|
||||
|
||||
@@ -213,8 +213,8 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// A spending proposal.
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, sr_primitives::RuntimeDebug)]
|
||||
pub struct Proposal<AccountId, Balance> {
|
||||
proposer: AccountId,
|
||||
value: Balance,
|
||||
|
||||
Reference in New Issue
Block a user