mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Use new AccountInfo struct for "System Account" storage data (#71)
* Add AccountInfo struct for "System Account" data * Fmt * Simplify AccountInfo struct constraints
This commit is contained in:
+9
-10
@@ -16,22 +16,21 @@
|
||||
|
||||
//! Implements support for the pallet_balances module.
|
||||
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
use crate::frame::{
|
||||
system::System,
|
||||
Call,
|
||||
};
|
||||
use codec::{
|
||||
Decode,
|
||||
Encode,
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use frame_support::Parameter;
|
||||
use sp_runtime::traits::{
|
||||
AtLeast32Bit,
|
||||
MaybeSerialize,
|
||||
Member,
|
||||
AtLeast32Bit,
|
||||
};
|
||||
use crate::{
|
||||
frame::{
|
||||
system::System,
|
||||
Call,
|
||||
},
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// The subset of the `pallet_balances::Trait` that a client must implement.
|
||||
pub trait Balances: System {
|
||||
|
||||
@@ -160,10 +160,7 @@ mod tests {
|
||||
|
||||
type AccountId = <Runtime as System>::AccountId;
|
||||
|
||||
async fn put_code<T, P, S>(
|
||||
client: &Client<T, S>,
|
||||
signer: P,
|
||||
) -> Result<T::Hash, Error>
|
||||
async fn put_code<T, P, S>(client: &Client<T, S>, signer: P) -> Result<T::Hash, Error>
|
||||
where
|
||||
T: System + Balances + Send + Sync,
|
||||
T::Address: From<T::AccountId>,
|
||||
|
||||
+41
-21
@@ -16,26 +16,33 @@
|
||||
|
||||
//! Implements support for the frame_system module.
|
||||
|
||||
use codec::Codec;
|
||||
use codec::{
|
||||
Codec,
|
||||
Decode,
|
||||
Encode,
|
||||
};
|
||||
use frame_support::Parameter;
|
||||
use futures::future::{
|
||||
self,
|
||||
Future,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use sp_runtime::traits::{
|
||||
Bounded,
|
||||
CheckEqual,
|
||||
Extrinsic,
|
||||
Hash,
|
||||
Header,
|
||||
MaybeDisplay,
|
||||
MaybeMallocSizeOf,
|
||||
MaybeSerialize,
|
||||
MaybeSerializeDeserialize,
|
||||
Member,
|
||||
AtLeast32Bit,
|
||||
SimpleBitOps,
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
AtLeast32Bit,
|
||||
Bounded,
|
||||
CheckEqual,
|
||||
Extrinsic,
|
||||
Hash,
|
||||
Header,
|
||||
MaybeDisplay,
|
||||
MaybeMallocSizeOf,
|
||||
MaybeSerialize,
|
||||
MaybeSerializeDeserialize,
|
||||
Member,
|
||||
SimpleBitOps,
|
||||
},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
@@ -118,10 +125,26 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
type Extrinsic: Parameter + Member + Extrinsic + Debug + MaybeSerializeDeserialize;
|
||||
|
||||
/// Data to be associated with an account (other than nonce/transaction counter, which this
|
||||
/// module does regardless).
|
||||
/// module does regardless).
|
||||
type AccountData: Member + Codec + Clone + Default;
|
||||
}
|
||||
|
||||
/// Type used to encode the number of references an account has.
|
||||
pub type RefCount = u8;
|
||||
|
||||
/// Information of an account.
|
||||
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
|
||||
pub struct AccountInfo<T: System> {
|
||||
/// The number of transactions this account has sent.
|
||||
pub nonce: T::Index,
|
||||
/// The number of other modules that currently depend on this account's existence. The account
|
||||
/// cannot be reaped until this is zero.
|
||||
pub refcount: RefCount,
|
||||
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
|
||||
/// chains.
|
||||
pub data: T::AccountData,
|
||||
}
|
||||
|
||||
/// The System extension trait for the Client.
|
||||
pub trait SystemStore {
|
||||
/// System type.
|
||||
@@ -131,9 +154,7 @@ pub trait SystemStore {
|
||||
fn account(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<dyn Future<Output = Result<(<Self::System as System>::Index, <Self::System as System>::AccountData), Error>> + Send>,
|
||||
>;
|
||||
) -> Pin<Box<dyn Future<Output = Result<AccountInfo<Self::System>, Error>> + Send>>;
|
||||
}
|
||||
|
||||
impl<T: System + Balances + Sync + Send + 'static, S: 'static> SystemStore
|
||||
@@ -144,9 +165,8 @@ impl<T: System + Balances + Sync + Send + 'static, S: 'static> SystemStore
|
||||
fn account(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<dyn Future<Output = Result<(<Self::System as System>::Index, <Self::System as System>::AccountData), Error>> + Send>,
|
||||
> {
|
||||
) -> Pin<Box<dyn Future<Output = Result<AccountInfo<Self::System>, Error>> + Send>>
|
||||
{
|
||||
let account_map = || {
|
||||
Ok(self
|
||||
.metadata
|
||||
|
||||
+2
-2
@@ -311,7 +311,7 @@ impl<T: System + Balances + Sync + Send + 'static, S: 'static> Client<T, S> {
|
||||
let account_id = S::Signer::from(signer.public()).into_account();
|
||||
let nonce = match nonce {
|
||||
Some(nonce) => nonce,
|
||||
None => self.account(account_id).await?.0,
|
||||
None => self.account(account_id).await?.nonce,
|
||||
};
|
||||
|
||||
let genesis_hash = self.genesis_hash;
|
||||
@@ -561,7 +561,7 @@ mod tests {
|
||||
let result: Result<_, Error> = async_std::task::block_on(async move {
|
||||
let account = AccountKeyring::Alice.to_account_id();
|
||||
let client = test_client().await;
|
||||
let balance = client.account(account.into()).await?.1.free;
|
||||
let balance = client.account(account.into()).await?.data.free;
|
||||
Ok(balance)
|
||||
});
|
||||
|
||||
|
||||
+18
-5
@@ -130,8 +130,15 @@ where
|
||||
from: T::Hash,
|
||||
to: Option<T::Hash>,
|
||||
) -> Result<Vec<StorageChangeSet<<T as System>::Hash>>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(keys)?, to_json_value(from)?, to_json_value(to)?]);
|
||||
self.client.request("state_queryStorage", params).await.map_err(Into::into)
|
||||
let params = Params::Array(vec![
|
||||
to_json_value(keys)?,
|
||||
to_json_value(from)?,
|
||||
to_json_value(to)?,
|
||||
]);
|
||||
self.client
|
||||
.request("state_queryStorage", params)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Fetch the genesis hash
|
||||
@@ -343,10 +350,16 @@ impl<T: System + Balances + 'static> Rpc<T> {
|
||||
TransactionStatus::Invalid => return Err("Extrinsic Invalid".into()),
|
||||
TransactionStatus::Usurped(_) => return Err("Extrinsic Usurped".into()),
|
||||
TransactionStatus::Dropped => return Err("Extrinsic Dropped".into()),
|
||||
TransactionStatus::Retracted(_) => return Err("Extrinsic Retracted".into()),
|
||||
TransactionStatus::Retracted(_) => {
|
||||
return Err("Extrinsic Retracted".into())
|
||||
}
|
||||
// should have made it `InBlock` before either of these
|
||||
TransactionStatus::Finalized(_) => return Err("Extrinsic Finalized".into()),
|
||||
TransactionStatus::FinalityTimeout(_) => return Err("Extrinsic FinalityTimeout".into()),
|
||||
TransactionStatus::Finalized(_) => {
|
||||
return Err("Extrinsic Finalized".into())
|
||||
}
|
||||
TransactionStatus::FinalityTimeout(_) => {
|
||||
return Err("Extrinsic FinalityTimeout".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
unreachable!()
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@ use sp_runtime::{
|
||||
};
|
||||
|
||||
use crate::frame::{
|
||||
balances::{Balances, AccountData},
|
||||
balances::{
|
||||
AccountData,
|
||||
Balances,
|
||||
},
|
||||
contracts::Contracts,
|
||||
system::System,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user