Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2e22b79
dont use String for creating connections
krzysztofziobro Dec 27, 2022
20aafa6
do not wrap client
krzysztofziobro Dec 27, 2022
1f10b03
wip
krzysztofziobro Dec 28, 2022
2f5cda9
should work as old one
krzysztofziobro Dec 28, 2022
f5b769f
hide connection
krzysztofziobro Dec 28, 2022
44a4e9a
hide the rest
krzysztofziobro Dec 28, 2022
1472fd7
Don not hide clone
krzysztofziobro Dec 28, 2022
40225ca
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 29, 2022
168ce19
bump
krzysztofziobro Dec 29, 2022
0247e81
wip
krzysztofziobro Dec 30, 2022
4c1a6eb
wrap client
krzysztofziobro Dec 30, 2022
e41d124
rename client
krzysztofziobro Dec 30, 2022
7968aea
add Clone
krzysztofziobro Dec 30, 2022
9a979f6
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Dec 30, 2022
50d7071
more general adder
krzysztofziobro Dec 30, 2022
dba9561
Add AsSigned
krzysztofziobro Dec 30, 2022
d700129
add impls for references
krzysztofziobro Dec 30, 2022
e45f361
wip
krzysztofziobro Jan 2, 2023
e6839b8
change TreasurySudoApi
krzysztofziobro Jan 2, 2023
8ec4625
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
3bf05d5
add methods to SignedConnectionApi
krzysztofziobro Jan 2, 2023
6b259b2
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
23d5a58
remove unnecessary casts
krzysztofziobro Jan 2, 2023
5600e11
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 2, 2023
b7ad771
review part 1
krzysztofziobro Jan 2, 2023
d156320
Merge branch 'A0-1613-improve-connection' of github.com:Cardinal-Cryp…
krzysztofziobro Jan 2, 2023
ef5625d
review part 2
krzysztofziobro Jan 2, 2023
af4d737
Make AsConnection visible only in crate
krzysztofziobro Jan 3, 2023
d15be1b
Merge branch 'main' into A0-1613-improve-connection
krzysztofziobro Jan 3, 2023
70db49a
Remove unnecessary dependencies on ConnectionApi
krzysztofziobro Jan 4, 2023
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
Add AsSigned
  • Loading branch information
krzysztofziobro committed Dec 30, 2022
commit dba95618f625ab5868a8a9823bece2b712195ff8
26 changes: 19 additions & 7 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub trait AsConnection: Sync {
fn as_connection(&self) -> &Connection;
}

pub trait AsSigned: Sync {
fn as_signed(&self) -> SignedConnection;
}

#[async_trait::async_trait]
pub trait ConnectionExt: AsConnection {
async fn get_storage_entry<T: DecodeWithMetadata + Sync, Defaultable: Sync, Iterable: Sync>(
Expand Down Expand Up @@ -140,6 +144,21 @@ impl AsConnection for RootConnection {
}
}

impl AsSigned for SignedConnection {
fn as_signed(&self) -> SignedConnection {
self.clone()
}
}

impl AsSigned for RootConnection {
fn as_signed(&self) -> SignedConnection {
SignedConnection {
connection: self.connection.clone(),
signer: KeyPair::new(self.root.signer().clone()),
}
}
}

#[async_trait::async_trait]
impl<C: AsConnection> ConnectionExt for C {
async fn get_storage_entry<T: DecodeWithMetadata + Sync, Defaultable: Sync, Iterable: Sync>(
Expand Down Expand Up @@ -282,11 +301,4 @@ impl RootConnection {
root: signer,
})
}

pub fn as_signed(&self) -> SignedConnection {
SignedConnection {
connection: self.connection.clone(),
signer: KeyPair::new(self.root.signer().clone()),
}
}
}
4 changes: 2 additions & 2 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub type BlockHash = H256;
pub(crate) type SubxtClient = OnlineClient<AlephConfig>;

pub use connections::{
create_connection, AsConnection, Connection, ConnectionExt, RootConnection, SignedConnection,
SudoCall,
create_connection, AsConnection, AsSigned, Connection, ConnectionExt, RootConnection,
SignedConnection, SudoCall,
};

#[derive(Copy, Clone)]
Expand Down
18 changes: 9 additions & 9 deletions aleph-client/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::{
pallet_sudo::pallet::Call::sudo_as,
pallets::utility::UtilityApi,
sp_arithmetic::per_things::Perbill,
AccountId, BlockHash,
AccountId, AsSigned, BlockHash,
Call::{Staking, Sudo},
ConnectionExt, RootConnection, SignedConnection, SudoCall, TxStatus,
ConnectionExt, RootConnection, SudoCall, TxStatus,
};

#[async_trait::async_trait]
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<C: ConnectionExt> StakingApi for C {
}

#[async_trait::async_trait]
impl StakingUserApi for SignedConnection {
impl<S: AsSigned> StakingUserApi for S {
async fn bond(
&self,
initial_stake: Balance,
Expand All @@ -205,7 +205,7 @@ impl StakingUserApi for SignedConnection {
RewardDestination::Staked,
);

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

async fn validate(
Expand All @@ -220,7 +220,7 @@ impl StakingUserApi for SignedConnection {
blocked: false,
});

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

async fn payout_stakers(
Expand All @@ -231,7 +231,7 @@ impl StakingUserApi for SignedConnection {
) -> anyhow::Result<BlockHash> {
let tx = api::tx().staking().payout_stakers(stash_account, era);

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

async fn nominate(
Expand All @@ -243,13 +243,13 @@ impl StakingUserApi for SignedConnection {
.staking()
.nominate(vec![MultiAddress::Id(nominee_account_id)]);

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

async fn chill(&self, status: TxStatus) -> anyhow::Result<BlockHash> {
let tx = api::tx().staking().chill();

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

async fn bond_extra_stake(
Expand All @@ -259,7 +259,7 @@ impl StakingUserApi for SignedConnection {
) -> anyhow::Result<BlockHash> {
let tx = api::tx().staking().bond_extra(extra_stake);

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

Expand Down
2 changes: 1 addition & 1 deletion benches/payout-stakers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aleph_client::{
staking::{StakingApi, StakingApiExt, StakingUserApi},
},
waiting::{BlockStatus, WaitingExt},
AccountId, ConnectionExt, KeyPair, RootConnection, SignedConnection, TxStatus,
AccountId, AsSigned, ConnectionExt, KeyPair, RootConnection, SignedConnection, TxStatus,
};
use clap::{ArgGroup, Parser};
use futures::future::join_all;
Expand Down
2 changes: 1 addition & 1 deletion bin/cliain/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use aleph_client::{
session::{SessionApi, SessionUserApi},
staking::StakingUserApi,
},
AccountId, Connection, RootConnection, SignedConnection, TxStatus,
AccountId, AsSigned, Connection, RootConnection, SignedConnection, TxStatus,
};
use hex::ToHex;
use log::{error, info};
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use aleph_client::{
primitives::{CommitteeSeats, EraValidators},
utility::BlocksApi,
waiting::{AlephWaiting, BlockStatus, WaitingExt},
AccountId, SignedConnection, TxStatus,
AccountId, AsSigned, SignedConnection, TxStatus,
};
use anyhow::anyhow;
use log::{debug, info};
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/test/electing_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aleph_client::{
},
primitives::CommitteeSeats,
waiting::{BlockStatus, WaitingExt},
AccountId, ConnectionExt, KeyPair, Pair, SignedConnection, TxStatus,
AccountId, AsSigned, ConnectionExt, KeyPair, Pair, SignedConnection, TxStatus,
};
use log::info;
use primitives::EraIndex;
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/test/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use aleph_client::{
primitives::CommitteeSeats,
sp_core::bounded::bounded_vec::BoundedVec,
waiting::{BlockStatus, WaitingExt},
AccountId, KeyPair, Pair, SignedConnection, TxStatus,
AccountId, AsSigned, KeyPair, Pair, SignedConnection, TxStatus,
};
use log::info;
use primitives::{
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/src/test/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aleph_client::{
treasury::{TreasureApiExt, TreasuryApi, TreasuryUserApi},
},
waiting::{AlephWaiting, BlockStatus},
AsConnection, ConnectionExt, KeyPair, RootConnection, SignedConnection, TxStatus,
AsConnection, AsSigned, ConnectionExt, KeyPair, RootConnection, SignedConnection, TxStatus,
};
use log::info;
use primitives::Balance;
Expand Down