diff --git a/sdk/src/client/api/types.rs b/sdk/src/client/api/types.rs index 3e73780289..fbebe53a74 100644 --- a/sdk/src/client/api/types.rs +++ b/sdk/src/client/api/types.rs @@ -61,19 +61,19 @@ impl TryFromDto for PreparedTransactionData { type Dto = PreparedTransactionDataDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(Self { - transaction: Transaction::try_from_dto_with_params(dto.transaction, ¶ms) + transaction: Transaction::try_from_dto_with_params(dto.transaction, params) .map_err(|_| Error::InvalidField("transaction"))?, inputs_data: dto .inputs_data .into_iter() - .map(|i| InputSigningData::try_from_dto_with_params(i, ¶ms)) + .map(|i| InputSigningData::try_from_dto_with_params(i, params)) .collect::>>() .map_err(|_| Error::InvalidField("input_data"))?, remainder: match dto.remainder { Some(remainder) => Some( - RemainderData::try_from_dto_with_params(remainder, ¶ms) + RemainderData::try_from_dto_with_params(remainder, params) .map_err(|_| Error::InvalidField("remainder"))?, ), None => None, @@ -114,14 +114,14 @@ impl TryFromDto for SignedTransactionData { type Dto = SignedTransactionDataDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(Self { - payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, ¶ms) + payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, params) .map_err(|_| Error::InvalidField("transaction_payload"))?, inputs_data: dto .inputs_data .into_iter() - .map(|i| InputSigningData::try_from_dto_with_params(i, ¶ms)) + .map(|i| InputSigningData::try_from_dto_with_params(i, params)) .collect::>>() .map_err(|_| Error::InvalidField("inputs_data"))?, }) @@ -155,7 +155,7 @@ impl TryFromDto for RemainderData { type Dto = RemainderDataDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(Self { output: Output::try_from_dto_with_params_inner(dto.output, params)?, chain: dto.chain, diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 75e8ba69ae..56f99bffda 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(Block::try_from_dto_with_params( dto, - self.get_protocol_parameters().await?, + &self.get_protocol_parameters().await?, )?) } @@ -257,7 +257,7 @@ impl ClientInner { Ok(Block::try_from_dto_with_params( dto, - self.get_protocol_parameters().await?, + &self.get_protocol_parameters().await?, )?) } diff --git a/sdk/src/client/secret/types.rs b/sdk/src/client/secret/types.rs index 62cc0e5bac..99e8d608bb 100644 --- a/sdk/src/client/secret/types.rs +++ b/sdk/src/client/secret/types.rs @@ -171,7 +171,7 @@ impl TryFromDto for InputSigningData { type Dto = InputSigningDataDto; type Error = crate::client::Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(Self { output: Output::try_from_dto_with_params_inner(dto.output, params)?, output_metadata: dto.output_metadata, diff --git a/sdk/src/types/block/core/basic.rs b/sdk/src/types/block/core/basic.rs index 4b5ac20636..c190fe39ad 100644 --- a/sdk/src/types/block/core/basic.rs +++ b/sdk/src/types/block/core/basic.rs @@ -240,7 +240,7 @@ pub(crate) mod dto { type Dto = BasicBlockBodyDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { BasicBlockBodyBuilder::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/block.rs b/sdk/src/types/block/core/block.rs index 5e8256da68..964698ce43 100644 --- a/sdk/src/types/block/core/block.rs +++ b/sdk/src/types/block/core/block.rs @@ -365,12 +365,7 @@ pub(crate) mod dto { fn from(value: &Block) -> Self { Self { inner: UnsignedBlockDto { - protocol_version: value.protocol_version(), - network_id: value.network_id(), - issuing_time: value.issuing_time(), - slot_commitment_id: value.slot_commitment_id(), - latest_finalized_slot: value.latest_finalized_slot(), - issuer_id: value.issuer_id(), + header: BlockHeaderDto::from(&value.header), body: BlockBodyDto::from(&value.body), }, signature: value.signature, @@ -382,32 +377,25 @@ pub(crate) mod dto { type Dto = BlockDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { if let Some(protocol_params) = params.protocol_parameters() { - if dto.inner.protocol_version != protocol_params.version() { + if dto.inner.header.protocol_version != protocol_params.version() { return Err(Error::ProtocolVersionMismatch { expected: protocol_params.version(), - actual: dto.inner.protocol_version, + actual: dto.inner.header.protocol_version, }); } - if dto.inner.network_id != protocol_params.network_id() { + if dto.inner.header.network_id != protocol_params.network_id() { return Err(Error::NetworkIdMismatch { expected: protocol_params.network_id(), - actual: dto.inner.network_id, + actual: dto.inner.header.network_id, }); } } Ok(Self::new( - BlockHeader::new( - dto.inner.protocol_version, - dto.inner.network_id, - dto.inner.issuing_time, - dto.inner.slot_commitment_id, - dto.inner.latest_finalized_slot, - dto.inner.issuer_id, - ), + BlockHeader::try_from_dto_with_params_inner(dto.inner.header, params)?, BlockBody::try_from_dto_with_params_inner(dto.inner.body, params)?, dto.signature, )) @@ -416,7 +404,7 @@ pub(crate) mod dto { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] - pub struct UnsignedBlockDto { + pub struct BlockHeaderDto { pub protocol_version: u8, #[serde(with = "string")] pub network_id: u64, @@ -425,28 +413,26 @@ pub(crate) mod dto { pub slot_commitment_id: SlotCommitmentId, pub latest_finalized_slot: SlotIndex, pub issuer_id: IssuerId, - pub body: BlockBodyDto, } - impl From<&UnsignedBlock> for UnsignedBlockDto { - fn from(value: &UnsignedBlock) -> Self { + impl From<&BlockHeader> for BlockHeaderDto { + fn from(value: &BlockHeader) -> Self { Self { - protocol_version: value.header.protocol_version(), - network_id: value.header.network_id(), - issuing_time: value.header.issuing_time(), - slot_commitment_id: value.header.slot_commitment_id(), - latest_finalized_slot: value.header.latest_finalized_slot(), - issuer_id: value.header.issuer_id(), - body: BlockBodyDto::from(&value.body), + protocol_version: value.protocol_version(), + network_id: value.network_id(), + issuing_time: value.issuing_time(), + slot_commitment_id: value.slot_commitment_id(), + latest_finalized_slot: value.latest_finalized_slot(), + issuer_id: value.issuer_id(), } } } - impl TryFromDto for UnsignedBlock { - type Dto = UnsignedBlockDto; + impl TryFromDto for BlockHeader { + type Dto = BlockHeaderDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { if let Some(protocol_params) = params.protocol_parameters() { if dto.protocol_version != protocol_params.version() { return Err(Error::ProtocolVersionMismatch { @@ -464,14 +450,39 @@ pub(crate) mod dto { } Ok(Self::new( - BlockHeader::new( - dto.protocol_version, - dto.network_id, - dto.issuing_time, - dto.slot_commitment_id, - dto.latest_finalized_slot, - dto.issuer_id, - ), + dto.protocol_version, + dto.network_id, + dto.issuing_time, + dto.slot_commitment_id, + dto.latest_finalized_slot, + dto.issuer_id, + )) + } + } + + #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct UnsignedBlockDto { + pub header: BlockHeaderDto, + pub body: BlockBodyDto, + } + + impl From<&UnsignedBlock> for UnsignedBlockDto { + fn from(value: &UnsignedBlock) -> Self { + Self { + header: BlockHeaderDto::from(&value.header), + body: BlockBodyDto::from(&value.body), + } + } + } + + impl TryFromDto for UnsignedBlock { + type Dto = UnsignedBlockDto; + type Error = Error; + + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { + Ok(Self::new( + BlockHeader::try_from_dto_with_params_inner(dto.header, params)?, BlockBody::try_from_dto_with_params_inner(dto.body, params)?, )) } diff --git a/sdk/src/types/block/core/mod.rs b/sdk/src/types/block/core/mod.rs index e4f8f2f7c5..66da64dd99 100644 --- a/sdk/src/types/block/core/mod.rs +++ b/sdk/src/types/block/core/mod.rs @@ -235,7 +235,7 @@ pub(crate) mod dto { type Dto = BlockBodyDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { match dto { Self::Dto::Basic(basic_block_body_dto) => { Ok(BasicBlockBody::try_from_dto_with_params_inner(basic_block_body_dto, params)?.into()) diff --git a/sdk/src/types/block/core/validation.rs b/sdk/src/types/block/core/validation.rs index 789a1d33bb..9411a62acc 100644 --- a/sdk/src/types/block/core/validation.rs +++ b/sdk/src/types/block/core/validation.rs @@ -260,7 +260,7 @@ pub(crate) mod dto { type Dto = ValidationBlockBodyDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { if let Some(protocol_params) = params.protocol_parameters() { validate_protocol_params_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 16ad2ff509..d2e5f6b676 100644 --- a/sdk/src/types/block/mana/allotment.rs +++ b/sdk/src/types/block/mana/allotment.rs @@ -99,7 +99,7 @@ pub(super) mod dto { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + params: &crate::types::ValidationParams<'_>, ) -> Result { Ok(if let Some(params) = params.protocol_parameters() { Self::new(dto.account_id, dto.mana, params)? diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index ddb2ec9501..2e6ce03b8a 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -676,7 +676,7 @@ pub(crate) mod dto { type Dto = AccountOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let mut builder = AccountOutputBuilder::new_with_amount(dto.amount, dto.account_id) .with_mana(dto.mana) .with_foundry_counter(dto.foundry_counter) @@ -685,7 +685,7 @@ pub(crate) mod dto { .with_immutable_features(dto.immutable_features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/anchor.rs b/sdk/src/types/block/output/anchor.rs index 60ae4bada5..b652e9a7b0 100644 --- a/sdk/src/types/block/output/anchor.rs +++ b/sdk/src/types/block/output/anchor.rs @@ -758,7 +758,7 @@ pub(crate) mod dto { type Dto = AnchorOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let mut builder = AnchorOutputBuilder::new_with_amount(dto.amount, dto.anchor_id) .with_mana(dto.mana) .with_state_index(dto.state_index) @@ -768,7 +768,7 @@ pub(crate) mod dto { .with_state_metadata(dto.state_metadata); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/basic.rs b/sdk/src/types/block/output/basic.rs index 4407b942d7..aa641b0931 100644 --- a/sdk/src/types/block/output/basic.rs +++ b/sdk/src/types/block/output/basic.rs @@ -468,14 +468,14 @@ pub(crate) mod dto { type Dto = BasicOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let mut builder = BasicOutputBuilder::new_with_amount(dto.amount) .with_native_tokens(dto.native_tokens) .with_mana(dto.mana) .with_features(dto.features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/delegation.rs b/sdk/src/types/block/output/delegation.rs index b4683aa063..882e68f9d8 100644 --- a/sdk/src/types/block/output/delegation.rs +++ b/sdk/src/types/block/output/delegation.rs @@ -481,7 +481,7 @@ pub(crate) mod dto { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + params: &crate::types::ValidationParams<'_>, ) -> Result { let mut builder = DelegationOutputBuilder::new_with_amount( dto.amount, @@ -493,7 +493,7 @@ pub(crate) mod dto { .with_end_epoch(dto.end_epoch); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/foundry.rs b/sdk/src/types/block/output/foundry.rs index cc4f9b59d9..b9507db344 100644 --- a/sdk/src/types/block/output/foundry.rs +++ b/sdk/src/types/block/output/foundry.rs @@ -718,7 +718,7 @@ pub(crate) mod dto { type Dto = FoundryOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let mut builder = FoundryOutputBuilder::new_with_amount(dto.amount, dto.serial_number, dto.token_scheme); for t in dto.native_tokens { @@ -734,7 +734,7 @@ pub(crate) mod dto { } for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 53095f9ee5..65b4fee472 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -511,7 +511,7 @@ pub mod dto { type Dto = OutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(match dto { OutputDto::Basic(o) => Self::Basic(BasicOutput::try_from_dto_with_params_inner(o, params)?), OutputDto::Account(o) => Self::Account(AccountOutput::try_from_dto_with_params_inner(o, params)?), diff --git a/sdk/src/types/block/output/nft.rs b/sdk/src/types/block/output/nft.rs index 11b758d456..b472542dbb 100644 --- a/sdk/src/types/block/output/nft.rs +++ b/sdk/src/types/block/output/nft.rs @@ -642,7 +642,7 @@ pub(crate) mod dto { type Dto = NftOutputDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let mut builder = NftOutputBuilder::new_with_amount(dto.amount, dto.nft_id) .with_mana(dto.mana) .with_native_tokens(dto.native_tokens) @@ -650,7 +650,7 @@ pub(crate) mod dto { .with_immutable_features(dto.immutable_features); for u in dto.unlock_conditions { - builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, ¶ms)?); + builder = builder.add_unlock_condition(UnlockCondition::try_from_dto_with_params(u, params)?); } builder.finish() diff --git a/sdk/src/types/block/output/unlock_condition/mod.rs b/sdk/src/types/block/output/unlock_condition/mod.rs index 6a6c9688f2..a0c01036b3 100644 --- a/sdk/src/types/block/output/unlock_condition/mod.rs +++ b/sdk/src/types/block/output/unlock_condition/mod.rs @@ -477,7 +477,7 @@ pub mod dto { type Dto = UnlockConditionDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(match dto { UnlockConditionDto::Address(v) => Self::Address(v), UnlockConditionDto::StorageDepositReturn(v) => Self::StorageDepositReturn( diff --git a/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs b/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs index fb937a0e05..a54b0df214 100644 --- a/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs +++ b/sdk/src/types/block/output/unlock_condition/storage_deposit_return.rs @@ -123,7 +123,7 @@ pub(crate) mod dto { type Dto = StorageDepositReturnUnlockConditionDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { Ok(if let Some(token_supply) = params.token_supply() { Self::new(dto.return_address, dto.amount, token_supply)? } else { diff --git a/sdk/src/types/block/payload/mod.rs b/sdk/src/types/block/payload/mod.rs index 8a86eb63e4..8920c22fbe 100644 --- a/sdk/src/types/block/payload/mod.rs +++ b/sdk/src/types/block/payload/mod.rs @@ -230,7 +230,7 @@ pub mod dto { type Dto = PayloadDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> 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..cbc1a3d1b8 100644 --- a/sdk/src/types/block/payload/signed_transaction/mod.rs +++ b/sdk/src/types/block/payload/signed_transaction/mod.rs @@ -116,7 +116,7 @@ pub mod dto { type Dto = SignedTransactionPayloadDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> 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 f211230ddf..e86fdb6317 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -580,7 +580,7 @@ pub(crate) mod dto { type Dto = TransactionDto; type Error = Error; - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result { + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result { let network_id = dto .network_id .parse::() @@ -588,12 +588,12 @@ 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(o, params)) .collect::, Error>>()?; let outputs = dto .outputs .into_iter() - .map(|o| Output::try_from_dto_with_params(o, ¶ms)) + .map(|o| Output::try_from_dto_with_params(o, params)) .collect::, Error>>()?; let mut builder = Self::builder(network_id) diff --git a/sdk/src/types/mod.rs b/sdk/src/types/mod.rs index 6858a10e87..018a53a49a 100644 --- a/sdk/src/types/mod.rs +++ b/sdk/src/types/mod.rs @@ -139,8 +139,8 @@ pub trait TryFromDto: Sized { dto: Self::Dto, params: impl Into> + Send, ) -> Result { - Self::try_from_dto_with_params_inner(dto, params.into()) + Self::try_from_dto_with_params_inner(dto, ¶ms.into()) } - fn try_from_dto_with_params_inner(dto: Self::Dto, params: ValidationParams<'_>) -> Result; + fn try_from_dto_with_params_inner(dto: Self::Dto, params: &ValidationParams<'_>) -> Result; } diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index a39f4516b0..a251c61c3b 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -584,7 +584,7 @@ impl TryFromDto for WalletData { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + params: &crate::types::ValidationParams<'_>, ) -> core::result::Result { Ok(Self { bip_path: dto.bip_path, @@ -593,30 +593,30 @@ impl TryFromDto for WalletData { outputs: dto .outputs .into_iter() - .map(|(id, o)| Ok((id, OutputData::try_from_dto_with_params(o, ¶ms)?))) + .map(|(id, o)| Ok((id, OutputData::try_from_dto_with_params(o, params)?))) .collect::>()?, locked_outputs: dto.locked_outputs, unspent_outputs: dto .unspent_outputs .into_iter() - .map(|(id, o)| Ok((id, OutputData::try_from_dto_with_params(o, ¶ms)?))) + .map(|(id, o)| Ok((id, OutputData::try_from_dto_with_params(o, params)?))) .collect::>()?, 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(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(o, params)?))) .collect::>()?, inaccessible_incoming_transactions: Default::default(), native_token_foundries: dto .native_token_foundries .into_iter() - .map(|(id, o)| Ok((id, FoundryOutput::try_from_dto_with_params(o, ¶ms)?))) + .map(|(id, o)| Ok((id, FoundryOutput::try_from_dto_with_params(o, params)?))) .collect::>()?, }) } 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 4ecef57081..32c04e3c48 100644 --- a/sdk/src/wallet/types/mod.rs +++ b/sdk/src/wallet/types/mod.rs @@ -128,7 +128,7 @@ impl TryFromDto for OutputData { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + params: &crate::types::ValidationParams<'_>, ) -> Result { Ok(Self { output_id: dto.output_id, @@ -211,7 +211,7 @@ impl TryFromDto for TransactionWithMetadata { fn try_from_dto_with_params_inner( dto: Self::Dto, - params: crate::types::ValidationParams<'_>, + params: &crate::types::ValidationParams<'_>, ) -> Result { Ok(Self { payload: SignedTransactionPayload::try_from_dto_with_params(dto.payload, params)?, diff --git a/sdk/tests/types/block.rs b/sdk/tests/types/block.rs index 042d3075b9..4aa1150298 100644 --- a/sdk/tests/types/block.rs +++ b/sdk/tests/types/block.rs @@ -130,13 +130,15 @@ fn dto_mismatch_version() { let network_id = protocol_parameters.network_id(); let protocol_version = 4; let block_dto_json = serde_json::json!({ - "protocolVersion": protocol_version, - "networkId": network_id.to_string(), - "issuingTime": issuing_time.to_string(), - "slotCommitmentId": "0x8633b2eb1845fdecf12ee6c5e789c3cf1f0d0bbb3cee65cb5fb2757e995b5cd700000000", - "latestFinalizedSlot": 0, - "issuerId": "0x0000000000000000000000000000000000000000000000000000000000000000", - "block": { + "header": { + "protocolVersion": protocol_version, + "networkId": network_id.to_string(), + "issuingTime": issuing_time.to_string(), + "slotCommitmentId": "0x8633b2eb1845fdecf12ee6c5e789c3cf1f0d0bbb3cee65cb5fb2757e995b5cd700000000", + "latestFinalizedSlot": 0, + "issuerId": "0x0000000000000000000000000000000000000000000000000000000000000000", + }, + "body": { "type":1, "strongParents": [ "0x417c5700320912627b604d4c376a5a1663634b09703538570b1d52440b3e474639490b10" ], "weakParents": [], @@ -171,13 +173,15 @@ fn dto_mismatch_network_id() { + (slot_index - 1) * protocol_parameters.slot_duration_in_seconds() as u64; let network_id = network_name_to_id("invalid-network"); let block_dto_json = serde_json::json!({ - "protocolVersion": 3, - "networkId": network_id.to_string(), - "issuingTime": issuing_time.to_string(), - "slotCommitmentId": "0x8633b2eb1845fdecf12ee6c5e789c3cf1f0d0bbb3cee65cb5fb2757e995b5cd700000000", - "latestFinalizedSlot": 0, - "issuerId": "0x0000000000000000000000000000000000000000000000000000000000000000", - "block": { + "header": { + "protocolVersion": 3, + "networkId": network_id.to_string(), + "issuingTime": issuing_time.to_string(), + "slotCommitmentId": "0x8633b2eb1845fdecf12ee6c5e789c3cf1f0d0bbb3cee65cb5fb2757e995b5cd700000000", + "latestFinalizedSlot": 0, + "issuerId": "0x0000000000000000000000000000000000000000000000000000000000000000", + }, + "body": { "type":1, "strongParents": [ "0x417c5700320912627b604d4c376a5a1663634b09703538570b1d52440b3e474639490b10" ], "weakParents": [],