From 53e4e496fa7445e4af2535a91eedcc8fbdb44c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Tue, 17 Jan 2023 13:13:27 +0100 Subject: [PATCH] Hide primitive types behind Balance and BlockNumber --- aleph-client/Cargo.lock | 2 +- aleph-client/Cargo.toml | 2 +- aleph-client/src/contract/mod.rs | 12 ++++++------ aleph-client/src/lib.rs | 1 + aleph-client/src/pallets/balances.rs | 3 +-- aleph-client/src/pallets/contract.rs | 19 +++++++++---------- aleph-client/src/pallets/staking.rs | 16 ++++++++-------- aleph-client/src/pallets/system.rs | 3 +-- aleph-client/src/pallets/vesting.rs | 13 +++++++------ benches/payout-stakers/Cargo.lock | 2 +- benches/payout-stakers/src/main.rs | 6 +++--- bin/cliain/Cargo.lock | 2 +- bin/cliain/src/commands.rs | 10 +++++----- bin/cliain/src/contracts.rs | 4 ++-- bin/cliain/src/staking.rs | 8 ++++---- bin/cliain/src/transfer.rs | 6 ++++-- bin/cliain/src/vesting.rs | 2 +- e2e-tests/Cargo.lock | 2 +- flooder/Cargo.lock | 2 +- flooder/src/main.rs | 6 +++--- 20 files changed, 61 insertions(+), 60 deletions(-) diff --git a/aleph-client/Cargo.lock b/aleph-client/Cargo.lock index 16f592794f..396e04014d 100644 --- a/aleph-client/Cargo.lock +++ b/aleph-client/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.8.1" dependencies = [ "anyhow", "async-trait", diff --git a/aleph-client/Cargo.toml b/aleph-client/Cargo.toml index 41268b2787..37d13f8769 100644 --- a/aleph-client/Cargo.toml +++ b/aleph-client/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "aleph_client" # TODO bump major version when API stablize -version = "2.8.0" +version = "2.8.1" edition = "2021" license = "Apache 2.0" diff --git a/aleph-client/src/contract/mod.rs b/aleph-client/src/contract/mod.rs index d692194026..575b57bc34 100644 --- a/aleph-client/src/contract/mod.rs +++ b/aleph-client/src/contract/mod.rs @@ -5,7 +5,7 @@ //! //! ```no_run //! # use anyhow::{Result, Context}; -//! # use aleph_client::AccountId; +//! # use aleph_client::{AccountId, Balance}; //! # use aleph_client::{Connection, SignedConnection}; //! # use aleph_client::contract::ContractInstance; //! # @@ -24,7 +24,7 @@ //! }) //! } //! -//! async fn transfer(&self, conn: &SignedConnection, to: AccountId, amount: u128) -> Result<()> { +//! async fn transfer(&self, conn: &SignedConnection, to: AccountId, amount: Balance) -> Result<()> { //! self.contract.contract_exec( //! conn, //! "PSP22::transfer", @@ -32,7 +32,7 @@ //! ).await //! } //! -//! async fn balance_of(&self, conn: &Connection, account: AccountId) -> Result { +//! async fn balance_of(&self, conn: &Connection, account: AccountId) -> Result { //! self.contract.contract_read( //! conn, //! "PSP22::balance_of", @@ -55,7 +55,7 @@ use crate::{ contract_transcode::Value, pallets::contract::{ContractCallArgs, ContractRpc, ContractsUserApi}, sp_weights::weight_v2::Weight, - AccountId, ConnectionApi, SignedConnectionApi, TxStatus, + AccountId, Balance, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Represents a contract instantiated on the chain. @@ -148,7 +148,7 @@ impl ContractInstance { &self, conn: &C, message: &str, - value: u128, + value: Balance, ) -> Result<()> { self.contract_exec_value::(conn, message, &[], value) .await @@ -160,7 +160,7 @@ impl ContractInstance { conn: &C, message: &str, args: &[S], - value: u128, + value: Balance, ) -> Result<()> { let data = self.encode(message, args)?; conn.call( diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index 2f0e79dbe3..83d98b34dd 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -34,6 +34,7 @@ pub mod utility; /// Waiting for some events API. pub mod waiting; +pub use ::primitives::{Balance, BlockNumber}; pub use aleph_zero::api; pub use runtime_types::*; diff --git a/aleph-client/src/pallets/balances.rs b/aleph-client/src/pallets/balances.rs index cf757be5af..ffd4e44132 100644 --- a/aleph-client/src/pallets/balances.rs +++ b/aleph-client/src/pallets/balances.rs @@ -1,4 +1,3 @@ -use primitives::Balance; use subxt::{ext::sp_runtime::MultiAddress, tx::PolkadotExtrinsicParamsBuilder}; use crate::{ @@ -6,7 +5,7 @@ use crate::{ connections::TxInfo, pallet_balances::pallet::Call::transfer, pallets::utility::UtilityApi, - AccountId, BlockHash, + AccountId, Balance, BlockHash, Call::Balances, ConnectionApi, SignedConnectionApi, TxStatus, }; diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index cf24c640f5..235f44678f 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -1,11 +1,10 @@ use codec::{Compact, Encode}; use pallet_contracts_primitives::ContractExecResult; -use primitives::Balance; use subxt::{ext::sp_core::Bytes, rpc_params}; use crate::{ api, connections::TxInfo, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, - AccountId, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, + AccountId, Balance, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Arguments to [`ContractRpc::call_and_get`]. @@ -45,7 +44,7 @@ pub trait ContractsUserApi { async fn upload_code( &self, code: Vec, - storage_limit: Option>, + storage_limit: Option>, status: TxStatus, ) -> anyhow::Result; @@ -56,7 +55,7 @@ pub trait ContractsUserApi { code_hash: BlockHash, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, salt: Vec, status: TxStatus, @@ -69,7 +68,7 @@ pub trait ContractsUserApi { code: Vec, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, salt: Vec, status: TxStatus, @@ -81,7 +80,7 @@ pub trait ContractsUserApi { destination: AccountId, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, status: TxStatus, ) -> anyhow::Result; @@ -118,7 +117,7 @@ impl ContractsUserApi for S { async fn upload_code( &self, code: Vec, - storage_limit: Option>, + storage_limit: Option>, status: TxStatus, ) -> anyhow::Result { let tx = api::tx().contracts().upload_code(code, storage_limit); @@ -131,7 +130,7 @@ impl ContractsUserApi for S { code_hash: BlockHash, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, salt: Vec, status: TxStatus, @@ -153,7 +152,7 @@ impl ContractsUserApi for S { code: Vec, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, salt: Vec, status: TxStatus, @@ -175,7 +174,7 @@ impl ContractsUserApi for S { destination: AccountId, balance: Balance, gas_limit: Weight, - storage_limit: Option>, + storage_limit: Option>, data: Vec, status: TxStatus, ) -> anyhow::Result { diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index 0ba312e626..e35743191b 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -50,7 +50,7 @@ pub trait StakingApi { /// Returns [`eras_validator_reward`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.eras_validator_reward) for a given era. /// * `era` - an era index /// * `at` - optional hash of a block to query state from - async fn get_payout_for_era(&self, era: EraIndex, at: Option) -> u128; + async fn get_payout_for_era(&self, era: EraIndex, at: Option) -> Balance; /// Returns [`eras_stakers`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.eras_stakers) for a given era and account id. /// * `era` - an era index @@ -61,7 +61,7 @@ pub trait StakingApi { era: EraIndex, account_id: &AccountId, at: Option, - ) -> Exposure; + ) -> Exposure; /// Returns [`eras_reward_points`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.eras_reward_points) for a given era. /// * `era` - an era index @@ -198,8 +198,8 @@ pub trait StakingSudoApi { /// API for [`set_staking_config`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.set_staking_configs) call. async fn set_staking_config( &self, - minimal_nominator_bond: Option, - minimal_validator_bond: Option, + minimal_nominator_bond: Option, + minimal_validator_bond: Option, max_nominators_count: Option, max_validators_count: Option, status: TxStatus, @@ -267,7 +267,7 @@ impl StakingApi for C { self.get_storage_entry(&addrs, at).await } - async fn get_payout_for_era(&self, era: EraIndex, at: Option) -> u128 { + async fn get_payout_for_era(&self, era: EraIndex, at: Option) -> Balance { let addrs = api::storage().staking().eras_validator_reward(era); self.get_storage_entry(&addrs, at).await @@ -278,7 +278,7 @@ impl StakingApi for C { era: EraIndex, account_id: &AccountId, at: Option, - ) -> Exposure { + ) -> Exposure { let addrs = api::storage().staking().eras_stakers(era, account_id); self.get_storage_entry(&addrs, at).await @@ -392,8 +392,8 @@ impl StakingSudoApi for RootConnection { async fn set_staking_config( &self, - min_nominator_bond: Option, - min_validator_bond: Option, + min_nominator_bond: Option, + min_validator_bond: Option, max_nominator_count: Option, max_validator_count: Option, status: TxStatus, diff --git a/aleph-client/src/pallets/system.rs b/aleph-client/src/pallets/system.rs index 6166759b8c..546ea24a79 100644 --- a/aleph-client/src/pallets/system.rs +++ b/aleph-client/src/pallets/system.rs @@ -1,4 +1,3 @@ -use primitives::Balance; use subxt::ext::sp_runtime::Perbill as SPerbill; use crate::{ @@ -6,7 +5,7 @@ use crate::{ connections::TxInfo, frame_system::pallet::Call::{fill_block, set_code}, sp_arithmetic::per_things::Perbill, - AccountId, BlockHash, + AccountId, Balance, BlockHash, Call::System, ConnectionApi, RootConnection, SudoCall, TxStatus, }; diff --git a/aleph-client/src/pallets/vesting.rs b/aleph-client/src/pallets/vesting.rs index 6b3171ac55..daab5915b3 100644 --- a/aleph-client/src/pallets/vesting.rs +++ b/aleph-client/src/pallets/vesting.rs @@ -1,8 +1,9 @@ +use primitives::BlockNumber; use subxt::ext::sp_runtime::MultiAddress; use crate::{ - api, connections::TxInfo, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, - ConnectionApi, SignedConnectionApi, TxStatus, + api, connections::TxInfo, pallet_vesting::vesting_info::VestingInfo, AccountId, Balance, + BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Read only pallet vesting API. @@ -15,7 +16,7 @@ pub trait VestingApi { &self, who: AccountId, at: Option, - ) -> Vec>; + ) -> Vec>; } /// Pallet vesting api. @@ -31,7 +32,7 @@ pub trait VestingUserApi { async fn vested_transfer( &self, receiver: AccountId, - schedule: VestingInfo, + schedule: VestingInfo, status: TxStatus, ) -> anyhow::Result; @@ -50,7 +51,7 @@ impl VestingApi for C { &self, who: AccountId, at: Option, - ) -> Vec> { + ) -> Vec> { let addrs = api::storage().vesting().vesting(who); self.get_storage_entry(&addrs, at).await.0 @@ -74,7 +75,7 @@ impl VestingUserApi for S { async fn vested_transfer( &self, receiver: AccountId, - schedule: VestingInfo, + schedule: VestingInfo, status: TxStatus, ) -> anyhow::Result { let tx = api::tx() diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index 0c42c14b3d..daa01de0c2 100644 --- a/benches/payout-stakers/Cargo.lock +++ b/benches/payout-stakers/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.8.1" dependencies = [ "anyhow", "async-trait", diff --git a/benches/payout-stakers/src/main.rs b/benches/payout-stakers/src/main.rs index ba9a3ab003..b2a54766cf 100644 --- a/benches/payout-stakers/src/main.rs +++ b/benches/payout-stakers/src/main.rs @@ -7,8 +7,8 @@ use aleph_client::{ staking::{StakingApi, StakingApiExt, StakingUserApi}, }, waiting::{BlockStatus, WaitingExt}, - AccountId, ConnectionApi, KeyPair, RootConnection, SignedConnection, SignedConnectionApi, - TxStatus, + AccountId, Balance, ConnectionApi, KeyPair, RootConnection, SignedConnection, + SignedConnectionApi, TxStatus, }; use clap::{ArgGroup, Parser}; use futures::future::join_all; @@ -235,7 +235,7 @@ async fn nominate_validator( .chunks(BOND_CALL_BATCH_LIMIT) .map(|c| c.to_vec()) { - let stake = (rng.gen::() % 100) * TOKEN + MIN_NOMINATOR_BOND; + let stake = (rng.gen::() % 100) * TOKEN + MIN_NOMINATOR_BOND; connection .batch_bond(&chunk, stake, TxStatus::Submitted) .await diff --git a/bin/cliain/Cargo.lock b/bin/cliain/Cargo.lock index 959eb48e46..da53bb0948 100644 --- a/bin/cliain/Cargo.lock +++ b/bin/cliain/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.8.1" dependencies = [ "anyhow", "async-trait", diff --git a/bin/cliain/src/commands.rs b/bin/cliain/src/commands.rs index 1847a6f849..029f4a527f 100644 --- a/bin/cliain/src/commands.rs +++ b/bin/cliain/src/commands.rs @@ -3,9 +3,9 @@ use std::{ path::{Path, PathBuf}, }; -use aleph_client::{AccountId, TxStatus}; +use aleph_client::{AccountId, Balance, TxStatus}; use clap::{clap_derive::ValueEnum, Args, Subcommand}; -use primitives::{Balance, BlockNumber, CommitteeSeats, SessionIndex}; +use primitives::{BlockNumber, CommitteeSeats, SessionIndex}; use serde::{Deserialize, Serialize}; use sp_core::H256; @@ -13,13 +13,13 @@ use sp_core::H256; pub struct ContractOptions { /// balance to transfer from the call origin to the contract #[clap(long, default_value = "0")] - pub balance: u128, + pub balance: Balance, /// The gas limit enforced when executing the constructor #[clap(long, default_value = "1000000000")] pub gas_limit: u64, /// The maximum amount of balance that can be charged/reserved from the caller to pay for the storage consumed #[clap(long)] - pub storage_deposit_limit: Option, + pub storage_deposit_limit: Option, } #[derive(Debug, Clone, Args)] @@ -29,7 +29,7 @@ pub struct ContractUploadCode { pub wasm_path: PathBuf, /// The maximum amount of balance that can be charged/reserved from the caller to pay for the storage consumed #[clap(long)] - pub storage_deposit_limit: Option, + pub storage_deposit_limit: Option, } #[derive(Debug, Clone, Args)] diff --git a/bin/cliain/src/contracts.rs b/bin/cliain/src/contracts.rs index cb6b939dad..dddbb47364 100644 --- a/bin/cliain/src/contracts.rs +++ b/bin/cliain/src/contracts.rs @@ -9,7 +9,7 @@ use aleph_client::{ pallets::contract::{ContractsApi, ContractsUserApi}, sp_weights::weight_v2::Weight, waiting::{AlephWaiting, BlockStatus}, - AccountId, Connection, SignedConnection, SignedConnectionApi, TxStatus, + AccountId, Balance, Connection, SignedConnection, SignedConnectionApi, TxStatus, }; use codec::{Compact, Decode}; use contract_metadata::ContractMetadata; @@ -29,7 +29,7 @@ pub struct InstantiateWithCodeReturnValue { pub code_hash: H256, } -fn storage_deposit(storage_deposit_limit: Option) -> Option> { +fn storage_deposit(storage_deposit_limit: Option) -> Option> { storage_deposit_limit.map(Compact) } diff --git a/bin/cliain/src/staking.rs b/bin/cliain/src/staking.rs index 0a5d0186df..f5670f135d 100644 --- a/bin/cliain/src/staking.rs +++ b/bin/cliain/src/staking.rs @@ -1,6 +1,6 @@ use aleph_client::{ pallets::staking::{StakingSudoApi, StakingUserApi}, - AccountId, RootConnection, SignedConnection, TxStatus, + AccountId, Balance, RootConnection, SignedConnection, TxStatus, }; use primitives::TOKEN; use subxt::ext::sp_core::crypto::Ss58Codec; @@ -13,7 +13,7 @@ pub async fn bond( let controller_account = AccountId::from_ss58check(&controller_account).expect("Address is valid"); - let initial_stake = initial_stake_in_tokens as u128 * TOKEN; + let initial_stake = initial_stake_in_tokens as Balance * TOKEN; stash_connection .bond(initial_stake, controller_account, TxStatus::Finalized) .await @@ -44,8 +44,8 @@ pub async fn set_staking_limits( ) { root_connection .set_staking_config( - Some(minimal_nominator_stake_tokens as u128 * TOKEN), - Some(minimal_validator_stake_tokens as u128 * TOKEN), + Some(minimal_nominator_stake_tokens as Balance * TOKEN), + Some(minimal_validator_stake_tokens as Balance * TOKEN), max_nominators_count, max_validators_count, TxStatus::Finalized, diff --git a/bin/cliain/src/transfer.rs b/bin/cliain/src/transfer.rs index 8ca1c92adf..9b0d607b19 100644 --- a/bin/cliain/src/transfer.rs +++ b/bin/cliain/src/transfer.rs @@ -1,4 +1,6 @@ -use aleph_client::{pallets::balances::BalanceUserApi, AccountId, SignedConnection, TxStatus}; +use aleph_client::{ + pallets::balances::BalanceUserApi, AccountId, Balance, SignedConnection, TxStatus, +}; use primitives::TOKEN; use subxt::ext::sp_core::crypto::Ss58Codec; @@ -7,7 +9,7 @@ pub async fn transfer(connection: SignedConnection, amount_in_tokens: u64, to_ac connection .transfer( to_account, - amount_in_tokens as u128 * TOKEN, + amount_in_tokens as Balance * TOKEN, TxStatus::Finalized, ) .await diff --git a/bin/cliain/src/vesting.rs b/bin/cliain/src/vesting.rs index 648e72be82..a39a563cc5 100644 --- a/bin/cliain/src/vesting.rs +++ b/bin/cliain/src/vesting.rs @@ -40,7 +40,7 @@ pub async fn vested_transfer( ) { let receiver = account_from_keypair(keypair_from_string(target_seed.as_str()).signer()); let schedule = VestingInfo { - locked: amount_in_tokens as u128 * TOKEN, + locked: amount_in_tokens as Balance * TOKEN, per_block, starting_block, }; diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 2f89f24521..1f43006247 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.8.1" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index 531c491c17..f4d812d32b 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.8.1" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/src/main.rs b/flooder/src/main.rs index 2a44a9c913..b616610597 100644 --- a/flooder/src/main.rs +++ b/flooder/src/main.rs @@ -2,7 +2,7 @@ use std::time::Duration; use aleph_client::{ account_from_keypair, pallets::balances::BalanceUserApi, raw_keypair_from_string, AccountId, - KeyPair, SignedConnection, SignedConnectionApi, TxStatus, + Balance, KeyPair, SignedConnection, SignedConnectionApi, TxStatus, }; use clap::Parser; use config::Config; @@ -16,7 +16,7 @@ mod config; async fn flood( connections: Vec, dest: AccountId, - transfer_amount: u128, + transfer_amount: Balance, tx_count: u64, rate_limiting: Option<(u64, u64)>, status: TxStatus, @@ -65,7 +65,7 @@ async fn initialize_n_accounts String>( connection: SignedConnection, n: u32, node: F, - account_balance: u128, + account_balance: Balance, skip: bool, ) -> Vec { let mut connections = vec![];