Skip to content

Commit

Permalink
Use cloned native IotaTransactionBlockResponse instead of a BCS deser…
Browse files Browse the repository at this point in the history
…ialization

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.
  • Loading branch information
chrisgitiota committed Jan 7, 2025
1 parent d8627e5 commit f348ff7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 35 deletions.
16 changes: 8 additions & 8 deletions bindings/wasm/iota_interaction_ts/src/iota_client_ts_sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider {
format!("{:?}", self.response.to_string())
}

fn to_bcs(&self) -> Result<IotaTransactionBlockResponseBcs, Self::Error> {
todo!() //
}

fn effects_execution_status(&self) -> Option<IotaExecutionStatus> {
self
.response
Expand All @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,10 +102,6 @@ impl IotaTransactionBlockResponseT for IotaTransactionBlockResponseProvider {
format!("{:?}", self.response)
}

fn to_bcs(&self) -> Result<IotaTransactionBlockResponseBcs, Self::Error> {
bcs::to_bytes(&self.response).map_err(rebased_err)
}

fn effects_execution_status(&self) -> Option<IotaExecutionStatus> {
self.response.effects.as_ref().map(|effects| effects.status().clone())
}
Expand All @@ -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()
}
}

Expand Down
14 changes: 6 additions & 8 deletions identity_iota_core/src/rebased/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ impl<T> Deref for TransactionOutputInternal<T> {
#[cfg(not(target_arch = "wasm32"))]
impl<T> From<TransactionOutputInternal<T>> for TransactionOutput<T> {
fn from(value: TransactionOutputInternal<T>) -> Self {
let response_bcs = value
.response
.to_bcs()
.expect("TransactionOutputInternal bcs serialization failed");
let response =
bcs::from_bytes::<IotaTransactionBlockResponse>(&response_bcs)
.expect("IotaTransactionBlockResponse bcs deserialization failed");
let TransactionOutputInternal::<T> {
output: out,
response: internal_response
} = value;
let response = internal_response.clone_native_response();
TransactionOutput {
output: value.output,
output: out,
response,
}
}
Expand Down
17 changes: 8 additions & 9 deletions identity_iota_interaction/src/iota_client_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<IotaTransactionBlockResponseBcs, Self::Error>;

/// 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<IotaExecutionStatus>;

Expand All @@ -94,10 +90,13 @@ pub trait IotaTransactionBlockResponseT: OptionalSend {
fn effects_created(&self) -> Option<Vec<OwnedObjectRef>>;

/// 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))]
Expand Down

0 comments on commit f348ff7

Please sign in to comment.