Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove BatchDeliveryTransaction::new and BatchConfirmationTransaction::new to avoid expects #1726

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 7 additions & 16 deletions 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 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