mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
b7565ff435
* 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
97 lines
3.3 KiB
Rust
97 lines
3.3 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 the pallet_balances module.
|
|
|
|
use std::{
|
|
fmt::Debug,
|
|
};
|
|
use codec::{Encode, Decode};
|
|
use frame_support::Parameter;
|
|
use sp_runtime::traits::{
|
|
MaybeSerialize,
|
|
Member,
|
|
AtLeast32Bit,
|
|
};
|
|
use crate::{
|
|
frame::{
|
|
system::System,
|
|
Call,
|
|
},
|
|
};
|
|
|
|
/// The subset of the `pallet_balances::Trait` that a client must implement.
|
|
pub trait Balances: System {
|
|
/// The balance of an account.
|
|
type Balance: Parameter
|
|
+ Member
|
|
+ AtLeast32Bit
|
|
+ codec::Codec
|
|
+ Default
|
|
+ Copy
|
|
+ MaybeSerialize
|
|
+ Debug
|
|
+ From<<Self as System>::BlockNumber>;
|
|
}
|
|
|
|
/// 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.
|
|
pub free: Balance,
|
|
/// Balance which is reserved and may not be used at all.
|
|
///
|
|
/// 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";
|
|
const TRANSFER: &str = "transfer";
|
|
|
|
/// Arguments for transferring a balance
|
|
#[derive(codec::Encode)]
|
|
pub struct TransferArgs<T: Balances> {
|
|
to: <T as System>::Address,
|
|
#[codec(compact)]
|
|
amount: <T as Balances>::Balance,
|
|
}
|
|
|
|
/// Transfer some liquid free balance to another account.
|
|
///
|
|
/// `transfer` will set the `FreeBalance` of the sender and receiver.
|
|
/// It will decrease the total issuance of the system by the `TransferFee`.
|
|
/// If the sender's account is below the existential deposit as a result
|
|
/// of the transfer, the account will be reaped.
|
|
pub fn transfer<T: Balances>(
|
|
to: <T as System>::Address,
|
|
amount: <T as Balances>::Balance,
|
|
) -> Call<TransferArgs<T>> {
|
|
Call::new(MODULE, TRANSFER, TransferArgs { to, amount })
|
|
}
|