From 4d50df6ede8796b564a5ea93b84f5a3d27dae93f Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 16 Dec 2022 17:08:35 +0300 Subject: [PATCH] remove BatchDeliveryTransaction::new and BatchConfirmationTransaction::new to avoid expects (#1726) --- .../src/messages_source.rs | 23 ++++++------------- .../src/messages_target.rs | 23 ++++++------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/relays/lib-substrate-relay/src/messages_source.rs b/relays/lib-substrate-relay/src/messages_source.rs index e2876b3107e..28b5e69410e 100644 --- a/relays/lib-substrate-relay/src/messages_source.rs +++ b/relays/lib-substrate-relay/src/messages_source.rs @@ -367,7 +367,13 @@ where ) -> Result, SubstrateError> { if let Some(ref target_to_source_headers_relay) = self.target_to_source_headers_relay { if P::SourceBatchCallBuilder::BATCH_CALL_SUPPORTED { - return BatchConfirmationTransaction::

::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; @@ -384,21 +390,6 @@ pub struct BatchConfirmationTransaction { prove_calls: Vec>, } -impl BatchConfirmationTransaction

{ - async fn new( - messages_source: SubstrateMessagesSource

, - required_target_header_on_source: TargetHeaderIdOf>, - ) -> Result { - 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 BatchTransaction< diff --git a/relays/lib-substrate-relay/src/messages_target.rs b/relays/lib-substrate-relay/src/messages_target.rs index 9d80b9166c8..5e67461ab30 100644 --- a/relays/lib-substrate-relay/src/messages_target.rs +++ b/relays/lib-substrate-relay/src/messages_target.rs @@ -274,7 +274,13 @@ where ) -> Result, SubstrateError> { if let Some(ref source_to_target_headers_relay) = self.source_to_target_headers_relay { if P::TargetBatchCallBuilder::BATCH_CALL_SUPPORTED { - return BatchDeliveryTransaction::

::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; @@ -291,21 +297,6 @@ pub struct BatchDeliveryTransaction { prove_calls: Vec>, } -impl BatchDeliveryTransaction

{ - async fn new( - messages_target: SubstrateMessagesTarget

, - required_source_header_on_target: SourceHeaderIdOf>, - ) -> Result { - 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 BatchTransaction<