From 09ea0ce4e0329105c75aa6f7221fd67edda06605 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 16 Nov 2023 09:23:36 -0500 Subject: [PATCH] refactor TryFromDto --- bindings/core/src/method_handler/client.rs | 2 +- bindings/core/src/method_handler/wallet.rs | 4 +- .../offline_signing/3_send_transaction.rs | 2 +- sdk/src/client/api/types.rs | 23 ++-- sdk/src/client/node_api/core/routes.rs | 4 +- sdk/src/types/block/core/basic.rs | 10 +- sdk/src/types/block/core/mod.rs | 14 ++- sdk/src/types/block/core/signed_block.rs | 22 ++-- sdk/src/types/block/core/validation.rs | 12 +- sdk/src/types/block/mana/allotment.rs | 9 +- sdk/src/types/block/payload/mod.rs | 10 +- .../block/payload/signed_transaction/mod.rs | 10 +- .../payload/signed_transaction/transaction.rs | 52 ++++---- sdk/src/types/mod.rs | 111 +----------------- sdk/src/wallet/core/mod.rs | 14 +-- .../transaction/build_transaction.rs | 2 +- sdk/src/wallet/types/mod.rs | 10 +- sdk/tests/client/signing/account.rs | 4 +- sdk/tests/client/signing/basic.rs | 6 +- sdk/tests/client/signing/mod.rs | 2 +- sdk/tests/client/signing/nft.rs | 2 +- 21 files changed, 123 insertions(+), 202 deletions(-) diff --git a/bindings/core/src/method_handler/client.rs b/bindings/core/src/method_handler/client.rs index 22bb79bb2f..91dffa93f4 100644 --- a/bindings/core/src/method_handler/client.rs +++ b/bindings/core/src/method_handler/client.rs @@ -196,7 +196,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM client .post_block(&SignedBlock::try_from_dto_with_params( block, - client.get_protocol_parameters().await?, + &client.get_protocol_parameters().await?, )?) .await?, ), diff --git a/bindings/core/src/method_handler/wallet.rs b/bindings/core/src/method_handler/wallet.rs index 6825dc72e0..d7dc3d1121 100644 --- a/bindings/core/src/method_handler/wallet.rs +++ b/bindings/core/src/method_handler/wallet.rs @@ -367,7 +367,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM .sign_and_submit_transaction( PreparedTransactionData::try_from_dto_with_params( prepared_transaction_data, - wallet.client().get_protocol_parameters().await?, + &wallet.client().get_protocol_parameters().await?, )?, None, ) @@ -387,7 +387,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM } => { let signed_transaction_data = SignedTransactionData::try_from_dto_with_params( signed_transaction_data, - wallet.client().get_protocol_parameters().await?, + &wallet.client().get_protocol_parameters().await?, )?; let transaction = wallet .submit_and_store_transaction(signed_transaction_data, None) diff --git a/sdk/examples/wallet/offline_signing/3_send_transaction.rs b/sdk/examples/wallet/offline_signing/3_send_transaction.rs index 8d1c91f13e..43f68883f7 100644 --- a/sdk/examples/wallet/offline_signing/3_send_transaction.rs +++ b/sdk/examples/wallet/offline_signing/3_send_transaction.rs @@ -56,7 +56,7 @@ async fn read_signed_transaction_from_file(client: &Client) -> Result for PreparedTransactionDataDto { } } -impl TryFromDto for PreparedTransactionData { - type Dto = PreparedTransactionDataDto; +impl TryFromDto for PreparedTransactionData { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: PreparedTransactionDataDto, + params: Option<&ProtocolParameters>, + ) -> Result { Ok(Self { - transaction: Transaction::try_from_dto_with_params(dto.transaction, ¶ms) + transaction: Transaction::try_from_dto_with_params_inner(dto.transaction, params) .map_err(|_| Error::InvalidField("transaction"))?, inputs_data: dto .inputs_data @@ -109,13 +112,15 @@ impl From<&SignedTransactionData> for SignedTransactionDataDto { } } -impl TryFromDto for SignedTransactionData { - type Dto = SignedTransactionDataDto; +impl TryFromDto for SignedTransactionData { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: SignedTransactionDataDto, + params: Option<&ProtocolParameters>, + ) -> Result { Ok(Self { - payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, ¶ms) + payload: SignedTransactionPayload::try_from_dto_with_params_inner(dto.payload, params) .map_err(|_| Error::InvalidField("transaction_payload"))?, inputs_data: dto .inputs_data diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 191ec80130..404b5d83a3 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -199,7 +199,7 @@ impl ClientInner { Ok(SignedBlock::try_from_dto_with_params( dto, - self.get_protocol_parameters().await?, + &self.get_protocol_parameters().await?, )?) } @@ -256,7 +256,7 @@ impl ClientInner { Ok(SignedBlock::try_from_dto_with_params( dto, - self.get_protocol_parameters().await?, + &self.get_protocol_parameters().await?, )?) } diff --git a/sdk/src/types/block/core/basic.rs b/sdk/src/types/block/core/basic.rs index 1ce750986e..a7109a6210 100644 --- a/sdk/src/types/block/core/basic.rs +++ b/sdk/src/types/block/core/basic.rs @@ -175,7 +175,7 @@ pub(crate) mod dto { use super::*; use crate::types::{ block::{payload::dto::PayloadDto, BlockId, Error}, - TryFromDto, ValidationParams, + TryFromDto, }; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -205,11 +205,13 @@ pub(crate) mod dto { } } - impl TryFromDto for BasicBlock { - type Dto = BasicBlockDto; + impl TryFromDto for BasicBlock { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: BasicBlockDto, + params: Option<&ProtocolParameters>, + ) -> Result { BasicBlockBuilder::new(StrongParents::from_set(dto.strong_parents)?, dto.max_burned_mana) .with_weak_parents(WeakParents::from_set(dto.weak_parents)?) .with_shallow_like_parents(ShallowLikeParents::from_set(dto.shallow_like_parents)?) diff --git a/sdk/src/types/block/core/mod.rs b/sdk/src/types/block/core/mod.rs index c873d35dff..051190ba34 100644 --- a/sdk/src/types/block/core/mod.rs +++ b/sdk/src/types/block/core/mod.rs @@ -113,7 +113,7 @@ pub(crate) mod dto { pub use crate::types::block::core::signed_block::dto::{SignedBlockDto, UnsignedBlockDto}; use crate::types::{ block::core::{basic::dto::BasicBlockDto, validation::dto::ValidationBlockDto}, - TryFromDto, ValidationParams, + TryFromDto, }; #[derive(Clone, Debug, Eq, PartialEq, From)] @@ -195,14 +195,16 @@ pub(crate) mod dto { } } - impl TryFromDto for Block { - type Dto = BlockDto; + impl TryFromDto for Block { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: BlockDto, + params: Option<&ProtocolParameters>, + ) -> Result { match dto { - Self::Dto::Basic(basic) => Ok(BasicBlock::try_from_dto_with_params_inner(basic, params)?.into()), - Self::Dto::Validation(validation) => { + BlockDto::Basic(basic) => Ok(BasicBlock::try_from_dto_with_params_inner(basic, params)?.into()), + BlockDto::Validation(validation) => { Ok(ValidationBlock::try_from_dto_with_params_inner(validation, params)?.into()) } } diff --git a/sdk/src/types/block/core/signed_block.rs b/sdk/src/types/block/core/signed_block.rs index 0c6b13ca2f..b961c85fb7 100644 --- a/sdk/src/types/block/core/signed_block.rs +++ b/sdk/src/types/block/core/signed_block.rs @@ -342,7 +342,7 @@ pub(crate) mod dto { use super::*; use crate::{ - types::{block::core::dto::BlockDto, TryFromDto, ValidationParams}, + types::{block::core::dto::BlockDto, TryFromDto}, utils::serde::string, }; @@ -380,12 +380,14 @@ pub(crate) mod dto { } } - impl TryFromDto for SignedBlock { - type Dto = SignedBlockDto; + impl TryFromDto for SignedBlock { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { - if let Some(protocol_params) = params.protocol_parameters() { + fn try_from_dto_with_params_inner( + dto: SignedBlockDto, + params: Option<&ProtocolParameters>, + ) -> Result { + if let Some(protocol_params) = params { if dto.inner.protocol_version != protocol_params.version() { return Err(Error::ProtocolVersionMismatch { expected: protocol_params.version(), @@ -444,12 +446,14 @@ pub(crate) mod dto { } } - impl TryFromDto for UnsignedBlock { - type Dto = UnsignedBlockDto; + impl TryFromDto for UnsignedBlock { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { - if let Some(protocol_params) = params.protocol_parameters() { + fn try_from_dto_with_params_inner( + dto: UnsignedBlockDto, + params: Option<&ProtocolParameters>, + ) -> Result { + if let Some(protocol_params) = params { if dto.protocol_version != protocol_params.version() { return Err(Error::ProtocolVersionMismatch { expected: protocol_params.version(), diff --git a/sdk/src/types/block/core/validation.rs b/sdk/src/types/block/core/validation.rs index 3e37275bc7..545574250f 100644 --- a/sdk/src/types/block/core/validation.rs +++ b/sdk/src/types/block/core/validation.rs @@ -202,7 +202,7 @@ pub(crate) mod dto { use super::*; use crate::types::{ block::{BlockId, Error}, - TryFromDto, ValidationParams, + TryFromDto, }; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -230,12 +230,14 @@ pub(crate) mod dto { } } - impl TryFromDto for ValidationBlock { - type Dto = ValidationBlockDto; + impl TryFromDto for ValidationBlock { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { - if let Some(protocol_params) = params.protocol_parameters() { + fn try_from_dto_with_params_inner( + dto: ValidationBlockDto, + params: Option<&ProtocolParameters>, + ) -> Result { + if let Some(protocol_params) = params { verify_protocol_parameters_hash::(&dto.protocol_parameters_hash, protocol_params)?; } diff --git a/sdk/src/types/block/mana/allotment.rs b/sdk/src/types/block/mana/allotment.rs index fbb319f4d2..1069f9aace 100644 --- a/sdk/src/types/block/mana/allotment.rs +++ b/sdk/src/types/block/mana/allotment.rs @@ -76,15 +76,14 @@ pub(super) mod dto { } } - impl TryFromDto for ManaAllotment { - type Dto = ManaAllotmentDto; + impl TryFromDto for ManaAllotment { type Error = Error; fn try_from_dto_with_params_inner( - dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + dto: ManaAllotmentDto, + params: Option<&ProtocolParameters>, ) -> Result { - Ok(if let Some(params) = params.protocol_parameters() { + Ok(if let Some(params) = params { Self::new(dto.account_id, dto.mana, params)? } else { Self { diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index c88fcad25f..b20b03cfe4 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -162,7 +162,7 @@ pub mod dto { pub use super::signed_transaction::dto::SignedTransactionPayloadDto; use super::*; - use crate::types::{block::Error, TryFromDto, ValidationParams}; + use crate::types::{block::Error, TryFromDto}; /// Describes all the different payload types. #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -197,11 +197,13 @@ pub mod dto { } } - impl TryFromDto for Payload { - type Dto = PayloadDto; + impl TryFromDto for Payload { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: PayloadDto, + params: Option<&ProtocolParameters>, + ) -> Result { Ok(match dto { PayloadDto::TaggedData(p) => Self::from(*p), PayloadDto::SignedTransaction(p) => { diff --git a/sdk/src/types/block/payload/signed_transaction/mod.rs b/sdk/src/types/block/payload/signed_transaction/mod.rs index caf4bc2233..5721d70afd 100644 --- a/sdk/src/types/block/payload/signed_transaction/mod.rs +++ b/sdk/src/types/block/payload/signed_transaction/mod.rs @@ -91,7 +91,7 @@ pub mod dto { use super::*; use crate::types::{ block::{unlock::Unlock, Error}, - TryFromDto, ValidationParams, + TryFromDto, }; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -112,11 +112,13 @@ pub mod dto { } } - impl TryFromDto for SignedTransactionPayload { - type Dto = SignedTransactionPayloadDto; + impl TryFromDto for SignedTransactionPayload { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: SignedTransactionPayloadDto, + params: Option<&ProtocolParameters>, + ) -> Result { let transaction = Transaction::try_from_dto_with_params_inner(dto.transaction, params)?; Self::new(transaction, Unlocks::new(dto.unlocks)?) } diff --git a/sdk/src/types/block/payload/signed_transaction/transaction.rs b/sdk/src/types/block/payload/signed_transaction/transaction.rs index b9f085d3da..8b8bea5d33 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -8,22 +8,19 @@ use hashbrown::HashSet; use packable::{bounded::BoundedU16, prefix::BoxedSlicePrefix, Packable, PackableExt}; use crate::{ - types::{ - block::{ - capabilities::{Capabilities, CapabilityFlag}, - context_input::{ContextInput, CONTEXT_INPUT_COUNT_RANGE}, - input::{Input, INPUT_COUNT_RANGE}, - mana::{verify_mana_allotments_sum, ManaAllotment, ManaAllotments}, - output::{NativeTokens, Output, OUTPUT_COUNT_RANGE}, - payload::{ - signed_transaction::{TransactionHash, TransactionId, TransactionSigningHash}, - OptionalPayload, Payload, - }, - protocol::ProtocolParameters, - slot::SlotIndex, - Error, + types::block::{ + capabilities::{Capabilities, CapabilityFlag}, + context_input::{ContextInput, CONTEXT_INPUT_COUNT_RANGE}, + input::{Input, INPUT_COUNT_RANGE}, + mana::{verify_mana_allotments_sum, ManaAllotment, ManaAllotments}, + output::{NativeTokens, Output, OUTPUT_COUNT_RANGE}, + payload::{ + signed_transaction::{TransactionHash, TransactionId, TransactionSigningHash}, + OptionalPayload, Payload, }, - ValidationParams, + protocol::ProtocolParameters, + slot::SlotIndex, + Error, }, utils::merkle_hasher, }; @@ -123,10 +120,13 @@ impl TransactionBuilder { } /// Finishes a [`TransactionBuilder`] into a [`Transaction`]. - pub fn finish_with_params<'a>(self, params: impl Into> + Send) -> Result { + pub fn finish_with_params<'a>( + self, + params: impl Into>, + ) -> Result { let params = params.into(); - if let Some(protocol_parameters) = params.protocol_parameters() { + if let Some(protocol_parameters) = params { if self.network_id != protocol_parameters.network_id() { return Err(Error::NetworkIdMismatch { expected: protocol_parameters.network_id(), @@ -139,7 +139,7 @@ impl TransactionBuilder { .creation_slot .or_else(|| { #[cfg(feature = "std")] - let creation_slot = params.protocol_parameters().map(|params| { + let creation_slot = params.map(|params| { params.slot_index( std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) @@ -169,7 +169,7 @@ impl TransactionBuilder { let allotments = ManaAllotments::from_set(self.allotments)?; - if let Some(protocol_parameters) = params.protocol_parameters() { + if let Some(protocol_parameters) = params { verify_mana_allotments_sum(allotments.iter(), protocol_parameters)?; } @@ -181,7 +181,7 @@ impl TransactionBuilder { .try_into() .map_err(Error::InvalidOutputCount)?; - if let Some(protocol_parameters) = params.protocol_parameters() { + if let Some(protocol_parameters) = params { verify_outputs::(&outputs, protocol_parameters)?; } @@ -200,7 +200,7 @@ impl TransactionBuilder { /// Finishes a [`TransactionBuilder`] into a [`Transaction`] without protocol /// validation. pub fn finish(self) -> Result { - self.finish_with_params(ValidationParams::default()) + self.finish_with_params(None) } } @@ -576,11 +576,13 @@ pub(crate) mod dto { } } - impl TryFromDto for Transaction { - type Dto = TransactionDto; + impl TryFromDto for Transaction { type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner( + dto: TransactionDto, + params: Option<&ProtocolParameters>, + ) -> Result { let network_id = dto .network_id .parse::() @@ -588,7 +590,7 @@ pub(crate) mod dto { let mana_allotments = dto .allotments .into_iter() - .map(|o| ManaAllotment::try_from_dto_with_params(o, ¶ms)) + .map(|o| ManaAllotment::try_from_dto_with_params_inner(o, params)) .collect::, Error>>()?; let outputs = dto .outputs diff --git a/sdk/src/types/mod.rs b/sdk/src/types/mod.rs index 3351fd0074..e8c63c81bc 100644 --- a/sdk/src/types/mod.rs +++ b/sdk/src/types/mod.rs @@ -10,117 +10,18 @@ extern crate std; pub mod api; pub mod block; -use core::ops::Deref; - use self::block::protocol::ProtocolParameters; -/// Borrowed or Owned. Useful for generic impls and UX. -#[derive(Clone, Debug)] -pub enum Boo<'a, T> { - Borrowed(&'a T), - Owned(T), -} - -impl<'a, T> Boo<'a, T> { - pub fn into_owned(self) -> T - where - T: Clone, - { - match self { - Boo::Borrowed(b) => b.clone(), - Boo::Owned(o) => o, - } - } -} - -impl<'a, T> AsRef for Boo<'a, T> { - fn as_ref(&self) -> &T { - self.deref() - } -} - -impl<'a, T> Deref for Boo<'a, T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - match *self { - Boo::Borrowed(b) => b, - Boo::Owned(ref o) => o, - } - } -} - -impl<'a, T> From for Boo<'a, T> { - fn from(value: T) -> Self { - Self::Owned(value) - } -} - -impl<'a, T> From<&'a T> for Boo<'a, T> { - fn from(value: &'a T) -> Self { - Self::Borrowed(value) - } -} - -impl<'a, T> From<&'a Boo<'a, T>> for Boo<'a, T> { - fn from(value: &'a Boo<'a, T>) -> Self { - match *value { - Self::Borrowed(b) => Self::Borrowed(b), - Self::Owned(ref o) => Self::Borrowed(o), - } - } -} - -#[derive(Clone, Default, Debug)] -pub struct ValidationParams<'a> { - protocol_parameters: Option>, -} - -impl<'a> ValidationParams<'a> { - pub fn with_protocol_parameters(mut self, protocol_parameters: impl Into>) -> Self { - self.protocol_parameters.replace(protocol_parameters.into()); - self - } - - pub fn protocol_parameters(&self) -> Option<&ProtocolParameters> { - self.protocol_parameters.as_deref() - } -} - -impl<'a> From for ValidationParams<'a> { - fn from(value: ProtocolParameters) -> Self { - Self::default().with_protocol_parameters(value) - } -} - -impl<'a> From<&'a ProtocolParameters> for ValidationParams<'a> { - fn from(value: &'a ProtocolParameters) -> Self { - Self::default().with_protocol_parameters(value) - } -} - -impl<'a> From<&'a ValidationParams<'a>> for ValidationParams<'a> { - fn from(value: &'a ValidationParams<'a>) -> Self { - Self { - protocol_parameters: value.protocol_parameters.as_ref().map(Into::into), - } - } -} - -pub trait TryFromDto: Sized { - type Dto; +pub trait TryFromDto: Sized { type Error; - fn try_from_dto(dto: Self::Dto) -> Result { - Self::try_from_dto_with_params(dto, ValidationParams::default()) + fn try_from_dto(dto: Dto) -> Result { + Self::try_from_dto_with_params_inner(dto, None) } - fn try_from_dto_with_params<'a>( - dto: Self::Dto, - params: impl Into> + Send, - ) -> Result { - Self::try_from_dto_with_params_inner(dto, params.into()) + fn try_from_dto_with_params(dto: Dto, params: &ProtocolParameters) -> Result { + Self::try_from_dto_with_params_inner(dto, Some(params)) } - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result; + fn try_from_dto_with_params_inner(dto: Dto, params: Option<&ProtocolParameters>) -> Result; } diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index f9ee311fab..3cb0a9900b 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -38,6 +38,7 @@ use crate::{ OutputId, TokenId, }, payload::signed_transaction::TransactionId, + protocol::ProtocolParameters, }, TryFromDto, }, @@ -578,13 +579,12 @@ pub struct WalletDataDto { pub native_token_foundries: HashMap, } -impl TryFromDto for WalletData { - type Dto = WalletDataDto; +impl TryFromDto for WalletData { type Error = crate::wallet::Error; fn try_from_dto_with_params_inner( - dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + dto: WalletDataDto, + params: Option<&ProtocolParameters>, ) -> core::result::Result { Ok(Self { bip_path: dto.bip_path, @@ -604,13 +604,13 @@ impl TryFromDto for WalletData { transactions: dto .transactions .into_iter() - .map(|(id, o)| Ok((id, TransactionWithMetadata::try_from_dto_with_params(o, ¶ms)?))) + .map(|(id, o)| Ok((id, TransactionWithMetadata::try_from_dto_with_params_inner(o, params)?))) .collect::>()?, pending_transactions: dto.pending_transactions, incoming_transactions: dto .incoming_transactions .into_iter() - .map(|(id, o)| Ok((id, TransactionWithMetadata::try_from_dto_with_params(o, ¶ms)?))) + .map(|(id, o)| Ok((id, TransactionWithMetadata::try_from_dto_with_params_inner(o, params)?))) .collect::>()?, inaccessible_incoming_transactions: Default::default(), native_token_foundries: dto @@ -715,7 +715,7 @@ mod test { .with_inputs([input1, input2]) .add_output(output) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters) + .finish_with_params(&protocol_parameters) .unwrap(); let pub_key_bytes = prefix_hex::decode(ED25519_PUBLIC_KEY).unwrap(); diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index a390abebc7..b5d9ce6dc7 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -51,7 +51,7 @@ where builder = builder.with_payload(options.tagged_data_payload); } - let transaction = builder.finish_with_params(protocol_parameters)?; + let transaction = builder.finish_with_params(&protocol_parameters)?; validate_transaction_length(&transaction)?; diff --git a/sdk/src/wallet/types/mod.rs b/sdk/src/wallet/types/mod.rs index cc70a0a417..f50f4b8615 100644 --- a/sdk/src/wallet/types/mod.rs +++ b/sdk/src/wallet/types/mod.rs @@ -24,6 +24,7 @@ use crate::{ address::Address, output::{dto::OutputDto, Output, OutputId, OutputMetadata}, payload::signed_transaction::{dto::SignedTransactionPayloadDto, SignedTransactionPayload, TransactionId}, + protocol::ProtocolParameters, slot::SlotIndex, BlockId, Error as BlockError, }, @@ -201,16 +202,15 @@ impl From<&TransactionWithMetadata> for TransactionWithMetadataDto { } } -impl TryFromDto for TransactionWithMetadata { - type Dto = TransactionWithMetadataDto; +impl TryFromDto for TransactionWithMetadata { type Error = BlockError; fn try_from_dto_with_params_inner( - dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + dto: TransactionWithMetadataDto, + params: Option<&ProtocolParameters>, ) -> Result { Ok(Self { - payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, params)?, + payload: SignedTransactionPayload::try_from_dto_with_params_inner(dto.payload, params)?, block_id: dto.block_id, inclusion_state: dto.inclusion_state, timestamp: dto diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index e510d3c0c0..9696182f7d 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -78,7 +78,7 @@ async fn sign_account_state_transition() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -186,7 +186,7 @@ async fn account_reference_unlocks() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index d7390f0d30..e0b1519fbb 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -72,7 +72,7 @@ async fn single_ed25519_unlock() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -167,7 +167,7 @@ async fn ed25519_reference_unlocks() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -273,7 +273,7 @@ async fn two_signature_unlocks() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index c2e1171c67..55c63fddf9 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -377,7 +377,7 @@ async fn all_combined() -> Result<()> { .with_outputs(outputs) .with_creation_slot(slot_index) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index 0508bc5bcd..1d4a52c785 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -117,7 +117,7 @@ async fn nft_reference_unlocks() -> Result<()> { ) .with_outputs(outputs) .add_mana_allotment(rand_mana_allotment(&protocol_parameters)) - .finish_with_params(protocol_parameters)?; + .finish_with_params(&protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction,