Double map and plain storage support, introduce macros (#93)

* Support custom clients.

* Simplify trait bounds.

* Plain and double map storage support.

* Simplify more trait bounds.

* Add proc macro.

* Add Call, Event and Store traits.

* Update proc-macros.

* Add with_system for proc-macro.

* proc-macro: test: support signature and extra fields.

* proc-macro: test: support sharing state accross steps.

* proc-macro: test: fetch state sequentially.

* Elide lifetimes.

* Add test for plain storage.

* Run rustfmt.
This commit is contained in:
David Craven
2020-04-28 21:04:26 +02:00
committed by GitHub
parent 216b5614dd
commit 6f27489378
20 changed files with 1924 additions and 501 deletions
+54 -19
View File
@@ -16,29 +16,64 @@
//! Implements support for built-in runtime modules.
use codec::Encode;
use crate::{
events::{
EventsDecoder,
EventsError,
},
metadata::{
Metadata,
MetadataError,
},
};
use codec::{
Decode,
Encode,
};
use sp_core::storage::StorageKey;
pub mod balances;
pub mod contracts;
pub mod system;
/// Creates module calls
pub struct Call<T: Encode> {
/// Module name
pub module: &'static str,
/// Function name
pub function: &'static str,
/// Call arguments
pub args: T,
}
impl<T: Encode> Call<T> {
/// Create a module call
pub fn new(module: &'static str, function: &'static str, args: T) -> Self {
Call {
module,
function,
args,
}
/// Store trait.
pub trait Store<T>: Encode {
/// Module name.
const MODULE: &'static str;
/// Field name.
const FIELD: &'static str;
/// Return type.
type Returns: Decode;
/// Returns the `StorageKey`.
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError>;
/// Returns the default value.
fn default(
&self,
metadata: &Metadata,
) -> Result<Option<Self::Returns>, MetadataError> {
Ok(metadata
.module(Self::MODULE)?
.storage(Self::FIELD)?
.default())
}
}
/// Call trait.
pub trait Call<T>: Encode {
/// Module name.
const MODULE: &'static str;
/// Function name.
const FUNCTION: &'static str;
/// Load event decoder.
fn events_decoder(_decoder: &mut EventsDecoder<T>) -> Result<(), EventsError> {
Ok(())
}
}
/// Event trait.
pub trait Event<T>: Decode {
/// Module name.
const MODULE: &'static str;
/// Event name.
const EVENT: &'static str;
}