mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 03:31:10 +00:00
Latest substrate updates (#70)
* Fix compilation errors with latest substrate * System::Account replaces FreeBalance and Nonce * System::Account replaces FreeBalance and Nonce * Remove Balances FreeBalance, replaced with System Account * Update system event, fix instantiate * reorder deps
This commit is contained in:
+23
-71
@@ -18,28 +18,19 @@
|
||||
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
pin::Pin,
|
||||
};
|
||||
|
||||
use futures::future::{
|
||||
self,
|
||||
Future,
|
||||
};
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use frame_support::Parameter;
|
||||
use sp_runtime::traits::{
|
||||
MaybeSerialize,
|
||||
Member,
|
||||
SimpleArithmetic,
|
||||
AtLeast32Bit,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::Error,
|
||||
frame::{
|
||||
system::System,
|
||||
Call,
|
||||
},
|
||||
Client,
|
||||
};
|
||||
|
||||
/// The subset of the `pallet_balances::Trait` that a client must implement.
|
||||
@@ -47,7 +38,7 @@ pub trait Balances: System {
|
||||
/// The balance of an account.
|
||||
type Balance: Parameter
|
||||
+ Member
|
||||
+ SimpleArithmetic
|
||||
+ AtLeast32Bit
|
||||
+ codec::Codec
|
||||
+ Default
|
||||
+ Copy
|
||||
@@ -56,67 +47,28 @@ pub trait Balances: System {
|
||||
+ From<<Self as System>::BlockNumber>;
|
||||
}
|
||||
|
||||
/// The Balances extension trait for the Client.
|
||||
pub trait BalancesStore {
|
||||
/// Balances type.
|
||||
type Balances: Balances;
|
||||
|
||||
/// The 'free' balance of a given account.
|
||||
/// All balance information for an account.
|
||||
#[derive(Debug, Encode, Decode, Clone, PartialEq, Eq, Default)]
|
||||
pub struct AccountData<Balance> {
|
||||
/// Non-reserved part of the balance. There may still be restrictions on this, but it is the
|
||||
/// total pool what may in principle be transferred, reserved and used for tipping.
|
||||
///
|
||||
/// This is the only balance that matters in terms of most operations on
|
||||
/// tokens. It alone is used to determine the balance when in the contract
|
||||
/// execution environment. When this balance falls below the value of
|
||||
/// `ExistentialDeposit`, then the 'current account' is deleted:
|
||||
/// specifically `FreeBalance`. Further, the `OnFreeBalanceZero` callback
|
||||
/// is invoked, giving a chance to external modules to clean up data
|
||||
/// associated with the deleted account.
|
||||
/// This is the only balance that matters in terms of most operations on tokens. It
|
||||
/// alone is used to determine the balance when in the contract execution environment.
|
||||
pub free: Balance,
|
||||
/// Balance which is reserved and may not be used at all.
|
||||
///
|
||||
/// `system::AccountNonce` is also deleted if `ReservedBalance` is also
|
||||
/// zero. It also gets collapsed to zero if it ever becomes less than
|
||||
/// `ExistentialDeposit`.
|
||||
fn free_balance(
|
||||
&self,
|
||||
account_id: <Self::Balances as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = Result<<Self::Balances as Balances>::Balance, Error>>
|
||||
+ Send,
|
||||
>,
|
||||
>;
|
||||
}
|
||||
|
||||
impl<T: Balances + Sync + Send + 'static, S: 'static> BalancesStore for Client<T, S> {
|
||||
type Balances = T;
|
||||
|
||||
fn free_balance(
|
||||
&self,
|
||||
account_id: <Self::Balances as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<
|
||||
dyn Future<Output = Result<<Self::Balances as Balances>::Balance, Error>>
|
||||
+ Send,
|
||||
>,
|
||||
> {
|
||||
let free_balance_map = || {
|
||||
Ok(self
|
||||
.metadata()
|
||||
.module("Balances")?
|
||||
.storage("FreeBalance")?
|
||||
.get_map::<
|
||||
<Self::Balances as System>::AccountId,
|
||||
<Self::Balances as Balances>::Balance>()?)
|
||||
};
|
||||
let map = match free_balance_map() {
|
||||
Ok(map) => map,
|
||||
Err(err) => return Box::pin(future::err(err)),
|
||||
};
|
||||
let client = self.clone();
|
||||
Box::pin(async move {
|
||||
client
|
||||
.fetch_or(map.key(account_id), None, map.default())
|
||||
.await
|
||||
})
|
||||
}
|
||||
/// This can still get slashed, but gets slashed last of all.
|
||||
///
|
||||
/// This balance is a 'reserve' balance that other subsystems use in order to set aside tokens
|
||||
/// that are still 'owned' by the account holder, but which are suspendable.
|
||||
pub reserved: Balance,
|
||||
/// The amount that `free` may not drop below when withdrawing for *anything except transaction
|
||||
/// fee payment*.
|
||||
pub misc_frozen: Balance,
|
||||
/// The amount that `free` may not drop below when withdrawing specifically for transaction
|
||||
/// fee payment.
|
||||
pub fee_frozen: Balance,
|
||||
}
|
||||
|
||||
const MODULE: &str = "Balances";
|
||||
|
||||
@@ -212,12 +212,12 @@ mod tests {
|
||||
fn tx_instantiate() {
|
||||
env_logger::try_init().ok();
|
||||
let result: Result<_, Error> = async_std::task::block_on(async move {
|
||||
let signer = AccountKeyring::Alice.pair();
|
||||
let signer = AccountKeyring::Bob.pair();
|
||||
let client = test_client().await;
|
||||
|
||||
let code_hash = put_code(&client, signer.clone()).await?;
|
||||
|
||||
println!("{:?}", code_hash);
|
||||
log::info!("Code hash: {:?}", code_hash);
|
||||
|
||||
let xt = client.xt(signer, None).await?;
|
||||
let result = xt
|
||||
@@ -235,9 +235,11 @@ mod tests {
|
||||
Ok(event)
|
||||
});
|
||||
|
||||
log::info!("Instantiate result: {:?}", result);
|
||||
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Contracts CodeStored event should be received and decoded"
|
||||
"Contract should be instantiated successfully"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-12
@@ -30,10 +30,11 @@ use sp_runtime::traits::{
|
||||
Hash,
|
||||
Header,
|
||||
MaybeDisplay,
|
||||
MaybeMallocSizeOf,
|
||||
MaybeSerialize,
|
||||
MaybeSerializeDeserialize,
|
||||
Member,
|
||||
SimpleArithmetic,
|
||||
AtLeast32Bit,
|
||||
SimpleBitOps,
|
||||
};
|
||||
use std::{
|
||||
@@ -60,16 +61,17 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
+ Debug
|
||||
+ Default
|
||||
+ MaybeDisplay
|
||||
+ SimpleArithmetic
|
||||
+ AtLeast32Bit
|
||||
+ Copy;
|
||||
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeMallocSizeOf
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ SimpleArithmetic
|
||||
+ AtLeast32Bit
|
||||
+ Default
|
||||
+ Bounded
|
||||
+ Copy
|
||||
@@ -79,6 +81,7 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ MaybeMallocSizeOf
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
@@ -113,6 +116,10 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
|
||||
/// Extrinsic type within blocks.
|
||||
type Extrinsic: Parameter + Member + Extrinsic + Debug + MaybeSerializeDeserialize;
|
||||
|
||||
/// Data to be associated with an account (other than nonce/transaction counter, which this
|
||||
/// module does regardless).
|
||||
type AccountData: Member + Codec + Clone + Default;
|
||||
}
|
||||
|
||||
/// The System extension trait for the Client.
|
||||
@@ -120,12 +127,12 @@ pub trait SystemStore {
|
||||
/// System type.
|
||||
type System: System;
|
||||
|
||||
/// Returns the account nonce for an account_id.
|
||||
fn account_nonce(
|
||||
/// Returns the nonce and account data for an account_id.
|
||||
fn account(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<dyn Future<Output = Result<<Self::System as System>::Index, Error>> + Send>,
|
||||
Box<dyn Future<Output = Result<(<Self::System as System>::Index, <Self::System as System>::AccountData), Error>> + Send>,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -134,20 +141,20 @@ impl<T: System + Balances + Sync + Send + 'static, S: 'static> SystemStore
|
||||
{
|
||||
type System = T;
|
||||
|
||||
fn account_nonce(
|
||||
fn account(
|
||||
&self,
|
||||
account_id: <Self::System as System>::AccountId,
|
||||
) -> Pin<
|
||||
Box<dyn Future<Output = Result<<Self::System as System>::Index, Error>> + Send>,
|
||||
Box<dyn Future<Output = Result<(<Self::System as System>::Index, <Self::System as System>::AccountData), Error>> + Send>,
|
||||
> {
|
||||
let account_nonce_map = || {
|
||||
let account_map = || {
|
||||
Ok(self
|
||||
.metadata
|
||||
.module("System")?
|
||||
.storage("AccountNonce")?
|
||||
.storage("Account")?
|
||||
.get_map()?)
|
||||
};
|
||||
let map = match account_nonce_map() {
|
||||
let map = match account_map() {
|
||||
Ok(map) => map,
|
||||
Err(err) => return Box::pin(future::err(err)),
|
||||
};
|
||||
@@ -175,11 +182,17 @@ use frame_support::weights::DispatchInfo;
|
||||
|
||||
/// Event for the System module.
|
||||
#[derive(Clone, Debug, codec::Decode)]
|
||||
pub enum SystemEvent {
|
||||
pub enum SystemEvent<T: System> {
|
||||
/// An extrinsic completed successfully.
|
||||
ExtrinsicSuccess(DispatchInfo),
|
||||
/// An extrinsic failed.
|
||||
ExtrinsicFailed(sp_runtime::DispatchError, DispatchInfo),
|
||||
/// `:code` was updated.
|
||||
CodeUpdated,
|
||||
/// A new account was created.
|
||||
NewAccount(T::AccountId),
|
||||
/// An account was reaped.
|
||||
ReapedAccount(T::AccountId),
|
||||
}
|
||||
|
||||
/// A phase of a block's execution.
|
||||
|
||||
Reference in New Issue
Block a user