mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 00:47:55 +00:00
Rename palette -> frame (#41)
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
//! Implements support for the frame_system module.
|
||||
use crate::{
|
||||
error::Error,
|
||||
frame::{
|
||||
Call,
|
||||
balances::Balances,
|
||||
},
|
||||
Client,
|
||||
};
|
||||
use futures::future::{
|
||||
self,
|
||||
Future,
|
||||
};
|
||||
use parity_scale_codec::Codec;
|
||||
use runtime_primitives::traits::{
|
||||
Bounded,
|
||||
CheckEqual,
|
||||
Hash,
|
||||
Header,
|
||||
MaybeDisplay,
|
||||
MaybeSerialize,
|
||||
MaybeSerializeDeserialize,
|
||||
Member,
|
||||
SimpleArithmetic,
|
||||
SimpleBitOps,
|
||||
StaticLookup,
|
||||
};
|
||||
use runtime_support::Parameter;
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// The subset of the `frame::Trait` that a client must implement.
|
||||
pub trait System: 'static + Eq + Clone + Debug {
|
||||
/// Account index (aka nonce) type. This stores the number of previous
|
||||
/// transactions associated with a sender account.
|
||||
type Index: Parameter
|
||||
+ Member
|
||||
+ MaybeSerialize
|
||||
+ Debug
|
||||
+ Default
|
||||
+ MaybeDisplay
|
||||
+ SimpleArithmetic
|
||||
+ Copy;
|
||||
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ SimpleArithmetic
|
||||
+ Default
|
||||
+ Bounded
|
||||
+ Copy
|
||||
+ std::hash::Hash;
|
||||
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ SimpleBitOps
|
||||
+ Default
|
||||
+ Copy
|
||||
+ CheckEqual
|
||||
+ std::hash::Hash
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>;
|
||||
|
||||
/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
|
||||
type Hashing: Hash<Output = Self::Hash>;
|
||||
|
||||
/// The user account identifier type for the runtime.
|
||||
type AccountId: Parameter
|
||||
+ Member
|
||||
+ MaybeSerialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ Ord
|
||||
+ Default;
|
||||
|
||||
/// The address type. This instead of `<frame_system::Trait::Lookup as StaticLookup>::Source`.
|
||||
type Address: Codec + Clone + PartialEq + Debug;
|
||||
|
||||
/// The block header.
|
||||
type Header: Parameter
|
||||
+ Header<Number = Self::BlockNumber, Hash = Self::Hash>
|
||||
+ DeserializeOwned;
|
||||
}
|
||||
|
||||
/// Blanket impl for using existing runtime types
|
||||
impl<T: frame_system::Trait + Debug> System for T
|
||||
where
|
||||
<T as frame_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
{
|
||||
type Index = T::Index;
|
||||
type BlockNumber = T::BlockNumber;
|
||||
type Hash = T::Hash;
|
||||
type Hashing = T::Hashing;
|
||||
type AccountId = T::AccountId;
|
||||
type Address = <T::Lookup as StaticLookup>::Source;
|
||||
type Header = T::Header;
|
||||
}
|
||||
|
||||
/// The System extension trait for the Client.
|
||||
pub trait SystemStore {
|
||||
/// System type.
|
||||
type System: System;
|
||||
|
||||
/// Returns the account nonce for an account_id.
|
||||
fn account_nonce(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Box<dyn Future<Item = <Self::System as System>::Index, Error = Error> + Send>;
|
||||
}
|
||||
|
||||
impl<T: System + Balances + 'static, S: 'static> SystemStore for Client<T, S> {
|
||||
type System = T;
|
||||
|
||||
fn account_nonce(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Box<dyn Future<Item = <Self::System as System>::Index, Error = Error> + Send>
|
||||
{
|
||||
let account_nonce_map = || {
|
||||
Ok(self
|
||||
.metadata
|
||||
.module("System")?
|
||||
.storage("AccountNonce")?
|
||||
.get_map()?)
|
||||
};
|
||||
let map = match account_nonce_map() {
|
||||
Ok(map) => map,
|
||||
Err(err) => return Box::new(future::err(err)),
|
||||
};
|
||||
Box::new(self.fetch_or(map.key(account_id), map.default()))
|
||||
}
|
||||
}
|
||||
|
||||
const MODULE: &str = "System";
|
||||
const SET_CODE: &str = "set_code";
|
||||
|
||||
/// Arguments for updating the runtime code
|
||||
pub type SetCode = Vec<u8>;
|
||||
|
||||
/// Sets the new code.
|
||||
pub fn set_code(code: Vec<u8>) -> Call<SetCode> {
|
||||
Call::new(MODULE, SET_CODE, code)
|
||||
}
|
||||
|
||||
/// Event for the System module.
|
||||
#[derive(Clone, Debug, parity_scale_codec::Decode)]
|
||||
pub enum SystemEvent {
|
||||
/// An extrinsic completed successfully.
|
||||
ExtrinsicSuccess,
|
||||
/// An extrinsic failed.
|
||||
ExtrinsicFailed(runtime_primitives::DispatchError),
|
||||
}
|
||||
Reference in New Issue
Block a user