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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review + fix
  • Loading branch information
kostekIV committed Nov 17, 2022
commit a808a0457aa48110fce9cef1d3eb6408ae8bb94a
22 changes: 11 additions & 11 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use codec::Decode;
use log::info;
use subxt::{
ext::sp_core::{Bytes, H256},
ext::sp_core::Bytes,
metadata::DecodeWithMetadata,
rpc::RpcParams,
storage::{address::Yes, StaticStorageAddress, StorageAddress},
tx::{BaseExtrinsicParamsBuilder, PlainTip, TxPayload},
SubstrateConfig,
};

use crate::{api, Call, Client, KeyPair, TxStatus};
use crate::{api, BlockHash, Call, Client, KeyPair, TxStatus};

#[derive(Clone)]
pub struct Connection {
Expand All @@ -28,20 +28,20 @@ pub struct RootConnection {

#[async_trait::async_trait]
pub trait SudoCall {
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<H256>;
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<H256>;
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash>;
}

#[async_trait::async_trait]
impl SudoCall for RootConnection {
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<H256> {
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash> {
info!(target: "aleph-client", "sending call as sudo_unchecked {:?}", call);
let sudo = api::tx().sudo().sudo_unchecked_weight(call, 0);

self.as_signed().send_tx(sudo, status).await
}

async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<H256> {
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash> {
info!(target: "aleph-client", "sending call as sudo {:?}", call);
let sudo = api::tx().sudo().sudo(call);

Expand All @@ -61,7 +61,7 @@ impl Connection {
pub async fn get_storage_entry<T: DecodeWithMetadata, _0, _1>(
&self,
addrs: &StaticStorageAddress<T, Yes, _0, _1>,
at: Option<H256>,
at: Option<BlockHash>,
) -> T::Target {
self.get_storage_entry_maybe(addrs, at)
.await
Expand All @@ -71,7 +71,7 @@ impl Connection {
pub async fn get_storage_entry_maybe<T: DecodeWithMetadata, _0, _1>(
&self,
addrs: &StaticStorageAddress<T, Yes, _0, _1>,
at: Option<H256>,
at: Option<BlockHash>,
) -> Option<T::Target> {
info!(target: "aleph-client", "accessing storage at {}::{} at block {:?}", addrs.pallet_name(), addrs.entry_name(), at);
self.client
Expand Down Expand Up @@ -106,7 +106,7 @@ impl SignedConnection {
&self,
tx: Call,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
self.send_tx_with_params(tx, Default::default(), status)
.await
}
Expand All @@ -116,7 +116,7 @@ impl SignedConnection {
tx: Call,
params: BaseExtrinsicParamsBuilder<SubstrateConfig, PlainTip>,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
if let Some(details) = tx.validation_details() {
info!(target:"aleph-client", "Sending extrinsic {}.{} with params: {:?}", details.pallet_name, details.call_name, params);
}
Expand All @@ -131,7 +131,7 @@ impl SignedConnection {
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 => H256::random(),
TxStatus::Submitted => return Ok(BlockHash::from_low_u64_be(0)),
};
info!(target: "aleph-client", "tx included in block {:?}", hash);

Expand Down
3 changes: 2 additions & 1 deletion aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate core;

pub use subxt::ext::sp_core::Pair;
use subxt::{
ext::sp_core::{ed25519, sr25519},
ext::sp_core::{ed25519, sr25519, H256},
tx::PairSigner,
OnlineClient, PolkadotConfig,
};
Expand All @@ -28,6 +28,7 @@ pub type RawKeyPair = sr25519::Pair;
pub type KeyPair = PairSigner<AlephConfig, sr25519::Pair>;
pub type AccountId = subxt::ext::sp_core::crypto::AccountId32;
pub type Client = OnlineClient<AlephConfig>;
pub type BlockHash = H256;

pub use connections::{Connection, RootConnection, SignedConnection, SudoCall};

Expand Down
16 changes: 8 additions & 8 deletions aleph-client/src/pallets/aleph.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use codec::Encode;
use primitives::{BlockNumber, SessionIndex};
use subxt::{ext::sp_core::H256, rpc_params};
use subxt::rpc_params;

use crate::{
api::runtime_types::{
pallet_aleph::pallet::Call::set_emergency_finalizer, primitives::app::Public,
sp_core::ed25519::Public as EdPublic,
},
pallet_aleph::pallet::Call::schedule_finality_version_change,
AccountId, AlephKeyPair,
AccountId, AlephKeyPair, BlockHash,
Call::Aleph,
Connection, Pair, RootConnection, SudoCall, TxStatus,
};
Expand All @@ -19,22 +19,22 @@ pub trait AlephSudoApi {
&self,
finalizer: AccountId,
status: TxStatus,
) -> anyhow::Result<H256>;
) -> anyhow::Result<BlockHash>;

async fn schedule_finality_version_change(
&self,
version: u32,
session: SessionIndex,
status: TxStatus,
) -> anyhow::Result<H256>;
) -> anyhow::Result<BlockHash>;
}

#[async_trait::async_trait]
pub trait AlephRpc {
async fn emergency_finalize(
&self,
number: BlockNumber,
hash: H256,
hash: BlockHash,
key_pair: AlephKeyPair,
) -> anyhow::Result<()>;
}
Expand All @@ -45,7 +45,7 @@ impl AlephSudoApi for RootConnection {
&self,
finalizer: AccountId,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
let call = Aleph(set_emergency_finalizer {
emergency_finalizer: Public(EdPublic(finalizer.into())),
});
Expand All @@ -57,7 +57,7 @@ impl AlephSudoApi for RootConnection {
version: u32,
session: SessionIndex,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
let call = Aleph(schedule_finality_version_change {
version_incoming: version,
session,
Expand All @@ -72,7 +72,7 @@ impl AlephRpc for Connection {
async fn emergency_finalize(
&self,
number: BlockNumber,
hash: H256,
hash: BlockHash,
key_pair: AlephKeyPair,
) -> anyhow::Result<()> {
let method = "alephNode_emergencyFinalize";
Expand Down
31 changes: 14 additions & 17 deletions aleph-client/src/pallets/balances.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use primitives::Balance;
use subxt::{
ext::{sp_core::H256, sp_runtime::MultiAddress},
tx::PolkadotExtrinsicParamsBuilder,
};
use subxt::{ext::sp_runtime::MultiAddress, tx::PolkadotExtrinsicParamsBuilder};

use crate::{
aleph_zero::{self, api, api::runtime_types::pallet_balances::BalanceLock},
pallet_balances::pallet::Call::transfer,
pallets::utility::UtilityApi,
AccountId,
AccountId, BlockHash,
Call::Balances,
Connection, SignedConnection, TxStatus,
};
Expand All @@ -18,14 +15,14 @@ pub trait BalanceApi {
async fn locks_for_account(
&self,
account: AccountId,
at: Option<H256>,
at: Option<BlockHash>,
) -> Vec<BalanceLock<Balance>>;
async fn locks(
&self,
accounts: &[AccountId],
at: Option<H256>,
at: Option<BlockHash>,
) -> Vec<Vec<BalanceLock<Balance>>>;
async fn total_issuance(&self, at: Option<H256>) -> Balance;
async fn total_issuance(&self, at: Option<BlockHash>) -> Balance;
}

#[async_trait::async_trait]
Expand All @@ -35,14 +32,14 @@ pub trait BalanceUserApi {
dest: AccountId,
amount: Balance,
status: TxStatus,
) -> anyhow::Result<H256>;
) -> anyhow::Result<BlockHash>;
async fn transfer_with_tip(
&self,
dest: AccountId,
amount: Balance,
tip: Balance,
status: TxStatus,
) -> anyhow::Result<H256>;
) -> anyhow::Result<BlockHash>;
}

#[async_trait::async_trait]
Expand All @@ -52,15 +49,15 @@ pub trait BalanceUserBatchExtApi {
dest: &[AccountId],
amount: Balance,
status: TxStatus,
) -> anyhow::Result<H256>;
) -> anyhow::Result<BlockHash>;
}

#[async_trait::async_trait]
impl BalanceApi for Connection {
async fn locks_for_account(
&self,
account: AccountId,
at: Option<H256>,
at: Option<BlockHash>,
) -> Vec<BalanceLock<Balance>> {
let address = aleph_zero::api::storage().balances().locks(&account);

Expand All @@ -70,7 +67,7 @@ impl BalanceApi for Connection {
async fn locks(
&self,
accounts: &[AccountId],
at: Option<H256>,
at: Option<BlockHash>,
) -> Vec<Vec<BalanceLock<Balance>>> {
let mut locks = vec![];

Expand All @@ -81,7 +78,7 @@ impl BalanceApi for Connection {
locks
}

async fn total_issuance(&self, at: Option<H256>) -> Balance {
async fn total_issuance(&self, at: Option<BlockHash>) -> Balance {
let address = api::storage().balances().total_issuance();

self.get_storage_entry(&address, at).await
Expand All @@ -95,7 +92,7 @@ impl BalanceUserApi for SignedConnection {
dest: AccountId,
amount: Balance,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
let tx = api::tx()
.balances()
.transfer(MultiAddress::Id(dest), amount);
Expand All @@ -108,7 +105,7 @@ impl BalanceUserApi for SignedConnection {
amount: Balance,
tip: Balance,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
let tx = api::tx()
.balances()
.transfer(MultiAddress::Id(dest), amount);
Expand All @@ -125,7 +122,7 @@ impl BalanceUserBatchExtApi for SignedConnection {
dests: &[AccountId],
amount: Balance,
status: TxStatus,
) -> anyhow::Result<H256> {
) -> anyhow::Result<BlockHash> {
let calls = dests
.iter()
.map(|dest| {
Expand Down
Loading