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:
Tomasz Drwięga
2019-10-22 14:13:44 +02:00
committed by Bastian Köcher
parent 934d7aac1c
commit 20a3989785
86 changed files with 1266 additions and 469 deletions
+41 -46
View File
@@ -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>>,