Skip to content

Commit

Permalink
remove BatchDeliveryTransaction::new and BatchConfirmationTransaction…
Browse files Browse the repository at this point in the history
…::new to avoid expects (paritytech#1726)
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 2cf250b commit a221b51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
23 changes: 7 additions & 16 deletions bridges/relays/lib-substrate-relay/src/messages_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ where
) -> Result<Option<Self::BatchTransaction>, SubstrateError> {
if let Some(ref target_to_source_headers_relay) = self.target_to_source_headers_relay {
if P::SourceBatchCallBuilder::BATCH_CALL_SUPPORTED {
return BatchConfirmationTransaction::<P>::new(self.clone(), id).await.map(Some)
let (proved_header, prove_calls) =
target_to_source_headers_relay.prove_header(id.0).await?;
return Ok(Some(BatchConfirmationTransaction {
messages_source: self.clone(),
proved_header,
prove_calls,
}))
}

target_to_source_headers_relay.require_more_headers(id.0).await;
Expand All @@ -384,21 +390,6 @@ pub struct BatchConfirmationTransaction<P: SubstrateMessageLane> {
prove_calls: Vec<CallOf<P::SourceChain>>,
}

impl<P: SubstrateMessageLane> BatchConfirmationTransaction<P> {
async fn new(
messages_source: SubstrateMessagesSource<P>,
required_target_header_on_source: TargetHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<Self, SubstrateError> {
let (proved_header, prove_calls) = messages_source
.target_to_source_headers_relay
.as_ref()
.expect("BatchConfirmationTransaction is only created when target_to_source_headers_relay is Some; qed")
.prove_header(required_target_header_on_source.0)
.await?;
Ok(Self { messages_source, proved_header, prove_calls })
}
}

#[async_trait]
impl<P: SubstrateMessageLane>
BatchTransaction<
Expand Down
23 changes: 7 additions & 16 deletions bridges/relays/lib-substrate-relay/src/messages_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,13 @@ where
) -> Result<Option<Self::BatchTransaction>, SubstrateError> {
if let Some(ref source_to_target_headers_relay) = self.source_to_target_headers_relay {
if P::TargetBatchCallBuilder::BATCH_CALL_SUPPORTED {
return BatchDeliveryTransaction::<P>::new(self.clone(), id).await.map(Some)
let (proved_header, prove_calls) =
source_to_target_headers_relay.prove_header(id.0).await?;
return Ok(Some(BatchDeliveryTransaction {
messages_target: self.clone(),
proved_header,
prove_calls,
}))
}

source_to_target_headers_relay.require_more_headers(id.0).await;
Expand All @@ -291,21 +297,6 @@ pub struct BatchDeliveryTransaction<P: SubstrateMessageLane> {
prove_calls: Vec<CallOf<P::TargetChain>>,
}

impl<P: SubstrateMessageLane> BatchDeliveryTransaction<P> {
async fn new(
messages_target: SubstrateMessagesTarget<P>,
required_source_header_on_target: SourceHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<Self, SubstrateError> {
let (proved_header, prove_calls) = messages_target
.source_to_target_headers_relay
.as_ref()
.expect("BatchDeliveryTransaction is only created when source_to_target_headers_relay is Some; qed")
.prove_header(required_source_header_on_target.0)
.await?;
Ok(Self { messages_target, proved_header, prove_calls })
}
}

#[async_trait]
impl<P: SubstrateMessageLane>
BatchTransaction<
Expand Down

0 comments on commit a221b51

Please sign in to comment.