Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ConvertTo to utils #1603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use iota_sdk::{
},
payload::signed_transaction::TransactionId,
slot::SlotIndex,
ConvertTo,
},
},
utils::ConvertTo,
wallet::{
types::{OutputData, TransactionWithMetadata},
ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim, SendNativeTokensParams,
Expand Down
6 changes: 2 additions & 4 deletions sdk/src/client/api/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use crate::{
secret::{GenerateAddressOptions, SecretManage, SecretManager},
Client, Result,
},
types::block::{
address::{Address, Bech32Address, Hrp, ToBech32Ext},
ConvertTo,
},
types::block::address::{Address, Bech32Address, Hrp, ToBech32Ext},
utils::ConvertTo,
};

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/client/node_api/participation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use crate::{
ParticipationEventType,
},
},
block::{address::Bech32Address, output::OutputId, ConvertTo},
block::{address::Bech32Address, output::OutputId},
},
utils::ConvertTo,
};

impl ClientInner {
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use crate::{
address::{Address, Bech32Address, Ed25519Address, Hrp, ToBech32Ext},
output::{AccountId, NftId},
payload::TaggedDataPayload,
BlockId, ConvertTo, SignedBlock,
BlockId, SignedBlock,
},
utils::ConvertTo,
};

/// Transforms bech32 to hex
Expand Down
9 changes: 6 additions & 3 deletions sdk/src/types/block/address/bech32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ use packable::{
Packable, PackableExt,
};

use crate::types::block::{
address::{Address, MultiAddress},
ConvertTo, Error,
use crate::{
types::block::{
address::{Address, MultiAddress},
Error,
},
utils::ConvertTo,
};

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, Display)]
Expand Down
15 changes: 9 additions & 6 deletions sdk/src/types/block/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ pub use self::{
nft::NftAddress,
restricted::{AddressCapabilities, AddressCapabilityFlag, RestrictedAddress},
};
use crate::types::block::{
output::Output,
semantic::{SemanticValidationContext, TransactionFailureReason},
signature::Signature,
unlock::Unlock,
ConvertTo, Error,
use crate::{
types::block::{
output::Output,
semantic::{SemanticValidationContext, TransactionFailureReason},
signature::Signature,
unlock::Unlock,
Error,
},
utils::ConvertTo,
};

/// A generic address supporting different address kinds.
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types/block/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ macro_rules! impl_id {
}
}

impl $crate::types::block::ConvertTo<$hash_name> for &alloc::string::String {
impl $crate::utils::ConvertTo<$hash_name> for &alloc::string::String {
fn convert(self) -> Result<$hash_name, $crate::types::block::Error> {
self.try_into()
}
}

impl $crate::types::block::ConvertTo<$hash_name> for &str {
impl $crate::utils::ConvertTo<$hash_name> for &str {
fn convert(self) -> Result<$hash_name, $crate::types::block::Error> {
self.try_into()
}
Expand Down Expand Up @@ -205,13 +205,13 @@ macro_rules! impl_id {
}
}

impl $crate::types::block::ConvertTo<$id_name> for &alloc::string::String {
impl $crate::utils::ConvertTo<$id_name> for &alloc::string::String {
fn convert(self) -> Result<$id_name, $crate::types::block::Error> {
self.try_into()
}
}

impl $crate::types::block::ConvertTo<$id_name> for &str {
impl $crate::utils::ConvertTo<$id_name> for &str {
fn convert(self) -> Result<$id_name, $crate::types::block::Error> {
self.try_into()
}
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/types/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! Core data types for blocks in the tangle.

mod block_id;
mod convert;
mod error;
mod issuer_id;
mod r#macro;
Expand Down Expand Up @@ -46,7 +45,6 @@ pub use self::core::dto::{BlockDto, SignedBlockDto, UnsignedBlockDto};
pub(crate) use self::r#macro::*;
pub use self::{
block_id::{BlockHash, BlockId},
convert::ConvertTo,
core::{Block, SignedBlock, UnsignedBlock},
error::Error,
issuer_id::IssuerId,
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use super::{
mana::{ManaParameters, RewardsParameters},
slot::{EpochIndex, SlotIndex},
};
use crate::types::block::{helper::network_name_to_id, output::RentStructure, ConvertTo, Error, PROTOCOL_VERSION};
use crate::{
types::block::{helper::network_name_to_id, output::RentStructure, Error, PROTOCOL_VERSION},
utils::ConvertTo,
};

/// Defines the parameters of the protocol at a particular version.
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable, Getters, CopyGetters)]
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions sdk/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

mod convert;

pub mod merkle_hasher;
#[cfg(feature = "serde")]
pub mod serde;

pub use convert::ConvertTo;
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::{
block::{
address::{AccountAddress, Bech32Address, ToBech32Ext},
output::{Output, OutputId},
ConvertTo,
},
},
utils::ConvertTo,
wallet::{operations::syncing::SyncOptions, task, Wallet},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

use crate::{
client::{node_api::indexer::query_parameters::BasicOutputQueryParameters, secret::SecretManage},
types::block::{address::Bech32Address, output::OutputId, ConvertTo},
types::block::{address::Bech32Address, output::OutputId},
utils::ConvertTo,
wallet::Wallet,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

use crate::{
client::{node_api::indexer::query_parameters::NftOutputQueryParameters, secret::SecretManage},
types::block::{address::Bech32Address, output::OutputId, ConvertTo},
types::block::{address::Bech32Address, output::OutputId},
utils::ConvertTo,
wallet::Wallet,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
unlock_condition::AddressUnlockCondition,
NftId, NftOutputBuilder,
},
ConvertTo,
},
utils::ConvertTo,
wallet::{
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Wallet,
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/wallet/operations/transaction/high_level/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use crate::{
BasicOutputBuilder, MinimumStorageDepositBasicOutput,
},
slot::SlotIndex,
ConvertTo,
},
utils::serde::string,
utils::{serde::string, ConvertTo},
wallet::{
constants::DEFAULT_EXPIRATION_SLOTS,
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
BasicOutputBuilder, MinimumStorageDepositBasicOutput, NativeToken, NativeTokens, TokenId,
},
slot::SlotIndex,
ConvertTo,
},
utils::ConvertTo,
wallet::{
constants::DEFAULT_EXPIRATION_SLOTS,
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
types::block::{
address::Bech32Address,
output::{unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, Output},
ConvertTo,
},
utils::ConvertTo,
wallet::{
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Wallet,
Expand Down
9 changes: 6 additions & 3 deletions sdk/src/wallet/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use std::hash::Hash;
use getset::{Getters, Setters};
use serde::{Deserialize, Serialize};

use crate::types::{
self,
block::{address::Bech32Address, output::OutputId, ConvertTo},
use crate::{
types::{
self,
block::{address::Bech32Address, output::OutputId},
},
utils::ConvertTo,
};

/// A BIP44 address.
Expand Down
Loading