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
wip
  • Loading branch information
krzysztofziobro committed Dec 30, 2022
commit 0247e81175012df810a56f7a9cb1c5b7a7a8a34f
34 changes: 24 additions & 10 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ use subxt::{

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

pub type Connection = Client;
#[derive(Clone)]
pub struct Connection {
client: Client,
}

impl Connection {
pub(crate) fn as_client(&self) -> &Client {
&self.client
}
}

const DEFAULT_RETRIES: u32 = 10;
const RETRY_WAIT_SECS: u64 = 1;
Expand All @@ -27,7 +36,7 @@ async fn create_connection_with_retries(address: &str, mut retries: u32) -> Conn
loop {
let client = Client::from_url(&address).await;
match (retries, client) {
(_, Ok(client)) => return client,
(_, Ok(client)) => return Connection { client },
(0, Err(e)) => panic!("{:?}", e),
_ => {
sleep(Duration::from_secs(RETRY_WAIT_SECS));
Expand Down Expand Up @@ -141,7 +150,7 @@ impl<C: AsConnection> ConnectionExt for C {
at: Option<BlockHash>,
) -> Option<T::Target> {
info!(target: "aleph-client", "accessing storage at {}::{} at block {:?}", addrs.pallet_name(), addrs.entry_name(), at);
self.as_connection()
self.as_client()
.storage()
.fetch(addrs, at)
.await
Expand All @@ -150,11 +159,7 @@ impl<C: AsConnection> ConnectionExt for C {

async fn rpc_call<R: Decode>(&self, func_name: String, params: RpcParams) -> anyhow::Result<R> {
info!(target: "aleph-client", "submitting rpc call `{}`, with params {:?}", func_name, params);
let bytes: Bytes = self
.as_connection()
.rpc()
.request(&func_name, params)
.await?;
let bytes: Bytes = self.as_client().rpc().request(&func_name, params).await?;

Ok(R::decode(&mut bytes.as_ref())?)
}
Expand Down Expand Up @@ -193,6 +198,7 @@ impl SignedConnection {
}
let progress = self
.connection
.as_client()
.tx()
.sign_and_submit_then_watch(&tx, &self.signer, params)
.await?;
Expand All @@ -214,10 +220,18 @@ impl RootConnection {
RootConnection::try_from_connection(create_connection(address).await, root).await
}

pub async fn try_from_connection(connection: Client, signer: KeyPair) -> anyhow::Result<Self> {
pub async fn try_from_connection(
connection: Connection,
signer: KeyPair,
) -> anyhow::Result<Self> {
let root_address = api::storage().sudo().key();

let root = match connection.storage().fetch(&root_address, None).await {
let root = match connection
.as_client()
.storage()
.fetch(&root_address, None)
.await
{
Ok(Some(account)) => account,
_ => return Err(anyhow!("Could not read sudo key from chain")),
};
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 @@ -26,9 +26,10 @@ pub type AlephKeyPair = ed25519::Pair;
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(crate) type Client = OnlineClient<AlephConfig>;

pub use connections::{
create_connection, AsConnection, Connection, ConnectionExt, RootConnection, SignedConnection,
SudoCall,
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/src/pallets/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait AuthorRpc {
#[async_trait::async_trait]
impl<C: ConnectionExt> AuthorRpc for C {
async fn author_rotate_keys(&self) -> anyhow::Result<SessionKeys> {
let bytes = self.as_connection().rpc().rotate_keys().await?;
let bytes = self.as_client().rpc().rotate_keys().await?;
SessionKeys::decode(&mut bytes.0.as_slice()).map_err(|e| e.into())
}
}
2 changes: 1 addition & 1 deletion aleph-client/src/pallets/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<C: ConnectionExt> ElectionsApi for C {

async fn get_session_period(&self) -> anyhow::Result<u32> {
let addrs = api::constants().elections().session_period();
self.as_connection()
self.as_client()
.constants()
.at(&addrs)
.map_err(|e| e.into())
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 @@ -183,7 +183,7 @@ impl<C: ConnectionExt> StakingApi for C {

async fn get_session_per_era(&self) -> anyhow::Result<u32> {
let addrs = api::constants().staking().sessions_per_era();
self.as_connection()
self.as_client()
.constants()
.at(&addrs)
.map_err(|e| e.into())
Expand Down Expand Up @@ -306,7 +306,7 @@ impl<C: ConnectionExt> StakingRawApi for C {
let key_addrs = api::storage().staking().eras_stakers_root();
let mut key = key_addrs.to_root_bytes();
StorageMapKey::new(era, StorageHasher::Twox64Concat).to_bytes(&mut key);
self.as_connection()
self.as_client()
.storage()
.fetch_keys(&key, 10, None, at)
.await
Expand Down
6 changes: 3 additions & 3 deletions aleph-client/src/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<C: ConnectionExt> BlocksApi for C {

async fn get_block_hash(&self, block: BlockNumber) -> anyhow::Result<Option<BlockHash>> {
info!(target: "aleph-client", "querying block hash for number #{}", block);
self.as_connection()
self.as_client()
.rpc()
.block_hash(Some(block.into()))
.await
Expand All @@ -53,7 +53,7 @@ impl<C: ConnectionExt> BlocksApi for C {
}

async fn get_finalized_block_hash(&self) -> anyhow::Result<BlockHash> {
self.as_connection()
self.as_client()
.rpc()
.finalized_head()
.await
Expand All @@ -64,7 +64,7 @@ impl<C: ConnectionExt> BlocksApi for C {
&self,
block: Option<BlockHash>,
) -> anyhow::Result<Option<BlockNumber>> {
self.as_connection()
self.as_client()
.rpc()
.header(block)
.await
Expand Down
10 changes: 5 additions & 5 deletions aleph-client/src/waiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ impl<C: ConnectionExt> AlephWaiting for C {
async fn wait_for_block<P: Fn(u32) -> bool + Send>(&self, predicate: P, status: BlockStatus) {
let mut block_sub = match status {
BlockStatus::Best => self
.as_connection()
.as_client()
.blocks()
.subscribe_best()
.await
.expect("Failed to subscribe to the best block stream!"),
BlockStatus::Finalized => self
.as_connection()
.as_client()
.blocks()
.subscribe_finalized()
.await
Expand All @@ -65,13 +65,13 @@ impl<C: ConnectionExt> AlephWaiting for C {
) -> T {
let mut block_sub = match status {
BlockStatus::Best => self
.as_connection()
.as_client()
.blocks()
.subscribe_best()
.await
.expect("Failed to subscribe to the best block stream!"),
BlockStatus::Finalized => self
.as_connection()
.as_client()
.blocks()
.subscribe_finalized()
.await
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<C: ConnectionExt> AlephWaiting for C {
async fn wait_for_era(&self, era: EraIndex, status: BlockStatus) {
let addrs = aleph_zero::api::constants().staking().sessions_per_era();
let sessions_per_era = self
.as_connection()
.as_client()
.constants()
.at(&addrs)
.expect("Failed to obtain sessions_per_era const!");
Expand Down
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.