Files
pezkuwi-subxt/src/frame/mod.rs
T
David Craven 6f27489378 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.
2020-04-28 20:04:26 +01:00

80 lines
2.0 KiB
Rust

// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of substrate-subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
//! Implements support for built-in runtime modules.
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;
/// 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;
}