Skip to content

Commit

Permalink
cleanup and don't sort all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Mar 13, 2024
1 parent e70e9d7 commit 4d6179d
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 48 deletions.
9 changes: 1 addition & 8 deletions sdk/examples/wallet/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
//! ```

use iota_sdk::{
client::{
api::GetAddressesOptions,
constants::SHIMMER_COIN_TYPE,
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
client::{constants::SHIMMER_COIN_TYPE, secret::mnemonic::MnemonicSecretManager},
crypto::keys::bip44::Bip44,
wallet::{ClientOptions, Wallet},
};
Expand All @@ -39,9 +35,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Restore a wallet
let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?;
let secret_manager = SecretManager::Mnemonic(MnemonicSecretManager::try_from_mnemonic(
std::env::var("MNEMONIC").unwrap(),
)?);

let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

Expand Down
5 changes: 1 addition & 4 deletions sdk/examples/wallet/offline_signing/1_prepare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
//! ```

use iota_sdk::{
client::{
api::PreparedTransactionDataDto, constants::SHIMMER_COIN_TYPE, secret::SecretManager,
stronghold::StrongholdAdapter,
},
client::{api::PreparedTransactionDataDto, constants::SHIMMER_COIN_TYPE, secret::SecretManager},
crypto::keys::bip44::Bip44,
types::block::address::Bech32Address,
wallet::{ClientOptions, SendParams, Wallet},
Expand Down
8 changes: 2 additions & 6 deletions sdk/examples/wallet/spammer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
request_funds_from_faucet,
secret::{mnemonic::MnemonicSecretManager, SecretManage, SecretManager},
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
crypto::keys::bip44::Bip44,
types::block::{
address::{Address, Bech32Address, Hrp},
output::BasicOutput,
payload::signed_transaction::TransactionId,
},
types::block::{address::Bech32Address, output::BasicOutput, payload::signed_transaction::TransactionId},
wallet::{ClientOptions, FilterOptions, SendParams, Wallet},
};

Expand Down
23 changes: 9 additions & 14 deletions sdk/src/client/api/block_builder/transaction_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,15 @@ pub(crate) struct OrderedInputs {
}

impl OrderedInputs {
pub(crate) fn iter(&self) -> OrderedInputsIter<&Address, &InputSigningData> {
self.into_iter()
pub(crate) fn iter_sorted(&self) -> OrderedInputsIter<&Address, &InputSigningData> {
OrderedInputsIter {
queue: self.ed25519.iter().collect(),
other: self.other.iter().map(|(k, v)| (k, v.iter().collect())).collect(),
}
}

pub(crate) fn iter(&self) -> impl Iterator<Item = &InputSigningData> + Clone {
self.ed25519.iter().chain(self.other.values().flatten())
}

pub(crate) fn insert(&mut self, required_address: Address, input: InputSigningData) {
Expand Down Expand Up @@ -777,18 +784,6 @@ impl<A: Borrow<Address> + Ord + core::hash::Hash, I: Borrow<InputSigningData>> I
}
}

impl<'a> IntoIterator for &'a OrderedInputs {
type Item = &'a InputSigningData;
type IntoIter = OrderedInputsIter<&'a Address, Self::Item>;

fn into_iter(self) -> Self::IntoIter {
OrderedInputsIter {
queue: self.ed25519.iter().collect(),
other: self.other.iter().map(|(k, v)| (k, v.iter().collect())).collect(),
}
}
}

impl IntoIterator for OrderedInputs {
type Item = InputSigningData;
type IntoIter = OrderedInputsIter<Address, Self::Item>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TransactionBuilder {
return Ok(Some((remainder_address.clone(), None)));
}

for input in &self.selected_inputs {
for input in self.selected_inputs.iter() {
let required_address = input
.output
.required_address(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl TransactionBuilder {
let mut inputs_sdr = HashMap::new();
let mut outputs_sdr = HashMap::new();

for selected_input in &self.selected_inputs {
for selected_input in self.selected_inputs.iter() {
inputs_sum += selected_input.output.amount();

if let Some(sdruc) = sdruc_not_expired(&selected_input.output, self.latest_slot_commitment_id.slot_index())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl TransactionBuilder {
if !self.selected_inputs.is_empty() && self.all_outputs().next().is_some() {
let inputs = self
.selected_inputs
.iter()
.iter_sorted()
.map(|i| Input::Utxo(UtxoInput::from(*i.output_id())));

let outputs = self.all_outputs().cloned();
Expand Down Expand Up @@ -305,7 +305,7 @@ impl TransactionBuilder {
.into()
.unwrap_or_else(|| self.burn.as_ref().map_or(true, |b| !b.generated_mana()));

for input in &self.selected_inputs {
for input in self.selected_inputs.iter() {
selected_mana += self.total_mana(input, include_generated)?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TransactionBuilder {
let TokenScheme::Simple(output_foundry_simple_ts) = output_foundry.token_scheme();
let mut initial_creation = true;

for input in &self.selected_inputs {
for input in self.selected_inputs.iter() {
if let Output::Foundry(input_foundry) = &input.output {
let token_id = output_foundry.token_id();

Expand Down
13 changes: 4 additions & 9 deletions sdk/tests/client/secret_manager/address_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@

#[cfg(feature = "stronghold")]
use crypto::keys::bip39::Mnemonic;
use crypto::keys::bip44::Bip44;
#[cfg(feature = "ledger_nano")]
use iota_sdk::client::secret::ledger_nano::LedgerSecretManager;
#[cfg(feature = "stronghold")]
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
#[cfg(feature = "ledger_nano")]
use iota_sdk::client::secret::{ledger_nano::LedgerSecretManager, GenerateAddressOptions};
#[cfg(feature = "events")]
use iota_sdk::wallet::events::{WalletEvent, WalletEventType};
use iota_sdk::{
client::{
api::GetAddressesOptions,
constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE},
secret::{mnemonic::MnemonicSecretManager, SecretManager},
ClientError,
},
types::block::address::{Hrp, ToBech32Ext},
wallet::{ClientOptions, Wallet},
types::block::address::ToBech32Ext,
};
use pretty_assertions::assert_eq;

use crate::client::common::{setup, tear_down, DEFAULT_MNEMONIC, NODE_LOCAL};
use crate::client::common::{setup, tear_down, DEFAULT_MNEMONIC};

#[tokio::test]
async fn address_generation_mnemonic() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
1 change: 0 additions & 1 deletion sdk/tests/client/secret_manager/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::client::{
api::GetAddressesOptions,
constants::{SHIMMER_COIN_TYPE, SHIMMER_TESTNET_BECH32_HRP},
secret::SecretManager,
ClientError,
Expand Down
1 change: 0 additions & 1 deletion sdk/tests/client/secret_manager/stronghold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::client::{
api::GetAddressesOptions,
constants::{SHIMMER_COIN_TYPE, SHIMMER_TESTNET_BECH32_HRP},
secret::SecretManager,
ClientError,
Expand Down

0 comments on commit 4d6179d

Please sign in to comment.