Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
31 changes: 20 additions & 11 deletions components/client-crab-s2s/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use common_primitives::Balance;
use common_primitives::BlockNumber;
use dp_fee::{Order, Relayer};
use relay_substrate_client::{ChainBase, Client, TransactionSignScheme, UnsignedTransaction};
use relay_utils::relay_loop::Client as RelayLoopClient;
use sp_core::storage::StorageKey;
use sp_core::{Bytes, Pair};

Expand All @@ -22,14 +23,17 @@ impl CrabApi {
}

impl CrabApi {
pub async fn client(&self) -> &Client<CrabChain> {
&self.client
pub async fn client(&self) -> anyhow::Result<Client<CrabChain>> {
let mut client = self.client.clone();
client.reconnect().await?;
Ok(client)
Comment thread
fewensa marked this conversation as resolved.
Outdated
}

/// Query assigned relayers
pub async fn assigned_relayers(&self) -> anyhow::Result<Vec<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "AssignedRelayers".as_bytes())
Expand All @@ -48,7 +52,8 @@ impl CrabApi {
message_nonce: MessageNonce,
) -> anyhow::Result<Option<Order<AccountId, BlockNumber, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -63,7 +68,8 @@ impl CrabApi {
/// Query all relayers
pub async fn relayers(&self) -> anyhow::Result<Vec<AccountId>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "Relayers".as_bytes()).to_vec(),
Expand All @@ -80,7 +86,8 @@ impl CrabApi {
account: AccountId,
) -> anyhow::Result<Option<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -100,7 +107,7 @@ impl CrabApi {
pub async fn best_finalized_header_number(
&self,
) -> anyhow::Result<common_primitives::BlockNumber> {
Ok(self.client.best_finalized_header_number().await?)
Ok(self.client().await?.best_finalized_header_number().await?)
}

/// Update relay fee
Expand All @@ -110,8 +117,9 @@ impl CrabApi {
amount: <CrabChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
CrabChain::sign_transaction(
Expand All @@ -137,8 +145,9 @@ impl CrabApi {
amount: <CrabChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
CrabChain::sign_transaction(
Expand Down
31 changes: 20 additions & 11 deletions components/client-darwinia-s2s/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use common_primitives::Balance;
use common_primitives::BlockNumber;
use dp_fee::{Order, Relayer};
use relay_substrate_client::{ChainBase, Client, TransactionSignScheme, UnsignedTransaction};
use relay_utils::relay_loop::Client as RelayLoopClient;
use sp_core::storage::StorageKey;
use sp_core::{Bytes, Pair};

Expand All @@ -22,14 +23,17 @@ impl DarwiniaApi {
}

impl DarwiniaApi {
pub async fn client(&self) -> &Client<DarwiniaChain> {
&self.client
pub async fn client(&self) -> anyhow::Result<Client<DarwiniaChain>> {
let mut client = self.client.clone();
client.reconnect().await?;
Ok(client)
}

/// Query assigned relayers
pub async fn assigned_relayers(&self) -> anyhow::Result<Vec<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "AssignedRelayers".as_bytes())
Expand All @@ -44,7 +48,8 @@ impl DarwiniaApi {
/// Query all relayers
pub async fn relayers(&self) -> anyhow::Result<Vec<AccountId>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "Relayers".as_bytes()).to_vec(),
Expand All @@ -61,7 +66,8 @@ impl DarwiniaApi {
account: AccountId,
) -> anyhow::Result<Option<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -84,7 +90,8 @@ impl DarwiniaApi {
message_nonce: MessageNonce,
) -> anyhow::Result<Option<Order<AccountId, BlockNumber, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -100,7 +107,7 @@ impl DarwiniaApi {
pub async fn best_finalized_header_number(
&self,
) -> anyhow::Result<common_primitives::BlockNumber> {
Ok(self.client.best_finalized_header_number().await?)
Ok(self.client().await?.best_finalized_header_number().await?)
}

/// Update relay fee
Expand All @@ -110,8 +117,9 @@ impl DarwiniaApi {
amount: <DarwiniaChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
DarwiniaChain::sign_transaction(
Expand All @@ -137,8 +145,9 @@ impl DarwiniaApi {
amount: <DarwiniaChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
DarwiniaChain::sign_transaction(
Expand Down
31 changes: 20 additions & 11 deletions components/client-pangolin-s2s/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use common_primitives::Balance;
use common_primitives::BlockNumber;
use dp_fee::{Order, Relayer};
use relay_substrate_client::{ChainBase, Client, TransactionSignScheme, UnsignedTransaction};
use relay_utils::relay_loop::Client as RelayLoopClient;
use sp_core::storage::StorageKey;
use sp_core::{Bytes, Pair};

Expand All @@ -22,14 +23,17 @@ impl PangolinApi {
}

impl PangolinApi {
pub async fn client(&self) -> &Client<PangolinChain> {
&self.client
pub async fn client(&self) -> anyhow::Result<Client<PangolinChain>> {
let mut client = self.client.clone();
client.reconnect().await?;
Ok(client)
}

/// Query assigned relayers
pub async fn assigned_relayers(&self) -> anyhow::Result<Vec<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "AssignedRelayers".as_bytes())
Expand All @@ -44,7 +48,8 @@ impl PangolinApi {
/// Query all relayers
pub async fn relayers(&self) -> anyhow::Result<Vec<AccountId>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "Relayers".as_bytes()).to_vec(),
Expand All @@ -61,7 +66,8 @@ impl PangolinApi {
account: AccountId,
) -> anyhow::Result<Option<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -84,7 +90,8 @@ impl PangolinApi {
message_nonce: MessageNonce,
) -> anyhow::Result<Option<Order<AccountId, BlockNumber, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -100,7 +107,7 @@ impl PangolinApi {
pub async fn best_finalized_header_number(
&self,
) -> anyhow::Result<common_primitives::BlockNumber> {
Ok(self.client.best_finalized_header_number().await?)
Ok(self.client().await?.best_finalized_header_number().await?)
}

/// Update relay fee
Expand All @@ -110,8 +117,9 @@ impl PangolinApi {
amount: <PangolinChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
PangolinChain::sign_transaction(
Expand All @@ -137,8 +145,9 @@ impl PangolinApi {
amount: <PangolinChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
PangolinChain::sign_transaction(
Expand Down
31 changes: 20 additions & 11 deletions components/client-pangoro-s2s/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use common_primitives::Balance;
use common_primitives::BlockNumber;
use dp_fee::{Order, Relayer};
use relay_substrate_client::{ChainBase, Client, TransactionSignScheme, UnsignedTransaction};
use relay_utils::relay_loop::Client as RelayLoopClient;
use sp_core::storage::StorageKey;
use sp_core::{Bytes, Pair};

Expand All @@ -22,14 +23,17 @@ impl PangoroApi {
}

impl PangoroApi {
pub async fn client(&self) -> &Client<PangoroChain> {
&self.client
pub async fn client(&self) -> anyhow::Result<Client<PangoroChain>> {
let mut client = self.client.clone();
client.reconnect().await?;
Ok(client)
}

/// Query assigned relayers
pub async fn assigned_relayers(&self) -> anyhow::Result<Vec<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "AssignedRelayers".as_bytes())
Expand All @@ -48,7 +52,8 @@ impl PangoroApi {
message_nonce: MessageNonce,
) -> anyhow::Result<Option<Order<AccountId, BlockNumber, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -63,7 +68,8 @@ impl PangoroApi {
/// Query all relayers
pub async fn relayers(&self) -> anyhow::Result<Vec<AccountId>> {
Ok(self
.client
.client()
.await?
.storage_value(
StorageKey(
patch::storage_prefix("FeeMarket".as_bytes(), "Relayers".as_bytes()).to_vec(),
Expand All @@ -80,7 +86,8 @@ impl PangoroApi {
account: AccountId,
) -> anyhow::Result<Option<Relayer<AccountId, Balance>>> {
Ok(self
.client
.client()
.await?
.storage_value(
bp_runtime::storage_map_final_key_blake2_128concat(
"FeeMarket",
Expand All @@ -100,7 +107,7 @@ impl PangoroApi {
pub async fn best_finalized_header_number(
&self,
) -> anyhow::Result<common_primitives::BlockNumber> {
Ok(self.client.best_finalized_header_number().await?)
Ok(self.client().await?.best_finalized_header_number().await?)
}

/// Update relay fee
Expand All @@ -110,8 +117,9 @@ impl PangoroApi {
amount: <PangoroChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
PangoroChain::sign_transaction(
Expand All @@ -137,8 +145,9 @@ impl PangoroApi {
amount: <PangoroChain as ChainBase>::Balance,
) -> anyhow::Result<()> {
let signer_id = (*signer.public().as_array_ref()).into();
let genesis_hash = *self.client.genesis_hash();
self.client
let client = self.client().await?;
let genesis_hash = *client.genesis_hash();
client
.submit_signed_extrinsic(signer_id, move |_, transaction_nonce| {
Bytes(
PangoroChain::sign_transaction(
Expand Down