Skip to content

Commit

Permalink
Hide primitive types behind Balance and BlockNumber (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 authored Jan 18, 2023
1 parent 2494ad1 commit 13254e1
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 60 deletions.
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
12 changes: 6 additions & 6 deletions aleph-client/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//! #
Expand All @@ -24,15 +24,15 @@
//! })
//! }
//!
//! 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",
//! vec![to.to_string().as_str(), amount.to_string().as_str(), "0x00"].as_slice(),
//! ).await
//! }
//!
//! async fn balance_of(&self, conn: &Connection, account: AccountId) -> Result<u128> {
//! async fn balance_of(&self, conn: &Connection, account: AccountId) -> Result<Balance> {
//! self.contract.contract_read(
//! conn,
//! "PSP22::balance_of",
Expand All @@ -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.
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ContractInstance {
&self,
conn: &C,
message: &str,
value: u128,
value: Balance,
) -> Result<()> {
self.contract_exec_value::<C, String>(conn, message, &[], value)
.await
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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::*;

Expand Down
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/balances.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use primitives::Balance;
use subxt::{ext::sp_runtime::MultiAddress, tx::PolkadotExtrinsicParamsBuilder};

use crate::{
aleph_zero::{self, api, api::runtime_types::pallet_balances::BalanceLock},
connections::TxInfo,
pallet_balances::pallet::Call::transfer,
pallets::utility::UtilityApi,
AccountId, BlockHash,
AccountId, Balance, BlockHash,
Call::Balances,
ConnectionApi, SignedConnectionApi, TxStatus,
};
Expand Down
19 changes: 9 additions & 10 deletions aleph-client/src/pallets/contract.rs
Original file line number Diff line number Diff line change
@@ -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`].
Expand Down Expand Up @@ -45,7 +44,7 @@ pub trait ContractsUserApi {
async fn upload_code(
&self,
code: Vec<u8>,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
status: TxStatus,
) -> anyhow::Result<TxInfo>;

Expand All @@ -56,7 +55,7 @@ pub trait ContractsUserApi {
code_hash: BlockHash,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
salt: Vec<u8>,
status: TxStatus,
Expand All @@ -69,7 +68,7 @@ pub trait ContractsUserApi {
code: Vec<u8>,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
salt: Vec<u8>,
status: TxStatus,
Expand All @@ -81,7 +80,7 @@ pub trait ContractsUserApi {
destination: AccountId,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
status: TxStatus,
) -> anyhow::Result<TxInfo>;
Expand Down Expand Up @@ -118,7 +117,7 @@ impl<S: SignedConnectionApi> ContractsUserApi for S {
async fn upload_code(
&self,
code: Vec<u8>,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
status: TxStatus,
) -> anyhow::Result<TxInfo> {
let tx = api::tx().contracts().upload_code(code, storage_limit);
Expand All @@ -131,7 +130,7 @@ impl<S: SignedConnectionApi> ContractsUserApi for S {
code_hash: BlockHash,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
salt: Vec<u8>,
status: TxStatus,
Expand All @@ -153,7 +152,7 @@ impl<S: SignedConnectionApi> ContractsUserApi for S {
code: Vec<u8>,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
salt: Vec<u8>,
status: TxStatus,
Expand All @@ -175,7 +174,7 @@ impl<S: SignedConnectionApi> ContractsUserApi for S {
destination: AccountId,
balance: Balance,
gas_limit: Weight,
storage_limit: Option<Compact<u128>>,
storage_limit: Option<Compact<Balance>>,
data: Vec<u8>,
status: TxStatus,
) -> anyhow::Result<TxInfo> {
Expand Down
16 changes: 8 additions & 8 deletions aleph-client/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockHash>) -> u128;
async fn get_payout_for_era(&self, era: EraIndex, at: Option<BlockHash>) -> 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
Expand All @@ -61,7 +61,7 @@ pub trait StakingApi {
era: EraIndex,
account_id: &AccountId,
at: Option<BlockHash>,
) -> Exposure<AccountId, u128>;
) -> Exposure<AccountId, Balance>;

/// 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
Expand Down Expand Up @@ -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<u128>,
minimal_validator_bond: Option<u128>,
minimal_nominator_bond: Option<Balance>,
minimal_validator_bond: Option<Balance>,
max_nominators_count: Option<u32>,
max_validators_count: Option<u32>,
status: TxStatus,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<C: ConnectionApi + AsConnection> StakingApi for C {
self.get_storage_entry(&addrs, at).await
}

async fn get_payout_for_era(&self, era: EraIndex, at: Option<BlockHash>) -> u128 {
async fn get_payout_for_era(&self, era: EraIndex, at: Option<BlockHash>) -> Balance {
let addrs = api::storage().staking().eras_validator_reward(era);

self.get_storage_entry(&addrs, at).await
Expand All @@ -278,7 +278,7 @@ impl<C: ConnectionApi + AsConnection> StakingApi for C {
era: EraIndex,
account_id: &AccountId,
at: Option<BlockHash>,
) -> Exposure<AccountId, u128> {
) -> Exposure<AccountId, Balance> {
let addrs = api::storage().staking().eras_stakers(era, account_id);

self.get_storage_entry(&addrs, at).await
Expand Down Expand Up @@ -392,8 +392,8 @@ impl StakingSudoApi for RootConnection {

async fn set_staking_config(
&self,
min_nominator_bond: Option<u128>,
min_validator_bond: Option<u128>,
min_nominator_bond: Option<Balance>,
min_validator_bond: Option<Balance>,
max_nominator_count: Option<u32>,
max_validator_count: Option<u32>,
status: TxStatus,
Expand Down
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/system.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use primitives::Balance;
use subxt::ext::sp_runtime::Perbill as SPerbill;

use crate::{
api,
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,
};
Expand Down
13 changes: 7 additions & 6 deletions aleph-client/src/pallets/vesting.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,7 +16,7 @@ pub trait VestingApi {
&self,
who: AccountId,
at: Option<BlockHash>,
) -> Vec<VestingInfo<u128, u32>>;
) -> Vec<VestingInfo<Balance, BlockNumber>>;
}

/// Pallet vesting api.
Expand All @@ -31,7 +32,7 @@ pub trait VestingUserApi {
async fn vested_transfer(
&self,
receiver: AccountId,
schedule: VestingInfo<u128, u32>,
schedule: VestingInfo<Balance, BlockNumber>,
status: TxStatus,
) -> anyhow::Result<TxInfo>;

Expand All @@ -50,7 +51,7 @@ impl<C: ConnectionApi> VestingApi for C {
&self,
who: AccountId,
at: Option<BlockHash>,
) -> Vec<VestingInfo<u128, u32>> {
) -> Vec<VestingInfo<Balance, BlockNumber>> {
let addrs = api::storage().vesting().vesting(who);

self.get_storage_entry(&addrs, at).await.0
Expand All @@ -74,7 +75,7 @@ impl<S: SignedConnectionApi> VestingUserApi for S {
async fn vested_transfer(
&self,
receiver: AccountId,
schedule: VestingInfo<u128, u32>,
schedule: VestingInfo<Balance, BlockNumber>,
status: TxStatus,
) -> anyhow::Result<TxInfo> {
let tx = api::tx()
Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions benches/payout-stakers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -235,7 +235,7 @@ async fn nominate_validator(
.chunks(BOND_CALL_BATCH_LIMIT)
.map(|c| c.to_vec())
{
let stake = (rng.gen::<u128>() % 100) * TOKEN + MIN_NOMINATOR_BOND;
let stake = (rng.gen::<Balance>() % 100) * TOKEN + MIN_NOMINATOR_BOND;
connection
.batch_bond(&chunk, stake, TxStatus::Submitted)
.await
Expand Down
2 changes: 1 addition & 1 deletion bin/cliain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions bin/cliain/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ 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;

#[derive(Debug, Clone, Args)]
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<u128>,
pub storage_deposit_limit: Option<Balance>,
}

#[derive(Debug, Clone, Args)]
Expand All @@ -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<u128>,
pub storage_deposit_limit: Option<Balance>,
}

#[derive(Debug, Clone, Args)]
Expand Down
4 changes: 2 additions & 2 deletions bin/cliain/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,7 @@ pub struct InstantiateWithCodeReturnValue {
pub code_hash: H256,
}

fn storage_deposit(storage_deposit_limit: Option<u128>) -> Option<Compact<u128>> {
fn storage_deposit(storage_deposit_limit: Option<Balance>) -> Option<Compact<u128>> {
storage_deposit_limit.map(Compact)
}

Expand Down
Loading

0 comments on commit 13254e1

Please sign in to comment.