Skip to content

Commit

Permalink
Made it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Nov 13, 2024
1 parent d2c76f2 commit 97ea329
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 145 deletions.
6 changes: 3 additions & 3 deletions avail-rust/src/transactions/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Balances {
.await?;

let event = find_event_or_return_error::<BalancesEvents::Transfer>(
"Failed to find Transfer event",
"Failed to find Balances::Transfer event",
&details,
)?;
let event2 = find_event_or_nothing::<SystemEvents::KilledAccount>(&details);
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Balances {
.await?;

let event = find_event_or_return_error::<BalancesEvents::Transfer>(
"Failed to find Transfer event",
"Failed to find Balances::Transfer event",
&details,
)?;
let event2 = find_event_or_nothing::<SystemEvents::KilledAccount>(&details);
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Balances {
.await?;

let event = find_event_or_return_error::<BalancesEvents::Transfer>(
"Failed to find Transfer event",
"Failed to find Balances::Transfer event",
&details,
)?;

Expand Down
35 changes: 15 additions & 20 deletions avail-rust/src/transactions/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use avail::sudo::events as SudoEvents;
use subxt::backend::rpc::RpcClient;
use subxt_signer::sr25519::Keypair;

use super::{find_event_or_return_error, TransactionFailed};
use super::{find_data_or_return_error, find_event_or_return_error, TransactionFailed};
use super::{options::Options, progress_and_parse_transaction, TransactionDetails};

#[derive(Debug)]
Expand Down Expand Up @@ -78,21 +78,16 @@ impl DataAvailability {
.await?;

let event = find_event_or_return_error::<DataAvailabilityEvents::DataSubmitted>(
"Failed to find DataSubmitted event",
"Failed to find DataAvailability::DataSubmitted event",
&details,
)?;

let block = details.fetch_block(&self.online_client).await;
let block = block.map_err(|e| TransactionFailed {
reason: e.into(),
details: Some(details.clone()),
})?;

let data = block
.transaction_by_index_static::<DataAvailabilityCalls::SubmitData>(details.tx_index);
let data = data
.ok_or(String::from("Failed to find transaction data"))?
.value;
let data = find_data_or_return_error::<DataAvailabilityCalls::SubmitData>(
&self.online_client,
"Failed to find DataAvailability::SubmitData data",
&details,
)
.await?;

Ok(SubmitDataTx {
event,
Expand Down Expand Up @@ -120,7 +115,7 @@ impl DataAvailability {
.await?;

let event = find_event_or_return_error::<DataAvailabilityEvents::ApplicationKeyCreated>(
"Failed to find ApplicationKeyCreated event",
"Failed to find DataAvailability::ApplicationKeyCreated event",
&details,
)?;

Expand Down Expand Up @@ -153,7 +148,7 @@ impl DataAvailability {
.await?;

let sudo_event = find_event_or_return_error::<SudoEvents::Sudid>(
"Failed to find Sudid event",
"Failed to find Sudo::Sudid event",
&details,
)?;

Expand All @@ -165,7 +160,7 @@ impl DataAvailability {
}

let event = find_event_or_return_error::<DataAvailabilityEvents::ApplicationKeySet>(
"Failed to find ApplicationKeySet event",
"Failed to find DataAvailability::ApplicationKeySet event",
&details,
)?;

Expand Down Expand Up @@ -198,7 +193,7 @@ impl DataAvailability {
.await?;

let sudo_event = find_event_or_return_error::<SudoEvents::Sudid>(
"Failed to find Sudid event",
"Failed to find Sudo::Sudid event",
&details,
)?;

Expand All @@ -211,7 +206,7 @@ impl DataAvailability {

let event =
find_event_or_return_error::<DataAvailabilityEvents::BlockLengthProposalSubmitted>(
"Failed to find BlockLengthProposalSubmitted event",
"Failed to find DataAvailability::BlockLengthProposalSubmitted event",
&details,
)?;

Expand Down Expand Up @@ -242,7 +237,7 @@ impl DataAvailability {
.await?;

let sudo_event = find_event_or_return_error::<SudoEvents::Sudid>(
"Failed to find Sudid event",
"Failed to find Sudo::Sudid event",
&details,
)?;

Expand All @@ -254,7 +249,7 @@ impl DataAvailability {
}

let event = find_event_or_return_error::<DataAvailabilityEvents::SubmitDataFeeModifierSet>(
"Failed to find SubmitDataFeeModifierSet event",
"Failed to find DataAvailability::SubmitDataFeeModifierSet event",
&details,
)?;

Expand Down
33 changes: 29 additions & 4 deletions avail-rust/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ pub mod staking;
use crate::{
error::ClientError,
utils::{self, *},
AOnlineClient, ATxInBlock, AvailConfig, H256,
AExtrinsicEvents, AOnlineClient, ATxInBlock, AvailConfig, H256,
};

pub use options::{Mortality, Nonce, Options};

use std::sync::Arc;
use subxt::{backend::rpc::RpcClient, blocks::ExtrinsicEvents, events::StaticEvent};
use subxt::{backend::rpc::RpcClient, blocks::StaticExtrinsic, events::StaticEvent};

pub type Params =
<<AvailConfig as subxt::Config>::ExtrinsicParams as subxt::config::ExtrinsicParams<
Expand Down Expand Up @@ -48,7 +48,7 @@ impl Transactions {
#[derive(Debug, Clone)]
pub struct TransactionDetails {
pub tx_in_block: Arc<ATxInBlock>,
pub events: Arc<ExtrinsicEvents<AvailConfig>>,
pub events: Arc<AExtrinsicEvents>,
pub tx_hash: H256,
pub tx_index: u32,
pub block_hash: H256,
Expand All @@ -58,7 +58,7 @@ pub struct TransactionDetails {
impl TransactionDetails {
pub fn new(
tx_in_block: ATxInBlock,
events: ExtrinsicEvents<AvailConfig>,
events: AExtrinsicEvents,
tx_hash: H256,
tx_index: u32,
block_hash: H256,
Expand Down Expand Up @@ -158,6 +158,31 @@ impl From<(ClientError, TransactionDetails)> for TransactionFailed {
}
}

async fn find_data_or_return_error<T: StaticExtrinsic>(
client: &AOnlineClient,
error: &str,
details: &TransactionDetails,
) -> Result<T, TransactionFailed> {
let block = details.fetch_block(client).await;
let block = block.map_err(|e| TransactionFailed {
reason: e.into(),
details: Some(details.clone()),
})?;

let data = block.transaction_by_index_static::<T>(details.tx_index);
let data = match data {
Some(d) => d.value,
None => {
return Err(TransactionFailed {
reason: error.into(),
details: Some(details.clone()),
})
},
};

Ok(data)
}

fn find_event_or_return_error<T: StaticEvent>(
error: &str,
details: &TransactionDetails,
Expand Down
Loading

0 comments on commit 97ea329

Please sign in to comment.