From 3bd78cc176c0259d65e90e0da76dd92bded4e5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:29:01 +0100 Subject: [PATCH 01/14] Change connection API --- aleph-client/src/connections.rs | 67 ++++++++++++++++++++++----------- aleph-client/src/lib.rs | 4 +- e2e-tests/Cargo.lock | 2 +- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index b21c1b54f8..388d51d1b7 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -3,7 +3,9 @@ use std::{thread::sleep, time::Duration}; use anyhow::anyhow; use codec::Decode; use log::info; +use serde::{Deserialize, Serialize}; use subxt::{ + blocks::ExtrinsicEvents, ext::sp_core::Bytes, metadata::DecodeWithMetadata, rpc::RpcParams, @@ -13,7 +15,8 @@ use subxt::{ }; use crate::{ - api, sp_weights::weight_v2::Weight, AccountId, BlockHash, Call, KeyPair, SubxtClient, TxStatus, + api, sp_weights::weight_v2::Weight, AccountId, AlephConfig, BlockHash, Call, KeyPair, + SubxtClient, TxHash, TxStatus, }; /// Capable of communicating with a live Aleph chain. @@ -105,6 +108,21 @@ pub trait ConnectionApi: Sync { async fn rpc_call(&self, func_name: String, params: RpcParams) -> anyhow::Result; } +#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct TxCoords { + pub block_hash: BlockHash, + pub tx_hash: TxHash, +} + +impl From> for TxCoords { + fn from(ee: ExtrinsicEvents) -> Self { + Self { + block_hash: ee.extrinsic_hash(), + tx_hash: ee.block_hash(), + } + } +} + /// Signed connection should be able to sends transactions to chain #[async_trait::async_trait] pub trait SignedConnectionApi: ConnectionApi { @@ -112,32 +130,32 @@ pub trait SignedConnectionApi: ConnectionApi { /// * `tx` - encoded transaction payload /// * `status` - a [`TxStatus`] for a tx to wait for /// # Returns - /// Block hash of block where transaction was put or error + /// Block hash of block where transaction was put together with transaction hash, or error. /// # Examples /// ```ignore - /// let tx = api::tx() - /// .balances() - /// .transfer(MultiAddress::Id(dest), amount); - /// send_tx(tx, status).await + /// let tx = api::tx() + /// .balances() + /// .transfer(MultiAddress::Id(dest), amount); + /// send_tx(tx, status).await /// ``` async fn send_tx( &self, tx: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Send a transaction to a chain. It waits for a given tx `status`. /// * `tx` - encoded transaction payload /// * `params` - optional tx params e.g. tip /// * `status` - a [`TxStatus`] of a tx to wait for /// # Returns - /// Block hash of block where transaction was put or error + /// Block hash of block where transaction was put together with transaction hash, or error. async fn send_tx_with_params( &self, tx: Call, params: BaseExtrinsicParamsBuilder, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Returns account id which signs this connection fn account_id(&self) -> &AccountId; @@ -153,14 +171,14 @@ pub trait SignedConnectionApi: ConnectionApi { #[async_trait::async_trait] pub trait SudoCall { /// API for [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo_unchecked_weight) call. - async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result; + async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result; /// API for [`sudo`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo) call. - async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result; + async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] impl SudoCall for RootConnection { - async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result { + async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result { info!(target: "aleph-client", "sending call as sudo_unchecked {:?}", call); let sudo = api::tx().sudo().sudo_unchecked_weight( call, @@ -173,7 +191,7 @@ impl SudoCall for RootConnection { self.as_signed().send_tx(sudo, status).await } - async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result { + async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result { info!(target: "aleph-client", "sending call as sudo {:?}", call); let sudo = api::tx().sudo().sudo(call); @@ -263,7 +281,7 @@ impl SignedConnectionApi for S { &self, tx: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { self.send_tx_with_params(tx, Default::default(), status) .await } @@ -273,7 +291,7 @@ impl SignedConnectionApi for S { tx: Call, params: BaseExtrinsicParamsBuilder, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { if let Some(details) = tx.validation_details() { info!(target:"aleph-client", "Sending extrinsic {}.{} with params: {:?}", details.pallet_name, details.call_name, params); } @@ -286,15 +304,20 @@ impl SignedConnectionApi for S { .await .map_err(|e| anyhow!("Failed to submit transaction: {:?}", e))?; - // In case of Submitted hash does not mean anything - let hash = match status { - TxStatus::InBlock => progress.wait_for_in_block().await?.block_hash(), - TxStatus::Finalized => progress.wait_for_finalized_success().await?.block_hash(), - TxStatus::Submitted => return Ok(BlockHash::from_low_u64_be(0)), + let coords: TxCoords = match status { + TxStatus::InBlock => progress + .wait_for_in_block() + .await? + .wait_for_success() + .await? + .into(), + TxStatus::Finalized => progress.wait_for_finalized_success().await?.into(), + // In case of Submitted coords do not mean anything + TxStatus::Submitted => return Ok(Default::default()), }; - info!(target: "aleph-client", "tx included in block {:?}", hash); + info!(target: "aleph-client", "tx with hash {} included in block {}", coords.tx_hash, coords.block_hash); - Ok(hash) + Ok(coords) } fn account_id(&self) -> &AccountId { diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index 74d232850f..a7c89cd778 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -49,8 +49,10 @@ pub type KeyPair = PairSigner; pub type AccountId = subxt::ext::sp_core::crypto::AccountId32; /// An alias for a client type. pub type Client = OnlineClient; -/// An alias for a hash type. +/// An alias for a block hash type. pub type BlockHash = H256; +/// An alias for a transaction hash type. +pub type TxHash = H256; /// An alias for an RPC client type. pub type SubxtClient = OnlineClient; diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 69fa1e40ed..9ee234048f 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.6.0" +version = "2.7.0" dependencies = [ "anyhow", "async-trait", From f0775a820c44f0c624a3299289bf1e755534f78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:43:40 +0100 Subject: [PATCH 02/14] Aleph client migrated --- aleph-client/src/pallets/aleph.rs | 9 ++-- aleph-client/src/pallets/balances.rs | 13 +++--- aleph-client/src/pallets/contract.rs | 29 ++++++------ aleph-client/src/pallets/elections.rs | 18 ++++---- aleph-client/src/pallets/multisig.rs | 64 +++++++++++++-------------- aleph-client/src/pallets/session.rs | 8 ++-- aleph-client/src/pallets/staking.rs | 42 +++++++++--------- aleph-client/src/pallets/system.rs | 9 ++-- aleph-client/src/pallets/treasury.rs | 22 ++++----- aleph-client/src/pallets/utility.rs | 6 +-- aleph-client/src/pallets/vesting.rs | 20 ++++----- 11 files changed, 120 insertions(+), 120 deletions(-) diff --git a/aleph-client/src/pallets/aleph.rs b/aleph-client/src/pallets/aleph.rs index 5e06267322..780d783ebe 100644 --- a/aleph-client/src/pallets/aleph.rs +++ b/aleph-client/src/pallets/aleph.rs @@ -7,6 +7,7 @@ use crate::{ pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public, sp_core::ed25519::Public as EdPublic, }, + connections::TxCoords, pallet_aleph::pallet::Call::schedule_finality_version_change, AccountId, AlephKeyPair, BlockHash, Call::Aleph, @@ -26,7 +27,7 @@ pub trait AlephSudoApi { &self, finalizer: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Schedules a finality version change for a future session. /// * `version` - next version of the finalizer @@ -39,7 +40,7 @@ pub trait AlephSudoApi { version: u32, session: SessionIndex, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet aleph RPC api. @@ -62,7 +63,7 @@ impl AlephSudoApi for RootConnection { &self, finalizer: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Aleph(set_emergency_finalizer { emergency_finalizer: Public(EdPublic(finalizer.into())), }); @@ -74,7 +75,7 @@ impl AlephSudoApi for RootConnection { version: u32, session: SessionIndex, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Aleph(schedule_finality_version_change { version_incoming: version, session, diff --git a/aleph-client/src/pallets/balances.rs b/aleph-client/src/pallets/balances.rs index b4e4be0aae..c0231cdaa5 100644 --- a/aleph-client/src/pallets/balances.rs +++ b/aleph-client/src/pallets/balances.rs @@ -3,6 +3,7 @@ use subxt::{ext::sp_runtime::MultiAddress, tx::PolkadotExtrinsicParamsBuilder}; use crate::{ aleph_zero::{self, api, api::runtime_types::pallet_balances::BalanceLock}, + connections::TxCoords, pallet_balances::pallet::Call::transfer, pallets::utility::UtilityApi, AccountId, BlockHash, @@ -44,7 +45,7 @@ pub trait BalanceUserApi { dest: AccountId, amount: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`transfer`](https://paritytech.github.io/substrate/master/pallet_balances/pallet/struct.Pallet.html#method.transfer) call. /// Include tip in the tx. @@ -54,7 +55,7 @@ pub trait BalanceUserApi { amount: Balance, tip: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet balances logic not directly related to any pallet call. @@ -79,7 +80,7 @@ pub trait BalanceUserBatchExtApi { dest: &[AccountId], amount: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -122,7 +123,7 @@ impl BalanceUserApi for S { dest: AccountId, amount: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .balances() .transfer(MultiAddress::Id(dest), amount); @@ -135,7 +136,7 @@ impl BalanceUserApi for S { amount: Balance, tip: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .balances() .transfer(MultiAddress::Id(dest), amount); @@ -152,7 +153,7 @@ impl BalanceUserBatchExtApi for S { dests: &[AccountId], amount: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = dests .iter() .map(|dest| { diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index eeebce4a3e..3bda930929 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -4,8 +4,8 @@ use primitives::Balance; use subxt::{ext::sp_core::Bytes, rpc_params}; use crate::{ - api, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, AccountId, BlockHash, - ConnectionApi, SignedConnectionApi, TxStatus, + api, connections::TxCoords, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, + AccountId, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Arguments to [`ContractRpc::call_and_get`]. @@ -47,7 +47,7 @@ pub trait ContractsUserApi { code: Vec, storage_limit: Option>, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`instantiate`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.instantiate) call. #[allow(clippy::too_many_arguments)] @@ -60,7 +60,7 @@ pub trait ContractsUserApi { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`instantiate_with_code`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.instantiate_with_code) call. #[allow(clippy::too_many_arguments)] @@ -73,7 +73,7 @@ pub trait ContractsUserApi { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`call`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.call) call. async fn call( @@ -84,14 +84,11 @@ pub trait ContractsUserApi { storage_limit: Option>, data: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`remove_code`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.remove_code) call. - async fn remove_code( - &self, - code_hash: BlockHash, - status: TxStatus, - ) -> anyhow::Result; + async fn remove_code(&self, code_hash: BlockHash, status: TxStatus) + -> anyhow::Result; } /// RPC for runtime ContractsApi @@ -124,7 +121,7 @@ impl ContractsUserApi for S { code: Vec, storage_limit: Option>, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().upload_code(code, storage_limit); self.send_tx(tx, status).await @@ -139,7 +136,7 @@ impl ContractsUserApi for S { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().instantiate( balance, gas_limit, @@ -161,7 +158,7 @@ impl ContractsUserApi for S { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().instantiate_with_code( balance, gas_limit, @@ -182,7 +179,7 @@ impl ContractsUserApi for S { storage_limit: Option>, data: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .contracts() @@ -194,7 +191,7 @@ impl ContractsUserApi for S { &self, code_hash: BlockHash, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().remove_code(code_hash); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/elections.rs b/aleph-client/src/pallets/elections.rs index 4ed650412a..6f387c9a5d 100644 --- a/aleph-client/src/pallets/elections.rs +++ b/aleph-client/src/pallets/elections.rs @@ -6,7 +6,7 @@ use crate::{ pallet_elections::pallet::Call::set_ban_config, primitives::{BanReason, CommitteeSeats, EraValidators}, }, - connections::AsConnection, + connections::{AsConnection, TxCoords}, pallet_elections::pallet::Call::{ ban_from_committee, change_validators, set_elections_openness, }, @@ -99,7 +99,7 @@ pub trait ElectionsSudoApi { clean_session_counter_delay: Option, ban_period: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Issues `elections.change_validators` that sets the committee for the next era. /// * `new_reserved_validators` - reserved validators to be in place in the next era; optional @@ -112,7 +112,7 @@ pub trait ElectionsSudoApi { new_non_reserved_validators: Option>, committee_size: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Schedule a non-reserved node to be banned out from the committee at the end of the era. /// * `account` - account to be banned, @@ -123,7 +123,7 @@ pub trait ElectionsSudoApi { account: AccountId, ban_reason: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Set openness of the elections. /// * `mode` - new elections openness mode @@ -132,7 +132,7 @@ pub trait ElectionsSudoApi { &self, mode: ElectionOpenness, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -241,7 +241,7 @@ impl ElectionsSudoApi for RootConnection { clean_session_counter_delay: Option, ban_period: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(set_ban_config { minimal_expected_performance, underperformed_session_count_threshold, @@ -258,7 +258,7 @@ impl ElectionsSudoApi for RootConnection { new_non_reserved_validators: Option>, committee_size: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(change_validators { reserved_validators: new_reserved_validators, non_reserved_validators: new_non_reserved_validators, @@ -273,7 +273,7 @@ impl ElectionsSudoApi for RootConnection { account: AccountId, ban_reason: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(ban_from_committee { banned: account, ban_reason, @@ -285,7 +285,7 @@ impl ElectionsSudoApi for RootConnection { &self, mode: ElectionOpenness, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(set_elections_openness { openness: mode }); self.sudo_unchecked(call, status).await diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 7fce899459..0ee3c9df80 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -8,8 +8,8 @@ use sp_runtime::traits::TrailingZeroInput; use crate::{ account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, - sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, - TxStatus, + connections::TxCoords, sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, + SignedConnectionApi, TxStatus, }; /// An alias for a call hash. @@ -42,7 +42,7 @@ pub trait MultisigUserApi { other_signatories: Vec, call: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.as_multi) call. async fn as_multi( &self, @@ -52,7 +52,7 @@ pub trait MultisigUserApi { max_weight: Weight, call: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`approve_as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.approve_as_multi) call. async fn approve_as_multi( &self, @@ -62,7 +62,7 @@ pub trait MultisigUserApi { max_weight: Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`cancel_as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.cancel_as_multi) call. async fn cancel_as_multi( &self, @@ -71,7 +71,7 @@ pub trait MultisigUserApi { timepoint: Timepoint, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -81,7 +81,7 @@ impl MultisigUserApi for S { other_signatories: Vec, call: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .multisig() .as_multi_threshold_1(other_signatories, call); @@ -97,7 +97,7 @@ impl MultisigUserApi for S { max_weight: Weight, call: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().as_multi( threshold, other_signatories, @@ -117,7 +117,7 @@ impl MultisigUserApi for S { max_weight: Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().approve_as_multi( threshold, other_signatories, @@ -136,7 +136,7 @@ impl MultisigUserApi for S { timepoint: Timepoint, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().cancel_as_multi( threshold, other_signatories, @@ -385,7 +385,7 @@ impl Context { #[async_trait::async_trait] pub trait MultisigContextualApi { /// Start signature aggregation for `party` and `call_hash`. Get `Context` object as a result - /// (together with standard block hash). + /// (together with standard tx coordinates). /// /// This is the recommended way of initialization. async fn initiate( @@ -394,9 +394,9 @@ pub trait MultisigContextualApi { max_weight: &Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)>; + ) -> anyhow::Result<(TxCoords, Context)>; /// Start signature aggregation for `party` and `call`. Get `Context` object as a result - /// (together with standard block hash). + /// (together with standard tx coordinates). /// /// Note: it is usually a better idea to pass `call` only with the final approval (so that it /// isn't stored on-chain). @@ -406,7 +406,7 @@ pub trait MultisigContextualApi { max_weight: &Weight, call: Call, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)>; + ) -> anyhow::Result<(TxCoords, Context)>; /// Express contextual approval for the call hash. /// /// This is the recommended way for every intermediate approval. @@ -414,7 +414,7 @@ pub trait MultisigContextualApi { &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(BlockHash, ContextAfterUse)>; + ) -> anyhow::Result<(TxCoords, ContextAfterUse)>; /// Express contextual approval for the `call`. /// /// This is the recommended way only for the final approval. @@ -423,13 +423,13 @@ pub trait MultisigContextualApi { context: Context, call: Option, status: TxStatus, - ) -> anyhow::Result<(BlockHash, ContextAfterUse)>; + ) -> anyhow::Result<(TxCoords, ContextAfterUse)>; /// Cancel signature aggregation. async fn cancel( &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)>; + ) -> anyhow::Result<(TxCoords, Context)>; } #[async_trait::async_trait] @@ -440,10 +440,10 @@ impl MultisigContextualApi for S { max_weight: &Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)> { + ) -> anyhow::Result<(TxCoords, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; - let block_hash = self + let tx_coords = self .approve_as_multi( party.threshold, other_signatories, @@ -461,11 +461,11 @@ impl MultisigContextualApi for S { // `connections` module. Secondly, if `Timepoint` struct change, this method (reading raw // extrinsic position) might become incorrect. let timepoint = self - .get_timepoint(&party.account(), &call_hash, Some(block_hash)) + .get_timepoint(&party.account(), &call_hash, Some(tx_coords.block_hash)) .await; Ok(( - block_hash, + tx_coords, Context::new( party.clone(), self.account_id().clone(), @@ -483,10 +483,10 @@ impl MultisigContextualApi for S { max_weight: &Weight, call: Call, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)> { + ) -> anyhow::Result<(TxCoords, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; - let block_hash = self + let tx_coords = self .as_multi( party.threshold, other_signatories, @@ -499,11 +499,11 @@ impl MultisigContextualApi for S { let call_hash = compute_call_hash(&call); let timepoint = self - .get_timepoint(&party.account(), &call_hash, Some(block_hash)) + .get_timepoint(&party.account(), &call_hash, Some(tx_coords.block_hash)) .await; Ok(( - block_hash, + tx_coords, Context::new( party.clone(), self.account_id().clone(), @@ -519,7 +519,7 @@ impl MultisigContextualApi for S { &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(BlockHash, ContextAfterUse)> { + ) -> anyhow::Result<(TxCoords, ContextAfterUse)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; self.approve_as_multi( @@ -531,7 +531,7 @@ impl MultisigContextualApi for S { status, ) .await - .map(|block_hash| (block_hash, context.add_approval(self.account_id().clone()))) + .map(|tx_coords| (tx_coords, context.add_approval(self.account_id().clone()))) } async fn approve_with_call( @@ -539,7 +539,7 @@ impl MultisigContextualApi for S { mut context: Context, call: Option, status: TxStatus, - ) -> anyhow::Result<(BlockHash, ContextAfterUse)> { + ) -> anyhow::Result<(TxCoords, ContextAfterUse)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; let call = match (call.as_ref(), context.call.as_ref()) { @@ -569,14 +569,14 @@ impl MultisigContextualApi for S { status, ) .await - .map(|block_hash| (block_hash, context.add_approval(self.account_id().clone()))) + .map(|tx_coords| (tx_coords, context.add_approval(self.account_id().clone()))) } async fn cancel( &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(BlockHash, Context)> { + ) -> anyhow::Result<(TxCoords, Context)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; ensure!( @@ -584,7 +584,7 @@ impl MultisigContextualApi for S { "Only the author can cancel multisig aggregation" ); - let block_hash = self + let tx_coords = self .cancel_as_multi( context.party.threshold, other_signatories, @@ -594,7 +594,7 @@ impl MultisigContextualApi for S { ) .await?; - Ok((block_hash, context.close())) + Ok((tx_coords, context.close())) } } diff --git a/aleph-client/src/pallets/session.rs b/aleph-client/src/pallets/session.rs index 4f2f2351e1..9e41547171 100644 --- a/aleph-client/src/pallets/session.rs +++ b/aleph-client/src/pallets/session.rs @@ -1,8 +1,8 @@ use primitives::SessionIndex; use crate::{ - api, api::runtime_types::aleph_runtime::SessionKeys, AccountId, BlockHash, ConnectionApi, - SignedConnectionApi, TxStatus, + api, api::runtime_types::aleph_runtime::SessionKeys, connections::TxCoords, AccountId, + BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Pallet session read-only api. @@ -26,7 +26,7 @@ pub trait SessionApi { #[async_trait::async_trait] pub trait SessionUserApi { /// API for [`set_keys`](https://paritytech.github.io/substrate/master/pallet_session/pallet/struct.Pallet.html#method.set_keys) call. - async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result; + async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] @@ -58,7 +58,7 @@ impl SessionApi for C { #[async_trait::async_trait] impl SessionUserApi for S { - async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result { + async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result { let tx = api::tx().session().set_keys(new_keys, vec![]); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index 6008a19636..f40cb49014 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -9,7 +9,7 @@ use subxt::{ use crate::{ api, - connections::AsConnection, + connections::{AsConnection, TxCoords}, pallet_staking::{ pallet::pallet::{ Call::{bond, force_new_era, nominate, set_staking_configs}, @@ -88,14 +88,14 @@ pub trait StakingUserApi { initial_stake: Balance, controller_id: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`validate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.validate) call. async fn validate( &self, validator_commission_percentage: u8, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`payout_stakers`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.payout_stakers) call. async fn payout_stakers( @@ -103,24 +103,24 @@ pub trait StakingUserApi { stash_account: AccountId, era: EraIndex, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`nominate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.nominate) call. async fn nominate( &self, nominee_account_id: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`chill`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.chill) call. - async fn chill(&self, status: TxStatus) -> anyhow::Result; + async fn chill(&self, status: TxStatus) -> anyhow::Result; /// API for [`bond_extra`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.bond_extra) call. async fn bond_extra_stake( &self, extra_stake: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet staking logic, not directly related to any particular pallet call. @@ -174,7 +174,7 @@ pub trait StakingApiExt { accounts: &[(AccountId, AccountId)], stake: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Send batch of [`nominate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.nominate) calls. /// * `nominator_nominee_pairs` - a slice of account ids pairs (nominator, nominee) @@ -186,14 +186,14 @@ pub trait StakingApiExt { &self, nominator_nominee_pairs: &[(AccountId, AccountId)], status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet staking api that requires sudo. #[async_trait::async_trait] pub trait StakingSudoApi { /// API for [`force_new_era`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.force_new_era) call. - async fn force_new_era(&self, status: TxStatus) -> anyhow::Result; + async fn force_new_era(&self, status: TxStatus) -> anyhow::Result; /// 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( @@ -203,7 +203,7 @@ pub trait StakingSudoApi { max_nominators_count: Option, max_validators_count: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Logic for retrieving raw storage keys or values from a pallet staking. @@ -317,7 +317,7 @@ impl StakingUserApi for S { initial_stake: Balance, controller_id: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().bond( MultiAddress::::Id(controller_id), initial_stake, @@ -331,7 +331,7 @@ impl StakingUserApi for S { &self, validator_commission_percentage: u8, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().validate(ValidatorPrefs { commission: Perbill( SPerbill::from_percent(validator_commission_percentage as u32).deconstruct(), @@ -347,7 +347,7 @@ impl StakingUserApi for S { stash_account: AccountId, era: EraIndex, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().payout_stakers(stash_account, era); self.send_tx(tx, status).await @@ -357,7 +357,7 @@ impl StakingUserApi for S { &self, nominee_account_id: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .staking() .nominate(vec![MultiAddress::Id(nominee_account_id)]); @@ -365,7 +365,7 @@ impl StakingUserApi for S { self.send_tx(tx, status).await } - async fn chill(&self, status: TxStatus) -> anyhow::Result { + async fn chill(&self, status: TxStatus) -> anyhow::Result { let tx = api::tx().staking().chill(); self.send_tx(tx, status).await @@ -375,7 +375,7 @@ impl StakingUserApi for S { &self, extra_stake: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().bond_extra(extra_stake); self.send_tx(tx, status).await @@ -384,7 +384,7 @@ impl StakingUserApi for S { #[async_trait::async_trait] impl StakingSudoApi for RootConnection { - async fn force_new_era(&self, status: TxStatus) -> anyhow::Result { + async fn force_new_era(&self, status: TxStatus) -> anyhow::Result { let call = Staking(force_new_era); self.sudo_unchecked(call, status).await @@ -397,7 +397,7 @@ impl StakingSudoApi for RootConnection { max_nominator_count: Option, max_validator_count: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { fn convert(arg: Option) -> ConfigOp { match arg { Some(v) => Set(v), @@ -462,7 +462,7 @@ impl StakingApiExt for RootConnection { accounts: &[(AccountId, AccountId)], stake: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = accounts .iter() .map(|(s, c)| { @@ -486,7 +486,7 @@ impl StakingApiExt for RootConnection { &self, nominator_nominee_pairs: &[(AccountId, AccountId)], status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = nominator_nominee_pairs .iter() .map(|(nominator, nominee)| { diff --git a/aleph-client/src/pallets/system.rs b/aleph-client/src/pallets/system.rs index 10a9e792f8..be79abfe47 100644 --- a/aleph-client/src/pallets/system.rs +++ b/aleph-client/src/pallets/system.rs @@ -3,6 +3,7 @@ use subxt::ext::sp_runtime::Perbill as SPerbill; use crate::{ api, + connections::TxCoords, frame_system::pallet::Call::{fill_block, set_code}, sp_arithmetic::per_things::Perbill, AccountId, BlockHash, @@ -25,7 +26,7 @@ pub trait SystemApi { #[async_trait::async_trait] pub trait SystemSudoApi { /// API for [`set_code`](https://paritytech.github.io/substrate/master/frame_system/pallet/struct.Pallet.html#method.set_code) call. - async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result; + async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result; /// A dispatch that will fill the block weight up to the given ratio. /// * `target_ratio_percent` - ratio to fill block @@ -34,12 +35,12 @@ pub trait SystemSudoApi { &self, target_ratio_percent: u8, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] impl SystemSudoApi for RootConnection { - async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result { + async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result { let call = System(set_code { code }); self.sudo_unchecked(call, status).await @@ -49,7 +50,7 @@ impl SystemSudoApi for RootConnection { &self, target_ratio_percent: u8, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = System(fill_block { ratio: Perbill(SPerbill::from_percent(target_ratio_percent as u32).deconstruct()), }); diff --git a/aleph-client/src/pallets/treasury.rs b/aleph-client/src/pallets/treasury.rs index ef4b4c4251..66f31c4379 100644 --- a/aleph-client/src/pallets/treasury.rs +++ b/aleph-client/src/pallets/treasury.rs @@ -5,7 +5,7 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ api, - connections::AsConnection, + connections::{AsConnection, TxCoords}, pallet_treasury::pallet::Call::{approve_proposal, reject_proposal}, pallets::{elections::ElectionsApi, staking::StakingApi}, AccountId, BlockHash, @@ -37,13 +37,13 @@ pub trait TreasuryUserApi { amount: Balance, beneficiary: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`approve_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.approve_proposal) call. - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; /// API for [`reject_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.reject_proposal) call. - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; } /// Pallet treasury funcionality that is not directly related to any pallet call. @@ -59,11 +59,11 @@ pub trait TreasureApiExt { pub trait TreasurySudoApi { /// API for [`approve_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.approve_proposal) call. /// wrapped in [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/struct.Pallet.html#method.sudo_unchecked_weight) - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; /// API for [`reject_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.reject_proposal) call. /// wrapped [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/struct.Pallet.html#method.sudo_unchecked_weight) - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] @@ -92,7 +92,7 @@ impl TreasuryUserApi for S { amount: Balance, beneficiary: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .treasury() .propose_spend(amount, MultiAddress::Id(beneficiary)); @@ -100,13 +100,13 @@ impl TreasuryUserApi for S { self.send_tx(tx, status).await } - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let tx = api::tx().treasury().approve_proposal(proposal_id); self.send_tx(tx, status).await } - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let tx = api::tx().treasury().reject_proposal(proposal_id); self.send_tx(tx, status).await @@ -115,13 +115,13 @@ impl TreasuryUserApi for S { #[async_trait::async_trait] impl TreasurySudoApi for RootConnection { - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let call = Treasury(approve_proposal { proposal_id }); self.sudo_unchecked(call, status).await } - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let call = Treasury(reject_proposal { proposal_id }); self.sudo_unchecked(call, status).await diff --git a/aleph-client/src/pallets/utility.rs b/aleph-client/src/pallets/utility.rs index 974ca4bedd..1a9b7123c3 100644 --- a/aleph-client/src/pallets/utility.rs +++ b/aleph-client/src/pallets/utility.rs @@ -1,15 +1,15 @@ -use crate::{api, BlockHash, Call, SignedConnectionApi, TxStatus}; +use crate::{api, connections::TxCoords, Call, SignedConnectionApi, TxStatus}; /// Pallet utility api. #[async_trait::async_trait] pub trait UtilityApi { /// API for [`batch`](https://paritytech.github.io/substrate/master/pallet_utility/pallet/struct.Pallet.html#method.batch) call. - async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result; + async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] impl UtilityApi for S { - async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result { + async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result { let tx = api::tx().utility().batch(calls); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/vesting.rs b/aleph-client/src/pallets/vesting.rs index 287ce17164..948ec4ddef 100644 --- a/aleph-client/src/pallets/vesting.rs +++ b/aleph-client/src/pallets/vesting.rs @@ -1,8 +1,8 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ - api, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, ConnectionApi, - SignedConnectionApi, TxStatus, + api, connections::TxCoords, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, + ConnectionApi, SignedConnectionApi, TxStatus, }; /// Read only pallet vesting API. @@ -22,10 +22,10 @@ pub trait VestingApi { #[async_trait::async_trait] pub trait VestingUserApi { /// API for [`vest`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vest) call. - async fn vest(&self, status: TxStatus) -> anyhow::Result; + async fn vest(&self, status: TxStatus) -> anyhow::Result; /// API for [`vest_other`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vest_other) call. - async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result; + async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result; /// API for [`vested_transfer`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vested_transfer) call. async fn vested_transfer( @@ -33,7 +33,7 @@ pub trait VestingUserApi { receiver: AccountId, schedule: VestingInfo, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`merge_schedules`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.merge_schedules) call. async fn merge_schedules( @@ -41,7 +41,7 @@ pub trait VestingUserApi { idx1: u32, idx2: u32, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -59,13 +59,13 @@ impl VestingApi for C { #[async_trait::async_trait] impl VestingUserApi for S { - async fn vest(&self, status: TxStatus) -> anyhow::Result { + async fn vest(&self, status: TxStatus) -> anyhow::Result { let tx = api::tx().vesting().vest(); self.send_tx(tx, status).await } - async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result { + async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result { let tx = api::tx().vesting().vest_other(MultiAddress::Id(other)); self.send_tx(tx, status).await @@ -76,7 +76,7 @@ impl VestingUserApi for S { receiver: AccountId, schedule: VestingInfo, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .vesting() .vested_transfer(MultiAddress::Id(receiver), schedule); @@ -89,7 +89,7 @@ impl VestingUserApi for S { idx1: u32, idx2: u32, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().vesting().merge_schedules(idx1, idx2); self.send_tx(tx, status).await From 823f144d3d5f6788220be8b6607d6def7d8bbc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:44:27 +0100 Subject: [PATCH 03/14] Incorrect bump, but bumping anyway --- aleph-client/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aleph-client/Cargo.toml b/aleph-client/Cargo.toml index 95961566c2..41268b2787 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.7.0" +version = "2.8.0" edition = "2021" license = "Apache 2.0" From 1ef3b7021f1554dc25e37102ad2962594281312c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:47:06 +0100 Subject: [PATCH 04/14] Rename to `TxInfo` --- aleph-client/Cargo.lock | 2 +- aleph-client/src/connections.rs | 23 ++++++++------- aleph-client/src/pallets/aleph.rs | 10 +++---- aleph-client/src/pallets/balances.rs | 14 ++++----- aleph-client/src/pallets/contract.rs | 27 +++++++---------- aleph-client/src/pallets/elections.rs | 18 ++++++------ aleph-client/src/pallets/multisig.rs | 42 +++++++++++++-------------- aleph-client/src/pallets/session.rs | 8 ++--- aleph-client/src/pallets/staking.rs | 42 +++++++++++++-------------- aleph-client/src/pallets/system.rs | 10 +++---- aleph-client/src/pallets/treasury.rs | 22 +++++++------- aleph-client/src/pallets/utility.rs | 6 ++-- aleph-client/src/pallets/vesting.rs | 18 ++++++------ bin/cliain/Cargo.lock | 2 +- 14 files changed, 120 insertions(+), 124 deletions(-) diff --git a/aleph-client/Cargo.lock b/aleph-client/Cargo.lock index 4ecf994c0a..16f592794f 100644 --- a/aleph-client/Cargo.lock +++ b/aleph-client/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.7.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index 388d51d1b7..d0973f7586 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -108,13 +108,14 @@ pub trait ConnectionApi: Sync { async fn rpc_call(&self, func_name: String, params: RpcParams) -> anyhow::Result; } +/// Data regarding submitted transaction. #[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] -pub struct TxCoords { +pub struct TxInfo { pub block_hash: BlockHash, pub tx_hash: TxHash, } -impl From> for TxCoords { +impl From> for TxInfo { fn from(ee: ExtrinsicEvents) -> Self { Self { block_hash: ee.extrinsic_hash(), @@ -142,7 +143,7 @@ pub trait SignedConnectionApi: ConnectionApi { &self, tx: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Send a transaction to a chain. It waits for a given tx `status`. /// * `tx` - encoded transaction payload @@ -155,7 +156,7 @@ pub trait SignedConnectionApi: ConnectionApi { tx: Call, params: BaseExtrinsicParamsBuilder, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Returns account id which signs this connection fn account_id(&self) -> &AccountId; @@ -171,14 +172,14 @@ pub trait SignedConnectionApi: ConnectionApi { #[async_trait::async_trait] pub trait SudoCall { /// API for [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo_unchecked_weight) call. - async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result; + async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result; /// API for [`sudo`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo) call. - async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result; + async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] impl SudoCall for RootConnection { - async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result { + async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result { info!(target: "aleph-client", "sending call as sudo_unchecked {:?}", call); let sudo = api::tx().sudo().sudo_unchecked_weight( call, @@ -191,7 +192,7 @@ impl SudoCall for RootConnection { self.as_signed().send_tx(sudo, status).await } - async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result { + async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result { info!(target: "aleph-client", "sending call as sudo {:?}", call); let sudo = api::tx().sudo().sudo(call); @@ -281,7 +282,7 @@ impl SignedConnectionApi for S { &self, tx: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { self.send_tx_with_params(tx, Default::default(), status) .await } @@ -291,7 +292,7 @@ impl SignedConnectionApi for S { tx: Call, params: BaseExtrinsicParamsBuilder, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { if let Some(details) = tx.validation_details() { info!(target:"aleph-client", "Sending extrinsic {}.{} with params: {:?}", details.pallet_name, details.call_name, params); } @@ -304,7 +305,7 @@ impl SignedConnectionApi for S { .await .map_err(|e| anyhow!("Failed to submit transaction: {:?}", e))?; - let coords: TxCoords = match status { + let coords: TxInfo = match status { TxStatus::InBlock => progress .wait_for_in_block() .await? diff --git a/aleph-client/src/pallets/aleph.rs b/aleph-client/src/pallets/aleph.rs index 780d783ebe..b68a00f30b 100644 --- a/aleph-client/src/pallets/aleph.rs +++ b/aleph-client/src/pallets/aleph.rs @@ -7,7 +7,7 @@ use crate::{ pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public, sp_core::ed25519::Public as EdPublic, }, - connections::TxCoords, + connections::TxInfo, pallet_aleph::pallet::Call::schedule_finality_version_change, AccountId, AlephKeyPair, BlockHash, Call::Aleph, @@ -27,7 +27,7 @@ pub trait AlephSudoApi { &self, finalizer: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Schedules a finality version change for a future session. /// * `version` - next version of the finalizer @@ -40,7 +40,7 @@ pub trait AlephSudoApi { version: u32, session: SessionIndex, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet aleph RPC api. @@ -63,7 +63,7 @@ impl AlephSudoApi for RootConnection { &self, finalizer: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Aleph(set_emergency_finalizer { emergency_finalizer: Public(EdPublic(finalizer.into())), }); @@ -75,7 +75,7 @@ impl AlephSudoApi for RootConnection { version: u32, session: SessionIndex, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Aleph(schedule_finality_version_change { version_incoming: version, session, diff --git a/aleph-client/src/pallets/balances.rs b/aleph-client/src/pallets/balances.rs index c0231cdaa5..cf757be5af 100644 --- a/aleph-client/src/pallets/balances.rs +++ b/aleph-client/src/pallets/balances.rs @@ -3,7 +3,7 @@ use subxt::{ext::sp_runtime::MultiAddress, tx::PolkadotExtrinsicParamsBuilder}; use crate::{ aleph_zero::{self, api, api::runtime_types::pallet_balances::BalanceLock}, - connections::TxCoords, + connections::TxInfo, pallet_balances::pallet::Call::transfer, pallets::utility::UtilityApi, AccountId, BlockHash, @@ -45,7 +45,7 @@ pub trait BalanceUserApi { dest: AccountId, amount: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`transfer`](https://paritytech.github.io/substrate/master/pallet_balances/pallet/struct.Pallet.html#method.transfer) call. /// Include tip in the tx. @@ -55,7 +55,7 @@ pub trait BalanceUserApi { amount: Balance, tip: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet balances logic not directly related to any pallet call. @@ -80,7 +80,7 @@ pub trait BalanceUserBatchExtApi { dest: &[AccountId], amount: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -123,7 +123,7 @@ impl BalanceUserApi for S { dest: AccountId, amount: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .balances() .transfer(MultiAddress::Id(dest), amount); @@ -136,7 +136,7 @@ impl BalanceUserApi for S { amount: Balance, tip: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .balances() .transfer(MultiAddress::Id(dest), amount); @@ -153,7 +153,7 @@ impl BalanceUserBatchExtApi for S { dests: &[AccountId], amount: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = dests .iter() .map(|dest| { diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index 3bda930929..cf24c640f5 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -4,7 +4,7 @@ use primitives::Balance; use subxt::{ext::sp_core::Bytes, rpc_params}; use crate::{ - api, connections::TxCoords, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, + api, connections::TxInfo, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; @@ -47,7 +47,7 @@ pub trait ContractsUserApi { code: Vec, storage_limit: Option>, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`instantiate`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.instantiate) call. #[allow(clippy::too_many_arguments)] @@ -60,7 +60,7 @@ pub trait ContractsUserApi { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`instantiate_with_code`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.instantiate_with_code) call. #[allow(clippy::too_many_arguments)] @@ -73,7 +73,7 @@ pub trait ContractsUserApi { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`call`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.call) call. async fn call( @@ -84,11 +84,10 @@ pub trait ContractsUserApi { storage_limit: Option>, data: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`remove_code`](https://paritytech.github.io/substrate/master/pallet_contracts/pallet/struct.Pallet.html#method.remove_code) call. - async fn remove_code(&self, code_hash: BlockHash, status: TxStatus) - -> anyhow::Result; + async fn remove_code(&self, code_hash: BlockHash, status: TxStatus) -> anyhow::Result; } /// RPC for runtime ContractsApi @@ -121,7 +120,7 @@ impl ContractsUserApi for S { code: Vec, storage_limit: Option>, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().upload_code(code, storage_limit); self.send_tx(tx, status).await @@ -136,7 +135,7 @@ impl ContractsUserApi for S { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().instantiate( balance, gas_limit, @@ -158,7 +157,7 @@ impl ContractsUserApi for S { data: Vec, salt: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().contracts().instantiate_with_code( balance, gas_limit, @@ -179,7 +178,7 @@ impl ContractsUserApi for S { storage_limit: Option>, data: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .contracts() @@ -187,11 +186,7 @@ impl ContractsUserApi for S { self.send_tx(tx, status).await } - async fn remove_code( - &self, - code_hash: BlockHash, - status: TxStatus, - ) -> anyhow::Result { + async fn remove_code(&self, code_hash: BlockHash, status: TxStatus) -> anyhow::Result { let tx = api::tx().contracts().remove_code(code_hash); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/elections.rs b/aleph-client/src/pallets/elections.rs index 6f387c9a5d..1e7a9083cb 100644 --- a/aleph-client/src/pallets/elections.rs +++ b/aleph-client/src/pallets/elections.rs @@ -6,7 +6,7 @@ use crate::{ pallet_elections::pallet::Call::set_ban_config, primitives::{BanReason, CommitteeSeats, EraValidators}, }, - connections::{AsConnection, TxCoords}, + connections::{AsConnection, TxInfo}, pallet_elections::pallet::Call::{ ban_from_committee, change_validators, set_elections_openness, }, @@ -99,7 +99,7 @@ pub trait ElectionsSudoApi { clean_session_counter_delay: Option, ban_period: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Issues `elections.change_validators` that sets the committee for the next era. /// * `new_reserved_validators` - reserved validators to be in place in the next era; optional @@ -112,7 +112,7 @@ pub trait ElectionsSudoApi { new_non_reserved_validators: Option>, committee_size: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Schedule a non-reserved node to be banned out from the committee at the end of the era. /// * `account` - account to be banned, @@ -123,7 +123,7 @@ pub trait ElectionsSudoApi { account: AccountId, ban_reason: Vec, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Set openness of the elections. /// * `mode` - new elections openness mode @@ -132,7 +132,7 @@ pub trait ElectionsSudoApi { &self, mode: ElectionOpenness, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -241,7 +241,7 @@ impl ElectionsSudoApi for RootConnection { clean_session_counter_delay: Option, ban_period: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(set_ban_config { minimal_expected_performance, underperformed_session_count_threshold, @@ -258,7 +258,7 @@ impl ElectionsSudoApi for RootConnection { new_non_reserved_validators: Option>, committee_size: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(change_validators { reserved_validators: new_reserved_validators, non_reserved_validators: new_non_reserved_validators, @@ -273,7 +273,7 @@ impl ElectionsSudoApi for RootConnection { account: AccountId, ban_reason: Vec, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(ban_from_committee { banned: account, ban_reason, @@ -285,7 +285,7 @@ impl ElectionsSudoApi for RootConnection { &self, mode: ElectionOpenness, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = Elections(set_elections_openness { openness: mode }); self.sudo_unchecked(call, status).await diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 0ee3c9df80..9207517cb9 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -7,9 +7,9 @@ use sp_core::blake2_256; use sp_runtime::traits::TrailingZeroInput; use crate::{ - account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, - connections::TxCoords, sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, - SignedConnectionApi, TxStatus, + account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, connections::TxInfo, + sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, + TxStatus, }; /// An alias for a call hash. @@ -42,7 +42,7 @@ pub trait MultisigUserApi { other_signatories: Vec, call: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.as_multi) call. async fn as_multi( &self, @@ -52,7 +52,7 @@ pub trait MultisigUserApi { max_weight: Weight, call: Call, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`approve_as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.approve_as_multi) call. async fn approve_as_multi( &self, @@ -62,7 +62,7 @@ pub trait MultisigUserApi { max_weight: Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`cancel_as_multi`](https://paritytech.github.io/substrate/master/pallet_multisig/pallet/struct.Pallet.html#method.cancel_as_multi) call. async fn cancel_as_multi( &self, @@ -71,7 +71,7 @@ pub trait MultisigUserApi { timepoint: Timepoint, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -81,7 +81,7 @@ impl MultisigUserApi for S { other_signatories: Vec, call: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .multisig() .as_multi_threshold_1(other_signatories, call); @@ -97,7 +97,7 @@ impl MultisigUserApi for S { max_weight: Weight, call: Call, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().as_multi( threshold, other_signatories, @@ -117,7 +117,7 @@ impl MultisigUserApi for S { max_weight: Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().approve_as_multi( threshold, other_signatories, @@ -136,7 +136,7 @@ impl MultisigUserApi for S { timepoint: Timepoint, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().multisig().cancel_as_multi( threshold, other_signatories, @@ -394,7 +394,7 @@ pub trait MultisigContextualApi { max_weight: &Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)>; + ) -> anyhow::Result<(TxInfo, Context)>; /// Start signature aggregation for `party` and `call`. Get `Context` object as a result /// (together with standard tx coordinates). /// @@ -406,7 +406,7 @@ pub trait MultisigContextualApi { max_weight: &Weight, call: Call, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)>; + ) -> anyhow::Result<(TxInfo, Context)>; /// Express contextual approval for the call hash. /// /// This is the recommended way for every intermediate approval. @@ -414,7 +414,7 @@ pub trait MultisigContextualApi { &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(TxCoords, ContextAfterUse)>; + ) -> anyhow::Result<(TxInfo, ContextAfterUse)>; /// Express contextual approval for the `call`. /// /// This is the recommended way only for the final approval. @@ -423,13 +423,13 @@ pub trait MultisigContextualApi { context: Context, call: Option, status: TxStatus, - ) -> anyhow::Result<(TxCoords, ContextAfterUse)>; + ) -> anyhow::Result<(TxInfo, ContextAfterUse)>; /// Cancel signature aggregation. async fn cancel( &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)>; + ) -> anyhow::Result<(TxInfo, Context)>; } #[async_trait::async_trait] @@ -440,7 +440,7 @@ impl MultisigContextualApi for S { max_weight: &Weight, call_hash: CallHash, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)> { + ) -> anyhow::Result<(TxInfo, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; let tx_coords = self @@ -483,7 +483,7 @@ impl MultisigContextualApi for S { max_weight: &Weight, call: Call, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)> { + ) -> anyhow::Result<(TxInfo, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; let tx_coords = self @@ -519,7 +519,7 @@ impl MultisigContextualApi for S { &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(TxCoords, ContextAfterUse)> { + ) -> anyhow::Result<(TxInfo, ContextAfterUse)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; self.approve_as_multi( @@ -539,7 +539,7 @@ impl MultisigContextualApi for S { mut context: Context, call: Option, status: TxStatus, - ) -> anyhow::Result<(TxCoords, ContextAfterUse)> { + ) -> anyhow::Result<(TxInfo, ContextAfterUse)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; let call = match (call.as_ref(), context.call.as_ref()) { @@ -576,7 +576,7 @@ impl MultisigContextualApi for S { &self, context: Context, status: TxStatus, - ) -> anyhow::Result<(TxCoords, Context)> { + ) -> anyhow::Result<(TxInfo, Context)> { let other_signatories = ensure_signer_in_party(self, &context.party)?; ensure!( diff --git a/aleph-client/src/pallets/session.rs b/aleph-client/src/pallets/session.rs index 9e41547171..eaeda5937c 100644 --- a/aleph-client/src/pallets/session.rs +++ b/aleph-client/src/pallets/session.rs @@ -1,8 +1,8 @@ use primitives::SessionIndex; use crate::{ - api, api::runtime_types::aleph_runtime::SessionKeys, connections::TxCoords, AccountId, - BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, + api, api::runtime_types::aleph_runtime::SessionKeys, connections::TxInfo, AccountId, BlockHash, + ConnectionApi, SignedConnectionApi, TxStatus, }; /// Pallet session read-only api. @@ -26,7 +26,7 @@ pub trait SessionApi { #[async_trait::async_trait] pub trait SessionUserApi { /// API for [`set_keys`](https://paritytech.github.io/substrate/master/pallet_session/pallet/struct.Pallet.html#method.set_keys) call. - async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result; + async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] @@ -58,7 +58,7 @@ impl SessionApi for C { #[async_trait::async_trait] impl SessionUserApi for S { - async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result { + async fn set_keys(&self, new_keys: SessionKeys, status: TxStatus) -> anyhow::Result { let tx = api::tx().session().set_keys(new_keys, vec![]); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index f40cb49014..0ba312e626 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -9,7 +9,7 @@ use subxt::{ use crate::{ api, - connections::{AsConnection, TxCoords}, + connections::{AsConnection, TxInfo}, pallet_staking::{ pallet::pallet::{ Call::{bond, force_new_era, nominate, set_staking_configs}, @@ -88,14 +88,14 @@ pub trait StakingUserApi { initial_stake: Balance, controller_id: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`validate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.validate) call. async fn validate( &self, validator_commission_percentage: u8, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`payout_stakers`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.payout_stakers) call. async fn payout_stakers( @@ -103,24 +103,24 @@ pub trait StakingUserApi { stash_account: AccountId, era: EraIndex, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`nominate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.nominate) call. async fn nominate( &self, nominee_account_id: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`chill`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.chill) call. - async fn chill(&self, status: TxStatus) -> anyhow::Result; + async fn chill(&self, status: TxStatus) -> anyhow::Result; /// API for [`bond_extra`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.bond_extra) call. async fn bond_extra_stake( &self, extra_stake: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet staking logic, not directly related to any particular pallet call. @@ -174,7 +174,7 @@ pub trait StakingApiExt { accounts: &[(AccountId, AccountId)], stake: Balance, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// Send batch of [`nominate`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.nominate) calls. /// * `nominator_nominee_pairs` - a slice of account ids pairs (nominator, nominee) @@ -186,14 +186,14 @@ pub trait StakingApiExt { &self, nominator_nominee_pairs: &[(AccountId, AccountId)], status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Pallet staking api that requires sudo. #[async_trait::async_trait] pub trait StakingSudoApi { /// API for [`force_new_era`](https://paritytech.github.io/substrate/master/pallet_staking/struct.Pallet.html#method.force_new_era) call. - async fn force_new_era(&self, status: TxStatus) -> anyhow::Result; + async fn force_new_era(&self, status: TxStatus) -> anyhow::Result; /// 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( @@ -203,7 +203,7 @@ pub trait StakingSudoApi { max_nominators_count: Option, max_validators_count: Option, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } /// Logic for retrieving raw storage keys or values from a pallet staking. @@ -317,7 +317,7 @@ impl StakingUserApi for S { initial_stake: Balance, controller_id: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().bond( MultiAddress::::Id(controller_id), initial_stake, @@ -331,7 +331,7 @@ impl StakingUserApi for S { &self, validator_commission_percentage: u8, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().validate(ValidatorPrefs { commission: Perbill( SPerbill::from_percent(validator_commission_percentage as u32).deconstruct(), @@ -347,7 +347,7 @@ impl StakingUserApi for S { stash_account: AccountId, era: EraIndex, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().payout_stakers(stash_account, era); self.send_tx(tx, status).await @@ -357,7 +357,7 @@ impl StakingUserApi for S { &self, nominee_account_id: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .staking() .nominate(vec![MultiAddress::Id(nominee_account_id)]); @@ -365,7 +365,7 @@ impl StakingUserApi for S { self.send_tx(tx, status).await } - async fn chill(&self, status: TxStatus) -> anyhow::Result { + async fn chill(&self, status: TxStatus) -> anyhow::Result { let tx = api::tx().staking().chill(); self.send_tx(tx, status).await @@ -375,7 +375,7 @@ impl StakingUserApi for S { &self, extra_stake: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().staking().bond_extra(extra_stake); self.send_tx(tx, status).await @@ -384,7 +384,7 @@ impl StakingUserApi for S { #[async_trait::async_trait] impl StakingSudoApi for RootConnection { - async fn force_new_era(&self, status: TxStatus) -> anyhow::Result { + async fn force_new_era(&self, status: TxStatus) -> anyhow::Result { let call = Staking(force_new_era); self.sudo_unchecked(call, status).await @@ -397,7 +397,7 @@ impl StakingSudoApi for RootConnection { max_nominator_count: Option, max_validator_count: Option, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { fn convert(arg: Option) -> ConfigOp { match arg { Some(v) => Set(v), @@ -462,7 +462,7 @@ impl StakingApiExt for RootConnection { accounts: &[(AccountId, AccountId)], stake: Balance, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = accounts .iter() .map(|(s, c)| { @@ -486,7 +486,7 @@ impl StakingApiExt for RootConnection { &self, nominator_nominee_pairs: &[(AccountId, AccountId)], status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let calls = nominator_nominee_pairs .iter() .map(|(nominator, nominee)| { diff --git a/aleph-client/src/pallets/system.rs b/aleph-client/src/pallets/system.rs index be79abfe47..6166759b8c 100644 --- a/aleph-client/src/pallets/system.rs +++ b/aleph-client/src/pallets/system.rs @@ -3,7 +3,7 @@ use subxt::ext::sp_runtime::Perbill as SPerbill; use crate::{ api, - connections::TxCoords, + connections::TxInfo, frame_system::pallet::Call::{fill_block, set_code}, sp_arithmetic::per_things::Perbill, AccountId, BlockHash, @@ -26,7 +26,7 @@ pub trait SystemApi { #[async_trait::async_trait] pub trait SystemSudoApi { /// API for [`set_code`](https://paritytech.github.io/substrate/master/frame_system/pallet/struct.Pallet.html#method.set_code) call. - async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result; + async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result; /// A dispatch that will fill the block weight up to the given ratio. /// * `target_ratio_percent` - ratio to fill block @@ -35,12 +35,12 @@ pub trait SystemSudoApi { &self, target_ratio_percent: u8, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] impl SystemSudoApi for RootConnection { - async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result { + async fn set_code(&self, code: Vec, status: TxStatus) -> anyhow::Result { let call = System(set_code { code }); self.sudo_unchecked(call, status).await @@ -50,7 +50,7 @@ impl SystemSudoApi for RootConnection { &self, target_ratio_percent: u8, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let call = System(fill_block { ratio: Perbill(SPerbill::from_percent(target_ratio_percent as u32).deconstruct()), }); diff --git a/aleph-client/src/pallets/treasury.rs b/aleph-client/src/pallets/treasury.rs index 66f31c4379..157ed4e9fd 100644 --- a/aleph-client/src/pallets/treasury.rs +++ b/aleph-client/src/pallets/treasury.rs @@ -5,7 +5,7 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ api, - connections::{AsConnection, TxCoords}, + connections::{AsConnection, TxInfo}, pallet_treasury::pallet::Call::{approve_proposal, reject_proposal}, pallets::{elections::ElectionsApi, staking::StakingApi}, AccountId, BlockHash, @@ -37,13 +37,13 @@ pub trait TreasuryUserApi { amount: Balance, beneficiary: AccountId, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`approve_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.approve_proposal) call. - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; /// API for [`reject_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.reject_proposal) call. - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; } /// Pallet treasury funcionality that is not directly related to any pallet call. @@ -59,11 +59,11 @@ pub trait TreasureApiExt { pub trait TreasurySudoApi { /// API for [`approve_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.approve_proposal) call. /// wrapped in [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/struct.Pallet.html#method.sudo_unchecked_weight) - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; /// API for [`reject_proposal`](https://paritytech.github.io/substrate/master/pallet_treasury/pallet/struct.Pallet.html#method.reject_proposal) call. /// wrapped [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/struct.Pallet.html#method.sudo_unchecked_weight) - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] @@ -92,7 +92,7 @@ impl TreasuryUserApi for S { amount: Balance, beneficiary: AccountId, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .treasury() .propose_spend(amount, MultiAddress::Id(beneficiary)); @@ -100,13 +100,13 @@ impl TreasuryUserApi for S { self.send_tx(tx, status).await } - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let tx = api::tx().treasury().approve_proposal(proposal_id); self.send_tx(tx, status).await } - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let tx = api::tx().treasury().reject_proposal(proposal_id); self.send_tx(tx, status).await @@ -115,13 +115,13 @@ impl TreasuryUserApi for S { #[async_trait::async_trait] impl TreasurySudoApi for RootConnection { - async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn approve(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let call = Treasury(approve_proposal { proposal_id }); self.sudo_unchecked(call, status).await } - async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { + async fn reject(&self, proposal_id: u32, status: TxStatus) -> anyhow::Result { let call = Treasury(reject_proposal { proposal_id }); self.sudo_unchecked(call, status).await diff --git a/aleph-client/src/pallets/utility.rs b/aleph-client/src/pallets/utility.rs index 1a9b7123c3..77ac93999c 100644 --- a/aleph-client/src/pallets/utility.rs +++ b/aleph-client/src/pallets/utility.rs @@ -1,15 +1,15 @@ -use crate::{api, connections::TxCoords, Call, SignedConnectionApi, TxStatus}; +use crate::{api, connections::TxInfo, Call, SignedConnectionApi, TxStatus}; /// Pallet utility api. #[async_trait::async_trait] pub trait UtilityApi { /// API for [`batch`](https://paritytech.github.io/substrate/master/pallet_utility/pallet/struct.Pallet.html#method.batch) call. - async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result; + async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result; } #[async_trait::async_trait] impl UtilityApi for S { - async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result { + async fn batch_call(&self, calls: Vec, status: TxStatus) -> anyhow::Result { let tx = api::tx().utility().batch(calls); self.send_tx(tx, status).await diff --git a/aleph-client/src/pallets/vesting.rs b/aleph-client/src/pallets/vesting.rs index 948ec4ddef..6b3171ac55 100644 --- a/aleph-client/src/pallets/vesting.rs +++ b/aleph-client/src/pallets/vesting.rs @@ -1,7 +1,7 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ - api, connections::TxCoords, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, + api, connections::TxInfo, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; @@ -22,10 +22,10 @@ pub trait VestingApi { #[async_trait::async_trait] pub trait VestingUserApi { /// API for [`vest`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vest) call. - async fn vest(&self, status: TxStatus) -> anyhow::Result; + async fn vest(&self, status: TxStatus) -> anyhow::Result; /// API for [`vest_other`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vest_other) call. - async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result; + async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result; /// API for [`vested_transfer`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.vested_transfer) call. async fn vested_transfer( @@ -33,7 +33,7 @@ pub trait VestingUserApi { receiver: AccountId, schedule: VestingInfo, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; /// API for [`merge_schedules`](https://paritytech.github.io/substrate/master/pallet_vesting/pallet/enum.Call.html#variant.merge_schedules) call. async fn merge_schedules( @@ -41,7 +41,7 @@ pub trait VestingUserApi { idx1: u32, idx2: u32, status: TxStatus, - ) -> anyhow::Result; + ) -> anyhow::Result; } #[async_trait::async_trait] @@ -59,13 +59,13 @@ impl VestingApi for C { #[async_trait::async_trait] impl VestingUserApi for S { - async fn vest(&self, status: TxStatus) -> anyhow::Result { + async fn vest(&self, status: TxStatus) -> anyhow::Result { let tx = api::tx().vesting().vest(); self.send_tx(tx, status).await } - async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result { + async fn vest_other(&self, status: TxStatus, other: AccountId) -> anyhow::Result { let tx = api::tx().vesting().vest_other(MultiAddress::Id(other)); self.send_tx(tx, status).await @@ -76,7 +76,7 @@ impl VestingUserApi for S { receiver: AccountId, schedule: VestingInfo, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx() .vesting() .vested_transfer(MultiAddress::Id(receiver), schedule); @@ -89,7 +89,7 @@ impl VestingUserApi for S { idx1: u32, idx2: u32, status: TxStatus, - ) -> anyhow::Result { + ) -> anyhow::Result { let tx = api::tx().vesting().merge_schedules(idx1, idx2); self.send_tx(tx, status).await diff --git a/bin/cliain/Cargo.lock b/bin/cliain/Cargo.lock index 0bf160d3fc..959eb48e46 100644 --- a/bin/cliain/Cargo.lock +++ b/bin/cliain/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.7.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", From 48a5ccd359ecd993d03756fb5f6a44dba1a0cfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:49:54 +0100 Subject: [PATCH 05/14] Migrate cliain --- bin/cliain/src/contracts.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/cliain/src/contracts.rs b/bin/cliain/src/contracts.rs index 301968a502..cb6b939dad 100644 --- a/bin/cliain/src/contracts.rs +++ b/bin/cliain/src/contracts.rs @@ -58,7 +58,7 @@ pub async fn upload_code( .await }); - let _block_hash = signed_connection + let _tx_info = signed_connection .upload_code( wasm, storage_deposit(storage_deposit_limit), @@ -109,7 +109,7 @@ pub async fn instantiate( .await }); - let _block_hash = signed_connection + let _tx_info = signed_connection .instantiate( code_hash, balance, @@ -182,7 +182,7 @@ pub async fn instantiate_with_code( .await }); - let _block_hash = signed_connection + let _tx_info = signed_connection .instantiate_with_code( wasm, balance, @@ -227,7 +227,7 @@ pub async fn call( debug!("Encoded call data {:?}", data); - let _block_hash = signed_connection + let _tx_info = signed_connection .call( destination, balance, @@ -267,7 +267,7 @@ pub async fn remove_code( .await }); - let _block_hash = signed_connection + let _tx_info = signed_connection .remove_code(code_hash, TxStatus::InBlock) .await?; From cb58f2a8c3d1c41473824c8c23db3974a208930c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 07:59:52 +0100 Subject: [PATCH 06/14] Move to lib --- aleph-client/src/connections.rs | 22 ++-------------------- aleph-client/src/lib.rs | 20 ++++++++++++++++++++ aleph-client/src/pallets/aleph.rs | 3 +-- aleph-client/src/pallets/balances.rs | 3 +-- aleph-client/src/pallets/contract.rs | 4 ++-- aleph-client/src/pallets/elections.rs | 4 ++-- aleph-client/src/pallets/multisig.rs | 4 ++-- aleph-client/src/pallets/session.rs | 4 ++-- aleph-client/src/pallets/staking.rs | 4 ++-- aleph-client/src/pallets/system.rs | 3 +-- aleph-client/src/pallets/treasury.rs | 4 ++-- aleph-client/src/pallets/utility.rs | 2 +- aleph-client/src/pallets/vesting.rs | 4 ++-- benches/payout-stakers/Cargo.lock | 2 +- e2e-tests/Cargo.lock | 2 +- flooder/Cargo.lock | 2 +- 16 files changed, 43 insertions(+), 44 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index d0973f7586..4371e3e910 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -3,9 +3,7 @@ use std::{thread::sleep, time::Duration}; use anyhow::anyhow; use codec::Decode; use log::info; -use serde::{Deserialize, Serialize}; use subxt::{ - blocks::ExtrinsicEvents, ext::sp_core::Bytes, metadata::DecodeWithMetadata, rpc::RpcParams, @@ -15,8 +13,8 @@ use subxt::{ }; use crate::{ - api, sp_weights::weight_v2::Weight, AccountId, AlephConfig, BlockHash, Call, KeyPair, - SubxtClient, TxHash, TxStatus, + api, sp_weights::weight_v2::Weight, AccountId, BlockHash, Call, KeyPair, SubxtClient, TxInfo, + TxStatus, }; /// Capable of communicating with a live Aleph chain. @@ -108,22 +106,6 @@ pub trait ConnectionApi: Sync { async fn rpc_call(&self, func_name: String, params: RpcParams) -> anyhow::Result; } -/// Data regarding submitted transaction. -#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] -pub struct TxInfo { - pub block_hash: BlockHash, - pub tx_hash: TxHash, -} - -impl From> for TxInfo { - fn from(ee: ExtrinsicEvents) -> Self { - Self { - block_hash: ee.extrinsic_hash(), - tx_hash: ee.block_hash(), - } - } -} - /// Signed connection should be able to sends transactions to chain #[async_trait::async_trait] pub trait SignedConnectionApi: ConnectionApi { diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index a7c89cd778..fd64b0d0a3 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -13,8 +13,10 @@ extern crate core; pub use contract_transcode; +use serde::{Deserialize, Serialize}; pub use subxt::ext::sp_core::Pair; use subxt::{ + blocks::ExtrinsicEvents, ext::sp_core::{ed25519, sr25519, H256}, tx::PairSigner, OnlineClient, PolkadotConfig, @@ -100,3 +102,21 @@ where { AccountId::from(keypair.public()) } + +/// Data regarding submitted transaction. +#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct TxInfo { + /// Hash of the block that contains the transaction. + pub block_hash: BlockHash, + /// The hash of the transaction. + pub tx_hash: TxHash, +} + +impl From> for TxInfo { + fn from(ee: ExtrinsicEvents) -> Self { + Self { + block_hash: ee.extrinsic_hash(), + tx_hash: ee.block_hash(), + } + } +} diff --git a/aleph-client/src/pallets/aleph.rs b/aleph-client/src/pallets/aleph.rs index b68a00f30b..ae323769cb 100644 --- a/aleph-client/src/pallets/aleph.rs +++ b/aleph-client/src/pallets/aleph.rs @@ -7,11 +7,10 @@ use crate::{ pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public, sp_core::ed25519::Public as EdPublic, }, - connections::TxInfo, pallet_aleph::pallet::Call::schedule_finality_version_change, AccountId, AlephKeyPair, BlockHash, Call::Aleph, - ConnectionApi, Pair, RootConnection, SudoCall, TxStatus, + ConnectionApi, Pair, RootConnection, SudoCall, TxInfo, TxStatus, }; // TODO replace docs with link to pallet aleph docs, once they are published diff --git a/aleph-client/src/pallets/balances.rs b/aleph-client/src/pallets/balances.rs index cf757be5af..51b783d2cc 100644 --- a/aleph-client/src/pallets/balances.rs +++ b/aleph-client/src/pallets/balances.rs @@ -3,12 +3,11 @@ 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, Call::Balances, - ConnectionApi, SignedConnectionApi, TxStatus, + ConnectionApi, SignedConnectionApi, TxInfo, TxStatus, }; /// Pallet balances read-only API. diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index cf24c640f5..a9266a8173 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -4,8 +4,8 @@ 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, + api, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, AccountId, BlockHash, + ConnectionApi, SignedConnectionApi, TxInfo, TxStatus, }; /// Arguments to [`ContractRpc::call_and_get`]. diff --git a/aleph-client/src/pallets/elections.rs b/aleph-client/src/pallets/elections.rs index 1e7a9083cb..8062a74813 100644 --- a/aleph-client/src/pallets/elections.rs +++ b/aleph-client/src/pallets/elections.rs @@ -6,14 +6,14 @@ use crate::{ pallet_elections::pallet::Call::set_ban_config, primitives::{BanReason, CommitteeSeats, EraValidators}, }, - connections::{AsConnection, TxInfo}, + connections::AsConnection, pallet_elections::pallet::Call::{ ban_from_committee, change_validators, set_elections_openness, }, primitives::{BanConfig, BanInfo, ElectionOpenness}, AccountId, BlockHash, Call::Elections, - ConnectionApi, RootConnection, SudoCall, TxStatus, + ConnectionApi, RootConnection, SudoCall, TxInfo, TxStatus, }; // TODO once pallet elections docs are published, replace api docs with links to public docs diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 9207517cb9..1e54f83b80 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -7,9 +7,9 @@ use sp_core::blake2_256; use sp_runtime::traits::TrailingZeroInput; use crate::{ - account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, connections::TxInfo, + account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, - TxStatus, + TxInfo, TxStatus, }; /// An alias for a call hash. diff --git a/aleph-client/src/pallets/session.rs b/aleph-client/src/pallets/session.rs index eaeda5937c..18d31cacab 100644 --- a/aleph-client/src/pallets/session.rs +++ b/aleph-client/src/pallets/session.rs @@ -1,8 +1,8 @@ use primitives::SessionIndex; use crate::{ - api, api::runtime_types::aleph_runtime::SessionKeys, connections::TxInfo, AccountId, BlockHash, - ConnectionApi, SignedConnectionApi, TxStatus, + api, api::runtime_types::aleph_runtime::SessionKeys, AccountId, BlockHash, ConnectionApi, + SignedConnectionApi, TxInfo, TxStatus, }; /// Pallet session read-only api. diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index 0ba312e626..c970542479 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -9,7 +9,7 @@ use subxt::{ use crate::{ api, - connections::{AsConnection, TxInfo}, + connections::AsConnection, pallet_staking::{ pallet::pallet::{ Call::{bond, force_new_era, nominate, set_staking_configs}, @@ -23,7 +23,7 @@ use crate::{ sp_arithmetic::per_things::Perbill, AccountId, BlockHash, Call::{Staking, Sudo}, - ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxStatus, + ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxInfo, TxStatus, }; /// Any object that implemnts pallet staking read-only api. diff --git a/aleph-client/src/pallets/system.rs b/aleph-client/src/pallets/system.rs index 6166759b8c..7b87d68834 100644 --- a/aleph-client/src/pallets/system.rs +++ b/aleph-client/src/pallets/system.rs @@ -3,12 +3,11 @@ 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, Call::System, - ConnectionApi, RootConnection, SudoCall, TxStatus, + ConnectionApi, RootConnection, SudoCall, TxInfo, TxStatus, }; /// Pallet system read-only api. diff --git a/aleph-client/src/pallets/treasury.rs b/aleph-client/src/pallets/treasury.rs index 157ed4e9fd..65806a51c4 100644 --- a/aleph-client/src/pallets/treasury.rs +++ b/aleph-client/src/pallets/treasury.rs @@ -5,12 +5,12 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ api, - connections::{AsConnection, TxInfo}, + connections::AsConnection, pallet_treasury::pallet::Call::{approve_proposal, reject_proposal}, pallets::{elections::ElectionsApi, staking::StakingApi}, AccountId, BlockHash, Call::Treasury, - ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxStatus, + ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxInfo, TxStatus, }; /// Pallet treasury read-only api. diff --git a/aleph-client/src/pallets/utility.rs b/aleph-client/src/pallets/utility.rs index 77ac93999c..a117b4355d 100644 --- a/aleph-client/src/pallets/utility.rs +++ b/aleph-client/src/pallets/utility.rs @@ -1,4 +1,4 @@ -use crate::{api, connections::TxInfo, Call, SignedConnectionApi, TxStatus}; +use crate::{api, Call, SignedConnectionApi, TxInfo, TxStatus}; /// Pallet utility api. #[async_trait::async_trait] diff --git a/aleph-client/src/pallets/vesting.rs b/aleph-client/src/pallets/vesting.rs index 6b3171ac55..d98d61dd1e 100644 --- a/aleph-client/src/pallets/vesting.rs +++ b/aleph-client/src/pallets/vesting.rs @@ -1,8 +1,8 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ - api, connections::TxInfo, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, - ConnectionApi, SignedConnectionApi, TxStatus, + api, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, ConnectionApi, + SignedConnectionApi, TxInfo, TxStatus, }; /// Read only pallet vesting API. diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index 9b1dad9c35..0c42c14b3d 100644 --- a/benches/payout-stakers/Cargo.lock +++ b/benches/payout-stakers/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.6.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 9ee234048f..45a437253c 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.7.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index 7abb059b74..531c491c17 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.6.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", From 8a16d0478ff0d85ff093a5db59a8c43a7365717f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 08:09:41 +0100 Subject: [PATCH 07/14] Revert "Move to lib" This reverts commit cb58f2a8c3d1c41473824c8c23db3974a208930c. --- aleph-client/src/connections.rs | 22 ++++++++++++++++++++-- aleph-client/src/lib.rs | 20 -------------------- aleph-client/src/pallets/aleph.rs | 3 ++- aleph-client/src/pallets/balances.rs | 3 ++- aleph-client/src/pallets/contract.rs | 4 ++-- aleph-client/src/pallets/elections.rs | 4 ++-- aleph-client/src/pallets/multisig.rs | 4 ++-- aleph-client/src/pallets/session.rs | 4 ++-- aleph-client/src/pallets/staking.rs | 4 ++-- aleph-client/src/pallets/system.rs | 3 ++- aleph-client/src/pallets/treasury.rs | 4 ++-- aleph-client/src/pallets/utility.rs | 2 +- aleph-client/src/pallets/vesting.rs | 4 ++-- benches/payout-stakers/Cargo.lock | 2 +- e2e-tests/Cargo.lock | 2 +- flooder/Cargo.lock | 2 +- 16 files changed, 44 insertions(+), 43 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index 4371e3e910..d0973f7586 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -3,7 +3,9 @@ use std::{thread::sleep, time::Duration}; use anyhow::anyhow; use codec::Decode; use log::info; +use serde::{Deserialize, Serialize}; use subxt::{ + blocks::ExtrinsicEvents, ext::sp_core::Bytes, metadata::DecodeWithMetadata, rpc::RpcParams, @@ -13,8 +15,8 @@ use subxt::{ }; use crate::{ - api, sp_weights::weight_v2::Weight, AccountId, BlockHash, Call, KeyPair, SubxtClient, TxInfo, - TxStatus, + api, sp_weights::weight_v2::Weight, AccountId, AlephConfig, BlockHash, Call, KeyPair, + SubxtClient, TxHash, TxStatus, }; /// Capable of communicating with a live Aleph chain. @@ -106,6 +108,22 @@ pub trait ConnectionApi: Sync { async fn rpc_call(&self, func_name: String, params: RpcParams) -> anyhow::Result; } +/// Data regarding submitted transaction. +#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] +pub struct TxInfo { + pub block_hash: BlockHash, + pub tx_hash: TxHash, +} + +impl From> for TxInfo { + fn from(ee: ExtrinsicEvents) -> Self { + Self { + block_hash: ee.extrinsic_hash(), + tx_hash: ee.block_hash(), + } + } +} + /// Signed connection should be able to sends transactions to chain #[async_trait::async_trait] pub trait SignedConnectionApi: ConnectionApi { diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index fd64b0d0a3..a7c89cd778 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -13,10 +13,8 @@ extern crate core; pub use contract_transcode; -use serde::{Deserialize, Serialize}; pub use subxt::ext::sp_core::Pair; use subxt::{ - blocks::ExtrinsicEvents, ext::sp_core::{ed25519, sr25519, H256}, tx::PairSigner, OnlineClient, PolkadotConfig, @@ -102,21 +100,3 @@ where { AccountId::from(keypair.public()) } - -/// Data regarding submitted transaction. -#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] -pub struct TxInfo { - /// Hash of the block that contains the transaction. - pub block_hash: BlockHash, - /// The hash of the transaction. - pub tx_hash: TxHash, -} - -impl From> for TxInfo { - fn from(ee: ExtrinsicEvents) -> Self { - Self { - block_hash: ee.extrinsic_hash(), - tx_hash: ee.block_hash(), - } - } -} diff --git a/aleph-client/src/pallets/aleph.rs b/aleph-client/src/pallets/aleph.rs index ae323769cb..b68a00f30b 100644 --- a/aleph-client/src/pallets/aleph.rs +++ b/aleph-client/src/pallets/aleph.rs @@ -7,10 +7,11 @@ use crate::{ pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public, sp_core::ed25519::Public as EdPublic, }, + connections::TxInfo, pallet_aleph::pallet::Call::schedule_finality_version_change, AccountId, AlephKeyPair, BlockHash, Call::Aleph, - ConnectionApi, Pair, RootConnection, SudoCall, TxInfo, TxStatus, + ConnectionApi, Pair, RootConnection, SudoCall, TxStatus, }; // TODO replace docs with link to pallet aleph docs, once they are published diff --git a/aleph-client/src/pallets/balances.rs b/aleph-client/src/pallets/balances.rs index 51b783d2cc..cf757be5af 100644 --- a/aleph-client/src/pallets/balances.rs +++ b/aleph-client/src/pallets/balances.rs @@ -3,11 +3,12 @@ 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, Call::Balances, - ConnectionApi, SignedConnectionApi, TxInfo, TxStatus, + ConnectionApi, SignedConnectionApi, TxStatus, }; /// Pallet balances read-only API. diff --git a/aleph-client/src/pallets/contract.rs b/aleph-client/src/pallets/contract.rs index a9266a8173..cf24c640f5 100644 --- a/aleph-client/src/pallets/contract.rs +++ b/aleph-client/src/pallets/contract.rs @@ -4,8 +4,8 @@ use primitives::Balance; use subxt::{ext::sp_core::Bytes, rpc_params}; use crate::{ - api, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, AccountId, BlockHash, - ConnectionApi, SignedConnectionApi, TxInfo, TxStatus, + api, connections::TxInfo, pallet_contracts::wasm::OwnerInfo, sp_weights::weight_v2::Weight, + AccountId, BlockHash, ConnectionApi, SignedConnectionApi, TxStatus, }; /// Arguments to [`ContractRpc::call_and_get`]. diff --git a/aleph-client/src/pallets/elections.rs b/aleph-client/src/pallets/elections.rs index 8062a74813..1e7a9083cb 100644 --- a/aleph-client/src/pallets/elections.rs +++ b/aleph-client/src/pallets/elections.rs @@ -6,14 +6,14 @@ use crate::{ pallet_elections::pallet::Call::set_ban_config, primitives::{BanReason, CommitteeSeats, EraValidators}, }, - connections::AsConnection, + connections::{AsConnection, TxInfo}, pallet_elections::pallet::Call::{ ban_from_committee, change_validators, set_elections_openness, }, primitives::{BanConfig, BanInfo, ElectionOpenness}, AccountId, BlockHash, Call::Elections, - ConnectionApi, RootConnection, SudoCall, TxInfo, TxStatus, + ConnectionApi, RootConnection, SudoCall, TxStatus, }; // TODO once pallet elections docs are published, replace api docs with links to public docs diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 1e54f83b80..9207517cb9 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -7,9 +7,9 @@ use sp_core::blake2_256; use sp_runtime::traits::TrailingZeroInput; use crate::{ - account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, + account_from_keypair, aleph_runtime::RuntimeCall, api, api::runtime_types, connections::TxInfo, sp_weights::weight_v2::Weight, AccountId, BlockHash, ConnectionApi, SignedConnectionApi, - TxInfo, TxStatus, + TxStatus, }; /// An alias for a call hash. diff --git a/aleph-client/src/pallets/session.rs b/aleph-client/src/pallets/session.rs index 18d31cacab..eaeda5937c 100644 --- a/aleph-client/src/pallets/session.rs +++ b/aleph-client/src/pallets/session.rs @@ -1,8 +1,8 @@ use primitives::SessionIndex; use crate::{ - api, api::runtime_types::aleph_runtime::SessionKeys, AccountId, BlockHash, ConnectionApi, - SignedConnectionApi, TxInfo, TxStatus, + api, api::runtime_types::aleph_runtime::SessionKeys, connections::TxInfo, AccountId, BlockHash, + ConnectionApi, SignedConnectionApi, TxStatus, }; /// Pallet session read-only api. diff --git a/aleph-client/src/pallets/staking.rs b/aleph-client/src/pallets/staking.rs index c970542479..0ba312e626 100644 --- a/aleph-client/src/pallets/staking.rs +++ b/aleph-client/src/pallets/staking.rs @@ -9,7 +9,7 @@ use subxt::{ use crate::{ api, - connections::AsConnection, + connections::{AsConnection, TxInfo}, pallet_staking::{ pallet::pallet::{ Call::{bond, force_new_era, nominate, set_staking_configs}, @@ -23,7 +23,7 @@ use crate::{ sp_arithmetic::per_things::Perbill, AccountId, BlockHash, Call::{Staking, Sudo}, - ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxInfo, TxStatus, + ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxStatus, }; /// Any object that implemnts pallet staking read-only api. diff --git a/aleph-client/src/pallets/system.rs b/aleph-client/src/pallets/system.rs index 7b87d68834..6166759b8c 100644 --- a/aleph-client/src/pallets/system.rs +++ b/aleph-client/src/pallets/system.rs @@ -3,11 +3,12 @@ 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, Call::System, - ConnectionApi, RootConnection, SudoCall, TxInfo, TxStatus, + ConnectionApi, RootConnection, SudoCall, TxStatus, }; /// Pallet system read-only api. diff --git a/aleph-client/src/pallets/treasury.rs b/aleph-client/src/pallets/treasury.rs index 65806a51c4..157ed4e9fd 100644 --- a/aleph-client/src/pallets/treasury.rs +++ b/aleph-client/src/pallets/treasury.rs @@ -5,12 +5,12 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ api, - connections::AsConnection, + connections::{AsConnection, TxInfo}, pallet_treasury::pallet::Call::{approve_proposal, reject_proposal}, pallets::{elections::ElectionsApi, staking::StakingApi}, AccountId, BlockHash, Call::Treasury, - ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxInfo, TxStatus, + ConnectionApi, RootConnection, SignedConnectionApi, SudoCall, TxStatus, }; /// Pallet treasury read-only api. diff --git a/aleph-client/src/pallets/utility.rs b/aleph-client/src/pallets/utility.rs index a117b4355d..77ac93999c 100644 --- a/aleph-client/src/pallets/utility.rs +++ b/aleph-client/src/pallets/utility.rs @@ -1,4 +1,4 @@ -use crate::{api, Call, SignedConnectionApi, TxInfo, TxStatus}; +use crate::{api, connections::TxInfo, Call, SignedConnectionApi, TxStatus}; /// Pallet utility api. #[async_trait::async_trait] diff --git a/aleph-client/src/pallets/vesting.rs b/aleph-client/src/pallets/vesting.rs index d98d61dd1e..6b3171ac55 100644 --- a/aleph-client/src/pallets/vesting.rs +++ b/aleph-client/src/pallets/vesting.rs @@ -1,8 +1,8 @@ use subxt::ext::sp_runtime::MultiAddress; use crate::{ - api, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, ConnectionApi, - SignedConnectionApi, TxInfo, TxStatus, + api, connections::TxInfo, pallet_vesting::vesting_info::VestingInfo, AccountId, BlockHash, + ConnectionApi, SignedConnectionApi, TxStatus, }; /// Read only pallet vesting API. diff --git a/benches/payout-stakers/Cargo.lock b/benches/payout-stakers/Cargo.lock index 0c42c14b3d..9b1dad9c35 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.6.0" dependencies = [ "anyhow", "async-trait", diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 45a437253c..9ee234048f 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.7.0" dependencies = [ "anyhow", "async-trait", diff --git a/flooder/Cargo.lock b/flooder/Cargo.lock index 531c491c17..7abb059b74 100644 --- a/flooder/Cargo.lock +++ b/flooder/Cargo.lock @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.8.0" +version = "2.6.0" dependencies = [ "anyhow", "async-trait", From f1e3ce178a2602c4908f5fa41b3c4ff6470a3936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 09:06:36 +0100 Subject: [PATCH 08/14] Get tx events --- aleph-client/src/lib.rs | 2 +- aleph-client/src/utility.rs | 30 ++++++++++++++++++++++++++++-- e2e-tests/Cargo.lock | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/aleph-client/src/lib.rs b/aleph-client/src/lib.rs index a7c89cd778..f147c58572 100644 --- a/aleph-client/src/lib.rs +++ b/aleph-client/src/lib.rs @@ -13,7 +13,7 @@ extern crate core; pub use contract_transcode; -pub use subxt::ext::sp_core::Pair; +pub use subxt::{blocks::ExtrinsicEvents, ext::sp_core::Pair}; use subxt::{ ext::sp_core::{ed25519, sr25519, H256}, tx::PairSigner, diff --git a/aleph-client/src/utility.rs b/aleph-client/src/utility.rs index 15821dbe9d..42acfcca1f 100644 --- a/aleph-client/src/utility.rs +++ b/aleph-client/src/utility.rs @@ -1,10 +1,12 @@ +use anyhow::anyhow; use log::info; use primitives::{BlockNumber, EraIndex, SessionIndex}; +use subxt::{blocks::ExtrinsicEvents, ext::sp_core::Hasher, Config}; use crate::{ - connections::AsConnection, + connections::{AsConnection, TxInfo}, pallets::{elections::ElectionsApi, staking::StakingApi}, - BlockHash, + AlephConfig, BlockHash, }; /// Block info API. @@ -38,6 +40,9 @@ pub trait BlocksApi { &self, block: Option, ) -> anyhow::Result>; + + /// Fetch all events that corresponds to the transaction identified by `tx_info`. + async fn get_tx_events(&self, tx_info: TxInfo) -> anyhow::Result>; } /// Interaction logic between pallet session and pallet staking. @@ -99,6 +104,27 @@ impl BlocksApi for C { async fn get_block_number(&self, block: BlockHash) -> anyhow::Result> { self.get_block_number_opt(Some(block)).await } + + async fn get_tx_events(&self, tx_info: TxInfo) -> anyhow::Result> { + let block_body = self + .as_connection() + .as_client() + .blocks() + .at(Some(tx_info.block_hash)) + .await? + .body() + .await?; + + let extrinsic_events = block_body + .extrinsics() + .find(|tx| tx_info.tx_hash == ::Hashing::hash(tx.bytes())) + .ok_or(anyhow!("Couldn't find the transaction in the block."))? + .events() + .await + .map_err(|e| anyhow!("Couldn't fetch events for the transaction: {e:?}"))?; + + Ok(extrinsic_events) + } } #[async_trait::async_trait] diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index 9ee234048f..45a437253c 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -78,7 +78,7 @@ dependencies = [ [[package]] name = "aleph_client" -version = "2.7.0" +version = "2.8.0" dependencies = [ "anyhow", "async-trait", From 34c9cb424aa1ffbeb9295e5d217e2e83f6f70bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 09:13:09 +0100 Subject: [PATCH 09/14] Example usage --- e2e-tests/src/test/fee.rs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/e2e-tests/src/test/fee.rs b/e2e-tests/src/test/fee.rs index 8bafab4b93..31b7be2b64 100644 --- a/e2e-tests/src/test/fee.rs +++ b/e2e-tests/src/test/fee.rs @@ -1,6 +1,7 @@ use aleph_client::{ api::transaction_payment::events::TransactionFeePaid, pallets::{balances::BalanceUserApi, fee::TransactionPaymentApi, system::SystemSudoApi}, + utility::BlocksApi, waiting::{AlephWaiting, BlockStatus}, AccountId, RootConnection, SignedConnection, SignedConnectionApi, TxStatus, }; @@ -109,29 +110,17 @@ pub async fn current_fees( let waiting_connection = connection.clone(); let signer = connection.account_id().clone(); - let event_handle = tokio::spawn(async move { - waiting_connection - .wait_for_event( - |e: &TransactionFeePaid| e.who == signer, - BlockStatus::Finalized, - ) - .await - }); - match tip { - None => { - connection - .transfer(to, transfer_value, TxStatus::Finalized) - .await - .unwrap(); - } - Some(tip) => { - connection - .transfer_with_tip(to, transfer_value, tip, TxStatus::Finalized) - .await - .unwrap(); - } + + let tx_info = match tip { + None => connection.transfer(to, transfer_value, TxStatus::Finalized), + Some(tip) => connection.transfer_with_tip(to, transfer_value, tip, TxStatus::Finalized), } - let event = event_handle.await.unwrap(); + .await + .unwrap(); + + let events = connection.get_tx_events(tx_info).await.unwrap(); + let event = events.find_first::().unwrap().unwrap(); + let fee = event.actual_fee; info!("fee payed: {}", fee); From ae2fb17b0a6e7a2fc1db421a50225d46d9936fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 09:27:25 +0100 Subject: [PATCH 10/14] rename variables --- aleph-client/src/connections.rs | 6 +++--- aleph-client/src/pallets/multisig.rs | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index d0973f7586..e4c38e2dcd 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -305,7 +305,7 @@ impl SignedConnectionApi for S { .await .map_err(|e| anyhow!("Failed to submit transaction: {:?}", e))?; - let coords: TxInfo = match status { + let info: TxInfo = match status { TxStatus::InBlock => progress .wait_for_in_block() .await? @@ -316,9 +316,9 @@ impl SignedConnectionApi for S { // In case of Submitted coords do not mean anything TxStatus::Submitted => return Ok(Default::default()), }; - info!(target: "aleph-client", "tx with hash {} included in block {}", coords.tx_hash, coords.block_hash); + info!(target: "aleph-client", "tx with hash {} included in block {}", info.tx_hash, info.block_hash); - Ok(coords) + Ok(info) } fn account_id(&self) -> &AccountId { diff --git a/aleph-client/src/pallets/multisig.rs b/aleph-client/src/pallets/multisig.rs index 9207517cb9..2032029e49 100644 --- a/aleph-client/src/pallets/multisig.rs +++ b/aleph-client/src/pallets/multisig.rs @@ -443,7 +443,7 @@ impl MultisigContextualApi for S { ) -> anyhow::Result<(TxInfo, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; - let tx_coords = self + let tx_info = self .approve_as_multi( party.threshold, other_signatories, @@ -461,11 +461,11 @@ impl MultisigContextualApi for S { // `connections` module. Secondly, if `Timepoint` struct change, this method (reading raw // extrinsic position) might become incorrect. let timepoint = self - .get_timepoint(&party.account(), &call_hash, Some(tx_coords.block_hash)) + .get_timepoint(&party.account(), &call_hash, Some(tx_info.block_hash)) .await; Ok(( - tx_coords, + tx_info, Context::new( party.clone(), self.account_id().clone(), @@ -486,7 +486,7 @@ impl MultisigContextualApi for S { ) -> anyhow::Result<(TxInfo, Context)> { let other_signatories = ensure_signer_in_party(self, party)?; - let tx_coords = self + let tx_info = self .as_multi( party.threshold, other_signatories, @@ -499,11 +499,11 @@ impl MultisigContextualApi for S { let call_hash = compute_call_hash(&call); let timepoint = self - .get_timepoint(&party.account(), &call_hash, Some(tx_coords.block_hash)) + .get_timepoint(&party.account(), &call_hash, Some(tx_info.block_hash)) .await; Ok(( - tx_coords, + tx_info, Context::new( party.clone(), self.account_id().clone(), @@ -531,7 +531,7 @@ impl MultisigContextualApi for S { status, ) .await - .map(|tx_coords| (tx_coords, context.add_approval(self.account_id().clone()))) + .map(|tx_info| (tx_info, context.add_approval(self.account_id().clone()))) } async fn approve_with_call( @@ -569,7 +569,7 @@ impl MultisigContextualApi for S { status, ) .await - .map(|tx_coords| (tx_coords, context.add_approval(self.account_id().clone()))) + .map(|tx_info| (tx_info, context.add_approval(self.account_id().clone()))) } async fn cancel( @@ -584,7 +584,7 @@ impl MultisigContextualApi for S { "Only the author can cancel multisig aggregation" ); - let tx_coords = self + let tx_info = self .cancel_as_multi( context.party.threshold, other_signatories, @@ -594,7 +594,7 @@ impl MultisigContextualApi for S { ) .await?; - Ok((tx_coords, context.close())) + Ok((tx_info, context.close())) } } From 7681dbd034dbe2b2bf334d32ae3a4e79f6d4a863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 09:40:56 +0100 Subject: [PATCH 11/14] Correct info for submitted --- aleph-client/src/connections.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index e4c38e2dcd..9a0bc56fd0 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -109,7 +109,7 @@ pub trait ConnectionApi: Sync { } /// Data regarding submitted transaction. -#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, Deserialize, Serialize)] +#[derive(Copy, Clone, Eq, PartialEq, Debug, Deserialize, Serialize)] pub struct TxInfo { pub block_hash: BlockHash, pub tx_hash: TxHash, @@ -313,8 +313,13 @@ impl SignedConnectionApi for S { .await? .into(), TxStatus::Finalized => progress.wait_for_finalized_success().await?.into(), - // In case of Submitted coords do not mean anything - TxStatus::Submitted => return Ok(Default::default()), + // In case of Submitted block hash do not mean anything + TxStatus::Submitted => { + return Ok(TxInfo { + block_hash: Default::default(), + tx_hash: progress.extrinsic_hash(), + }) + } }; info!(target: "aleph-client", "tx with hash {} included in block {}", info.tx_hash, info.block_hash); From 58315e0e369797c23ffe078a1ebbf246bda30d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 09:52:52 +0100 Subject: [PATCH 12/14] Grammar --- aleph-client/src/connections.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index 9a0bc56fd0..28be3f0324 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -313,7 +313,7 @@ impl SignedConnectionApi for S { .await? .into(), TxStatus::Finalized => progress.wait_for_finalized_success().await?.into(), - // In case of Submitted block hash do not mean anything + // In case of Submitted block hash does not mean anything TxStatus::Submitted => { return Ok(TxInfo { block_hash: Default::default(), From 7dd756270419e867d96e4f607391b70cddea9045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 11:30:29 +0100 Subject: [PATCH 13/14] xD for the first time --- aleph-client/src/connections.rs | 6 +++--- e2e-tests/src/test/fee.rs | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/aleph-client/src/connections.rs b/aleph-client/src/connections.rs index 28be3f0324..f4c7b77568 100644 --- a/aleph-client/src/connections.rs +++ b/aleph-client/src/connections.rs @@ -118,8 +118,8 @@ pub struct TxInfo { impl From> for TxInfo { fn from(ee: ExtrinsicEvents) -> Self { Self { - block_hash: ee.extrinsic_hash(), - tx_hash: ee.block_hash(), + block_hash: ee.block_hash(), + tx_hash: ee.extrinsic_hash(), } } } @@ -321,7 +321,7 @@ impl SignedConnectionApi for S { }) } }; - info!(target: "aleph-client", "tx with hash {} included in block {}", info.tx_hash, info.block_hash); + info!(target: "aleph-client", "tx with hash {:?} included in block {:?}", info.tx_hash, info.block_hash); Ok(info) } diff --git a/e2e-tests/src/test/fee.rs b/e2e-tests/src/test/fee.rs index 31b7be2b64..5f32204251 100644 --- a/e2e-tests/src/test/fee.rs +++ b/e2e-tests/src/test/fee.rs @@ -2,8 +2,7 @@ use aleph_client::{ api::transaction_payment::events::TransactionFeePaid, pallets::{balances::BalanceUserApi, fee::TransactionPaymentApi, system::SystemSudoApi}, utility::BlocksApi, - waiting::{AlephWaiting, BlockStatus}, - AccountId, RootConnection, SignedConnection, SignedConnectionApi, TxStatus, + AccountId, RootConnection, SignedConnection, TxStatus, }; use log::info; use primitives::Balance; @@ -108,9 +107,6 @@ pub async fn current_fees( ) -> (Balance, u128) { let actual_multiplier = connection.get_next_fee_multiplier(None).await; - let waiting_connection = connection.clone(); - let signer = connection.account_id().clone(); - let tx_info = match tip { None => connection.transfer(to, transfer_value, TxStatus::Finalized), Some(tip) => connection.transfer_with_tip(to, transfer_value, tip, TxStatus::Finalized), From 2e35cefbc292e0015c7620fa6a78a35f871d22d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Miko=C5=82ajczyk?= Date: Fri, 13 Jan 2023 11:37:02 +0100 Subject: [PATCH 14/14] xD for the second time --- aleph-client/src/utility.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aleph-client/src/utility.rs b/aleph-client/src/utility.rs index 42acfcca1f..b68236fed5 100644 --- a/aleph-client/src/utility.rs +++ b/aleph-client/src/utility.rs @@ -1,7 +1,7 @@ use anyhow::anyhow; use log::info; use primitives::{BlockNumber, EraIndex, SessionIndex}; -use subxt::{blocks::ExtrinsicEvents, ext::sp_core::Hasher, Config}; +use subxt::{blocks::ExtrinsicEvents, ext::sp_runtime::traits::Hash, Config}; use crate::{ connections::{AsConnection, TxInfo}, @@ -117,7 +117,7 @@ impl BlocksApi for C { let extrinsic_events = block_body .extrinsics() - .find(|tx| tx_info.tx_hash == ::Hashing::hash(tx.bytes())) + .find(|tx| tx_info.tx_hash == ::Hashing::hash_of(&tx.bytes())) .ok_or(anyhow!("Couldn't find the transaction in the block."))? .events() .await