mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 09:51:10 +00:00
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:
+54
-19
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user