Balance Pallet Skeleton

성시완·2022년 6월 26일
0
use frame_support::traits::GenesisBuild;
use frame_support::{
	ensure,
	pallet_prelude::DispatchResult,
	traits::{
		tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence},
		Currency, DefensiveSaturating, ExistenceRequirement,
		ExistenceRequirement::{AllowDeath, KeepAlive},
		Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency, OnUnbalanced,
		ReservableCurrency, SignedImbalance, StoredMap, TryDrop, WithdrawReasons,
	},
	WeakBoundedVec,
};

#[frame_support::pallet]
pub mod pallet {
	  #[pallet::call]
      impl<T: Config<I>, I: 'static> Pallet<T, I> {

      #[pallet::weight(T::WeightInfo::transfer())]
      pub fn transfer()
      
      /// Set the balances of a given account.
      #[pallet::weight(
      T::WeightInfo::set_balance_creating() // Creates a new account
      .max(T::WeightInfo::set_balance_killing()) // Kills an existing account.
      )]
      pub fn set_balance()
      
/// Same as transfer, but additional read and write 
/// because the source account is not assumed to be in the overlay.
      #[pallet::weight(T::WeightInfo::force_transfer())]
      pub fn force_transfer()
      
/// Same as the [`transfer`] call, but with a check that the 
/// transfer will not kill the origin account.
      #[pallet::weight(T::WeightInfo::transfer_keep_alive())]
      pub fn transfer_keep_alive()

/// Transfer the entire transferable balance from the caller account.
      #[pallet::weight(T::WeightInfo::transfer_all())]
      pub fn transfer_all()

/// Unreserve some balance from a user by force.
      #[pallet::weight(T::WeightInfo::force_unreserve())]
      pub fn force_unreserve()

      #[pallet::event]
      #[pallet::generate_deposit(pub(super) fn deposit_event)]
      pub enum Event<T: Config<I>, I: 'static = ()> {
/// An account was created with some free balance.
          Endowed,
/// An account was removed whose balance was non-zero but below ExistentialDeposit,
/// resulting in an outright loss.
          DustLost,
          Transfer,
          BalanceSet,
          Reserved,
          Unreserved,
          ReserveRepatriated,
          Deposit,
          Withdraw,
          Slashed,
          }
      #[pallet::error]
      pub enum Error<T, I = ()> {
          VestingBalance,
          LiquidityRestrictions,
          InsufficientBalance,
          ExistentialDeposit,
/// Transfer/payment would kill account
          KeepAlive,
          ExistingVestingSchedule,
          DeadAccount,
          ToomanyReserves,
          }
  /// The total units issued in the system.
      #[pallet::storage]
      #[pallet::getter(fn total_issuance)]
      pub type TotalIssuance
      /// Any liquidity locks on some account balances.
      /// NOTE: Should only be accessed when setting, changing and freeing a lock.
      #[pallet::storage]
      #[pallet::getter(fn locks)]
      pub type Locks<T: Config<I>, I: 'static = ()> = StorageMap<
          _,
          Blake2_128Concat,
          T::AccountId,
          WeakBoundedVec<BalanceLock<T::Balance>, T::MaxLocks>,
          ValueQuery,
      >;
      /// Blake2~ : Hash storage keys with concat(blake2_128(key), key)
}
      /// Named reserves on some account balances.
      #[pallet::storage]
      #[pallet::getter(fn reserves)]
      pub type Reserves
      
      impl<T: Config<I>, I: 'static> Pallet<T, I>
      	  pub fn free_balance
          
          pub fn usable_balance
          
          pub fn usable_balance_for_fees
          
          pub fn reserved_balance
          
          pub fn mutate_account
          
      impl<T: Config<I>, I: 'static> fungible::Inspect<T::AccountId> for Pallet<T, I>
      	  fn total_issuance()
          
          fn minimum_balance()
          
          fn balance(who: &T::AccountId)
          
          fn reducible_balance()
          
          fn can_deposit
          
          fn can_withdraw
          
      impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I>
          fn mint_into
          
          fn burn_from
      
      impl<T: Config<I>, I: 'static> fungible::Transfer<T::AccountId> for Pallet<T, I>
      	  fn transfer
      
      impl<T: Config<I>, I: 'static> fungible::Unbalanced<T::AccountId> for Pallet<T, I>
      	  fn set_balance
          
          fn set_total_issuance
      
      	 
      impl<T: Config<I>, I: 'static> fungible::InspectHold<T::AccountId> for Pallet<T, I>
      	  fn balance_on_hold
          
          fn can_hold
      
      impl<T: Config<I>, I: 'static> fungible::MutateHold<T::AccountId> for Pallet<T, I>
      	  fn hold
          
          fn release
          
          fn transfer_held
      
      impl<T: Config<I>, I: 'static> Currency<T::AccountId> for Pallet<T, I>
      where
          T::Balance: MaybeSerializeDeserialize + Debug,{}
      impl<T: Config<I>, I: 'static> ReservableCurrency<T::AccountId> for Pallet<T, I>
	  where
          T::Balance: MaybeSerializeDeserialize + Debug,{}
          
      impl<T: Config<I>, I: 'static> NamedReservableCurrency<T::AccountId> for Pallet<T, I>
      where
          T::Balance: MaybeSerializeDeserialize + Debug,{}
    
      impl<T: Config<I>, I: 'static> LockableCurrency<T::AccountId> for Pallet<T, I>
      where
          T::Balance: MaybeSerializeDeserialize + Debug,{}
profile
메모장 // 화이팅

0개의 댓글