Include default values in storage metadata (#1264)

* Add a 'default' field to metadata. It contains code to generate the
default value.

* wasm update

* Make 'default' field an `Option`

* Boxed fn is not static, that won't be fine

* static fn won't do it to as it cannot get T param, will try fat trait

* Fat pointer over phantom data compatible with static instantiation

* DecodeDifferent is cool, using it for decoding.

* using once cell to do what would require copying lazy_static internals.

* Remove cache when no_std (non compatible deps)

* wasm bins update

* Fuse tooling struct and enum derive.
This commit is contained in:
cheme
2018-12-20 14:31:03 +01:00
committed by Gav Wood
parent 2742975169
commit 23634b6b95
15 changed files with 300 additions and 85 deletions
+17 -11
View File
@@ -15,7 +15,8 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub use srml_metadata::{
DecodeDifferent, FnEncode, RuntimeMetadata, RuntimeModuleMetadata
DecodeDifferent, FnEncode, RuntimeMetadata, RuntimeModuleMetadata,
DefaultByteGetter,
};
/// Implements the metadata support for the given runtime and all its modules.
@@ -188,7 +189,7 @@ mod tests {
StorageMethod : Option<u32>;
}
add_extra_genesis {
build(|_, _, _| {});
build(|_, _, _| {});
}
}
}
@@ -311,15 +312,20 @@ mod tests {
)),
storage: Some(DecodeDifferent::Encode(FnEncode(||
StorageMetadata {
prefix: DecodeDifferent::Encode("TestStorage"),
functions: DecodeDifferent::Encode(&[
StorageFunctionMetadata {
name: DecodeDifferent::Encode("StorageMethod"),
modifier: StorageFunctionModifier::Optional,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("u32")),
documentation: DecodeDifferent::Encode(&[]),
}
])
prefix: DecodeDifferent::Encode("TestStorage"),
functions: DecodeDifferent::Encode(&[
StorageFunctionMetadata {
name: DecodeDifferent::Encode("StorageMethod"),
modifier: StorageFunctionModifier::Optional,
ty: StorageFunctionType::Plain(DecodeDifferent::Encode("u32")),
default: DecodeDifferent::Encode(
DefaultByteGetter(
&event_module2::__GetByteStructStorageMethod(::std::marker::PhantomData::<TestRuntime>)
)
),
documentation: DecodeDifferent::Encode(&[]),
}
])
}
))),
}