diff --git a/demo/executor/src/lib.rs b/demo/executor/src/lib.rs index cef697589e702..89ab8de55974e 100644 --- a/demo/executor/src/lib.rs +++ b/demo/executor/src/lib.rs @@ -257,7 +257,7 @@ mod tests { // Blake // hex!("3437bf4b182ab17bb322af5c67e55f6be487a77084ad2b4e27ddac7242e4ad21").into(), // Keccak - hex!("56c9a542e48ccf4e0821de301ea4384e87425604278b12a9db31c6d4e89ca51e").into(), + hex!("0b401681b95d04e91dbe53835867bdcb5d9e0590b54ae06bd7b347d49f9a737f").into(), vec![BareExtrinsic { signed: alice(), index: 0, @@ -273,7 +273,7 @@ mod tests { // Blake // hex!("741fcb660e6fa9f625fbcd993b49f6c1cc4040f5e0cc8727afdedf11fd3c464b").into(), // Keccak - hex!("166a2593d35f2d1bc87eca8cf2e320ed06759000a02aa88e51fa85b12c6f1267").into(), + hex!("03f051dc4f588fdc713145772486a129d33c7f178c133b5801fa79c3ecca2dc9").into(), vec![ BareExtrinsic { signed: bob(), @@ -296,7 +296,7 @@ mod tests { // Blake // hex!("2c7231a9c210a7aa4bea169d944bc4aaacd517862b244b8021236ffa7f697991").into(), // Keccak - hex!("be186810570e437f0d803493fced9879207b064a0701fd8d68662b9563b4d33e").into(), + hex!("6e3b6aaf0be927394b520e3ebc0c34a7c26519711bc836e116e371273c3aca44").into(), vec![BareExtrinsic { signed: alice(), index: 0, diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm index 13f21018e4b30..02a7fed93297c 100644 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm differ diff --git a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm index 18a824ea0eb23..b3376fd74f7cd 100755 Binary files a/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm and b/demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm differ diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm index 70c0935b3f41f..dc23e6a75f3dd 100644 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm differ diff --git a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm index 086250bae2849..c1ef690b3fa2c 100755 Binary files a/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm and b/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm differ diff --git a/substrate/runtime-support/src/storage/generator.rs b/substrate/runtime-support/src/storage/generator.rs index ed15dc845cf96..54a551addf848 100644 --- a/substrate/runtime-support/src/storage/generator.rs +++ b/substrate/runtime-support/src/storage/generator.rs @@ -182,6 +182,125 @@ pub trait StorageMap { } } +// TODO: Remove this in favour of `decl_storage` macro. +/// Declares strongly-typed wrappers around codec-compatible types in storage. +#[macro_export] +macro_rules! storage_items { + // simple values + ($name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() () (Option<$ty>) (get) (take) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) () (Option<$ty>) (get) (take) $name: $key => $ty); + storage_items!($($t)*); + }; + ($name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); + storage_items!($($t)*); + }; + ($name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $key => $ty); + storage_items!($($t)*); + }; + + ($name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); + storage_items!($($t)*); + }; + ($name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); + storage_items!($($t)*); + }; + ($name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); + storage_items!($($t)*); + }; + + // maps + ($name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + ($name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + ($name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + + ($name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + ($name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + ($name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + (pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); + storage_items!($($t)*); + }; + + + // lists + ($name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { + __storage_items_internal!(() $name: $prefix => list [$ty]); + storage_items!($($t)*); + }; + (pub $name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { + __storage_items_internal!((pub) $name: $prefix => list [$ty]); + storage_items!($($t)*); + }; + () => () +} + #[macro_export] #[doc(hidden)] macro_rules! __storage_items_internal { @@ -331,132 +450,170 @@ macro_rules! __storage_items_internal { }; } +// TODO: revisit this idiom once we get `type`s in `impl`s. +/*impl Module { + type Now = super::Now; +}*/ + /// Declares strongly-typed wrappers around codec-compatible types in storage. +/// +/// For now we implement a convenience trait with pre-specialised associated types, one for each +/// storage item. This allows you to gain access to publicly visisible storage items from a +/// module type. Currently you must disambiguate by using `::Item` rather than +/// the simpler `Module::Item`. Hopefully the rust guys with fix this soon. #[macro_export] -macro_rules! storage_items { +macro_rules! decl_storage { + ( + trait $storetype:ident for $modulename:ident<$traitinstance:ident: $traittype:ident> as $cratename:ident { + $($t:tt)* + } + ) => { + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); + trait $storetype { + __decl_store_items!($($t)*); + } + impl<$traitinstance: $traittype> $storetype for $modulename<$traitinstance> { + __impl_store_items!($traitinstance $($t)*); + } + impl<$traitinstance: $traittype> $modulename<$traitinstance> { + __impl_store_fns!($traitinstance $($t)*); + } + }; + ( + pub trait $storetype:ident for $modulename:ident<$traitinstance:ident: $traittype:ident> as $cratename:ident { + $($t:tt)* + } + ) => { + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); + pub trait $storetype { + __decl_store_items!($($t)*); + } + impl<$traitinstance: $traittype> $storetype for $modulename<$traitinstance> { + __impl_store_items!($traitinstance $($t)*); + } + impl<$traitinstance: $traittype> $modulename<$traitinstance> { + __impl_store_fns!($traitinstance $($t)*); + } + } +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __decl_storage_items { // simple values - ($name:ident : $key:expr => $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() () (Option<$ty>) (get) (take) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) () (Option<$ty>) (get) (take) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : default $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : default $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : required $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : required $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $cratename $name: $ty); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; // maps - ($name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - storage_items!($($t)*); + ($cratename:ident $traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $cratename $name: map [$kty => $ty]); + __decl_storage_items!($cratename $traittype $traitinstance $($t)*); }; - - // lists - ($name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { - __storage_items_internal!(() $name: $prefix => list [$ty]); - storage_items!($($t)*); - }; - (pub $name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { - __storage_items_internal!((pub) $name: $prefix => list [$ty]); - storage_items!($($t)*); - }; - () => () + // exit + ($cratename:ident $traittype:ident $traitinstance:ident) => () } #[macro_export] #[doc(hidden)] macro_rules! __decl_storage_item { // generator for values. - (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) ($get_fn:ident) ($gettype:ty) ($getter:ident) ($taker:ident) $name:ident : $key:expr => $ty:ty) => { - __decl_storage_item!{ ($($vis)*) ($traittype as $traitinstance) () ($gettype) ($getter) ($taker) $name : $key => $ty } + (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) ($get_fn:ident) ($gettype:ty) ($getter:ident) ($taker:ident) $cratename:ident $name:ident : $ty:ty) => { + __decl_storage_item!{ ($($vis)*) ($traittype as $traitinstance) () ($gettype) ($getter) ($taker) $cratename $name : $ty } }; - (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) () ($gettype:ty) ($getter:ident) ($taker:ident) $name:ident : $key:expr => $ty:ty) => { + (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) () ($gettype:ty) ($getter:ident) ($taker:ident) $cratename:ident $name:ident : $ty:ty) => { $($vis)* struct $name<$traitinstance: $traittype>($crate::storage::generator::PhantomData<$traitinstance>); impl<$traitinstance: $traittype> $crate::storage::generator::StorageValue<$ty> for $name<$traitinstance> { @@ -464,25 +621,25 @@ macro_rules! __decl_storage_item { /// Get the storage key. fn key() -> &'static [u8] { - $key + stringify!($cratename $name).as_bytes() } /// Load the value from the provided storage instance. fn get(storage: &S) -> Self::Query { - storage.$getter($key) + storage.$getter(<$name<$traitinstance> as $crate::storage::generator::StorageValue<$ty>>::key()) } /// Take a value from storage, removing it afterwards. fn take(storage: &S) -> Self::Query { - storage.$taker($key) + storage.$taker(<$name<$traitinstance> as $crate::storage::generator::StorageValue<$ty>>::key()) } } }; // generator for maps. - (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) ($get_fn:ident) ($gettype:ty) ($getter:ident) ($taker:ident) $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]) => { - __decl_storage_item!{ ($($vis)*) ($traittype as $traitinstance) () ($gettype) ($getter) ($taker) $name : $prefix => map [$kty => $ty] } + (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) ($get_fn:ident) ($gettype:ty) ($getter:ident) ($taker:ident) $cratename:ident $name:ident : map [$kty:ty => $ty:ty]) => { + __decl_storage_item!{ ($($vis)*) ($traittype as $traitinstance) () ($gettype) ($getter) ($taker) $cratename $name : map [$kty => $ty] } }; - (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) () ($gettype:ty) ($getter:ident) ($taker:ident) $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]) => { + (($($vis:tt)*) ($traittype:ident as $traitinstance:ident) () ($gettype:ty) ($getter:ident) ($taker:ident) $cratename:ident $name:ident : map [$kty:ty => $ty:ty]) => { $($vis)* struct $name<$traitinstance: $traittype>($crate::storage::generator::PhantomData<$traitinstance>); impl<$traitinstance: $traittype> $crate::storage::generator::StorageMap<$kty, $ty> for $name<$traitinstance> { @@ -490,12 +647,12 @@ macro_rules! __decl_storage_item { /// Get the prefix key in storage. fn prefix() -> &'static [u8] { - $prefix + stringify!($cratename $name).as_bytes() } /// Get the storage key used to fetch a value corresponding to a specific key. fn key_for(x: &$kty) -> Vec { - let mut key = $prefix.to_vec(); + let mut key = <$name<$traitinstance> as $crate::storage::generator::StorageMap<$kty, $ty>>::prefix().to_vec(); $crate::codec::Encode::encode_to(x, &mut key); key } @@ -515,135 +672,84 @@ macro_rules! __decl_storage_item { }; } -// TODO: revisit this idiom once we get `type`s in `impl`s. -/*impl Module { - type Now = super::Now; -}*/ - -/// Declares strongly-typed wrappers around codec-compatible types in storage. -/// -/// For now we implement a convenience trait with pre-specialised associated types, one for each -/// storage item. This allows you to gain access to publicly visisible storage items from a -/// module type. Currently you must disambiguate by using `::Item` rather than -/// the simpler `Module::Item`. Hopefully the rust guys with fix this soon. -#[macro_export] -macro_rules! decl_storage { - ( - trait $storetype:ident for $modulename:ident<$traitinstance:ident: $traittype:ident>; - $($t:tt)* - ) => { - __decl_storage_items!($traittype $traitinstance $($t)*); - trait $storetype { - __decl_store_items!($($t)*); - } - impl<$traitinstance: $traittype> $storetype for $modulename<$traitinstance> { - __impl_store_items!($traitinstance $($t)*); - } - impl<$traitinstance: $traittype> $modulename<$traitinstance> { - __impl_store_fns!($traitinstance $($t)*); - } - }; - ( - pub trait $storetype:ident for $modulename:ident<$traitinstance:ident: $traittype:ident>; - $($t:tt)* - ) => { - __decl_storage_items!($traittype $traitinstance $($t)*); - pub trait $storetype { - __decl_store_items!($($t)*); - } - impl<$traitinstance: $traittype> $storetype for $modulename<$traitinstance> { - __impl_store_items!($traitinstance $($t)*); - } - impl<$traitinstance: $traittype> $modulename<$traitinstance> { - __impl_store_fns!($traitinstance $($t)*); - } - } -} - -#[macro_export] -#[doc(hidden)] -macro_rules! __decl_store_item { - ($name:ident) => { type $name; } -} - #[macro_export] #[doc(hidden)] macro_rules! __decl_store_items { // simple values - ($name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + ($name:ident : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + (pub $name:ident : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + ($name:ident : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + (pub $name:ident : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + ($name:ident : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + (pub $name:ident : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + ($name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + ($name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + ($name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; // maps - ($name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - ($name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; - (pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + (pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __decl_store_item!($name); __decl_store_items!($($t)*); }; @@ -653,109 +759,100 @@ macro_rules! __decl_store_items { #[macro_export] #[doc(hidden)] -macro_rules! __impl_store_fn { - ($traitinstance:ident $name:ident $get_fn:ident ($gettype:ty) $key:expr => $ty:ty) => { - pub fn $get_fn() -> $gettype { - <$name<$traitinstance> as $crate::storage::generator::StorageValue<$ty>> :: get(&$crate::storage::RuntimeStorage) - } - }; - ($traitinstance:ident $name:ident $get_fn:ident ($gettype:ty) $prefix:expr => map [$kty:ty => $ty:ty]) => { - pub fn $get_fn>(key: K) -> $gettype { - <$name<$traitinstance> as $crate::storage::generator::StorageMap<$kty, $ty>> :: get(key.borrow(), &$crate::storage::RuntimeStorage) - } - } +macro_rules! __decl_store_item { + ($name:ident) => { type $name; } } #[macro_export] #[doc(hidden)] macro_rules! __impl_store_fns { // simple values - ($traitinstance:ident $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : required $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : required $ty:ty; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $gettype $key => $ty); + ($traitinstance:ident $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $gettype $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $key => $ty); + ($traitinstance:ident pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $key => $ty); + ($traitinstance:ident $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $key => $ty); + ($traitinstance:ident pub $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $key => $ty); + ($traitinstance:ident $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $key => $ty); + ($traitinstance:ident pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) $ty); __impl_store_fns!($traitinstance $($t)*); }; // maps - ($traitinstance:ident $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn (Option<$ty>) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident pub $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __impl_store_fn!($traitinstance $name $getfn ($ty) $prefix:expr => map [$kty => $ty]); + ($traitinstance:ident pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + __impl_store_fn!($traitinstance $name $getfn ($ty) map [$kty => $ty]); __impl_store_fns!($traitinstance $($t)*); }; @@ -765,111 +862,120 @@ macro_rules! __impl_store_fns { #[macro_export] #[doc(hidden)] -macro_rules! __impl_store_item { - ($name:ident $traitinstance:ident) => { type $name = $name<$traitinstance>; } +macro_rules! __impl_store_fn { + ($traitinstance:ident $name:ident $get_fn:ident ($gettype:ty) $ty:ty) => { + pub fn $get_fn() -> $gettype { + <$name<$traitinstance> as $crate::storage::generator::StorageValue<$ty>> :: get(&$crate::storage::RuntimeStorage) + } + }; + ($traitinstance:ident $name:ident $get_fn:ident ($gettype:ty) map [$kty:ty => $ty:ty]) => { + pub fn $get_fn>(key: K) -> $gettype { + <$name<$traitinstance> as $crate::storage::generator::StorageMap<$kty, $ty>> :: get(key.borrow(), &$crate::storage::RuntimeStorage) + } + } } #[macro_export] #[doc(hidden)] macro_rules! __impl_store_items { // simple values - ($traitinstance:ident $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident : required $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : required $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : default $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : required $ty:ty; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; // maps - ($traitinstance:ident $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : default map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; - ($traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { + ($traitinstance:ident pub $name:ident get($getfn:ident) : required map [$kty:ty => $ty:ty]; $($t:tt)*) => { __impl_store_item!($name $traitinstance); __impl_store_items!($traitinstance $($t)*); }; @@ -880,111 +986,8 @@ macro_rules! __impl_store_items { #[macro_export] #[doc(hidden)] -macro_rules! __decl_storage_items { - // simple values - ($traittype:ident $traitinstance:ident $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $key:expr => $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $key:expr => default $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $key:expr => required $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => default $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $key:expr => required $ty:ty; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $name: $key => $ty); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - - // maps - ($traittype:ident $traitinstance:ident $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) () ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) (Option<$ty>) (get) (take) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => default map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (get_or_default) (take_or_default) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!(() ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - ($traittype:ident $traitinstance:ident pub $name:ident get($getfn:ident) : $prefix:expr => required map [$kty:ty => $ty:ty]; $($t:tt)*) => { - __decl_storage_item!((pub) ($traittype as $traitinstance) ($getfn) ($ty) (require) (take_or_panic) $name: $prefix => map [$kty => $ty]); - __decl_storage_items!($traittype $traitinstance $($t)*); - }; - - // exit - ($traittype:ident $traitinstance:ident) => () +macro_rules! __impl_store_item { + ($name:ident $traitinstance:ident) => { type $name = $name<$traitinstance>; } } #[cfg(test)] diff --git a/substrate/runtime/contract/src/lib.rs b/substrate/runtime/contract/src/lib.rs index 814e945ea3102..7479686ddc453 100644 --- a/substrate/runtime/contract/src/lib.rs +++ b/substrate/runtime/contract/src/lib.rs @@ -150,25 +150,25 @@ decl_module! { } decl_storage! { - trait Store for Module; - - // The fee required to create a contract. At least as big as staking's ReclaimRebate. - ContractFee get(contract_fee): b"con:contract_fee" => required T::Balance; - // The fee charged for a call into a contract. - CallBaseFee get(call_base_fee): b"con:base_call_fee" => required T::Gas; - // The fee charged for a create of a contract. - CreateBaseFee get(create_base_fee): b"con:base_create_fee" => required T::Gas; - // The price of one unit of gas. - GasPrice get(gas_price): b"con:gas_price" => required T::Balance; - // The maximum nesting level of a call/create stack. - MaxDepth get(max_depth): b"con:max_depth" => required u32; - // The maximum amount of gas that could be expended per block. - BlockGasLimit get(block_gas_limit): b"con:block_gas_limit" => required T::Gas; - // Gas spent so far in this block. - GasSpent get(gas_spent): b"con:gas_spent" => default T::Gas; - - // The code associated with an account. - CodeOf: b"con:cod:" => default map [ T::AccountId => Vec ]; // TODO Vec values should be optimised to not do a length prefix. + trait Store for Module as Contract { + // The fee required to create a contract. At least as big as staking's ReclaimRebate. + ContractFee get(contract_fee): required T::Balance; + // The fee charged for a call into a contract. + CallBaseFee get(call_base_fee): required T::Gas; + // The fee charged for a create of a contract. + CreateBaseFee get(create_base_fee): required T::Gas; + // The price of one unit of gas. + GasPrice get(gas_price): required T::Balance; + // The maximum nesting level of a call/create stack. + MaxDepth get(max_depth): required u32; + // The maximum amount of gas that could be expended per block. + BlockGasLimit get(block_gas_limit): required T::Gas; + // Gas spent so far in this block. + GasSpent get(gas_spent): default T::Gas; + + // The code associated with an account. + pub CodeOf: default map [ T::AccountId => Vec ]; // TODO Vec values should be optimised to not do a length prefix. + } } // TODO: consider storing upper-bound for contract's gas limit in fixed-length runtime diff --git a/substrate/runtime/council/src/lib.rs b/substrate/runtime/council/src/lib.rs index 8118075fd3f1b..103679e8a7f0f 100644 --- a/substrate/runtime/council/src/lib.rs +++ b/substrate/runtime/council/src/lib.rs @@ -131,57 +131,58 @@ decl_module! { } decl_storage! { - trait Store for Module; - - // parameters - // How much should be locked up in order to submit one's candidacy. - pub CandidacyBond get(candidacy_bond): b"cou:cbo" => required T::Balance; - // How much should be locked up in order to be able to submit votes. - pub VotingBond get(voting_bond): b"cou:vbo" => required T::Balance; - // The punishment, per voter, if you provide an invalid presentation. - pub PresentSlashPerVoter get(present_slash_per_voter): b"cou:pss" => required T::Balance; - // How many runners-up should have their approvals persist until the next vote. - pub CarryCount get(carry_count): b"cou:cco" => required u32; - // How long to give each top candidate to present themselves after the vote ends. - pub PresentationDuration get(presentation_duration): b"cou:pdu" => required T::BlockNumber; - // How many votes need to go by after a voter's last vote before they can be reaped if their - // approvals are moot. - pub InactiveGracePeriod get(inactivity_grace_period): b"cou:vgp" => required VoteIndex; - // How often (in blocks) to check for new votes. - pub VotingPeriod get(voting_period): b"cou:per" => required T::BlockNumber; - // How long each position is active for. - pub TermDuration get(term_duration): b"cou:trm" => required T::BlockNumber; - // Number of accounts that should be sitting on the council. - pub DesiredSeats get(desired_seats): b"cou:sts" => required u32; - - // permanent state (always relevant, changes only at the finalisation of voting) - // The current council. When there's a vote going on, this should still be used for executive - // matters. - pub ActiveCouncil get(active_council): b"cou:act" => default Vec<(T::AccountId, T::BlockNumber)>; - // The total number of votes that have happened or are in progress. - pub VoteCount get(vote_index): b"cou:vco" => default VoteIndex; - - // persistent state (always relevant, changes constantly) - // The last cleared vote index that this voter was last active at. - pub ApprovalsOf get(approvals_of): b"cou:apr" => default map [ T::AccountId => Vec ]; - // The vote index and list slot that the candidate `who` was registered or `None` if they are not - // currently registered. - pub RegisterInfoOf get(candidate_reg_info): b"cou:reg" => map [ T::AccountId => (VoteIndex, u32) ]; - // The last cleared vote index that this voter was last active at. - pub LastActiveOf get(voter_last_active): b"cou:lac" => map [ T::AccountId => VoteIndex ]; - // The present voter list. - pub Voters get(voters): b"cou:vrs" => default Vec; - // The present candidate list. - pub Candidates get(candidates): b"cou:can" => default Vec; // has holes - pub CandidateCount get(candidate_count): b"cou:cnc" => default u32; - - // temporary state (only relevant during finalisation/presentation) - // The accounts holding the seats that will become free on the next tally. - pub NextFinalise get(next_finalise): b"cou:nxt" => (T::BlockNumber, u32, Vec); - // The stakes as they were at the point that the vote ended. - pub SnapshotedStakes get(snapshoted_stakes): b"cou:sss" => required Vec; - // Get the leaderboard if we;re in the presentation phase. - pub Leaderboard get(leaderboard): b"cou:win" => Vec<(T::Balance, T::AccountId)>; // ORDERED low -> high + trait Store for Module as Council { + + // parameters + // How much should be locked up in order to submit one's candidacy. + pub CandidacyBond get(candidacy_bond): required T::Balance; + // How much should be locked up in order to be able to submit votes. + pub VotingBond get(voting_bond): required T::Balance; + // The punishment, per voter, if you provide an invalid presentation. + pub PresentSlashPerVoter get(present_slash_per_voter): required T::Balance; + // How many runners-up should have their approvals persist until the next vote. + pub CarryCount get(carry_count): required u32; + // How long to give each top candidate to present themselves after the vote ends. + pub PresentationDuration get(presentation_duration): required T::BlockNumber; + // How many votes need to go by after a voter's last vote before they can be reaped if their + // approvals are moot. + pub InactiveGracePeriod get(inactivity_grace_period): required VoteIndex; + // How often (in blocks) to check for new votes. + pub VotingPeriod get(voting_period): required T::BlockNumber; + // How long each position is active for. + pub TermDuration get(term_duration): required T::BlockNumber; + // Number of accounts that should be sitting on the council. + pub DesiredSeats get(desired_seats): required u32; + + // permanent state (always relevant, changes only at the finalisation of voting) + // The current council. When there's a vote going on, this should still be used for executive + // matters. + pub ActiveCouncil get(active_council): default Vec<(T::AccountId, T::BlockNumber)>; + // The total number of votes that have happened or are in progress. + pub VoteCount get(vote_index): default VoteIndex; + + // persistent state (always relevant, changes constantly) + // The last cleared vote index that this voter was last active at. + pub ApprovalsOf get(approvals_of): default map [ T::AccountId => Vec ]; + // The vote index and list slot that the candidate `who` was registered or `None` if they are not + // currently registered. + pub RegisterInfoOf get(candidate_reg_info): map [ T::AccountId => (VoteIndex, u32) ]; + // The last cleared vote index that this voter was last active at. + pub LastActiveOf get(voter_last_active): map [ T::AccountId => VoteIndex ]; + // The present voter list. + pub Voters get(voters): default Vec; + // The present candidate list. + pub Candidates get(candidates): default Vec; // has holes + pub CandidateCount get(candidate_count): default u32; + + // temporary state (only relevant during finalisation/presentation) + // The accounts holding the seats that will become free on the next tally. + pub NextFinalise get(next_finalise): (T::BlockNumber, u32, Vec); + // The stakes as they were at the point that the vote ended. + pub SnapshotedStakes get(snapshoted_stakes): required Vec; + // Get the leaderboard if we;re in the presentation phase. + pub Leaderboard get(leaderboard): Vec<(T::Balance, T::AccountId)>; // ORDERED low -> high + } } impl Module { diff --git a/substrate/runtime/council/src/voting.rs b/substrate/runtime/council/src/voting.rs index ecc5e074f7783..b26df57e604f8 100644 --- a/substrate/runtime/council/src/voting.rs +++ b/substrate/runtime/council/src/voting.rs @@ -43,15 +43,15 @@ decl_module! { } decl_storage! { - trait Store for Module; - - pub CooloffPeriod get(cooloff_period): b"cov:cooloff" => required T::BlockNumber; - pub VotingPeriod get(voting_period): b"cov:period" => required T::BlockNumber; - pub Proposals get(proposals): b"cov:prs" => required Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry. - pub ProposalOf get(proposal_of): b"cov:pro" => map [ T::Hash => T::Proposal ]; - pub ProposalVoters get(proposal_voters): b"cov:voters:" => default map [ T::Hash => Vec ]; - pub CouncilVoteOf get(vote_of): b"cov:vote:" => map [ (T::Hash, T::AccountId) => bool ]; - pub VetoedProposal get(veto_of): b"cov:veto:" => map [ T::Hash => (T::BlockNumber, Vec) ]; + trait Store for Module as CouncilVoting { + pub CooloffPeriod get(cooloff_period): required T::BlockNumber; + pub VotingPeriod get(voting_period): required T::BlockNumber; + pub Proposals get(proposals): required Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry. + pub ProposalOf get(proposal_of): map [ T::Hash => T::Proposal ]; + pub ProposalVoters get(proposal_voters): default map [ T::Hash => Vec ]; + pub CouncilVoteOf get(vote_of): map [ (T::Hash, T::AccountId) => bool ]; + pub VetoedProposal get(veto_of): map [ T::Hash => (T::BlockNumber, Vec) ]; + } } impl Module { diff --git a/substrate/runtime/democracy/src/lib.rs b/substrate/runtime/democracy/src/lib.rs index dfbd2180bbc74..bc04fe877acd0 100644 --- a/substrate/runtime/democracy/src/lib.rs +++ b/substrate/runtime/democracy/src/lib.rs @@ -84,34 +84,35 @@ decl_module! { } decl_storage! { - trait Store for Module; - - // The number of (public) proposals that have been made so far. - pub PublicPropCount get(public_prop_count): b"dem:ppc" => default PropIndex; - // The public proposals. Unsorted. - pub PublicProps get(public_props): b"dem:pub" => default Vec<(PropIndex, T::Proposal, T::AccountId)>; - // Those who have locked a deposit. - pub DepositOf get(deposit_of): b"dem:dep:" => map [ PropIndex => (T::Balance, Vec) ]; - // How often (in blocks) new public referenda are launched. - pub LaunchPeriod get(launch_period): b"dem:lau" => required T::BlockNumber; - // The minimum amount to be used as a deposit for a public referendum proposal. - pub MinimumDeposit get(minimum_deposit): b"dem:min" => required T::Balance; - - // How often (in blocks) to check for new votes. - pub VotingPeriod get(voting_period): b"dem:per" => required T::BlockNumber; - - // The next free referendum index, aka the number of referendums started so far. - pub ReferendumCount get(referendum_count): b"dem:rco" => required ReferendumIndex; - // The next referendum index that should be tallied. - pub NextTally get(next_tally): b"dem:nxt" => required ReferendumIndex; - // Information concerning any given referendum. - pub ReferendumInfoOf get(referendum_info): b"dem:pro:" => map [ ReferendumIndex => (T::BlockNumber, T::Proposal, VoteThreshold) ]; - - // Get the voters for the current proposal. - pub VotersFor get(voters_for): b"dem:vtr:" => default map [ ReferendumIndex => Vec ]; - - // Get the vote, if Some, of `who`. - pub VoteOf get(vote_of): b"dem:vot:" => map [ (ReferendumIndex, T::AccountId) => bool ]; + trait Store for Module as Democracy { + + // The number of (public) proposals that have been made so far. + pub PublicPropCount get(public_prop_count): default PropIndex; + // The public proposals. Unsorted. + pub PublicProps get(public_props): default Vec<(PropIndex, T::Proposal, T::AccountId)>; + // Those who have locked a deposit. + pub DepositOf get(deposit_of): map [ PropIndex => (T::Balance, Vec) ]; + // How often (in blocks) new public referenda are launched. + pub LaunchPeriod get(launch_period): required T::BlockNumber; + // The minimum amount to be used as a deposit for a public referendum proposal. + pub MinimumDeposit get(minimum_deposit): required T::Balance; + + // How often (in blocks) to check for new votes. + pub VotingPeriod get(voting_period): required T::BlockNumber; + + // The next free referendum index, aka the number of referendums started so far. + pub ReferendumCount get(referendum_count): required ReferendumIndex; + // The next referendum index that should be tallied. + pub NextTally get(next_tally): required ReferendumIndex; + // Information concerning any given referendum. + pub ReferendumInfoOf get(referendum_info): map [ ReferendumIndex => (T::BlockNumber, T::Proposal, VoteThreshold) ]; + + // Get the voters for the current proposal. + pub VotersFor get(voters_for): default map [ ReferendumIndex => Vec ]; + + // Get the vote, if Some, of `who`. + pub VoteOf get(vote_of): map [ (ReferendumIndex, T::AccountId) => bool ]; + } } impl Module { diff --git a/substrate/runtime/executive/src/lib.rs b/substrate/runtime/executive/src/lib.rs index 476a5cf1ac217..4f7d6bd27822e 100644 --- a/substrate/runtime/executive/src/lib.rs +++ b/substrate/runtime/executive/src/lib.rs @@ -336,7 +336,7 @@ mod tests { // Blake // state_root: hex!("02532989c613369596025dfcfc821339fc9861987003924913a5a1382f87034a").into(), // Keccak - state_root: hex!("246ea6d86eefe3fc32f746fdcb1749a5f245570c70a04b43d08b5defac44505a").into(), + state_root: hex!("e576ed2adacdc09b61844b5106bfaa18d2a4bfd7feb56d7af97c3421cdefca48").into(), extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), digest: Digest { logs: vec![], }, }, @@ -370,7 +370,7 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, - state_root: hex!("246ea6d86eefe3fc32f746fdcb1749a5f245570c70a04b43d08b5defac44505a").into(), + state_root: hex!("e576ed2adacdc09b61844b5106bfaa18d2a4bfd7feb56d7af97c3421cdefca48").into(), extrinsics_root: [0u8; 32].into(), digest: Digest { logs: vec![], }, }, diff --git a/substrate/runtime/session/src/lib.rs b/substrate/runtime/session/src/lib.rs index e5fa1a678a739..1530723907086 100644 --- a/substrate/runtime/session/src/lib.rs +++ b/substrate/runtime/session/src/lib.rs @@ -103,30 +103,31 @@ impl From> for () { } decl_storage! { - trait Store for Module; - - // The current set of validators. - pub Validators get(validators): b"ses:val" => required Vec; - // Current length of the session. - pub SessionLength get(length): b"ses:len" => required T::BlockNumber; - // Current index of the session. - pub CurrentIndex get(current_index): b"ses:ind" => required T::BlockNumber; - // Timestamp when current session started. - pub CurrentStart get(current_start): b"ses:current_start" => required T::Moment; - - // Opinions of the current validator set about the activeness of their peers. - // Gets cleared when the validator set changes. - pub BadValidators get(bad_validators): b"ses:bad_validators" => Vec; - - // New session is being forced is this entry exists; in which case, the boolean value is whether - // the new session should be considered a normal rotation (rewardable) or exceptional (slashable). - pub ForcingNewSession get(forcing_new_session): b"ses:forcing_new_session" => bool; - // Block at which the session length last changed. - LastLengthChange: b"ses:llc" => T::BlockNumber; - // The next key for a given validator. - NextKeyFor: b"ses:nxt:" => map [ T::AccountId => T::SessionKey ]; - // The next session length. - NextSessionLength: b"ses:nln" => T::BlockNumber; + trait Store for Module as Session { + + // The current set of validators. + pub Validators get(validators): required Vec; + // Current length of the session. + pub SessionLength get(length): required T::BlockNumber; + // Current index of the session. + pub CurrentIndex get(current_index): required T::BlockNumber; + // Timestamp when current session started. + pub CurrentStart get(current_start): required T::Moment; + + // Opinions of the current validator set about the activeness of their peers. + // Gets cleared when the validator set changes. + pub BadValidators get(bad_validators): Vec; + + // New session is being forced is this entry exists; in which case, the boolean value is whether + // the new session should be considered a normal rotation (rewardable) or exceptional (slashable). + pub ForcingNewSession get(forcing_new_session): bool; + // Block at which the session length last changed. + LastLengthChange: T::BlockNumber; + // The next key for a given validator. + NextKeyFor: map [ T::AccountId => T::SessionKey ]; + // The next session length. + NextSessionLength: T::BlockNumber; + } } impl Module { diff --git a/substrate/runtime/staking/src/lib.rs b/substrate/runtime/staking/src/lib.rs index 981c8f6f200b7..92c8f47faa244 100644 --- a/substrate/runtime/staking/src/lib.rs +++ b/substrate/runtime/staking/src/lib.rs @@ -190,97 +190,98 @@ impl From> for () { } decl_storage! { - trait Store for Module; - - // The length of the bonding duration in eras. - pub BondingDuration get(bonding_duration): b"sta:loc" => required T::BlockNumber; - // The ideal number of staking participants. - pub ValidatorCount get(validator_count): b"sta:vac" => required u32; - // Minimum number of staking participants before emergency conditions are imposed. - pub MinimumValidatorCount: b"sta:minimum_validator_count" => u32; - // The length of a staking era in sessions. - pub SessionsPerEra get(sessions_per_era): b"sta:spe" => required T::BlockNumber; - // The total amount of stake on the system. - // TODO: this doesn't actually track total stake yet - it should do. - pub TotalStake get(total_stake): b"sta:tot" => required T::Balance; - // The fee to be paid for making a transaction; the base. - pub TransactionBaseFee get(transaction_base_fee): b"sta:basefee" => required T::Balance; - // The fee to be paid for making a transaction; the per-byte portion. - pub TransactionByteFee get(transaction_byte_fee): b"sta:bytefee" => required T::Balance; - // The minimum amount allowed to keep an account open. - pub ExistentialDeposit get(existential_deposit): b"sta:existential_deposit" => required T::Balance; - // The amount credited to a destination's account whose index was reclaimed. - pub ReclaimRebate get(reclaim_rebate): b"sta:reclaim_rebate" => required T::Balance; - // The fee required to make a transfer. - pub TransferFee get(transfer_fee): b"sta:transfer_fee" => required T::Balance; - // The fee required to create an account. At least as big as ReclaimRebate. - pub CreationFee get(creation_fee): b"sta:creation_fee" => required T::Balance; - // Maximum reward, per validator, that is provided per acceptable session. - pub SessionReward get(session_reward): b"sta:session_reward" => required T::Balance; - // Slash, per validator that is taken per abnormal era end. - pub EarlyEraSlash get(early_era_slash): b"sta:early_era_slash" => required T::Balance; - // Number of instances of offline reports before slashing begins for validators. - pub OfflineSlashGrace get(offline_slash_grace): b"sta:offline_slash_grace" => default u32; - - // The current era index. - pub CurrentEra get(current_era): b"sta:era" => required T::BlockNumber; - // Preference over how many times the validator should get slashed for being offline before they are automatically unstaked. - pub SlashPreferenceOf get(slash_preference_of): b"sta:slash_preference_of" => default map [ T::AccountId => SlashPreference ]; - // All the accounts with a desire to stake. - pub Intentions get(intentions): b"sta:wil:" => default Vec; - // All nominator -> nominee relationships. - pub Nominating get(nominating): b"sta:nominating" => map [ T::AccountId => T::AccountId ]; - // Nominators for a particular account. - pub NominatorsFor get(nominators_for): b"sta:nominators_for" => default map [ T::AccountId => Vec ]; - // Nominators for a particular account that is in action right now. - pub CurrentNominatorsFor get(current_nominators_for): b"sta:current_nominators_for" => default map [ T::AccountId => Vec ]; - // The next value of sessions per era. - pub NextSessionsPerEra get(next_sessions_per_era): b"sta:nse" => T::BlockNumber; - // The session index at which the era length last changed. - pub LastEraLengthChange get(last_era_length_change): b"sta:lec" => default T::BlockNumber; - // The current era stake threshold - pub StakeThreshold get(stake_threshold): b"sta:stake_threshold" => required T::Balance; - - // The number of times a given validator has been reported offline. This gets decremented by one each era that passes. - pub SlashCount get(slash_count): b"sta:slash_count" => default map [ T::AccountId => u32 ]; - - // The next free enumeration set. - pub NextEnumSet get(next_enum_set): b"sta:next_enum" => required T::AccountIndex; - // The enumeration sets. - pub EnumSet get(enum_set): b"sta:enum_set" => default map [ T::AccountIndex => Vec ]; - - // We are forcing a new era. - pub ForcingNewEra get(forcing_new_era): b"sta:forcing_new_era" => (); - - // The "free" balance of a given account. - // - // This is the only balance that matters in terms of most operations on tokens. It is - // alone used to determine the balance when in the contract execution environment. When this - // balance falls below the value of `ExistentialDeposit`, then the "current account" is - // deleted: specifically, `Bondage` and `FreeBalance`. Furthermore, `OnFreeBalanceZero` callback - // is invoked, giving a chance to external modules to cleanup data associated with - // the deleted account. - // - // `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets - // collapsed to zero if it ever becomes less than `ExistentialDeposit`. - pub FreeBalance get(free_balance): b"sta:bal:" => default map [ T::AccountId => T::Balance ]; - - // The amount of the balance of a given account that is exterally reserved; this can still get - // slashed, but gets slashed last of all. - // - // This balance is a "reserve" balance that other subsystems use in order to set aside tokens - // that are still "owned" by the account holder, but which are unspendable. This is different - // and wholly unrelated to the `Bondage` system used for staking. - // - // When this balance falls below the value of `ExistentialDeposit`, then this "reserve account" - // is deleted: specifically, `ReservedBalance`. - // - // `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets - // collapsed to zero if it ever becomes less than `ExistentialDeposit`. - pub ReservedBalance get(reserved_balance): b"sta:lbo:" => default map [ T::AccountId => T::Balance ]; - - // The block at which the `who`'s funds become entirely liquid. - pub Bondage get(bondage): b"sta:bon:" => default map [ T::AccountId => T::BlockNumber ]; + trait Store for Module as Staking { + + // The length of the bonding duration in eras. + pub BondingDuration get(bonding_duration): required T::BlockNumber; + // The ideal number of staking participants. + pub ValidatorCount get(validator_count): required u32; + // Minimum number of staking participants before emergency conditions are imposed. + pub MinimumValidatorCount: u32; + // The length of a staking era in sessions. + pub SessionsPerEra get(sessions_per_era): required T::BlockNumber; + // The total amount of stake on the system. + // TODO: this doesn't actually track total stake yet - it should do. + pub TotalStake get(total_stake): required T::Balance; + // The fee to be paid for making a transaction; the base. + pub TransactionBaseFee get(transaction_base_fee): required T::Balance; + // The fee to be paid for making a transaction; the per-byte portion. + pub TransactionByteFee get(transaction_byte_fee): required T::Balance; + // The minimum amount allowed to keep an account open. + pub ExistentialDeposit get(existential_deposit): required T::Balance; + // The amount credited to a destination's account whose index was reclaimed. + pub ReclaimRebate get(reclaim_rebate): required T::Balance; + // The fee required to make a transfer. + pub TransferFee get(transfer_fee): required T::Balance; + // The fee required to create an account. At least as big as ReclaimRebate. + pub CreationFee get(creation_fee): required T::Balance; + // Maximum reward, per validator, that is provided per acceptable session. + pub SessionReward get(session_reward): required T::Balance; + // Slash, per validator that is taken per abnormal era end. + pub EarlyEraSlash get(early_era_slash): required T::Balance; + // Number of instances of offline reports before slashing begins for validators. + pub OfflineSlashGrace get(offline_slash_grace): default u32; + + // The current era index. + pub CurrentEra get(current_era): required T::BlockNumber; + // Preference over how many times the validator should get slashed for being offline before they are automatically unstaked. + pub SlashPreferenceOf get(slash_preference_of): default map [ T::AccountId => SlashPreference ]; + // All the accounts with a desire to stake. + pub Intentions get(intentions): default Vec; + // All nominator -> nominee relationships. + pub Nominating get(nominating): map [ T::AccountId => T::AccountId ]; + // Nominators for a particular account. + pub NominatorsFor get(nominators_for): default map [ T::AccountId => Vec ]; + // Nominators for a particular account that is in action right now. + pub CurrentNominatorsFor get(current_nominators_for): default map [ T::AccountId => Vec ]; + // The next value of sessions per era. + pub NextSessionsPerEra get(next_sessions_per_era): T::BlockNumber; + // The session index at which the era length last changed. + pub LastEraLengthChange get(last_era_length_change): default T::BlockNumber; + // The current era stake threshold + pub StakeThreshold get(stake_threshold): required T::Balance; + + // The number of times a given validator has been reported offline. This gets decremented by one each era that passes. + pub SlashCount get(slash_count): default map [ T::AccountId => u32 ]; + + // The next free enumeration set. + pub NextEnumSet get(next_enum_set): required T::AccountIndex; + // The enumeration sets. + pub EnumSet get(enum_set): default map [ T::AccountIndex => Vec ]; + + // We are forcing a new era. + pub ForcingNewEra get(forcing_new_era): (); + + // The "free" balance of a given account. + // + // This is the only balance that matters in terms of most operations on tokens. It is + // alone used to determine the balance when in the contract execution environment. When this + // balance falls below the value of `ExistentialDeposit`, then the "current account" is + // deleted: specifically, `Bondage` and `FreeBalance`. Furthermore, `OnFreeBalanceZero` callback + // is invoked, giving a chance to external modules to cleanup data associated with + // the deleted account. + // + // `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets + // collapsed to zero if it ever becomes less than `ExistentialDeposit`. + pub FreeBalance get(free_balance): default map [ T::AccountId => T::Balance ]; + + // The amount of the balance of a given account that is exterally reserved; this can still get + // slashed, but gets slashed last of all. + // + // This balance is a "reserve" balance that other subsystems use in order to set aside tokens + // that are still "owned" by the account holder, but which are unspendable. This is different + // and wholly unrelated to the `Bondage` system used for staking. + // + // When this balance falls below the value of `ExistentialDeposit`, then this "reserve account" + // is deleted: specifically, `ReservedBalance`. + // + // `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets + // collapsed to zero if it ever becomes less than `ExistentialDeposit`. + pub ReservedBalance get(reserved_balance): default map [ T::AccountId => T::Balance ]; + + // The block at which the `who`'s funds become entirely liquid. + pub Bondage get(bondage): default map [ T::AccountId => T::BlockNumber ]; + } } /// Whatever happened about the hint given when creating the new account. diff --git a/substrate/runtime/system/src/lib.rs b/substrate/runtime/system/src/lib.rs index 1c4d39da01ed5..c91799dc93952 100644 --- a/substrate/runtime/system/src/lib.rs +++ b/substrate/runtime/system/src/lib.rs @@ -108,22 +108,23 @@ pub struct EventRecord { } decl_storage! { - trait Store for Module; - - pub AccountNonce get(account_nonce): b"sys:non" => default map [ T::AccountId => T::Index ]; - pub BlockHash get(block_hash): b"sys:old" => required map [ T::BlockNumber => T::Hash ]; - - ExtrinsicCount: b"sys:extrinsic_count" => u32; - pub ExtrinsicIndex get(extrinsic_index): b"sys:xti" => u32; - ExtrinsicData get(extrinsic_data): b"sys:xtd" => required map [ u32 => Vec ]; - RandomSeed get(random_seed): b"sys:rnd" => required T::Hash; - // The current block number being processed. Set by `execute_block`. - Number get(block_number): b"sys:num" => required T::BlockNumber; - ParentHash get(parent_hash): b"sys:pha" => required T::Hash; - ExtrinsicsRoot get(extrinsics_root): b"sys:txr" => required T::Hash; - Digest get(digest): b"sys:dig" => default T::Digest; - - Events get(events): b"sys:events" => default Vec>; + trait Store for Module as System { + + pub AccountNonce get(account_nonce): default map [ T::AccountId => T::Index ]; + + ExtrinsicCount: u32; + pub BlockHash get(block_hash): required map [ T::BlockNumber => T::Hash ]; + pub ExtrinsicIndex get(extrinsic_index): u32; + ExtrinsicData get(extrinsic_data): required map [ u32 => Vec ]; + RandomSeed get(random_seed): required T::Hash; + // The current block number being processed. Set by `execute_block`. + Number get(block_number): required T::BlockNumber; + ParentHash get(parent_hash): required T::Hash; + ExtrinsicsRoot get(extrinsics_root): required T::Hash; + Digest get(digest): default T::Digest; + + Events get(events): default Vec>; + } } impl Module { diff --git a/substrate/runtime/timestamp/src/lib.rs b/substrate/runtime/timestamp/src/lib.rs index 3591f9489e2ed..db1c7e1281128 100644 --- a/substrate/runtime/timestamp/src/lib.rs +++ b/substrate/runtime/timestamp/src/lib.rs @@ -61,13 +61,14 @@ decl_module! { } decl_storage! { - trait Store for Module; - pub Now get(now): b"tim:val" => required T::Moment; - // The minimum (and advised) period between blocks. - pub BlockPeriod get(block_period): b"tim:block_period" => required T::Moment; + trait Store for Module as Timestamp { + pub Now get(now): required T::Moment; + // The minimum (and advised) period between blocks. + pub BlockPeriod get(block_period): required T::Moment; - // Did the timestamp get updated in this block? - DidUpdate: b"tim:did" => default bool; + // Did the timestamp get updated in this block? + DidUpdate: default bool; + } } impl Module { diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm index adee6b02cf463..7d2f104d0966a 100644 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm differ diff --git a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm index 223765126290d..5618789cf379b 100755 Binary files a/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm and b/substrate/test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.wasm differ