Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into A0-1608-Add-documentation-to-aleph-client
  • Loading branch information
Marcin-Radecki committed Jan 2, 2023
commit cc8cb3950482f03b0e39fd07f0af77248acd72c2
3 changes: 2 additions & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "aleph_client"
version = "2.5.0"
# TODO bump major version when API stablize
version = "2.6.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
3 changes: 3 additions & 0 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//! [Substrate](https://github.com/paritytech/substrate) chain, but there are some unique to `aleph-node`,
//! e.g. [`pallets::elections::ElectionsApi`].
//!

#![feature(auto_traits)]
#![feature(negative_impls)]
extern crate core;

pub use contract_transcode;
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/src/pallets/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{aleph_runtime::SessionKeys, Connection};
#[async_trait::async_trait]
pub trait AuthorRpc {
/// API for [`rotate_keys`](https://paritytech.github.io/substrate/master/sc_rpc/author/struct.Author.html#method.rotate_keys) call
async fn author_rotate_keys(&self) -> SessionKeys;
async fn author_rotate_keys(&self) -> anyhow::Result<SessionKeys>;
}

#[async_trait::async_trait]
Expand Down
7 changes: 5 additions & 2 deletions aleph-client/src/pallets/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct ContractCallArgs {
/// The balance to transfer from the `origin` to `dest`.
pub value: Balance,
/// The gas limit enforced when executing the constructor.
pub gas_limit: Weight,
pub gas_limit: Option<Weight>,
/// The maximum amount of balance that can be charged from the caller to pay for the storage consumed.
pub storage_deposit_limit: Option<Balance>,
/// The input data to pass to the contract.
Expand Down Expand Up @@ -98,7 +98,10 @@ pub trait ContractsUserApi {
#[async_trait::async_trait]
pub trait ContractRpc {
/// API for [`call`](https://paritytech.github.io/substrate/master/pallet_contracts/trait.ContractsApi.html#method.call) call.
async fn call_and_get<T: Decode>(&self, args: ContractCallArgs) -> anyhow::Result<T>;
async fn call_and_get(
&self,
args: ContractCallArgs,
) -> anyhow::Result<ContractExecResult<Balance>>;
}

#[async_trait::async_trait]
Expand Down
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ pub trait ElectionsApi {
validator: AccountId,
at: Option<BlockHash>,
) -> Option<BanInfo>;

/// Returns `elections.session_period` const of the elections pallet.
async fn get_session_period(&self) -> u32;
async fn get_session_period(&self) -> anyhow::Result<u32>;
}

/// any object that implements pallet elections api that requires sudo
Expand Down
5 changes: 2 additions & 3 deletions aleph-client/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ pub trait StakingApi {
/// Returns [`minimum_validator_count`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.minimum_validator_count).
/// * `at` - optional hash of a block to query state from
async fn get_minimum_validator_count(&self, at: Option<BlockHash>) -> u32;

/// Returns [`SessionsPerEra`](https://paritytech.github.io/substrate/master/pallet_staking/trait.Config.html#associatedtype.SessionsPerEra) const.
async fn get_session_per_era(&self) -> u32;
async fn get_session_per_era(&self) -> anyhow::Result<u32>;
}

/// Any object that implements pallet staking api
Expand Down Expand Up @@ -226,7 +225,7 @@ pub trait StakingRawApi {
&self,
era: EraIndex,
at: Option<BlockHash>,
) -> Vec<StorageKey>;
) -> anyhow::Result<Vec<StorageKey>>;

/// Returns encoded [`eras_stakers`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.eras_stakers).
/// storage keys for a given era and given account ids
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/src/pallets/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait TreasuryUserApi {
pub trait TreasureApiExt {
/// When `staking.payout_stakers` is done, what amount of AZERO is transferred to.
/// the treasury
async fn possible_treasury_payout(&self) -> Balance;
async fn possible_treasury_payout(&self) -> anyhow::Result<Balance>;
}

/// Any object that implements pallet treasury api issued by the sudo account.
Expand Down
29 changes: 23 additions & 6 deletions aleph-client/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,46 @@ use crate::{
pub trait BlocksApi {
/// Returns the first block of a session.
/// * `session` - number of the session to query the first block from
async fn first_block_of_session(&self, session: SessionIndex) -> Option<BlockHash>;
async fn first_block_of_session(
&self,
session: SessionIndex,
) -> anyhow::Result<Option<BlockHash>>;

/// Returns hash of a given block.
/// * `block` - number of the block
async fn get_block_hash(&self, block: BlockNumber) -> Option<BlockHash>;
async fn get_block_hash(&self, block: BlockNumber) -> anyhow::Result<Option<BlockHash>>;

/// Returns the most recent block from the current best chain.
async fn get_best_block(&self) -> BlockNumber;
async fn get_best_block(&self) -> anyhow::Result<Option<BlockNumber>>;

/// Returns the most recent block from the finalized chain.
async fn get_finalized_block_hash(&self) -> BlockHash;
async fn get_finalized_block_hash(&self) -> anyhow::Result<BlockHash>;

/// Returns number of a given block hash.
/// * `block` - hash of the block to query its number
async fn get_block_number(&self, block: BlockHash) -> Option<BlockNumber>;
async fn get_block_number(&self, block: BlockHash) -> anyhow::Result<Option<BlockNumber>>;
}

/// Any object that implements interaction logic between session and staking.
#[async_trait::async_trait]
pub trait SessionEraApi {
/// Returns which era given session is.
/// * `session` - session index
async fn get_active_era_for_session(&self, session: SessionIndex) -> EraIndex;
async fn get_active_era_for_session(&self, session: SessionIndex) -> anyhow::Result<EraIndex>;
}

impl Connection {
async fn get_block_number_inner(
&self,
block: Option<BlockHash>,
) -> anyhow::Result<Option<BlockNumber>> {
self.client
.rpc()
.header(block)
.await
.map(|maybe_header| maybe_header.map(|header| header.number))
.map_err(|e| e.into())
}
}

#[async_trait::async_trait]
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.