From f348ff71d05762508675e4a3a13c493b171de59a Mon Sep 17 00:00:00 2001 From: chrisgitiota Date: Tue, 7 Jan 2025 11:09:56 +0100 Subject: [PATCH] Use cloned native IotaTransactionBlockResponse instead of a BCS deserialization BCS deserialization is not available for IotaTransactionBlockResponse because the BCS format is not self describing and several struct fields of IotaTransactionBlockResponse are optionally skipped during serialization. JSON deserialization will probably be available but using a cloned instance to convert a TransactionOutputInternal into a TransactionOutput will have a much better efficiency. --- .../src/iota_client_ts_sdk.rs | 16 ++++++++-------- .../iota_client_rust_sdk.rs | 19 +++++++++---------- identity_iota_core/src/rebased/transaction.rs | 14 ++++++-------- .../src/iota_client_trait.rs | 17 ++++++++--------- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/bindings/wasm/iota_interaction_ts/src/iota_client_ts_sdk.rs b/bindings/wasm/iota_interaction_ts/src/iota_client_ts_sdk.rs index 4ba583b1f..a494778a9 100644 --- a/bindings/wasm/iota_interaction_ts/src/iota_client_ts_sdk.rs +++ b/bindings/wasm/iota_interaction_ts/src/iota_client_ts_sdk.rs @@ -132,10 +132,6 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider { format!("{:?}", self.response.to_string()) } - fn to_bcs(&self) -> Result { - todo!() // - } - fn effects_execution_status(&self) -> Option { self .response @@ -150,12 +146,16 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider { .map(|wasm_o_ref_vec| wasm_o_ref_vec.into()) } - fn as_native_response(&mut self) -> &mut Self::NativeResponse { - todo!() + fn as_native_response(&self) -> &Self::NativeResponse { + &self.response + } + + fn as_mut_native_response(&mut self) -> &mut Self::NativeResponse { + &mut self.response } - fn into_native_response(self) -> Self::NativeResponse { - todo!() + fn clone_native_response(&self) -> Self::NativeResponse { + self.response.clone() } } diff --git a/identity_iota_core/src/iota_interaction_rust/iota_client_rust_sdk.rs b/identity_iota_core/src/iota_interaction_rust/iota_client_rust_sdk.rs index 2ba2b64da..6731cf1c4 100644 --- a/identity_iota_core/src/iota_interaction_rust/iota_client_rust_sdk.rs +++ b/identity_iota_core/src/iota_interaction_rust/iota_client_rust_sdk.rs @@ -29,13 +29,13 @@ use identity_iota_interaction::types::{ quorum_driver_types::ExecuteTransactionRequestType, transaction::{ProgrammableTransaction, Transaction, TransactionData}, }; -use identity_iota_interaction::{IotaKeySignature, IotaTransactionBlockResponseBcs}; +use identity_iota_interaction::{IotaKeySignature}; use identity_iota_interaction::{ CoinReadTrait, EventTrait, IotaClientTrait, IotaTransactionBlockResponseT, ProgrammableTransactionBcs, QuorumDriverTrait, ReadTrait, }; use identity_iota_interaction::{IotaClient, SignatureBcs, TransactionDataBcs}; -use crate::rebased::{rebased_err, Error}; +use crate::rebased::Error; /// The minimum balance required to execute a transaction. pub(crate) const MINIMUM_BALANCE: u64 = 1_000_000_000; @@ -102,10 +102,6 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider { format!("{:?}", self.response) } - fn to_bcs(&self) -> Result { - bcs::to_bytes(&self.response).map_err(rebased_err) - } - fn effects_execution_status(&self) -> Option { self.response.effects.as_ref().map(|effects| effects.status().clone()) } @@ -114,13 +110,16 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider { self.response.effects.as_ref().map(|effects| effects.created().to_vec()) } - fn as_native_response(&mut self) -> &mut Self::NativeResponse { + fn as_native_response(&self) -> &Self::NativeResponse { + &self.response + } + + fn as_mut_native_response(&mut self) -> &mut Self::NativeResponse { &mut self.response } - /// Consumes this adapter and returns the internally used platform specific response - fn into_native_response(self) -> Self::NativeResponse { - self.response + fn clone_native_response(&self) -> Self::NativeResponse { + self.response.clone() } } diff --git a/identity_iota_core/src/rebased/transaction.rs b/identity_iota_core/src/rebased/transaction.rs index 486dce8dd..95c98989d 100644 --- a/identity_iota_core/src/rebased/transaction.rs +++ b/identity_iota_core/src/rebased/transaction.rs @@ -84,15 +84,13 @@ impl Deref for TransactionOutputInternal { #[cfg(not(target_arch = "wasm32"))] impl From> for TransactionOutput { fn from(value: TransactionOutputInternal) -> Self { - let response_bcs = value - .response - .to_bcs() - .expect("TransactionOutputInternal bcs serialization failed"); - let response = - bcs::from_bytes::(&response_bcs) - .expect("IotaTransactionBlockResponse bcs deserialization failed"); + let TransactionOutputInternal:: { + output: out, + response: internal_response + } = value; + let response = internal_response.clone_native_response(); TransactionOutput { - output: value.output, + output: out, response, } } diff --git a/identity_iota_interaction/src/iota_client_trait.rs b/identity_iota_interaction/src/iota_client_trait.rs index f8d87250b..d3afc0c1d 100644 --- a/identity_iota_interaction/src/iota_client_trait.rs +++ b/identity_iota_interaction/src/iota_client_trait.rs @@ -7,8 +7,7 @@ use std::boxed::Box; use std::marker::Send; use async_trait::async_trait; use secret_storage::{Signer, SignatureScheme}; -use crate::{OptionalSend, ProgrammableTransactionBcs, TransactionDataBcs, SignatureBcs, - IotaTransactionBlockResponseBcs}; +use crate::{OptionalSend, ProgrammableTransactionBcs, TransactionDataBcs, SignatureBcs}; use crate::rpc_types::{ IotaTransactionBlockResponseOptions, IotaObjectResponse, @@ -81,10 +80,7 @@ pub trait IotaTransactionBlockResponseT: OptionalSend { /// Returns Debug representation of the IotaTransactionBlockResponse fn to_string(&self) -> String; - /// Returns Bcs serialization of the IotaTransactionBlockResponse - fn to_bcs(&self) -> Result; - - /// If effects_is_some(), returns a clone of the IotaTransactionBlockEffectsAPI::status() + /// If effects_is_some(), returns a clone of the IotaTransactionBlockEffectsAPI::status() /// Otherwise, returns None fn effects_execution_status(&self) -> Option; @@ -94,10 +90,13 @@ pub trait IotaTransactionBlockResponseT: OptionalSend { fn effects_created(&self) -> Option>; /// Returns a reference to the platform specific client sdk response instance wrapped by this adapter - fn as_native_response(&mut self) -> &mut Self::NativeResponse; + fn as_native_response(&self) -> &Self::NativeResponse; + + /// Returns a mutable reference to the platform specific client sdk response instance wrapped by this adapter + fn as_mut_native_response(&mut self) -> &mut Self::NativeResponse; - /// Consumes this adapter and returns the wrapped platform specific client sdk response - fn into_native_response(self) -> Self::NativeResponse ; + /// Returns a clone of the wrapped platform specific client sdk response + fn clone_native_response(&self) -> Self::NativeResponse; } #[cfg_attr(not(feature = "send-sync-transaction"), async_trait(?Send))]