Skip to content

Commit

Permalink
Move to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
pmikolajczyk41 committed Jan 13, 2023
1 parent 48a5ccd commit cb58f2a
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 44 deletions.
22 changes: 2 additions & 20 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -108,22 +106,6 @@ pub trait ConnectionApi: Sync {
async fn rpc_call<R: Decode>(&self, func_name: String, params: RpcParams) -> anyhow::Result<R>;
}

/// 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<ExtrinsicEvents<AlephConfig>> for TxInfo {
fn from(ee: ExtrinsicEvents<AlephConfig>) -> 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 {
Expand Down
20 changes: 20 additions & 0 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ExtrinsicEvents<AlephConfig>> for TxInfo {
fn from(ee: ExtrinsicEvents<AlephConfig>) -> Self {
Self {
block_hash: ee.extrinsic_hash(),
tx_hash: ee.block_hash(),
}
}
}
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/aleph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/session.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions aleph-client/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/src/pallets/utility.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions aleph-client/src/pallets/vesting.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/Cargo.lock

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

2 changes: 1 addition & 1 deletion e2e-tests/Cargo.lock

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

2 changes: 1 addition & 1 deletion flooder/Cargo.lock

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

0 comments on commit cb58f2a

Please sign in to comment.