Skip to content

Commit

Permalink
Make output dtos private (#1712)
Browse files Browse the repository at this point in the history
* Make output dtos private

* Derive Deserialize, private mod

* PRIVATE

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Thoralf-M and thibault-martinez committed Nov 30, 2023
1 parent 3f2d737 commit 9387a35
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 312 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use iota_sdk::{
types::block::{
address::{Bech32Address, Hrp},
output::{
dto::OutputDto, feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId,
DelegationId, FoundryId, NftId, OutputId, TokenScheme,
feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId, DelegationId, FoundryId,
NftId, Output, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockDto, BlockId,
Expand Down Expand Up @@ -356,7 +356,7 @@ pub enum ClientMethod {
/// Calculate the minimum required amount for an output.
/// Expected response:
/// [`OutputAmount`](crate::Response::OutputAmount)
ComputeMinimumOutputAmount { output: OutputDto },
ComputeMinimumOutputAmount { output: Output },
/// Requests funds for a given address from the faucet, for example `https://faucet.testnet.shimmer.network/api/enqueue` or `http://localhost:8091/api/enqueue`.
RequestFundsFromFaucet {
/// Faucet URL
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iota_sdk::{
client::secret::types::InputSigningDataDto,
types::block::{
address::{Bech32Address, Hrp},
output::{dto::OutputDto, AccountId, NftId, OutputId, StorageScoreParameters},
output::{AccountId, NftId, Output, OutputId, StorageScoreParameters},
payload::signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
TransactionId,
Expand Down Expand Up @@ -134,7 +134,7 @@ pub enum UtilsMethod {
/// Computes the minimum required amount of an output.
#[serde(rename_all = "camelCase")]
ComputeMinimumOutputAmount {
output: OutputDto,
output: Output,
storage_score_parameters: StorageScoreParameters,
},
/// Checks if the given mnemonic is valid.
Expand Down Expand Up @@ -163,7 +163,7 @@ pub enum UtilsMethod {
ComputeSlotCommitmentId { slot_commitment: SlotCommitment },
/// Returns the hex representation of the serialized output bytes.
#[serde(rename_all = "camelCase")]
OutputHexBytes { output: OutputDto },
OutputHexBytes { output: Output },
/// Verifies the semantic of a transaction.
VerifyTransactionSemantic {
inputs: Vec<InputSigningDataDto>,
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use iota_sdk::{
},
types::block::{
address::{Bech32Address, Hrp},
output::{dto::OutputDto, OutputId, TokenId},
output::{Output, OutputId, TokenId},
payload::signed_transaction::TransactionId,
},
wallet::{
Expand Down Expand Up @@ -321,7 +321,7 @@ pub enum WalletMethod {
/// Prepare transaction.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareTransaction {
outputs: Vec<OutputDto>,
outputs: Vec<Output>,
options: Option<TransactionOptions>,
},
/// Vote for a participation event.
Expand Down Expand Up @@ -371,7 +371,7 @@ pub enum WalletMethod {
/// Send outputs in a transaction.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendOutputs {
outputs: Vec<OutputDto>,
outputs: Vec<Output>,
options: Option<TransactionOptions>,
},
/// Set the alias of the wallet.
Expand Down
12 changes: 5 additions & 7 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use iota_sdk::{
api::core::OutputWithMetadataResponse,
block::{
output::{
dto::OutputDto, AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output,
OutputBuilderAmount,
AccountOutput, BasicOutput, FoundryOutput, MinimumOutputAmount, NftOutput, Output, OutputBuilderAmount,
},
payload::Payload,
Block, BlockDto, UnsignedBlockDto,
Expand Down Expand Up @@ -79,7 +78,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildBasicOutput {
amount,
Expand All @@ -98,7 +97,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildFoundryOutput {
amount,
Expand All @@ -121,7 +120,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildNftOutput {
amount,
Expand All @@ -144,7 +143,7 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
immutable_features,
)?);

Response::Output(OutputDto::from(&output))
Response::Output(output)
}
ClientMethod::BuildBasicBlock { issuer_id, payload } => {
let payload = if let Some(payload) = payload {
Expand Down Expand Up @@ -285,7 +284,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
Response::Bech32Address(client.hex_public_key_to_bech32_address(&hex, bech32_hrp).await?)
}
ClientMethod::ComputeMinimumOutputAmount { output } => {
let output = Output::try_from(output)?;
let storage_score_params = client.get_storage_score_parameters().await?;

Response::OutputAmount(output.minimum_amount(storage_score_params))
Expand Down
12 changes: 3 additions & 9 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use iota_sdk::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, Output, OutputId, TokenId},
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, OutputId, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
Block,
},
Expand Down Expand Up @@ -78,10 +78,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
UtilsMethod::ComputeMinimumOutputAmount {
output,
storage_score_parameters: storage_params,
} => {
let out = Output::try_from(output)?;
Response::OutputAmount(out.minimum_amount(storage_params))
}
} => Response::OutputAmount(output.minimum_amount(storage_params)),
UtilsMethod::VerifyMnemonic { mnemonic } => {
let mnemonic = Mnemonic::from(mnemonic);
verify_mnemonic(mnemonic)?;
Expand All @@ -107,10 +104,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
}
UtilsMethod::OutputIdToUtxoInput { output_id } => Response::Input(UtxoInput::from(output_id)),
UtilsMethod::ComputeSlotCommitmentId { slot_commitment } => Response::SlotCommitmentId(slot_commitment.id()),
UtilsMethod::OutputHexBytes { output } => {
let output = Output::try_from(output)?;
Response::HexBytes(prefix_hex::encode(output.pack_to_vec()))
}
UtilsMethod::OutputHexBytes { output } => Response::HexBytes(prefix_hex::encode(output.pack_to_vec())),
UtilsMethod::VerifyTransactionSemantic { inputs, transaction } => {
let conflict = verify_semantic(
&inputs
Expand Down
32 changes: 5 additions & 27 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ use iota_sdk::{
client::api::{
PreparedTransactionData, PreparedTransactionDataDto, SignedTransactionData, SignedTransactionDataDto,
},
types::{
block::{
address::ToBech32Ext,
output::{dto::OutputDto, Output},
},
TryFromDto,
},
types::{block::address::ToBech32Ext, TryFromDto},
wallet::{types::TransactionWithMetadataDto, OutputDataDto, PreparedCreateNativeTokenTransactionDto, Wallet},
};

Expand Down Expand Up @@ -158,7 +152,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::GetBalance => Response::Balance(wallet.balance().await?),
WalletMethod::GetFoundryOutput { token_id } => {
let output = wallet.get_foundry_output(token_id).await?;
Response::Output(OutputDto::from(&output))
Response::Output(output)
}
WalletMethod::GetIncomingTransaction { transaction_id } => {
let transaction = wallet.get_incoming_transaction(&transaction_id).await;
Expand Down Expand Up @@ -285,7 +279,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
transaction_options,
} => {
let output = wallet.prepare_output(*params, transaction_options).await?;
Response::Output(OutputDto::from(&output))
Response::Output(output)
}
WalletMethod::PrepareSend { params, options } => {
let data = wallet.prepare_send(params, options).await?;
Expand All @@ -305,15 +299,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
Response::PreparedTransaction(PreparedTransactionDataDto::from(&data))
}
WalletMethod::PrepareTransaction { outputs, options } => {
let data = wallet
.prepare_transaction(
outputs
.into_iter()
.map(Output::try_from)
.collect::<Result<Vec<Output>, _>>()?,
options,
)
.await?;
let data = wallet.prepare_transaction(outputs, options).await?;
Response::PreparedTransaction(PreparedTransactionDataDto::from(&data))
}
#[cfg(feature = "participation")]
Expand Down Expand Up @@ -349,15 +335,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SendOutputs { outputs, options } => {
let transaction = wallet
.send_outputs(
outputs
.into_iter()
.map(Output::try_from)
.collect::<Result<Vec<Output>, _>>()?,
options,
)
.await?;
let transaction = wallet.send_outputs(outputs, options).await?;
Response::SentTransaction(TransactionWithMetadataDto::from(&transaction))
}
WalletMethod::SetAlias { alias } => {
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use iota_sdk::{
block::{
address::{Address, Bech32Address, Hrp},
input::UtxoInput,
output::{dto::OutputDto, AccountId, FoundryId, NftId, OutputId, OutputMetadata, TokenId},
output::{AccountId, FoundryId, NftId, Output, OutputId, OutputMetadata, TokenId},
payload::{dto::SignedTransactionPayloadDto, signed_transaction::TransactionId},
protocol::ProtocolParameters,
semantic::TransactionFailureReason,
Expand Down Expand Up @@ -206,7 +206,7 @@ pub enum Response {
/// - [`BuildNftOutput`](crate::method::ClientMethod::BuildNftOutput)
/// - [`GetFoundryOutput`](crate::method::WalletMethod::GetFoundryOutput)
/// - [`PrepareOutput`](crate::method::WalletMethod::PrepareOutput)
Output(OutputDto),
Output(Output),
/// Response for:
/// - [`AccountIdToBech32`](crate::method::ClientMethod::AccountIdToBech32)
/// - [`HexPublicKeyToBech32Address`](crate::method::ClientMethod::HexPublicKeyToBech32Address)
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/how_tos/outputs/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use iota_sdk::{
types::block::{
address::Address,
output::{
dto::OutputDto,
feature::{IssuerFeature, MetadataFeature, SenderFeature, TagFeature},
unlock_condition::AddressUnlockCondition,
NftId, NftOutputBuilder,
Expand Down Expand Up @@ -66,7 +65,7 @@ async fn main() -> Result<()> {
];

// Convert output array to json array
let json_outputs = serde_json::to_string_pretty(&outputs.iter().map(OutputDto::from).collect::<Vec<OutputDto>>())?;
let json_outputs = serde_json::to_string_pretty(&outputs)?;
println!("{json_outputs}");

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions sdk/examples/how_tos/outputs/unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use iota_sdk::{
types::block::{
address::Address,
output::{
dto::OutputDto,
unlock_condition::{
AddressUnlockCondition, ExpirationUnlockCondition, ImmutableAccountAddressUnlockCondition,
StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
Expand Down Expand Up @@ -70,7 +69,7 @@ async fn main() -> Result<()> {
];

// Convert output array to json array
let json_outputs = serde_json::to_string_pretty(&outputs.iter().map(OutputDto::from).collect::<Vec<OutputDto>>())?;
let json_outputs = serde_json::to_string_pretty(&outputs)?;
println!("{json_outputs}");

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/client/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
types::{
block::{
address::Address,
output::{dto::OutputDto, Output},
output::Output,
payload::{
signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct RemainderData {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct RemainderDataDto {
/// The remainder output
pub output: OutputDto,
pub output: Output,
/// The chain derived from seed, for the remainder addresses
#[serde(with = "option_bip44", default)]
pub chain: Option<Bip44>,
Expand All @@ -160,7 +160,7 @@ impl TryFrom<RemainderDataDto> for RemainderData {

fn try_from(dto: RemainderDataDto) -> Result<Self, Self::Error> {
Ok(Self {
output: Output::try_from(dto.output)?,
output: dto.output,
chain: dto.chain,
address: dto.address,
})
Expand All @@ -169,7 +169,7 @@ impl TryFrom<RemainderDataDto> for RemainderData {
impl From<&RemainderData> for RemainderDataDto {
fn from(remainder: &RemainderData) -> Self {
Self {
output: OutputDto::from(&remainder.output),
output: remainder.output.clone(),
chain: remainder.chain,
address: remainder.address.clone(),
}
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
},
block::{
address::ToBech32Ext,
output::{dto::OutputDto, AccountId, Output, OutputId, OutputMetadata},
output::{AccountId, Output, OutputId, OutputMetadata},
payload::signed_transaction::TransactionId,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Block, BlockDto, BlockId,
Expand Down Expand Up @@ -237,9 +237,7 @@ impl ClientInner {
pub async fn get_output(&self, output_id: &OutputId) -> Result<Output> {
let path = &format!("api/core/v3/outputs/{output_id}");

Ok(Output::try_from(
self.get_request::<OutputDto>(path, None, false, true).await?,
)?)
self.get_request(path, None, false, true).await
}

/// Finds an output by its ID and returns it as raw bytes.
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/client/secret/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crypto::keys::bip44::Bip44;
use serde::{Deserialize, Serialize};

use crate::{
types::block::output::{dto::OutputDto, Output, OutputId, OutputMetadata},
types::block::output::{Output, OutputId, OutputMetadata},
utils::serde::bip44::option_bip44,
};

Expand Down Expand Up @@ -156,7 +156,7 @@ impl InputSigningData {
#[serde(rename_all = "camelCase")]
pub struct InputSigningDataDto {
/// The output
pub output: OutputDto,
pub output: Output,
/// The output metadata
pub output_metadata: OutputMetadata,
/// The chain derived from seed, only for ed25519 addresses
Expand All @@ -169,7 +169,7 @@ impl TryFrom<InputSigningDataDto> for InputSigningData {

fn try_from(dto: InputSigningDataDto) -> Result<Self, Self::Error> {
Ok(Self {
output: Output::try_from(dto.output)?,
output: dto.output,
output_metadata: dto.output_metadata,
chain: dto.chain,
})
Expand All @@ -179,7 +179,7 @@ impl TryFrom<InputSigningDataDto> for InputSigningData {
impl From<&InputSigningData> for InputSigningDataDto {
fn from(input: &InputSigningData) -> Self {
Self {
output: OutputDto::from(&input.output),
output: input.output.clone(),
output_metadata: input.output_metadata,
chain: input.chain,
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
types::block::{
address::Bech32Address,
core::Parents,
output::{dto::OutputDto, OutputId, OutputMetadata, OutputWithMetadata},
output::{Output, OutputId, OutputMetadata, OutputWithMetadata},
protocol::{ProtocolParameters, ProtocolParametersHash},
semantic::TransactionFailureReason,
slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex},
Expand Down Expand Up @@ -418,14 +418,14 @@ pub struct BlockWithMetadataResponse {
#[serde(rename_all = "camelCase")]
pub struct OutputWithMetadataResponse {
pub metadata: OutputMetadata,
pub output: OutputDto,
pub output: Output,
}

impl From<&OutputWithMetadata> for OutputWithMetadataResponse {
fn from(value: &OutputWithMetadata) -> Self {
Self {
metadata: value.metadata,
output: OutputDto::from(value.output()),
output: value.output().clone(),
}
}
}
Expand Down
Loading

0 comments on commit 9387a35

Please sign in to comment.