Skip to content

Commit

Permalink
Remove more dtos (#1717)
Browse files Browse the repository at this point in the history
* Remove more dtos

* Fix merge
  • Loading branch information
Thoralf-M authored Dec 1, 2023
1 parent 1f6ff33 commit 5416d86
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 364 deletions.
12 changes: 6 additions & 6 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::{
feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId, DelegationId, FoundryId,
NftId, Output, OutputId, TokenScheme,
feature::Feature, unlock_condition::UnlockCondition, AccountId, AnchorId, DelegationId, FoundryId, NftId,
Output, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockDto, BlockId,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub enum ClientMethod {
mana: u64,
account_id: AccountId,
foundry_counter: Option<u32>,
unlock_conditions: Vec<UnlockConditionDto>,
unlock_conditions: Vec<UnlockCondition>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
},
Expand All @@ -60,7 +60,7 @@ pub enum ClientMethod {
// TODO: Determine if `default` is wanted here
#[serde(default, with = "string")]
mana: u64,
unlock_conditions: Vec<UnlockConditionDto>,
unlock_conditions: Vec<UnlockCondition>,
features: Option<Vec<Feature>>,
},
/// Build a FoundryOutput.
Expand All @@ -73,7 +73,7 @@ pub enum ClientMethod {
amount: Option<u64>,
serial_number: u32,
token_scheme: TokenScheme,
unlock_conditions: Vec<UnlockConditionDto>,
unlock_conditions: Vec<UnlockCondition>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
},
Expand All @@ -89,7 +89,7 @@ pub enum ClientMethod {
#[serde(default, with = "string")]
mana: u64,
nft_id: NftId,
unlock_conditions: Vec<UnlockConditionDto>,
unlock_conditions: Vec<UnlockCondition>,
features: Option<Vec<Feature>>,
immutable_features: Option<Vec<Feature>>,
},
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use derivative::Derivative;
use iota_sdk::{
client::secret::types::InputSigningDataDto,
client::secret::types::InputSigningData,
types::block::{
address::{Bech32Address, Hrp},
output::{AccountId, NftId, Output, OutputId, StorageScoreParameters},
Expand Down Expand Up @@ -168,7 +168,7 @@ pub enum UtilsMethod {
/// Verifies the semantic of a transaction.
VerifyTransactionSemantic {
transaction: TransactionDto,
inputs: Vec<InputSigningDataDto>,
inputs: Vec<InputSigningData>,
unlocks: Option<Vec<Unlock>>,
},
}
8 changes: 1 addition & 7 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

use crypto::keys::bip39::Mnemonic;
use iota_sdk::{
client::{
hex_public_key_to_bech32_address, hex_to_bech32, secret::types::InputSigningData, verify_mnemonic, Client,
},
client::{hex_public_key_to_bech32_address, hex_to_bech32, verify_mnemonic, Client},
types::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
Expand Down Expand Up @@ -111,10 +109,6 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
unlocks,
} => {
let transaction = Transaction::try_from_dto(transaction)?;
let inputs = &inputs
.into_iter()
.map(InputSigningData::try_from)
.collect::<iota_sdk::client::Result<Vec<InputSigningData>>>()?;
let inputs = inputs
.iter()
.map(|input| (input.output_id(), &input.output))
Expand Down
43 changes: 12 additions & 31 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ use iota_sdk::{
PreparedTransactionData, PreparedTransactionDataDto, SignedTransactionData, SignedTransactionDataDto,
},
types::{block::address::ToBech32Ext, TryFromDto},
wallet::{types::TransactionWithMetadataDto, OutputDataDto, PreparedCreateNativeTokenTransactionDto, Wallet},
wallet::{types::TransactionWithMetadataDto, PreparedCreateNativeTokenTransactionDto, Wallet},
};

use crate::{method::WalletMethod, response::Response};

/// Call a wallet method.
pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletMethod) -> crate::Result<Response> {
let response = match method {
WalletMethod::Accounts => {
Response::OutputsData(wallet.data().await.accounts().map(OutputDataDto::from).collect())
}
WalletMethod::Accounts => Response::OutputsData(wallet.data().await.accounts().cloned().collect()),
#[cfg(feature = "stronghold")]
WalletMethod::Backup { destination, password } => {
wallet.backup(destination, password).await?;
Expand Down Expand Up @@ -161,14 +159,9 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
|| Response::Transaction(None),
|transaction| Response::Transaction(Some(Box::new(TransactionWithMetadataDto::from(transaction)))),
),
WalletMethod::GetOutput { output_id } => Response::OutputData(
wallet
.data()
.await
.get_output(&output_id)
.map(OutputDataDto::from)
.map(Box::new),
),
WalletMethod::GetOutput { output_id } => {
Response::OutputData(wallet.data().await.get_output(&output_id).cloned().map(Box::new))
}
#[cfg(feature = "participation")]
WalletMethod::GetParticipationEvent { event_id } => {
let event_and_nodes = wallet.get_participation_event(event_id).await?;
Expand Down Expand Up @@ -211,14 +204,9 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
let implicit_account_creation_address = wallet.implicit_account_creation_address().await?;
Response::Bech32Address(implicit_account_creation_address)
}
WalletMethod::ImplicitAccounts => Response::OutputsData(
wallet
.data()
.await
.implicit_accounts()
.map(OutputDataDto::from)
.collect(),
),
WalletMethod::ImplicitAccounts => {
Response::OutputsData(wallet.data().await.implicit_accounts().cloned().collect())
}
WalletMethod::PrepareImplicitAccountTransition { output_id } => {
let data = wallet.prepare_implicit_account_transition(&output_id).await?;
Response::PreparedTransaction(PreparedTransactionDataDto::from(&data))
Expand All @@ -235,9 +223,9 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::Outputs { filter_options } => {
let wallet_data = wallet.data().await;
Response::OutputsData(if let Some(filter) = filter_options {
wallet_data.filtered_outputs(filter).map(OutputDataDto::from).collect()
wallet_data.filtered_outputs(filter).cloned().collect()
} else {
wallet_data.outputs().values().map(OutputDataDto::from).collect()
wallet_data.outputs().values().cloned().collect()
})
}
WalletMethod::PendingTransactions => Response::Transactions(
Expand Down Expand Up @@ -417,16 +405,9 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::UnspentOutputs { filter_options } => {
let wallet_data = wallet.data().await;
Response::OutputsData(if let Some(filter) = filter_options {
wallet_data
.filtered_unspent_outputs(filter)
.map(OutputDataDto::from)
.collect()
wallet_data.filtered_unspent_outputs(filter).cloned().collect()
} else {
wallet_data
.unspent_outputs()
.values()
.map(OutputDataDto::from)
.collect()
wallet_data.unspent_outputs().values().cloned().collect()
})
}
};
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use iota_sdk::{
},
utils::serde::string,
wallet::{
types::{Balance, OutputDataDto, TransactionWithMetadataDto},
types::{Balance, OutputData, TransactionWithMetadataDto},
PreparedCreateNativeTokenTransactionDto,
},
};
Expand Down Expand Up @@ -270,11 +270,11 @@ pub enum Response {
OutputIds(Vec<OutputId>),
/// Response for:
/// - [`GetOutput`](crate::method::WalletMethod::GetOutput)
OutputData(Option<Box<OutputDataDto>>),
OutputData(Option<Box<OutputData>>),
/// Response for:
/// - [`Outputs`](crate::method::WalletMethod::Outputs),
/// - [`UnspentOutputs`](crate::method::WalletMethod::UnspentOutputs)
OutputsData(Vec<OutputDataDto>),
OutputsData(Vec<OutputData>),
/// Response for:
/// - [`PrepareBurn`](crate::method::WalletMethod::PrepareBurn),
/// - [`PrepareClaimOutputs`](crate::method::WalletMethod::PrepareClaimOutputs)
Expand Down
69 changes: 11 additions & 58 deletions sdk/src/client/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crypto::keys::bip44::Bip44;
use serde::{Deserialize, Serialize};

use crate::{
client::secret::types::{InputSigningData, InputSigningDataDto},
client::secret::types::InputSigningData,
types::{
block::{
address::Address,
Expand Down Expand Up @@ -43,17 +43,17 @@ pub struct PreparedTransactionDataDto {
/// Transaction
pub transaction: TransactionDto,
/// Required address information for signing
pub inputs_data: Vec<InputSigningDataDto>,
pub inputs_data: Vec<InputSigningData>,
/// Optional remainder output information
pub remainder: Option<RemainderDataDto>,
pub remainder: Option<RemainderData>,
}

impl From<&PreparedTransactionData> for PreparedTransactionDataDto {
fn from(value: &PreparedTransactionData) -> Self {
Self {
transaction: TransactionDto::from(&value.transaction),
inputs_data: value.inputs_data.iter().map(InputSigningDataDto::from).collect(),
remainder: value.remainder.as_ref().map(RemainderDataDto::from),
inputs_data: value.inputs_data.clone(),
remainder: value.remainder.clone(),
}
}
}
Expand All @@ -68,18 +68,8 @@ impl TryFromDto<PreparedTransactionDataDto> for PreparedTransactionData {
Ok(Self {
transaction: Transaction::try_from_dto_with_params_inner(dto.transaction, params)
.map_err(|_| Error::InvalidField("transaction"))?,
inputs_data: dto
.inputs_data
.into_iter()
.map(InputSigningData::try_from)
.collect::<crate::client::Result<Vec<InputSigningData>>>()
.map_err(|_| Error::InvalidField("input_data"))?,
remainder: match dto.remainder {
Some(remainder) => {
Some(RemainderData::try_from(remainder).map_err(|_| Error::InvalidField("remainder"))?)
}
None => None,
},
inputs_data: dto.inputs_data,
remainder: dto.remainder,
})
}
}
Expand All @@ -100,14 +90,14 @@ pub struct SignedTransactionDataDto {
/// Signed transaction payload
pub payload: SignedTransactionPayloadDto,
/// Required address information for signing
pub inputs_data: Vec<InputSigningDataDto>,
pub inputs_data: Vec<InputSigningData>,
}

impl From<&SignedTransactionData> for SignedTransactionDataDto {
fn from(value: &SignedTransactionData) -> Self {
Self {
payload: SignedTransactionPayloadDto::from(&value.payload),
inputs_data: value.inputs_data.iter().map(InputSigningDataDto::from).collect(),
inputs_data: value.inputs_data.clone(),
}
}
}
Expand All @@ -122,30 +112,14 @@ impl TryFromDto<SignedTransactionDataDto> for SignedTransactionData {
Ok(Self {
payload: SignedTransactionPayload::try_from_dto_with_params_inner(dto.payload, params)
.map_err(|_| Error::InvalidField("transaction_payload"))?,
inputs_data: dto
.inputs_data
.into_iter()
.map(InputSigningData::try_from)
.collect::<crate::client::Result<Vec<InputSigningData>>>()
.map_err(|_| Error::InvalidField("inputs_data"))?,
inputs_data: dto.inputs_data,
})
}
}

/// Data for a remainder output, used for ledger nano
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RemainderData {
/// The remainder output
pub output: Output,
/// The chain derived from seed, for the remainder addresses
pub chain: Option<Bip44>,
/// The remainder address
pub address: Address,
}

/// Data for a remainder output, used for ledger nano
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct RemainderDataDto {
pub struct RemainderData {
/// The remainder output
pub output: Output,
/// The chain derived from seed, for the remainder addresses
Expand All @@ -154,24 +128,3 @@ pub struct RemainderDataDto {
/// The remainder address
pub address: Address,
}

impl TryFrom<RemainderDataDto> for RemainderData {
type Error = Error;

fn try_from(dto: RemainderDataDto) -> Result<Self, Self::Error> {
Ok(Self {
output: dto.output,
chain: dto.chain,
address: dto.address,
})
}
}
impl From<&RemainderData> for RemainderDataDto {
fn from(remainder: &RemainderData) -> Self {
Self {
output: remainder.output.clone(),
chain: remainder.chain,
address: remainder.address.clone(),
}
}
}
39 changes: 3 additions & 36 deletions sdk/src/client/secret/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ impl LedgerNanoStatus {
}

/// Data for transaction inputs for signing and ordering of unlock blocks
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InputSigningData {
/// The output
pub output: Output,
/// The output metadata
pub output_metadata: OutputMetadata,
/// The chain derived from seed, only for ed25519 addresses
#[serde(with = "option_bip44", default)]
pub chain: Option<Bip44>,
}

Expand All @@ -150,38 +152,3 @@ impl InputSigningData {
self.output_metadata.output_id()
}
}

/// Dto for data for transaction inputs for signing and ordering of unlock blocks
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InputSigningDataDto {
/// The output
pub output: Output,
/// The output metadata
pub output_metadata: OutputMetadata,
/// The chain derived from seed, only for ed25519 addresses
#[serde(with = "option_bip44", default)]
pub chain: Option<Bip44>,
}

impl TryFrom<InputSigningDataDto> for InputSigningData {
type Error = crate::client::Error;

fn try_from(dto: InputSigningDataDto) -> Result<Self, Self::Error> {
Ok(Self {
output: dto.output,
output_metadata: dto.output_metadata,
chain: dto.chain,
})
}
}

impl From<&InputSigningData> for InputSigningDataDto {
fn from(input: &InputSigningData) -> Self {
Self {
output: input.output.clone(),
output_metadata: input.output_metadata,
chain: input.chain,
}
}
}
Loading

0 comments on commit 5416d86

Please sign in to comment.