From 4b651a967d45bda4972722ecfbe74b64fc6297d4 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 12:19:58 -0500 Subject: [PATCH 01/23] Rename input selection to transaction builder. Move transaction options to client to support a client version of transaction builder. --- bindings/core/src/method/wallet.rs | 6 +- cli/src/wallet_cli/mod.rs | 4 +- .../how_tos/account_output/send_amount.rs | 4 +- .../send_micro_transaction.rs | 5 +- sdk/src/client/api/block_builder/mod.rs | 3 +- .../api/block_builder}/options.rs | 8 +- .../burn.rs | 2 +- .../error.rs | 8 +- .../mod.rs | 179 ++++++++++++++---- .../remainder.rs | 6 +- .../requirement/account.rs | 4 +- .../requirement/amount.rs | 38 ++-- .../requirement/context_inputs.rs | 4 +- .../requirement/delegation.rs | 4 +- .../requirement/ed25519.rs | 4 +- .../requirement/foundry.rs | 4 +- .../requirement/issuer.rs | 4 +- .../requirement/mana.rs | 8 +- .../requirement/mod.rs | 4 +- .../requirement/native_tokens.rs | 4 +- .../requirement/nft.rs | 4 +- .../requirement/sender.rs | 4 +- .../transition.rs | 4 +- sdk/src/client/api/high_level.rs | 4 +- sdk/src/client/error.rs | 7 +- sdk/src/client/secret/mod.rs | 6 +- sdk/src/wallet/error.rs | 8 +- sdk/src/wallet/events/types.rs | 2 +- sdk/src/wallet/mod.rs | 1 - sdk/src/wallet/operations/output_claiming.rs | 9 +- .../wallet/operations/output_consolidation.rs | 14 +- .../wallet/operations/participation/mod.rs | 2 +- ...nput_selection.rs => build_transaction.rs} | 38 ++-- .../burning_melting/melt_native_token.rs | 2 +- .../high_level/burning_melting/mod.rs | 4 +- .../transaction/high_level/staking/begin.rs | 7 +- .../transaction/high_level/staking/end.rs | 7 +- .../transaction/high_level/staking/extend.rs | 7 +- sdk/src/wallet/operations/transaction/mod.rs | 6 +- .../operations/transaction/prepare_output.rs | 8 +- .../transaction/prepare_transaction.rs | 2 +- sdk/tests/client/error.rs | 10 +- sdk/tests/client/mod.rs | 2 +- sdk/tests/client/signing/mod.rs | 6 +- .../account_outputs.rs | 142 +++++++------- .../basic_outputs.rs | 168 ++++++++-------- .../burn.rs | 40 ++-- .../delegation_outputs.rs | 20 +- .../expiration.rs | 38 ++-- .../foundry_outputs.rs | 42 ++-- .../mod.rs | 0 .../native_tokens.rs | 54 +++--- .../nft_outputs.rs | 60 +++--- .../outputs.rs | 20 +- .../storage_deposit_return.rs | 24 +-- .../timelock.rs | 12 +- sdk/tests/wallet/burn_outputs.rs | 2 +- sdk/tests/wallet/claim_outputs.rs | 3 +- 58 files changed, 602 insertions(+), 490 deletions(-) rename sdk/src/{wallet/operations/transaction => client/api/block_builder}/options.rs (92%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/burn.rs (98%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/error.rs (93%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/mod.rs (83%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/remainder.rs (98%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/account.rs (96%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/amount.rs (94%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/context_inputs.rs (98%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/delegation.rs (96%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/ed25519.rs (97%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/foundry.rs (95%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/issuer.rs (91%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/mana.rs (98%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/mod.rs (99%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/native_tokens.rs (99%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/nft.rs (96%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/requirement/sender.rs (97%) rename sdk/src/client/api/block_builder/{input_selection => transaction_builder}/transition.rs (99%) rename sdk/src/wallet/operations/transaction/{input_selection.rs => build_transaction.rs} (85%) rename sdk/tests/client/{input_selection => transaction_builder}/account_outputs.rs (96%) rename sdk/tests/client/{input_selection => transaction_builder}/basic_outputs.rs (95%) rename sdk/tests/client/{input_selection => transaction_builder}/burn.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/delegation_outputs.rs (88%) rename sdk/tests/client/{input_selection => transaction_builder}/expiration.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/foundry_outputs.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/mod.rs (100%) rename sdk/tests/client/{input_selection => transaction_builder}/native_tokens.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/nft_outputs.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/outputs.rs (96%) rename sdk/tests/client/{input_selection => transaction_builder}/storage_deposit_return.rs (97%) rename sdk/tests/client/{input_selection => transaction_builder}/timelock.rs (96%) diff --git a/bindings/core/src/method/wallet.rs b/bindings/core/src/method/wallet.rs index 40647618bf..755dc01e0f 100644 --- a/bindings/core/src/method/wallet.rs +++ b/bindings/core/src/method/wallet.rs @@ -6,9 +6,9 @@ use std::path::PathBuf; use crypto::keys::bip44::Bip44; use derivative::Derivative; -use iota_sdk::utils::serde::string; #[cfg(feature = "events")] use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType}; +use iota_sdk::{client::api::options::TransactionOptions, utils::serde::string}; // #[cfg(feature = "participation")] // use iota_sdk::{ // client::node_manager::node::Node, @@ -17,7 +17,7 @@ use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType}; // }; use iota_sdk::{ client::{ - api::{input_selection::Burn, PreparedTransactionDataDto, SignedTransactionDataDto}, + api::{transaction_builder::Burn, PreparedTransactionDataDto, SignedTransactionDataDto}, node_manager::node::NodeAuth, secret::GenerateAddressOptions, }, @@ -29,7 +29,7 @@ use iota_sdk::{ wallet::{ BeginStakingParams, ClientOptions, ConsolidationParams, CreateAccountParams, CreateDelegationParams, CreateNativeTokenParams, FilterOptions, MintNftParams, OutputParams, OutputsToClaim, SendManaParams, - SendNativeTokenParams, SendNftParams, SendParams, SyncOptions, TransactionOptions, + SendNativeTokenParams, SendNftParams, SendParams, SyncOptions, }, U256, }; diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 322d5a6f2b..cd62a76cbe 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use clap::{CommandFactory, Parser, Subcommand}; use colored::Colorize; use iota_sdk::{ - client::{request_funds_from_faucet, secret::SecretManager}, + client::{api::options::TransactionOptions, request_funds_from_faucet, secret::SecretManager}, types::block::{ address::{AccountAddress, Bech32Address, ToBech32Ext}, mana::ManaAllotment, @@ -25,7 +25,7 @@ use iota_sdk::{ wallet::{ types::OutputData, BeginStakingParams, ConsolidationParams, CreateDelegationParams, CreateNativeTokenParams, Error as WalletError, MintNftParams, OutputsToClaim, ReturnStrategy, SendManaParams, SendNativeTokenParams, - SendNftParams, SendParams, SyncOptions, TransactionOptions, Wallet, + SendNftParams, SendParams, SyncOptions, Wallet, }, U256, }; diff --git a/sdk/examples/how_tos/account_output/send_amount.rs b/sdk/examples/how_tos/account_output/send_amount.rs index 9388d31f71..bb487e0004 100644 --- a/sdk/examples/how_tos/account_output/send_amount.rs +++ b/sdk/examples/how_tos/account_output/send_amount.rs @@ -7,9 +7,9 @@ //! `cargo run --release --all-features --example account_output_send_amount` use iota_sdk::{ - client::node_api::indexer::query_parameters::BasicOutputQueryParameters, + client::{api::options::TransactionOptions, node_api::indexer::query_parameters::BasicOutputQueryParameters}, types::block::address::{AccountAddress, ToBech32Ext}, - wallet::{AccountSyncOptions, Result, SyncOptions, TransactionOptions}, + wallet::{AccountSyncOptions, Result, SyncOptions}, Wallet, }; diff --git a/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs b/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs index 3214dc9226..24bd2996ea 100644 --- a/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs +++ b/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs @@ -11,10 +11,7 @@ //! cargo run --release --all-features --example send_micro_transaction //! ``` -use iota_sdk::{ - wallet::{Result, TransactionOptions}, - Wallet, -}; +use iota_sdk::{client::api::options::TransactionOptions, wallet::Result, Wallet}; // The base coin micro amount to send const SEND_MICRO_AMOUNT: u64 = 1; diff --git a/sdk/src/client/api/block_builder/mod.rs b/sdk/src/client/api/block_builder/mod.rs index 45483daa0b..dfb3312368 100644 --- a/sdk/src/client/api/block_builder/mod.rs +++ b/sdk/src/client/api/block_builder/mod.rs @@ -1,8 +1,9 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub mod input_selection; +pub mod options; pub mod transaction; +pub mod transaction_builder; pub use self::transaction::verify_semantic; use crate::{ diff --git a/sdk/src/wallet/operations/transaction/options.rs b/sdk/src/client/api/block_builder/options.rs similarity index 92% rename from sdk/src/wallet/operations/transaction/options.rs rename to sdk/src/client/api/block_builder/options.rs index f3bc9bcde4..0b629c3b60 100644 --- a/sdk/src/wallet/operations/transaction/options.rs +++ b/sdk/src/client/api/block_builder/options.rs @@ -6,7 +6,7 @@ use alloc::collections::{BTreeMap, BTreeSet}; use serde::{Deserialize, Serialize}; use crate::{ - client::api::input_selection::Burn, + client::api::transaction_builder::Burn, types::block::{ address::Address, context_input::ContextInput, @@ -28,14 +28,14 @@ pub struct TransactionOptions { pub context_inputs: Vec, /// Inputs that must be used for the transaction. pub required_inputs: BTreeSet, - /// Specifies what needs to be burned during input selection. + /// Specifies what needs to be burned during iransaction builder. pub burn: Option, /// A string attached to the transaction. pub note: Option, /// Whether to allow sending a micro amount. pub allow_micro_amount: bool, /// Whether to allow the selection of additional inputs for this transaction. - pub allow_additional_input_selection: bool, + pub allow_additional_transaction_builder: bool, /// Transaction capabilities. pub capabilities: Option, /// Mana allotments for the transaction. @@ -54,7 +54,7 @@ impl Default for TransactionOptions { burn: Default::default(), note: Default::default(), allow_micro_amount: false, - allow_additional_input_selection: true, + allow_additional_transaction_builder: true, capabilities: Default::default(), mana_allotments: Default::default(), issuer_id: Default::default(), diff --git a/sdk/src/client/api/block_builder/input_selection/burn.rs b/sdk/src/client/api/block_builder/transaction_builder/burn.rs similarity index 98% rename from sdk/src/client/api/block_builder/input_selection/burn.rs rename to sdk/src/client/api/block_builder/transaction_builder/burn.rs index c621b1dfb0..7413ba85d3 100644 --- a/sdk/src/client/api/block_builder/input_selection/burn.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/burn.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::types::block::output::{AccountId, DelegationId, FoundryId, NativeToken, NftId, TokenId}; -/// A type to specify what needs to be burned during input selection. +/// A type to specify what needs to be burned during iransaction builder. /// Nothing will be burned that has not been explicitly set with this struct. #[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/sdk/src/client/api/block_builder/input_selection/error.rs b/sdk/src/client/api/block_builder/transaction_builder/error.rs similarity index 93% rename from sdk/src/client/api/block_builder/input_selection/error.rs rename to sdk/src/client/api/block_builder/transaction_builder/error.rs index bd0c302a87..1d1f935f6a 100644 --- a/sdk/src/client/api/block_builder/input_selection/error.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/error.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -//! Error handling for input selection. +//! Error handling for iransaction builder. use std::fmt::Debug; @@ -10,11 +10,11 @@ use primitive_types::U256; use super::Requirement; use crate::types::block::output::{ChainId, OutputId, TokenId}; -/// Errors related to input selection. +/// Errors related to iransaction builder. #[derive(Debug, Eq, PartialEq, thiserror::Error)] #[non_exhaustive] pub enum Error { - #[error("additional inputs required for {0:?}, but additional input selection is disabled")] + #[error("additional inputs required for {0:?}, but additional iransaction builder is disabled")] AdditionalInputsRequired(Requirement), /// Block error. #[error("{0}")] @@ -59,7 +59,7 @@ pub enum Error { /// No input with matching ed25519 address provided. #[error("no input with matching ed25519 address provided")] MissingInputWithEd25519Address, - /// No available inputs were provided to input selection. + /// No available inputs were provided to iransaction builder. #[error("no available inputs provided")] NoAvailableInputsProvided, /// Required input is forbidden. diff --git a/sdk/src/client/api/block_builder/input_selection/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs similarity index 83% rename from sdk/src/client/api/block_builder/input_selection/mod.rs rename to sdk/src/client/api/block_builder/transaction_builder/mod.rs index bf88f8552f..583a8a91d4 100644 --- a/sdk/src/client/api/block_builder/input_selection/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -//! Input selection for transactions +//!Bbuilder for transactions pub(crate) mod burn; pub(crate) mod error; @@ -19,11 +19,17 @@ use self::requirement::account::is_account_with_id; pub use self::{burn::Burn, error::Error, requirement::Requirement}; use crate::{ client::{ - api::{PreparedTransactionData, RemainderData}, + api::{ + options::{RemainderValueStrategy, TransactionOptions}, + transaction::validate_transaction_length, + PreparedTransactionData, RemainderData, + }, + node_api::indexer::query_parameters::OutputQueryParameters, secret::types::InputSigningData, + Client, }, types::block::{ - address::{AccountAddress, Address, NftAddress}, + address::{AccountAddress, Address, NftAddress, ToBech32Ext}, context_input::ContextInput, input::{Input, UtxoInput, INPUT_COUNT_RANGE}, mana::ManaAllotment, @@ -40,12 +46,133 @@ use crate::{ }, }; -/// Working state for the input selection algorithm. +impl Client { + /// Builds a transaction using the given inputs, outputs, addresses, and options. + pub async fn build_transaction( + &self, + addresses: impl IntoIterator, + outputs: impl IntoIterator, + options: TransactionOptions, + ) -> crate::wallet::Result { + let outputs = outputs.into_iter().collect::>(); + let addresses = addresses.into_iter().collect::>(); + // Voting output needs to be requested before to prevent a deadlock + let protocol_parameters = self.get_protocol_parameters().await?; + let creation_slot = self.get_slot_index().await?; + let slot_commitment_id = self.get_issuance().await?.latest_commitment.id(); + let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { + Some(self.get_account_congestion(&issuer_id, None).await?.reference_mana_cost) + } else { + None + }; + let remainder_address = match options.remainder_value_strategy { + RemainderValueStrategy::ReuseAddress => None, + RemainderValueStrategy::CustomAddress(address) => Some(address), + }; + + let hrp = self.get_bech32_hrp().await?; + + let mut available_input_ids = HashSet::new(); + for address in &addresses { + let mut cursor = None; + loop { + let mut query = OutputQueryParameters::new().unlockable_by_address(address.clone().to_bech32(hrp)); + if let Some(cursor) = cursor { + query = query.cursor(cursor); + } + let res = self.output_ids(query).await?; + cursor = res.cursor; + available_input_ids.extend(res.items); + if cursor.is_none() { + break; + } + } + } + let available_inputs = self + .get_outputs_with_metadata(&available_input_ids.into_iter().collect::>()) + .await? + .into_iter() + .map(|res| InputSigningData { + output: res.output, + output_metadata: res.metadata, + chain: None, + }) + .collect::>(); + + let mut mana_rewards = HashMap::new(); + + if let Some(burn) = &options.burn { + for delegation_id in burn.delegations() { + let output_id = self.delegation_output_id(*delegation_id).await?; + mana_rewards.insert( + output_id, + self.get_output_mana_rewards(&output_id, slot_commitment_id.slot_index()) + .await? + .rewards, + ); + } + } + + // Check that no input got already locked + for output_id in &options.required_inputs { + let input = self.get_output(output_id).await?; + if input.output.can_claim_rewards(outputs.iter().find(|o| { + input + .output + .chain_id() + .map(|chain_id| chain_id.or_from_output_id(output_id)) + == o.chain_id() + })) { + mana_rewards.insert( + *output_id, + self.get_output_mana_rewards(output_id, slot_commitment_id.slot_index()) + .await? + .rewards, + ); + } + } + + let mut transaction_builder = TransactionBuilder::new( + available_inputs, + outputs, + addresses, + creation_slot, + slot_commitment_id, + protocol_parameters.clone(), + ) + .with_required_inputs(options.required_inputs) + .with_context_inputs(options.context_inputs) + .with_mana_rewards(mana_rewards) + .with_payload(options.tagged_data_payload) + .with_mana_allotments(options.mana_allotments) + .with_remainder_address(remainder_address) + .with_burn(options.burn); + + if let (Some(account_id), Some(reference_mana_cost)) = (options.issuer_id, reference_mana_cost) { + transaction_builder = transaction_builder.with_min_mana_allotment(account_id, reference_mana_cost); + } + + if !options.allow_additional_transaction_builder { + transaction_builder = transaction_builder.disable_additional_transaction_builder(); + } + + if let Some(capabilities) = options.capabilities { + transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) + } + + let prepared_transaction_data = transaction_builder.select()?; + + validate_transaction_length(&prepared_transaction_data.transaction)?; + + Ok(prepared_transaction_data) + } +} + +/// Working state for the iransaction builder algorithm. #[derive(Debug)] -pub struct InputSelection { +pub struct TransactionBuilder { available_inputs: Vec, required_inputs: HashSet, - forbidden_inputs: HashSet, selected_inputs: Vec, context_inputs: HashSet, provided_outputs: Vec, @@ -60,7 +187,7 @@ pub struct InputSelection { mana_allotments: BTreeMap, mana_rewards: HashMap, payload: Option, - allow_additional_input_selection: bool, + allow_additional_transaction_builder: bool, transaction_capabilities: TransactionCapabilities, protocol_parameters: ProtocolParameters, } @@ -81,8 +208,8 @@ pub(crate) struct Remainders { added_mana: u64, } -impl InputSelection { - /// Creates a new [`InputSelection`]. +impl TransactionBuilder { + /// Creates a new [`TransactionBuilder`]. pub fn new( available_inputs: impl IntoIterator, outputs: impl IntoIterator, @@ -116,7 +243,6 @@ impl InputSelection { Self { available_inputs, required_inputs: HashSet::new(), - forbidden_inputs: HashSet::new(), selected_inputs: Vec::new(), context_inputs: HashSet::new(), provided_outputs: outputs.into_iter().collect(), @@ -130,7 +256,7 @@ impl InputSelection { min_mana_allotment: None, mana_allotments: Default::default(), mana_rewards: Default::default(), - allow_additional_input_selection: true, + allow_additional_transaction_builder: true, transaction_capabilities: Default::default(), payload: None, protocol_parameters, @@ -156,19 +282,10 @@ impl InputSelection { Requirement::NativeTokens, ]); - // Removes forbidden inputs from available inputs. - self.available_inputs - .retain(|input| !self.forbidden_inputs.contains(input.output_id())); - // This is to avoid a borrow of self since there is a mutable borrow in the loop already. let required_inputs = std::mem::take(&mut self.required_inputs); for required_input in required_inputs { - // Checks that required input is not forbidden. - if self.forbidden_inputs.contains(&required_input) { - return Err(Error::RequiredInputIsForbidden(required_input)); - } - // Checks that required input is available. match self .available_inputs @@ -223,7 +340,7 @@ impl InputSelection { // Fulfill the requirement. let inputs = self.fulfill_requirement(&requirement)?; - if !self.allow_additional_input_selection && !inputs.is_empty() { + if !self.allow_additional_transaction_builder && !inputs.is_empty() { return Err(Error::AdditionalInputsRequired(requirement)); } @@ -362,37 +479,31 @@ impl InputSelection { Ok(added_output) } - /// Sets the required inputs of an [`InputSelection`]. + /// Sets the required inputs of an [`TransactionBuilder`]. pub fn with_required_inputs(mut self, inputs: impl IntoIterator) -> Self { self.required_inputs = inputs.into_iter().collect(); self } - /// Sets the forbidden inputs of an [`InputSelection`]. - pub fn with_forbidden_inputs(mut self, inputs: impl IntoIterator) -> Self { - self.forbidden_inputs = inputs.into_iter().collect(); - self - } - - /// Sets the context inputs of an [`InputSelection`]. + /// Sets the context inputs of an [`TransactionBuilder`]. pub fn with_context_inputs(mut self, context_inputs: impl IntoIterator) -> Self { self.context_inputs = context_inputs.into_iter().collect(); self } - /// Sets the burn of an [`InputSelection`]. + /// Sets the burn of an [`TransactionBuilder`]. pub fn with_burn(mut self, burn: impl Into>) -> Self { self.burn = burn.into(); self } - /// Sets the remainder address of an [`InputSelection`]. + /// Sets the remainder address of an [`TransactionBuilder`]. pub fn with_remainder_address(mut self, address: impl Into>) -> Self { self.remainders.address = address.into(); self } - /// Sets the mana allotments of an [`InputSelection`]. + /// Sets the mana allotments of an [`TransactionBuilder`]. pub fn with_mana_allotments(mut self, mana_allotments: impl IntoIterator) -> Self { self.mana_allotments = mana_allotments.into_iter().collect(); self @@ -427,8 +538,8 @@ impl InputSelection { } /// Disables selecting additional inputs. - pub fn disable_additional_input_selection(mut self) -> Self { - self.allow_additional_input_selection = false; + pub fn disable_additional_transaction_builder(mut self) -> Self { + self.allow_additional_transaction_builder = false; self } diff --git a/sdk/src/client/api/block_builder/input_selection/remainder.rs b/sdk/src/client/api/block_builder/transaction_builder/remainder.rs similarity index 98% rename from sdk/src/client/api/block_builder/input_selection/remainder.rs rename to sdk/src/client/api/block_builder/transaction_builder/remainder.rs index c2cfcc4d67..888ea919ba 100644 --- a/sdk/src/client/api/block_builder/input_selection/remainder.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/remainder.rs @@ -6,10 +6,10 @@ use std::collections::HashMap; use crypto::keys::bip44::Bip44; -use super::{Error, InputSelection}; +use super::{Error, TransactionBuilder}; use crate::{ client::api::{ - input_selection::requirement::native_tokens::{get_native_tokens, get_native_tokens_diff}, + transaction_builder::requirement::native_tokens::{get_native_tokens, get_native_tokens_diff}, RemainderData, }, types::block::{ @@ -22,7 +22,7 @@ use crate::{ }, }; -impl InputSelection { +impl TransactionBuilder { /// Updates the remainders, overwriting old values. pub(crate) fn update_remainders(&mut self) -> Result<(), Error> { let (storage_deposit_returns, remainders) = self.storage_deposit_returns_and_remainders()?; diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/account.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/account.rs similarity index 96% rename from sdk/src/client/api/block_builder/input_selection/requirement/account.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/account.rs index 87f8cd20cd..8b1e59a119 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/account.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/account.rs @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::output::{AccountId, Output, OutputId}, @@ -26,7 +26,7 @@ pub(crate) fn is_account_with_id_non_null(output: &Output, account_id: &AccountI } } -impl InputSelection { +impl TransactionBuilder { /// Fulfills an account requirement by selecting the appropriate account from the available inputs. pub(crate) fn fulfill_account_requirement( &mut self, diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs similarity index 94% rename from sdk/src/client/api/block_builder/input_selection/requirement/amount.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs index 801e962951..58b5c09ca4 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/amount.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs @@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet}; -use super::{native_tokens::get_native_tokens, Error, InputSelection, Requirement}; +use super::{native_tokens::get_native_tokens, Error, Requirement, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::{ @@ -31,11 +31,15 @@ pub(crate) fn sdruc_not_expired( .map_or(false, |expiration| slot_index >= expiration.slot_index()); // We only have to send the storage deposit return back if the output is not expired - if !expired { Some(sdr) } else { None } + if !expired { + Some(sdr) + } else { + None + } }) } -impl InputSelection { +impl TransactionBuilder { pub(crate) fn amount_sums(&self) -> (u64, u64, HashMap, HashMap) { let mut inputs_sum = 0; let mut outputs_sum = 0; @@ -88,15 +92,15 @@ struct AmountSelection { } impl AmountSelection { - fn new(input_selection: &InputSelection) -> Result { - let (inputs_sum, outputs_sum, inputs_sdr, outputs_sdr) = input_selection.amount_sums(); + fn new(transaction_builder: &TransactionBuilder) -> Result { + let (inputs_sum, outputs_sum, inputs_sdr, outputs_sdr) = transaction_builder.amount_sums(); let selected_native_tokens = HashSet::::from_iter( - input_selection + transaction_builder .selected_inputs .iter() .filter_map(|i| i.output.native_token().map(|n| *n.token_id())), ); - let (remainder_amount, native_tokens_remainder, mana_remainder) = input_selection.remainder_amount()?; + let (remainder_amount, native_tokens_remainder, mana_remainder) = transaction_builder.remainder_amount()?; Ok(Self { newly_selected_inputs: HashMap::new(), @@ -132,7 +136,7 @@ impl AmountSelection { fn fulfil<'a>( &mut self, - input_selection: &InputSelection, + transaction_builder: &TransactionBuilder, inputs: impl Iterator, ) -> Result { for input in inputs { @@ -140,9 +144,10 @@ impl AmountSelection { continue; } - if let Some(sdruc) = - sdruc_not_expired(&input.output, input_selection.latest_slot_commitment_id.slot_index()) - { + if let Some(sdruc) = sdruc_not_expired( + &input.output, + transaction_builder.latest_slot_commitment_id.slot_index(), + ) { // Skip if no additional amount is made available if input.output.amount() == sdruc.amount() { continue; @@ -169,7 +174,7 @@ impl AmountSelection { if input.output.native_token().is_some() { // Recalculate the remaining amount, as a new native token may require a new remainder output. let (remainder_amount, native_tokens_remainder, mana_remainder) = - self.remainder_amount(input_selection)?; + self.remainder_amount(transaction_builder)?; log::debug!( "Calculated new remainder_amount: {remainder_amount}, native_tokens_remainder: {native_tokens_remainder}" ); @@ -186,11 +191,14 @@ impl AmountSelection { Ok(false) } - pub(crate) fn remainder_amount(&self, input_selection: &InputSelection) -> Result<(u64, bool, bool), Error> { + pub(crate) fn remainder_amount( + &self, + transaction_builder: &TransactionBuilder, + ) -> Result<(u64, bool, bool), Error> { let input_native_tokens = get_native_tokens(self.newly_selected_inputs.values().map(|input| &input.output))?.finish()?; - input_selection.required_remainder_amount(Some(input_native_tokens)) + transaction_builder.required_remainder_amount(Some(input_native_tokens)) } fn into_newly_selected_inputs(self) -> Vec { @@ -198,7 +206,7 @@ impl AmountSelection { } } -impl InputSelection { +impl TransactionBuilder { fn fulfil<'a>( &self, base_inputs: impl Iterator + Clone, diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/context_inputs.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs similarity index 98% rename from sdk/src/client/api/block_builder/input_selection/requirement/context_inputs.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs index ed95a7b027..37620e9fa4 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/context_inputs.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection}; +use super::{Error, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::{ @@ -10,7 +10,7 @@ use crate::{ }, }; -impl InputSelection { +impl TransactionBuilder { pub(crate) fn fulfill_context_inputs_requirement(&mut self) -> Result, Error> { let mut needs_commitment_context = false; diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/delegation.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/delegation.rs similarity index 96% rename from sdk/src/client/api/block_builder/input_selection/requirement/delegation.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/delegation.rs index b2e11a5269..cbb1c414ce 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/delegation.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/delegation.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::output::{DelegationId, Output, OutputId}, @@ -29,7 +29,7 @@ pub(crate) fn is_delegation_with_id_non_null(output: &Output, delegation_id: &De } } -impl InputSelection { +impl TransactionBuilder { /// Fulfills an delegation requirement by selecting the appropriate delegation from the available inputs. pub(crate) fn fulfill_delegation_requirement( &mut self, diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/ed25519.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/ed25519.rs similarity index 97% rename from sdk/src/client/api/block_builder/input_selection/requirement/ed25519.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/ed25519.rs index 5862af536c..ef508ff755 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/ed25519.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/ed25519.rs @@ -1,10 +1,10 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{client::secret::types::InputSigningData, types::block::address::Address}; -impl InputSelection { +impl TransactionBuilder { // Checks if a selected input unlocks a given ED25519 address. fn selected_unlocks_ed25519_address(&self, input: &InputSigningData, address: &Address) -> bool { let required_address = input diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/foundry.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/foundry.rs similarity index 95% rename from sdk/src/client/api/block_builder/input_selection/requirement/foundry.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/foundry.rs index f1a2f5be1b..3222aff91d 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/foundry.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/foundry.rs @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::output::{FoundryId, Output}, @@ -16,7 +16,7 @@ pub(crate) fn is_foundry_with_id(output: &Output, foundry_id: &FoundryId) -> boo } } -impl InputSelection { +impl TransactionBuilder { /// Fulfills a foundry requirement by selecting the appropriate foundry from the available inputs. pub(crate) fn fulfill_foundry_requirement( &mut self, diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/issuer.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/issuer.rs similarity index 91% rename from sdk/src/client/api/block_builder/input_selection/requirement/issuer.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/issuer.rs index 99c961c418..bf9d7ae247 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/issuer.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/issuer.rs @@ -1,10 +1,10 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{client::secret::types::InputSigningData, types::block::address::Address}; -impl InputSelection { +impl TransactionBuilder { /// Fulfills an issuer requirement by fulfilling the equivalent sender requirement. /// Potentially converts the error for a more accurate one. pub(crate) fn fulfill_issuer_requirement(&mut self, address: &Address) -> Result, Error> { diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs similarity index 98% rename from sdk/src/client/api/block_builder/input_selection/requirement/mana.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index 2b85eb0c79..23e16e3987 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -5,10 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 use std::collections::HashMap; -use super::{Error, InputSelection}; +use super::{Error, TransactionBuilder}; use crate::{ client::{ - api::input_selection::{MinManaAllotment, Requirement}, + api::transaction_builder::{MinManaAllotment, Requirement}, secret::types::InputSigningData, }, types::block::{ @@ -23,7 +23,7 @@ use crate::{ }, }; -impl InputSelection { +impl TransactionBuilder { pub(crate) fn fulfill_mana_requirement(&mut self) -> Result, Error> { let Some(MinManaAllotment { issuer_id, @@ -240,7 +240,7 @@ impl InputSelection { if selected_mana >= required_mana { log::debug!("Mana requirement already fulfilled"); } else { - if !self.allow_additional_input_selection { + if !self.allow_additional_transaction_builder { return Err(Error::AdditionalInputsRequired(Requirement::Mana)); } // TODO we should do as for the amount and have preferences on which inputs to pick. diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mod.rs similarity index 99% rename from sdk/src/client/api/block_builder/input_selection/requirement/mod.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/mod.rs index ac2751ae56..2e26d7b05b 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mod.rs @@ -17,7 +17,7 @@ use self::{ account::is_account_with_id_non_null, delegation::is_delegation_with_id_non_null, foundry::is_foundry_with_id, nft::is_nft_with_id_non_null, }; -use super::{Error, InputSelection}; +use super::{Error, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::{ @@ -53,7 +53,7 @@ pub enum Requirement { ContextInputs, } -impl InputSelection { +impl TransactionBuilder { /// Fulfills a requirement by selecting the appropriate available inputs. /// Returns the selected inputs and an optional new requirement. pub(crate) fn fulfill_requirement(&mut self, requirement: &Requirement) -> Result, Error> { diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/native_tokens.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/native_tokens.rs similarity index 99% rename from sdk/src/client/api/block_builder/input_selection/requirement/native_tokens.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/native_tokens.rs index aa0fef119e..e08279009d 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/native_tokens.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/native_tokens.rs @@ -5,7 +5,7 @@ use std::{cmp::Ordering, collections::HashSet}; use primitive_types::U256; -use super::{Error, InputSelection}; +use super::{Error, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::output::{NativeToken, NativeTokens, NativeTokensBuilder, Output, TokenScheme}, @@ -50,7 +50,7 @@ pub(crate) fn get_native_tokens_diff( } } -impl InputSelection { +impl TransactionBuilder { pub(crate) fn fulfill_native_tokens_requirement(&mut self) -> Result, Error> { let mut input_native_tokens = get_native_tokens(self.selected_inputs.iter().map(|input| &input.output))?; let mut output_native_tokens = get_native_tokens(self.non_remainder_outputs())?; diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/nft.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/nft.rs similarity index 96% rename from sdk/src/client/api/block_builder/input_selection/requirement/nft.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/nft.rs index 0ae00082c3..c49cad490e 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/nft.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/nft.rs @@ -1,7 +1,7 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{ client::secret::types::InputSigningData, types::block::output::{NftId, Output, OutputId}, @@ -29,7 +29,7 @@ pub(crate) fn is_nft_with_id_non_null(output: &Output, nft_id: &NftId) -> bool { } } -impl InputSelection { +impl TransactionBuilder { /// Fulfills an nft requirement by selecting the appropriate nft from the available inputs. pub(crate) fn fulfill_nft_requirement(&mut self, nft_id: NftId) -> Result, Error> { // Check if the requirement is already fulfilled. diff --git a/sdk/src/client/api/block_builder/input_selection/requirement/sender.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/sender.rs similarity index 97% rename from sdk/src/client/api/block_builder/input_selection/requirement/sender.rs rename to sdk/src/client/api/block_builder/transaction_builder/requirement/sender.rs index e481cf3023..5ef11bd41d 100644 --- a/sdk/src/client/api/block_builder/input_selection/requirement/sender.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/sender.rs @@ -1,10 +1,10 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use super::{Error, InputSelection, Requirement}; +use super::{Error, Requirement, TransactionBuilder}; use crate::{client::secret::types::InputSigningData, types::block::address::Address}; -impl InputSelection { +impl TransactionBuilder { /// Fulfills a sender requirement by selecting an available input that unlocks its address. pub(crate) fn fulfill_sender_requirement(&mut self, address: &Address) -> Result, Error> { match address { diff --git a/sdk/src/client/api/block_builder/input_selection/transition.rs b/sdk/src/client/api/block_builder/transaction_builder/transition.rs similarity index 99% rename from sdk/src/client/api/block_builder/input_selection/transition.rs rename to sdk/src/client/api/block_builder/transaction_builder/transition.rs index bbfa9f644f..ca49174409 100644 --- a/sdk/src/client/api/block_builder/input_selection/transition.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/transition.rs @@ -3,7 +3,7 @@ use super::{ requirement::{account::is_account_with_id_non_null, foundry::is_foundry_with_id, nft::is_nft_with_id_non_null}, - Error, InputSelection, + Error, TransactionBuilder, }; use crate::{ client::secret::types::InputSigningData, @@ -13,7 +13,7 @@ use crate::{ }, }; -impl InputSelection { +impl TransactionBuilder { /// Transitions an account input by creating a new account output if required. fn transition_account_input( &mut self, diff --git a/sdk/src/client/api/high_level.rs b/sdk/src/client/api/high_level.rs index 220a481f17..c63c3c98de 100644 --- a/sdk/src/client/api/high_level.rs +++ b/sdk/src/client/api/high_level.rs @@ -7,7 +7,7 @@ use futures::{StreamExt, TryStreamExt}; use crate::{ client::{ - api::input_selection::Error as InputSelectionError, + api::transaction_builder::Error as TransactionBuilderError, constants::FIVE_MINUTES_IN_NANOSECONDS, error::{Error, Result}, node_api::indexer::query_parameters::BasicOutputQueryParameters, @@ -105,7 +105,7 @@ impl Client { } if total_already_spent < amount { - return Err(InputSelectionError::InsufficientAmount { + return Err(TransactionBuilderError::InsufficientAmount { found: total_already_spent, required: amount, })?; diff --git a/sdk/src/client/error.rs b/sdk/src/client/error.rs index f40f7b41bd..42a5844602 100644 --- a/sdk/src/client/error.rs +++ b/sdk/src/client/error.rs @@ -9,7 +9,8 @@ use packable::error::UnexpectedEOF; use serde::{ser::Serializer, Serialize}; use crate::{ - client::api::input_selection::Error as InputSelectionError, types::block::semantic::TransactionFailureReason, + client::api::transaction_builder::Error as TransactionBuilderError, + types::block::semantic::TransactionFailureReason, }; /// Type alias of `Result` in iota-client @@ -143,9 +144,9 @@ pub enum Error { /// URL validation error #[error("{0}")] UrlValidation(String), - /// Input selection error. + /// Transaction builder error. #[error("{0}")] - InputSelection(#[from] InputSelectionError), + TransactionBuilder(#[from] TransactionBuilderError), /// Missing BIP32 chain to sign with. #[error("missing BIP32 chain to sign with")] MissingBip32Chain, diff --git a/sdk/src/client/secret/mod.rs b/sdk/src/client/secret/mod.rs index 2bb291b1ce..5d9c1653d9 100644 --- a/sdk/src/client/secret/mod.rs +++ b/sdk/src/client/secret/mod.rs @@ -49,8 +49,8 @@ use crate::client::secret::types::StrongholdDto; use crate::{ client::{ api::{ - input_selection::Error as InputSelectionError, transaction::validate_signed_transaction_payload_length, - verify_semantic, PreparedTransactionData, + transaction::validate_signed_transaction_payload_length, + transaction_builder::Error as TransactionBuilderError, verify_semantic, PreparedTransactionData, }, Error, }, @@ -612,7 +612,7 @@ where // than the current block index match &required_address { Address::Ed25519(_) | Address::ImplicitAccountCreation(_) => {} - _ => Err(InputSelectionError::MissingInputWithEd25519Address)?, + _ => Err(TransactionBuilderError::MissingInputWithEd25519Address)?, } let chain = input.chain.ok_or(Error::MissingBip32Chain)?; diff --git a/sdk/src/wallet/error.rs b/sdk/src/wallet/error.rs index 201a66bf52..c16f73325b 100644 --- a/sdk/src/wallet/error.rs +++ b/sdk/src/wallet/error.rs @@ -176,17 +176,17 @@ impl From for Error { } } -impl From for Error { - fn from(error: crate::client::api::input_selection::Error) -> Self { +impl From for Error { + fn from(error: crate::client::api::transaction_builder::Error) -> Self { // Map "same" error so it's easier to handle match error { - crate::client::api::input_selection::Error::InsufficientAmount { found, required } => { + crate::client::api::transaction_builder::Error::InsufficientAmount { found, required } => { Self::InsufficientFunds { available: found, required, } } - _ => Self::Client(Box::new(crate::client::Error::InputSelection(error))), + _ => Self::Client(Box::new(crate::client::Error::TransactionBuilder(error))), } } } diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 4cca02d6d4..207fc33f29 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -192,7 +192,7 @@ pub struct TransactionInclusionEvent { #[derive(Clone, Debug, Eq, PartialEq)] #[non_exhaustive] pub enum TransactionProgressEvent { - /// Performing input selection. + /// Performing iransaction builder. SelectingInputs, /// Generating remainder value deposit address. GeneratingRemainderDepositAddress(AddressData), diff --git a/sdk/src/wallet/mod.rs b/sdk/src/wallet/mod.rs index 23a51a0506..5c3feb3a15 100644 --- a/sdk/src/wallet/mod.rs +++ b/sdk/src/wallet/mod.rs @@ -68,7 +68,6 @@ pub use self::{ staking::begin::BeginStakingParams, }, prepare_output::{Assets, Features, OutputParams, ReturnStrategy, StorageDeposit, Unlocks}, - RemainderValueStrategy, TransactionOptions, }, }, types::OutputData, diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index 7d063c7e88..2feedc01c5 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -6,7 +6,10 @@ use std::collections::HashSet; use serde::{Deserialize, Serialize}; use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, + client::{ + api::{options::TransactionOptions, PreparedTransactionData}, + secret::SecretManage, + }, types::block::{ address::{Address, Bech32Address, Ed25519Address}, output::{ @@ -17,7 +20,7 @@ use crate::{ }, wallet::{ core::WalletLedger, - operations::{helpers::time::can_output_be_unlocked_now, transaction::TransactionOptions}, + operations::helpers::time::can_output_be_unlocked_now, types::{OutputData, TransactionWithMetadata}, Wallet, }, @@ -309,7 +312,7 @@ where // add additional inputs .chain(possible_additional_inputs.iter().map(|o| o.output_id)) .collect(), - allow_additional_input_selection: false, + allow_additional_transaction_builder: false, ..Default::default() }, ) diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index e9e970fcd1..a6fe8d0fbc 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -8,7 +8,13 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "ledger_nano")] use crate::client::secret::{ledger_nano::LedgerSecretManager, DowncastSecretManager}; use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, + client::{ + api::{ + options::{RemainderValueStrategy, TransactionOptions}, + PreparedTransactionData, + }, + secret::SecretManage, + }, types::block::{ address::{Address, Bech32Address}, input::INPUT_COUNT_MAX, @@ -17,9 +23,9 @@ use crate::{ }, wallet::{ constants::DEFAULT_OUTPUT_CONSOLIDATION_THRESHOLD, - operations::{helpers::time::can_output_be_unlocked_now, transaction::TransactionOptions}, + operations::helpers::time::can_output_be_unlocked_now, types::{OutputData, TransactionWithMetadata}, - RemainderValueStrategy, Result, Wallet, + Result, Wallet, }, }; @@ -103,7 +109,7 @@ where .map(|bech32| bech32.into_inner()) .unwrap_or_else(|| wallet_address.into_inner()), ), - allow_additional_input_selection: false, + allow_additional_transaction_builder: false, ..Default::default() }); diff --git a/sdk/src/wallet/operations/participation/mod.rs b/sdk/src/wallet/operations/participation/mod.rs index bd05b35560..b114d755ac 100644 --- a/sdk/src/wallet/operations/participation/mod.rs +++ b/sdk/src/wallet/operations/participation/mod.rs @@ -6,7 +6,7 @@ // They become spendable again when the user reduces the “voting power”. // This is done by creating a special “voting output” that adheres to the following rules, NOT by sending to a different // address. -// If the user has designated funds to vote with, the resulting output MUST NOT be used for input selection. +// If the user has designated funds to vote with, the resulting output MUST NOT be used for iransaction builder. // pub(crate) mod event; // pub(crate) mod voting; diff --git a/sdk/src/wallet/operations/transaction/input_selection.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs similarity index 85% rename from sdk/src/wallet/operations/transaction/input_selection.rs rename to sdk/src/wallet/operations/transaction/build_transaction.rs index 3f3022f368..a8134159b6 100644 --- a/sdk/src/wallet/operations/transaction/input_selection.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -10,7 +10,12 @@ use crypto::keys::bip44::Bip44; use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::{ - api::{input_selection::InputSelection, transaction::validate_transaction_length, PreparedTransactionData}, + api::{ + options::{RemainderValueStrategy, TransactionOptions}, + transaction::validate_transaction_length, + transaction_builder::TransactionBuilder, + PreparedTransactionData, + }, secret::{types::InputSigningData, SecretManage}, }, types::block::{ @@ -19,10 +24,7 @@ use crate::{ protocol::CommittableAgeRange, slot::SlotIndex, }, - wallet::{ - operations::helpers::time::can_output_be_unlocked_forever_from_now_on, types::OutputData, - RemainderValueStrategy, TransactionOptions, Wallet, - }, + wallet::{operations::helpers::time::can_output_be_unlocked_forever_from_now_on, types::OutputData, Wallet}, }; impl Wallet @@ -30,13 +32,13 @@ where crate::wallet::Error: From, crate::client::Error: From, { - /// Selects inputs for a transaction and locks them in the wallet, so they don't get used again - pub(crate) async fn select_inputs( + /// Builds a transaction using the given outputs and options. + pub(crate) async fn build_transaction( &self, outputs: Vec, mut options: TransactionOptions, ) -> crate::wallet::Result { - log::debug!("[TRANSACTION] select_inputs"); + log::debug!("[TRANSACTION] build_transaction"); // Voting output needs to be requested before to prevent a deadlock #[cfg(feature = "participation")] let voting_output = self.get_voting_output().await?; @@ -85,7 +87,10 @@ where let available_outputs_signing_data = filter_inputs( &self.address().await, self.bip_path().await, - wallet_ledger.unspent_outputs.values(), + wallet_ledger + .unspent_outputs + .iter() + .filter_map(|(id, data)| (!forbidden_inputs.contains(id)).then_some(data)), slot_commitment_id.slot_index(), protocol_parameters.committable_age_range(), &options.required_inputs, @@ -133,7 +138,7 @@ where } } - let mut input_selection = InputSelection::new( + let mut transaction_builder = TransactionBuilder::new( available_outputs_signing_data, outputs, Some(self.address().await.into_inner()), @@ -142,7 +147,6 @@ where protocol_parameters.clone(), ) .with_required_inputs(options.required_inputs) - .with_forbidden_inputs(forbidden_inputs) .with_context_inputs(options.context_inputs) .with_mana_rewards(mana_rewards) .with_payload(options.tagged_data_payload) @@ -151,18 +155,18 @@ where .with_burn(options.burn); if let (Some(account_id), Some(reference_mana_cost)) = (options.issuer_id, reference_mana_cost) { - input_selection = input_selection.with_min_mana_allotment(account_id, reference_mana_cost); + transaction_builder = transaction_builder.with_min_mana_allotment(account_id, reference_mana_cost); } - if !options.allow_additional_input_selection { - input_selection = input_selection.disable_additional_input_selection(); + if !options.allow_additional_transaction_builder { + transaction_builder = transaction_builder.disable_additional_transaction_builder(); } if let Some(capabilities) = options.capabilities { - input_selection = input_selection.with_transaction_capabilities(capabilities) + transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) } - let prepared_transaction_data = input_selection.select()?; + let prepared_transaction_data = transaction_builder.select()?; validate_transaction_length(&prepared_transaction_data.transaction)?; @@ -177,7 +181,7 @@ where } /// Filter available outputs to only include outputs that can be unlocked forever from this moment. -/// Note: this is only for the default input selection, it's still possible to send these outputs by using +/// Note: this is only for the default iransaction builder, it's still possible to send these outputs by using /// `claim_outputs` or providing their OutputId's in the custom_inputs #[allow(clippy::too_many_arguments)] fn filter_inputs<'a>( diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs index 29e4d5cdbf..e539e8382b 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs @@ -77,7 +77,7 @@ where token_scheme.maximum_supply(), )?)) .finish_output()?]; - // Input selection will detect that we're melting native tokens and add the required inputs if available + // Transaction builder will detect that we're melting native tokens and add the required inputs if available self.prepare_transaction(outputs, options).await } diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs index 8d615eb482..588c8fd64a 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - client::api::{input_selection::Burn, PreparedTransactionData}, + client::api::{transaction_builder::Burn, PreparedTransactionData}, wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Wallet}, }; @@ -40,7 +40,7 @@ impl Wallet { options.burn = Some(burn.into()); // The empty list of outputs is used. Outputs will be generated by - // the input selection algorithm based on the content of the [`Burn`] object. + // the iransaction builder algorithm based on the content of the [`Burn`] object. self.prepare_transaction([], options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs b/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs index 1adbd1d2b3..5d2bb83bde 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs @@ -4,13 +4,16 @@ use serde::{Deserialize, Serialize}; use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, + client::{ + api::{options::TransactionOptions, PreparedTransactionData}, + secret::SecretManage, + }, types::block::{ output::{feature::StakingFeature, AccountId, AccountOutputBuilder}, slot::EpochIndex, }, utils::serde::string, - wallet::{types::TransactionWithMetadata, TransactionOptions, Wallet}, + wallet::{types::TransactionWithMetadata, Wallet}, }; /// Parameters for beginning a staking period. diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/end.rs b/sdk/src/wallet/operations/transaction/high_level/staking/end.rs index fc84dbbc4a..1a1d588d2c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/end.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/end.rs @@ -2,9 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, + client::{ + api::{options::TransactionOptions, PreparedTransactionData}, + secret::SecretManage, + }, types::block::output::{AccountId, AccountOutputBuilder}, - wallet::{types::TransactionWithMetadata, TransactionOptions, Wallet}, + wallet::{types::TransactionWithMetadata, Wallet}, }; impl Wallet diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs b/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs index e2b8b6efbe..802e5b2656 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs @@ -2,9 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, + client::{ + api::{options::TransactionOptions, PreparedTransactionData}, + secret::SecretManage, + }, types::block::output::{feature::StakingFeature, AccountId, AccountOutputBuilder}, - wallet::{types::TransactionWithMetadata, TransactionOptions, Wallet}, + wallet::{types::TransactionWithMetadata, Wallet}, }; impl Wallet diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 2c6239fed8..4241426050 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -2,20 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 pub(crate) mod account; +mod build_transaction; pub(crate) mod high_level; -mod input_selection; -mod options; pub(crate) mod prepare_output; mod prepare_transaction; mod sign_transaction; pub(crate) mod submit_transaction; -pub use self::options::{RemainderValueStrategy, TransactionOptions}; #[cfg(feature = "storage")] use crate::wallet::core::WalletLedgerDto; use crate::{ client::{ - api::{verify_semantic, PreparedTransactionData, SignedTransactionData}, + api::{options::TransactionOptions, verify_semantic, PreparedTransactionData, SignedTransactionData}, secret::{types::InputSigningData, SecretManage}, Error, }, diff --git a/sdk/src/wallet/operations/transaction/prepare_output.rs b/sdk/src/wallet/operations/transaction/prepare_output.rs index 3daf27b867..a5016163c3 100644 --- a/sdk/src/wallet/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/operations/transaction/prepare_output.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ - client::secret::SecretManage, + client::{api::options::RemainderValueStrategy, secret::SecretManage}, types::block::{ address::{Address, Bech32Address, Ed25519Address}, output::{ @@ -20,11 +20,7 @@ use crate::{ Error, }, utils::serde::string, - wallet::{ - operations::transaction::{RemainderValueStrategy, TransactionOptions}, - types::OutputData, - Wallet, - }, + wallet::{operations::transaction::TransactionOptions, types::OutputData, Wallet}, }; impl Wallet diff --git a/sdk/src/wallet/operations/transaction/prepare_transaction.rs b/sdk/src/wallet/operations/transaction/prepare_transaction.rs index 54113ac0e7..a54e656a33 100644 --- a/sdk/src/wallet/operations/transaction/prepare_transaction.rs +++ b/sdk/src/wallet/operations/transaction/prepare_transaction.rs @@ -38,7 +38,7 @@ where ))?; } - let prepared_transaction_data = self.select_inputs(outputs, options).await?; + let prepared_transaction_data = self.build_transaction(outputs, options).await?; log::debug!( "[TRANSACTION] finished prepare_transaction in {:.2?}", diff --git a/sdk/tests/client/error.rs b/sdk/tests/client/error.rs index 6e2c562a72..461877a050 100644 --- a/sdk/tests/client/error.rs +++ b/sdk/tests/client/error.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::{ - client::{api::input_selection::Error as IsaError, Error}, + client::{api::transaction_builder::Error as IsaError, Error}, types::block::Error as BlockError, }; use pretty_assertions::assert_eq; @@ -30,18 +30,18 @@ fn stringified_error() { "{\"type\":\"placeholderSecretManager\",\"error\":\"placeholderSecretManager can't be used for address generation or signing\"}" ); - let error = Error::InputSelection(IsaError::InsufficientAmount { + let error = Error::TransactionBuilder(IsaError::InsufficientAmount { found: 0, required: 100, }); assert_eq!( &serde_json::to_string(&error).unwrap(), - "{\"type\":\"inputSelection\",\"error\":\"insufficient amount: found 0, required 100\"}" + "{\"type\":\"transactionBuilder\",\"error\":\"insufficient amount: found 0, required 100\"}" ); - let error = Error::InputSelection(IsaError::Block(BlockError::InvalidAddress)); + let error = Error::TransactionBuilder(IsaError::Block(BlockError::InvalidAddress)); assert_eq!( &serde_json::to_string(&error).unwrap(), - "{\"type\":\"inputSelection\",\"error\":\"invalid address provided\"}" + "{\"type\":\"transactionBuilder\",\"error\":\"invalid address provided\"}" ); } diff --git a/sdk/tests/client/mod.rs b/sdk/tests/client/mod.rs index ee47dc0575..dc146c6b45 100644 --- a/sdk/tests/client/mod.rs +++ b/sdk/tests/client/mod.rs @@ -6,7 +6,6 @@ mod client_builder; mod common; mod error; mod high_level; -mod input_selection; mod input_signing_data; mod mnemonic; #[cfg(feature = "mqtt")] @@ -14,6 +13,7 @@ mod mqtt; mod node_api; mod secret_manager; mod signing; +mod transaction_builder; use std::{collections::HashMap, hash::Hash, str::FromStr}; diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 83be3697fc..d1a103bdb9 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -12,8 +12,8 @@ use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ api::{ - input_selection::InputSelection, transaction::validate_signed_transaction_payload_length, verify_semantic, - GetAddressesOptions, PreparedTransactionData, + transaction::validate_signed_transaction_payload_length, transaction_builder::TransactionBuilder, + verify_semantic, GetAddressesOptions, PreparedTransactionData, }, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, @@ -368,7 +368,7 @@ async fn all_combined() -> Result<()> { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ed25519_0, ed25519_1, ed25519_2], diff --git a/sdk/tests/client/input_selection/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs similarity index 96% rename from sdk/tests/client/input_selection/account_outputs.rs rename to sdk/tests/client/transaction_builder/account_outputs.rs index c935580bbb..4a27ddb656 100644 --- a/sdk/tests/client/input_selection/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use iota_sdk::{ client::{ - api::input_selection::{Burn, Error, InputSelection, Requirement}, + api::transaction_builder::{Burn, Error, Requirement, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -53,7 +53,7 @@ fn input_account_eq_output_account() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -95,7 +95,7 @@ fn transition_account_id_zero() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -137,7 +137,7 @@ fn transition_account_id_zero() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -185,7 +185,7 @@ fn transition_account_id_zero() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -230,7 +230,7 @@ fn transition_account_id_zero() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs.clone(), // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -272,7 +272,7 @@ fn create_account() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -324,7 +324,7 @@ fn burn_account() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -368,7 +368,7 @@ fn burn_account() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -413,7 +413,7 @@ fn missing_input_for_account_output() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -470,7 +470,7 @@ fn missing_input_for_account_output_2() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -514,7 +514,7 @@ fn missing_input_for_account_output_but_created() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -573,7 +573,7 @@ fn account_in_output_and_sender() { }]); outputs.push(account_output); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -614,7 +614,7 @@ fn missing_ed25519_sender() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -658,7 +658,7 @@ fn missing_ed25519_issuer_created() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -700,7 +700,7 @@ fn missing_ed25519_issuer_transition() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -739,7 +739,7 @@ fn missing_account_sender() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -783,7 +783,7 @@ fn missing_account_issuer_created() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -825,7 +825,7 @@ fn missing_account_issuer_transition() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_ACCOUNT_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -864,7 +864,7 @@ fn missing_nft_sender() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -908,7 +908,7 @@ fn missing_nft_issuer_created() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -950,7 +950,7 @@ fn missing_nft_issuer_transition() { issuer: Some(Address::try_from_bech32(BECH32_ADDRESS_NFT_1).unwrap()), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1003,7 +1003,7 @@ fn increase_account_amount() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1058,7 +1058,7 @@ fn decrease_account_amount() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1127,7 +1127,7 @@ fn prefer_basic_to_account() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1185,7 +1185,7 @@ fn take_amount_from_account_to_fund_basic() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1257,7 +1257,7 @@ fn account_burn_should_validate_account_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1327,7 +1327,7 @@ fn account_burn_should_validate_account_address() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1383,7 +1383,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1454,7 +1454,7 @@ fn two_accounts_required() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1468,28 +1468,24 @@ fn two_accounts_required() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 3); assert!(selected.transaction.outputs().contains(&outputs[0])); - assert!( - selected - .transaction - .outputs() - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_1 - } else { - false - }) - ); - assert!( - selected - .transaction - .outputs() - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_2 - } else { - false - }) - ) + assert!(selected + .transaction + .outputs() + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_1 + } else { + false + })); + assert!(selected + .transaction + .outputs() + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_2 + } else { + false + })) } #[test] @@ -1520,7 +1516,7 @@ fn state_controller_sender_required() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1573,7 +1569,7 @@ fn state_controller_sender_required_already_selected() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1615,7 +1611,7 @@ fn state_transition_and_required() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1657,7 +1653,7 @@ fn remainder_address_in_state_controller() { issuer: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1715,7 +1711,7 @@ fn min_allot_account_mana() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1785,7 +1781,7 @@ fn min_allot_account_mana_additional() { .finish_output() .unwrap()]; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1851,7 +1847,7 @@ fn min_allot_account_mana_cannot_select_additional() { }) .collect::>(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1862,7 +1858,7 @@ fn min_allot_account_mana_cannot_select_additional() { .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_2, provided_allotment))) .with_required_inputs([*inputs[0].output_id()]) - .disable_additional_input_selection() + .disable_additional_transaction_builder() .select() .unwrap_err(); @@ -1904,7 +1900,7 @@ fn min_allot_account_mana_requirement_twice() { }) .collect::>(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1985,7 +1981,7 @@ fn min_allot_account_mana_requirement_covered() { }]); outputs.push(account_output); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2060,7 +2056,7 @@ fn min_allot_account_mana_requirement_covered_2() { }]); outputs.push(account_output); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2109,16 +2105,14 @@ fn implicit_account_transition() { let input_output_id = *inputs[0].output_id(); let account_id = AccountId::from(&input_output_id); - let outputs = vec![ - AccountOutputBuilder::new_with_amount(1_000_000, account_id) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .finish_output() - .unwrap(), - ]; + let outputs = vec![AccountOutputBuilder::new_with_amount(1_000_000, account_id) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .finish_output() + .unwrap()]; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2164,7 +2158,7 @@ fn auto_transition_account_less_than_min() { Some(SLOT_INDEX), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2226,7 +2220,7 @@ fn auto_transition_account_less_than_min_additional() { Some(SLOT_INDEX), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/basic_outputs.rs b/sdk/tests/client/transaction_builder/basic_outputs.rs similarity index 95% rename from sdk/tests/client/input_selection/basic_outputs.rs rename to sdk/tests/client/transaction_builder/basic_outputs.rs index 7b468b4786..00c0cb6bea 100644 --- a/sdk/tests/client/input_selection/basic_outputs.rs +++ b/sdk/tests/client/transaction_builder/basic_outputs.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use iota_sdk::{ client::{ - api::input_selection::{Error, InputSelection, Requirement}, + api::transaction_builder::{Error, Requirement, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -55,7 +55,7 @@ fn input_amount_equal_output_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -99,7 +99,7 @@ fn input_amount_lower_than_output_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -161,7 +161,7 @@ fn input_amount_lower_than_output_amount_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -209,7 +209,7 @@ fn input_amount_greater_than_output_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -266,7 +266,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -337,7 +337,7 @@ fn two_same_inputs_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -408,7 +408,7 @@ fn two_inputs_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -466,7 +466,7 @@ fn two_inputs_one_needed_reversed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -524,7 +524,7 @@ fn two_inputs_both_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -582,7 +582,7 @@ fn two_inputs_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -634,7 +634,7 @@ fn two_inputs_remainder() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -731,7 +731,7 @@ fn ed25519_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [ @@ -747,12 +747,10 @@ fn ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!( - selected - .inputs_data - .iter() - .any(|input| *input.output.as_basic().address() == sender) - ); + assert!(selected + .inputs_data + .iter() + .any(|input| *input.output.as_basic().address() == sender)); // Provided output + remainder assert_eq!(selected.transaction.outputs().len(), 2); } @@ -786,7 +784,7 @@ fn missing_ed25519_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -880,7 +878,7 @@ fn account_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -893,12 +891,10 @@ fn account_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!( - selected - .inputs_data - .iter() - .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1) - ); + assert!(selected + .inputs_data + .iter() + .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1)); // Provided output + account assert_eq!(selected.transaction.outputs().len(), 2); assert!(selected.transaction.outputs().contains(&outputs[0])); @@ -947,7 +943,7 @@ fn account_sender_zero_id() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -960,13 +956,11 @@ fn account_sender_zero_id() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 2); - assert!( - selected - .transaction - .outputs() - .iter() - .any(|output| output.is_account() && *output.as_account().account_id() == account_id) - ); + assert!(selected + .transaction + .outputs() + .iter() + .any(|output| output.is_account() && *output.as_account().account_id() == account_id)); } #[test] @@ -998,7 +992,7 @@ fn missing_account_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1094,7 +1088,7 @@ fn nft_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1107,12 +1101,10 @@ fn nft_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!( - selected - .inputs_data - .iter() - .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1) - ); + assert!(selected + .inputs_data + .iter() + .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1)); // Provided output + nft assert_eq!(selected.transaction.outputs().len(), 2); assert!(selected.transaction.outputs().contains(&inputs[2].output)); @@ -1164,7 +1156,7 @@ fn nft_sender_zero_id() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1177,13 +1169,11 @@ fn nft_sender_zero_id() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 2); - assert!( - selected - .transaction - .outputs() - .iter() - .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id) - ); + assert!(selected + .transaction + .outputs() + .iter() + .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id)); } #[test] @@ -1215,7 +1205,7 @@ fn missing_nft_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1260,7 +1250,7 @@ fn simple_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1311,7 +1301,7 @@ fn simple_remainder() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1349,7 +1339,7 @@ fn simple_remainder() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1395,7 +1385,7 @@ fn one_provided_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1439,7 +1429,7 @@ fn insufficient_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1501,7 +1491,7 @@ fn two_inputs_remainder_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1571,7 +1561,7 @@ fn two_inputs_remainder_3() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1618,7 +1608,7 @@ fn two_inputs_remainder_3() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs.clone(), // outputs.clone(), // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1666,7 +1656,7 @@ fn sender_already_selected() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -1714,7 +1704,7 @@ fn single_mandatory_input() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -1766,7 +1756,7 @@ fn too_many_inputs() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1778,7 +1768,7 @@ fn too_many_inputs() { assert_eq!( selected.unwrap_err(), - iota_sdk::client::api::input_selection::Error::InvalidInputCount(129) + iota_sdk::client::api::transaction_builder::Error::InvalidInputCount(129) ) } @@ -1833,7 +1823,7 @@ fn more_than_max_inputs_only_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1880,7 +1870,7 @@ fn too_many_outputs() { .take(129), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1892,7 +1882,7 @@ fn too_many_outputs() { assert_eq!( selected.unwrap_err(), - iota_sdk::client::api::input_selection::Error::InvalidOutputCount(129) + iota_sdk::client::api::transaction_builder::Error::InvalidOutputCount(129) ) } @@ -1929,7 +1919,7 @@ fn too_many_outputs_with_remainder() { .take(128), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1942,7 +1932,7 @@ fn too_many_outputs_with_remainder() { assert_eq!( selected.unwrap_err(), // 129 because of required remainder - iota_sdk::client::api::input_selection::Error::InvalidOutputCount(129) + iota_sdk::client::api::transaction_builder::Error::InvalidOutputCount(129) ) } @@ -2027,7 +2017,7 @@ fn restricted_ed25519() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], @@ -2089,7 +2079,7 @@ fn restricted_nft() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2149,7 +2139,7 @@ fn restricted_account() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -2246,7 +2236,7 @@ fn restricted_ed25519_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -2262,12 +2252,10 @@ fn restricted_ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!( - selected - .inputs_data - .iter() - .any(|input| *input.output.as_basic().address() == sender) - ); + assert!(selected + .inputs_data + .iter() + .any(|input| *input.output.as_basic().address() == sender)); // Provided output + remainder assert_eq!(selected.transaction.outputs().len(), 2); } @@ -2341,7 +2329,7 @@ fn multi_address_sender_already_fulfilled() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -2421,7 +2409,7 @@ fn ed25519_backed_available_address() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), // Restricted address is provided, but it can also unlock the ed25519 one @@ -2459,17 +2447,15 @@ fn automatic_allotment_provided_in_and_output() { }) .collect::>(); - let outputs = vec![ - BasicOutputBuilder::new_with_amount(1_000_000) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .with_mana(1) - .finish_output() - .unwrap(), - ]; + let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .with_mana(1) + .finish_output() + .unwrap()]; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/burn.rs b/sdk/tests/client/transaction_builder/burn.rs similarity index 97% rename from sdk/tests/client/input_selection/burn.rs rename to sdk/tests/client/transaction_builder/burn.rs index 5616feaac3..10e94f06a8 100644 --- a/sdk/tests/client/input_selection/burn.rs +++ b/sdk/tests/client/transaction_builder/burn.rs @@ -7,7 +7,7 @@ use std::{ }; use iota_sdk::{ - client::api::input_selection::{Burn, Error, InputSelection, Requirement}, + client::api::transaction_builder::{Burn, Error, Requirement, TransactionBuilder}, types::block::{ address::Address, output::{AccountId, ChainId, NftId, SimpleTokenScheme, TokenId}, @@ -18,7 +18,7 @@ use pretty_assertions::assert_eq; use crate::client::{ assert_remainder_or_return, build_inputs, build_outputs, - input_selection::native_tokens::nt_remainder_min_storage_deposit, + transaction_builder::native_tokens::nt_remainder_min_storage_deposit, unsorted_eq, Build::{Account, Basic, Foundry, Nft}, ACCOUNT_ID_0, ACCOUNT_ID_1, ACCOUNT_ID_2, BECH32_ADDRESS_ED25519_0, NFT_ID_0, NFT_ID_1, NFT_ID_2, @@ -67,7 +67,7 @@ fn burn_account_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -126,7 +126,7 @@ fn burn_account_present_and_required() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -189,7 +189,7 @@ fn burn_account_id_zero() { }]); let nft_id = NftId::from(inputs[0].output_id()); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -236,7 +236,7 @@ fn burn_account_absent() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -306,7 +306,7 @@ fn burn_accounts_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -373,7 +373,7 @@ fn burn_account_in_outputs() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -434,7 +434,7 @@ fn burn_nft_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -495,7 +495,7 @@ fn burn_nft_present_and_required() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -556,7 +556,7 @@ fn burn_nft_id_zero() { }]); let account_id = AccountId::from(inputs[0].output_id()); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -603,7 +603,7 @@ fn burn_nft_absent() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -677,7 +677,7 @@ fn burn_nfts_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -748,7 +748,7 @@ fn burn_nft_in_outputs() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -817,7 +817,7 @@ fn burn_foundry_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -918,7 +918,7 @@ fn burn_foundry_absent() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -985,7 +985,7 @@ fn burn_foundries_present() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1071,7 +1071,7 @@ fn burn_foundry_in_outputs() { ]); let foundry_id_1 = inputs[0].output.as_foundry().id(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1124,7 +1124,7 @@ fn burn_native_tokens() { let nt_remainder_output_amount = nt_remainder_min_storage_deposit(&protocol_parameters); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1208,7 +1208,7 @@ fn burn_foundry_and_its_account() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/delegation_outputs.rs b/sdk/tests/client/transaction_builder/delegation_outputs.rs similarity index 88% rename from sdk/tests/client/input_selection/delegation_outputs.rs rename to sdk/tests/client/transaction_builder/delegation_outputs.rs index ad48472b28..f04590a6bd 100644 --- a/sdk/tests/client/input_selection/delegation_outputs.rs +++ b/sdk/tests/client/transaction_builder/delegation_outputs.rs @@ -3,7 +3,7 @@ use iota_sdk::{ client::{ - api::input_selection::{Burn, InputSelection}, + api::transaction_builder::{Burn, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -61,19 +61,17 @@ fn remainder_needed_for_mana() { let delegation_output_id = *inputs[0].output_id(); let delegation_id = DelegationId::from(&delegation_output_id); - let outputs = vec![ - BasicOutputBuilder::new_with_amount(1_000_000) - .with_mana(200) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .finish_output() - .unwrap(), - ]; + let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000) + .with_mana(200) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .finish_output() + .unwrap()]; let mana_rewards = 100; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/expiration.rs b/sdk/tests/client/transaction_builder/expiration.rs similarity index 97% rename from sdk/tests/client/input_selection/expiration.rs rename to sdk/tests/client/transaction_builder/expiration.rs index d79a8f9e7f..579669b73f 100644 --- a/sdk/tests/client/input_selection/expiration.rs +++ b/sdk/tests/client/transaction_builder/expiration.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use iota_sdk::{ - client::api::input_selection::{Error, InputSelection}, + client::api::transaction_builder::{Error, TransactionBuilder}, types::block::{ address::Address, output::{AccountId, NftId}, @@ -50,7 +50,7 @@ fn one_output_expiration_not_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -92,7 +92,7 @@ fn expiration_equal_timestamp() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -136,7 +136,7 @@ fn one_output_expiration_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -194,7 +194,7 @@ fn two_outputs_one_expiration_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -253,7 +253,7 @@ fn two_outputs_one_unexpired_one_missing() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -324,7 +324,7 @@ fn two_outputs_two_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_2).unwrap()], @@ -383,7 +383,7 @@ fn two_outputs_two_expired_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -430,7 +430,7 @@ fn expiration_expired_with_sdr() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -474,7 +474,7 @@ fn expiration_expired_with_sdr_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -518,7 +518,7 @@ fn expiration_expired_with_sdr_and_timelock() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -562,7 +562,7 @@ fn expiration_expired_with_sdr_and_timelock_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -656,7 +656,7 @@ fn sender_in_expiration() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -704,7 +704,7 @@ fn sender_in_expiration_already_selected() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -752,7 +752,7 @@ fn remainder_in_expiration() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -810,7 +810,7 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -868,7 +868,7 @@ fn expiration_expired_only_account_addresses() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -913,7 +913,7 @@ fn one_nft_output_expiration_unexpired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], @@ -958,7 +958,7 @@ fn one_nft_output_expiration_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/foundry_outputs.rs b/sdk/tests/client/transaction_builder/foundry_outputs.rs similarity index 97% rename from sdk/tests/client/input_selection/foundry_outputs.rs rename to sdk/tests/client/transaction_builder/foundry_outputs.rs index 6969fac375..5eef53bba7 100644 --- a/sdk/tests/client/input_selection/foundry_outputs.rs +++ b/sdk/tests/client/transaction_builder/foundry_outputs.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use iota_sdk::{ client::{ - api::input_selection::{Burn, Error, InputSelection, Requirement}, + api::transaction_builder::{Burn, Error, Requirement, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -54,7 +54,7 @@ fn missing_input_account_for_foundry() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -94,7 +94,7 @@ fn missing_input_account_for_foundry() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs.clone(), // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -148,7 +148,7 @@ fn minted_native_tokens_in_new_remainder() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -224,7 +224,7 @@ fn minted_native_tokens_in_provided_output() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -297,7 +297,7 @@ fn melt_native_tokens() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -357,7 +357,7 @@ fn destroy_foundry_with_account_state_transition() { // Account output gets the amount from the foundry output added let outputs = [account_output]; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -414,7 +414,7 @@ fn destroy_foundry_with_account_burn() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -497,7 +497,7 @@ fn prefer_basic_to_foundry() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -566,7 +566,7 @@ fn simple_foundry_transition_basic_not_needed() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -650,7 +650,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -718,7 +718,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { // Some(BECH32_ADDRESS_ACCOUNT_SENDER), // )]; -// let selected = InputSelection::new(inputs.clone(), outputs.clone(), [],protocol_parameters) +// let selected = TransactionBuilder::new(inputs.clone(), outputs.clone(), [],protocol_parameters) // .select() // .unwrap(); @@ -800,7 +800,7 @@ fn mint_and_burn_at_the_same_time() { native_token: Some((&token_id.to_string(), 110)), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -873,7 +873,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -940,7 +940,7 @@ fn create_native_token_but_burn_account() { native_token: Some((&token_id.to_string(), 100)), }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1008,7 +1008,7 @@ fn melted_tokens_not_provided() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1067,7 +1067,7 @@ fn burned_tokens_not_provided() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1125,7 +1125,7 @@ fn foundry_in_outputs_and_required() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1201,7 +1201,7 @@ fn melt_and_burn_native_tokens() { native_token: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1263,7 +1263,7 @@ fn auto_transition_foundry_less_than_min() { chain: None, }); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1344,7 +1344,7 @@ fn auto_transition_foundry_less_than_min_additional() { chain: None, }); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/mod.rs b/sdk/tests/client/transaction_builder/mod.rs similarity index 100% rename from sdk/tests/client/input_selection/mod.rs rename to sdk/tests/client/transaction_builder/mod.rs diff --git a/sdk/tests/client/input_selection/native_tokens.rs b/sdk/tests/client/transaction_builder/native_tokens.rs similarity index 97% rename from sdk/tests/client/input_selection/native_tokens.rs rename to sdk/tests/client/transaction_builder/native_tokens.rs index 769c2bc3ea..d5f6a1644d 100644 --- a/sdk/tests/client/input_selection/native_tokens.rs +++ b/sdk/tests/client/transaction_builder/native_tokens.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use iota_sdk::{ - client::api::input_selection::{Burn, Error, InputSelection}, + client::api::transaction_builder::{Burn, Error, TransactionBuilder}, types::block::{ address::Address, output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder, NativeToken, TokenId}, @@ -62,7 +62,7 @@ fn two_native_tokens_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -132,7 +132,7 @@ fn two_native_tokens_both_needed_plus_remainder() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -213,7 +213,7 @@ fn three_inputs_two_needed_plus_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -294,7 +294,7 @@ fn three_inputs_two_needed_no_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -338,7 +338,7 @@ fn insufficient_native_tokens_one_input() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -412,7 +412,7 @@ fn insufficient_native_tokens_three_inputs() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -474,7 +474,7 @@ fn burn_and_send_at_the_same_time() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -525,7 +525,7 @@ fn burn_one_input_no_output() { Some(SLOT_INDEX), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -590,7 +590,7 @@ fn multiple_native_tokens() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -635,7 +635,7 @@ fn insufficient_native_tokens() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -683,7 +683,7 @@ fn insufficient_native_tokens_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -733,7 +733,7 @@ fn insufficient_amount_for_remainder() { let nt_remainder_min_storage_deposit = nt_remainder_min_storage_deposit(&protocol_parameters); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -781,7 +781,7 @@ fn single_output_native_token_no_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -825,7 +825,7 @@ fn single_output_native_token_remainder_1() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -876,7 +876,7 @@ fn single_output_native_token_remainder_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -941,7 +941,7 @@ fn two_basic_outputs_1() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1007,7 +1007,7 @@ fn two_basic_outputs_2() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1073,7 +1073,7 @@ fn two_basic_outputs_3() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1139,7 +1139,7 @@ fn two_basic_outputs_4() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1205,7 +1205,7 @@ fn two_basic_outputs_5() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1271,7 +1271,7 @@ fn two_basic_outputs_6() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1336,7 +1336,7 @@ fn two_basic_outputs_7() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1401,7 +1401,7 @@ fn two_basic_outputs_8() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1463,7 +1463,7 @@ fn two_basic_outputs_native_tokens_not_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1555,7 +1555,7 @@ fn multiple_remainders() { let nt_remainder_min_storage_deposit = nt_remainder_min_storage_deposit(&protocol_parameters); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1648,7 +1648,7 @@ pub fn nt_remainder_min_storage_deposit(protocol_parameters: &ProtocolParameters // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs.clone(), // outputs.clone(), // addresses([BECH32_ADDRESS_ED25519_0]), diff --git a/sdk/tests/client/input_selection/nft_outputs.rs b/sdk/tests/client/transaction_builder/nft_outputs.rs similarity index 97% rename from sdk/tests/client/input_selection/nft_outputs.rs rename to sdk/tests/client/transaction_builder/nft_outputs.rs index 59e9ea7154..c446d4caa1 100644 --- a/sdk/tests/client/input_selection/nft_outputs.rs +++ b/sdk/tests/client/transaction_builder/nft_outputs.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use iota_sdk::{ client::{ - api::input_selection::{Burn, Error, InputSelection, Requirement}, + api::transaction_builder::{Burn, Error, Requirement, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -54,7 +54,7 @@ fn input_nft_eq_output_nft() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -100,7 +100,7 @@ fn transition_nft_id_zero() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -142,7 +142,7 @@ fn transition_nft_id_zero() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -189,7 +189,7 @@ fn transition_nft_id_zero() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs.clone(), // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -233,7 +233,7 @@ fn mint_nft() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -287,7 +287,7 @@ fn burn_nft() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -331,7 +331,7 @@ fn burn_nft() { // None, // )]); -// let selected = InputSelection::new( +// let selected = TransactionBuilder::new( // inputs, // outputs, // [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -378,7 +378,7 @@ fn missing_input_for_nft_output() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -424,7 +424,7 @@ fn missing_input_for_nft_output_but_created() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -492,7 +492,7 @@ fn nft_in_output_and_sender() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -545,7 +545,7 @@ fn missing_ed25519_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -591,7 +591,7 @@ fn missing_ed25519_issuer_created() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -637,7 +637,7 @@ fn missing_ed25519_issuer_transition() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -680,7 +680,7 @@ fn missing_account_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -726,7 +726,7 @@ fn missing_account_issuer_created() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -772,7 +772,7 @@ fn missing_account_issuer_transition() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -815,7 +815,7 @@ fn missing_nft_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -861,7 +861,7 @@ fn missing_nft_issuer_created() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -907,7 +907,7 @@ fn missing_nft_issuer_transition() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -964,7 +964,7 @@ fn increase_nft_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1023,7 +1023,7 @@ fn decrease_nft_amount() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1094,7 +1094,7 @@ fn prefer_basic_to_nft() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1154,7 +1154,7 @@ fn take_amount_from_nft_to_fund_basic() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1226,7 +1226,7 @@ fn nft_burn_should_validate_nft_sender() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1286,7 +1286,7 @@ fn nft_burn_should_validate_nft_address() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1332,7 +1332,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1410,7 +1410,7 @@ fn changed_immutable_metadata() { let outputs = [updated_nft_output]; - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1451,7 +1451,7 @@ fn auto_transition_nft_less_than_min() { Some(SLOT_INDEX), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -1515,7 +1515,7 @@ fn auto_transition_nft_less_than_min_additional() { Some(SLOT_INDEX), ); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/outputs.rs b/sdk/tests/client/transaction_builder/outputs.rs similarity index 96% rename from sdk/tests/client/input_selection/outputs.rs rename to sdk/tests/client/transaction_builder/outputs.rs index 4af1cd6ffc..35ebec4f0d 100644 --- a/sdk/tests/client/input_selection/outputs.rs +++ b/sdk/tests/client/transaction_builder/outputs.rs @@ -5,7 +5,7 @@ use std::{collections::HashSet, str::FromStr}; use iota_sdk::{ client::{ - api::input_selection::{Burn, Error, InputSelection}, + api::transaction_builder::{Burn, Error, TransactionBuilder}, secret::types::InputSigningData, }, types::block::{ @@ -38,7 +38,7 @@ fn no_inputs() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -72,7 +72,7 @@ fn no_outputs() { ); let outputs = Vec::new(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -106,7 +106,7 @@ fn no_outputs_but_required_input() { ); let outputs = Vec::new(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -149,7 +149,7 @@ fn no_outputs_but_burn() { ); let outputs = Vec::new(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -200,7 +200,7 @@ fn no_address_provided() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, None, @@ -242,7 +242,7 @@ fn no_matching_address_provided() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_1).unwrap()], @@ -298,7 +298,7 @@ fn two_addresses_one_missing() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -360,7 +360,7 @@ fn two_addresses() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -423,7 +423,7 @@ fn consolidate_with_min_allotment() { }) .collect::>(); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), None, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/storage_deposit_return.rs b/sdk/tests/client/transaction_builder/storage_deposit_return.rs similarity index 97% rename from sdk/tests/client/input_selection/storage_deposit_return.rs rename to sdk/tests/client/transaction_builder/storage_deposit_return.rs index 40a8c7a29c..a84188efe9 100644 --- a/sdk/tests/client/input_selection/storage_deposit_return.rs +++ b/sdk/tests/client/transaction_builder/storage_deposit_return.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use iota_sdk::{ - client::api::input_selection::{Error, InputSelection}, + client::api::transaction_builder::{Error, TransactionBuilder}, types::block::{address::Address, output::AccountId, protocol::iota_mainnet_protocol_parameters}, }; use pretty_assertions::assert_eq; @@ -45,7 +45,7 @@ fn sdruc_output_not_provided_no_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -111,7 +111,7 @@ fn sdruc_output_provided_no_remainder() { }, ]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -155,7 +155,7 @@ fn sdruc_output_provided_remainder() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -224,7 +224,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -293,7 +293,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -363,7 +363,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -444,7 +444,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -500,7 +500,7 @@ fn insufficient_amount_because_of_sdruc() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -562,7 +562,7 @@ fn useless_sdruc_required_for_sender_feature() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [ @@ -633,7 +633,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -713,7 +713,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/client/input_selection/timelock.rs b/sdk/tests/client/transaction_builder/timelock.rs similarity index 96% rename from sdk/tests/client/input_selection/timelock.rs rename to sdk/tests/client/transaction_builder/timelock.rs index 214a92f6df..63e2d00f25 100644 --- a/sdk/tests/client/input_selection/timelock.rs +++ b/sdk/tests/client/transaction_builder/timelock.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::{ - client::api::input_selection::{Error, InputSelection}, + client::api::transaction_builder::{Error, TransactionBuilder}, types::block::{ address::Address, protocol::iota_mainnet_protocol_parameters, @@ -44,7 +44,7 @@ fn one_output_timelock_not_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs, outputs, [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -86,7 +86,7 @@ fn timelock_equal_timestamp() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -144,7 +144,7 @@ fn two_outputs_one_timelock_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -203,7 +203,7 @@ fn two_outputs_one_timelocked_one_missing() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], @@ -248,7 +248,7 @@ fn one_output_timelock_expired() { expiration: None, }]); - let selected = InputSelection::new( + let selected = TransactionBuilder::new( inputs.clone(), outputs.clone(), [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], diff --git a/sdk/tests/wallet/burn_outputs.rs b/sdk/tests/wallet/burn_outputs.rs index 4676de5a62..897f764e61 100644 --- a/sdk/tests/wallet/burn_outputs.rs +++ b/sdk/tests/wallet/burn_outputs.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::{ - client::api::input_selection::Burn, + client::api::transaction_builder::Burn, types::block::output::{ feature::MetadataFeature, unlock_condition::{AddressUnlockCondition, ExpirationUnlockCondition}, diff --git a/sdk/tests/wallet/claim_outputs.rs b/sdk/tests/wallet/claim_outputs.rs index 946db76f53..6f5948fd9c 100644 --- a/sdk/tests/wallet/claim_outputs.rs +++ b/sdk/tests/wallet/claim_outputs.rs @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 use iota_sdk::{ + client::api::options::TransactionOptions, types::block::output::{ unlock_condition::{AddressUnlockCondition, ExpirationUnlockCondition}, BasicOutputBuilder, NativeToken, NftId, NftOutputBuilder, UnlockCondition, }, - wallet::{CreateNativeTokenParams, OutputsToClaim, Result, SendNativeTokenParams, SendParams, TransactionOptions}, + wallet::{CreateNativeTokenParams, OutputsToClaim, Result, SendNativeTokenParams, SendParams}, U256, }; use pretty_assertions::assert_eq; From 871d012dd2ed9e2fe1a76a5ae3ba54016a7e3421 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 12:59:29 -0500 Subject: [PATCH 02/23] fmt --- .../block_builder/transaction_builder/mod.rs | 2 +- .../transaction_builder/requirement/amount.rs | 6 +- .../transaction_builder/account_outputs.rs | 54 +++++++------ .../transaction_builder/basic_outputs.rs | 80 +++++++++++-------- .../transaction_builder/delegation_outputs.rs | 16 ++-- 5 files changed, 88 insertions(+), 70 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 583a8a91d4..5ebf470dc9 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -//!Bbuilder for transactions +//! Bbuilder for transactions pub(crate) mod burn; pub(crate) mod error; diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs index 58b5c09ca4..c028bc7908 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs @@ -31,11 +31,7 @@ pub(crate) fn sdruc_not_expired( .map_or(false, |expiration| slot_index >= expiration.slot_index()); // We only have to send the storage deposit return back if the output is not expired - if !expired { - Some(sdr) - } else { - None - } + if !expired { Some(sdr) } else { None } }) } diff --git a/sdk/tests/client/transaction_builder/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs index 4a27ddb656..949d04fbdb 100644 --- a/sdk/tests/client/transaction_builder/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -1468,24 +1468,28 @@ fn two_accounts_required() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 3); assert!(selected.transaction.outputs().contains(&outputs[0])); - assert!(selected - .transaction - .outputs() - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_1 - } else { - false - })); - assert!(selected - .transaction - .outputs() - .iter() - .any(|output| if let Output::Account(output) = output { - output.account_id() == &account_id_2 - } else { - false - })) + assert!( + selected + .transaction + .outputs() + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_1 + } else { + false + }) + ); + assert!( + selected + .transaction + .outputs() + .iter() + .any(|output| if let Output::Account(output) = output { + output.account_id() == &account_id_2 + } else { + false + }) + ) } #[test] @@ -2105,12 +2109,14 @@ fn implicit_account_transition() { let input_output_id = *inputs[0].output_id(); let account_id = AccountId::from(&input_output_id); - let outputs = vec![AccountOutputBuilder::new_with_amount(1_000_000, account_id) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .finish_output() - .unwrap()]; + let outputs = vec![ + AccountOutputBuilder::new_with_amount(1_000_000, account_id) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .finish_output() + .unwrap(), + ]; let selected = TransactionBuilder::new( inputs.clone(), diff --git a/sdk/tests/client/transaction_builder/basic_outputs.rs b/sdk/tests/client/transaction_builder/basic_outputs.rs index 00c0cb6bea..5f5cda1151 100644 --- a/sdk/tests/client/transaction_builder/basic_outputs.rs +++ b/sdk/tests/client/transaction_builder/basic_outputs.rs @@ -747,10 +747,12 @@ fn ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!(selected - .inputs_data - .iter() - .any(|input| *input.output.as_basic().address() == sender)); + assert!( + selected + .inputs_data + .iter() + .any(|input| *input.output.as_basic().address() == sender) + ); // Provided output + remainder assert_eq!(selected.transaction.outputs().len(), 2); } @@ -891,10 +893,12 @@ fn account_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!(selected - .inputs_data - .iter() - .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1)); + assert!( + selected + .inputs_data + .iter() + .any(|input| input.output.is_account() && *input.output.as_account().account_id() == account_id_1) + ); // Provided output + account assert_eq!(selected.transaction.outputs().len(), 2); assert!(selected.transaction.outputs().contains(&outputs[0])); @@ -956,11 +960,13 @@ fn account_sender_zero_id() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 2); - assert!(selected - .transaction - .outputs() - .iter() - .any(|output| output.is_account() && *output.as_account().account_id() == account_id)); + assert!( + selected + .transaction + .outputs() + .iter() + .any(|output| output.is_account() && *output.as_account().account_id() == account_id) + ); } #[test] @@ -1101,10 +1107,12 @@ fn nft_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!(selected - .inputs_data - .iter() - .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1)); + assert!( + selected + .inputs_data + .iter() + .any(|input| input.output.is_nft() && *input.output.as_nft().nft_id() == nft_id_1) + ); // Provided output + nft assert_eq!(selected.transaction.outputs().len(), 2); assert!(selected.transaction.outputs().contains(&inputs[2].output)); @@ -1169,11 +1177,13 @@ fn nft_sender_zero_id() { assert!(unsorted_eq(&selected.inputs_data, &inputs)); assert_eq!(selected.transaction.outputs().len(), 2); - assert!(selected - .transaction - .outputs() - .iter() - .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id)); + assert!( + selected + .transaction + .outputs() + .iter() + .any(|output| output.is_nft() && *output.as_nft().nft_id() == nft_id) + ); } #[test] @@ -2252,10 +2262,12 @@ fn restricted_ed25519_sender() { // Sender + another for amount assert_eq!(selected.inputs_data.len(), 2); - assert!(selected - .inputs_data - .iter() - .any(|input| *input.output.as_basic().address() == sender)); + assert!( + selected + .inputs_data + .iter() + .any(|input| *input.output.as_basic().address() == sender) + ); // Provided output + remainder assert_eq!(selected.transaction.outputs().len(), 2); } @@ -2447,13 +2459,15 @@ fn automatic_allotment_provided_in_and_output() { }) .collect::>(); - let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .with_mana(1) - .finish_output() - .unwrap()]; + let outputs = vec![ + BasicOutputBuilder::new_with_amount(1_000_000) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .with_mana(1) + .finish_output() + .unwrap(), + ]; let selected = TransactionBuilder::new( inputs.clone(), diff --git a/sdk/tests/client/transaction_builder/delegation_outputs.rs b/sdk/tests/client/transaction_builder/delegation_outputs.rs index f04590a6bd..9c522ea798 100644 --- a/sdk/tests/client/transaction_builder/delegation_outputs.rs +++ b/sdk/tests/client/transaction_builder/delegation_outputs.rs @@ -61,13 +61,15 @@ fn remainder_needed_for_mana() { let delegation_output_id = *inputs[0].output_id(); let delegation_id = DelegationId::from(&delegation_output_id); - let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000) - .with_mana(200) - .add_unlock_condition(AddressUnlockCondition::new( - Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), - )) - .finish_output() - .unwrap()]; + let outputs = vec![ + BasicOutputBuilder::new_with_amount(1_000_000) + .with_mana(200) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .finish_output() + .unwrap(), + ]; let mana_rewards = 100; From 5a06ec3d89f512c99afaac4290d3c14cbe0b77e1 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 13:04:32 -0500 Subject: [PATCH 03/23] revert flag name --- sdk/src/client/api/block_builder/options.rs | 4 ++-- .../api/block_builder/transaction_builder/mod.rs | 10 +++++----- .../transaction_builder/requirement/mana.rs | 2 +- sdk/src/wallet/operations/output_claiming.rs | 2 +- sdk/src/wallet/operations/output_consolidation.rs | 2 +- .../wallet/operations/transaction/build_transaction.rs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/src/client/api/block_builder/options.rs b/sdk/src/client/api/block_builder/options.rs index 0b629c3b60..fd0fd2f58b 100644 --- a/sdk/src/client/api/block_builder/options.rs +++ b/sdk/src/client/api/block_builder/options.rs @@ -35,7 +35,7 @@ pub struct TransactionOptions { /// Whether to allow sending a micro amount. pub allow_micro_amount: bool, /// Whether to allow the selection of additional inputs for this transaction. - pub allow_additional_transaction_builder: bool, + pub allow_additional_input_selection: bool, /// Transaction capabilities. pub capabilities: Option, /// Mana allotments for the transaction. @@ -54,7 +54,7 @@ impl Default for TransactionOptions { burn: Default::default(), note: Default::default(), allow_micro_amount: false, - allow_additional_transaction_builder: true, + allow_additional_input_selection: true, capabilities: Default::default(), mana_allotments: Default::default(), issuer_id: Default::default(), diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 5ebf470dc9..644a7d47ed 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -152,7 +152,7 @@ impl Client { transaction_builder = transaction_builder.with_min_mana_allotment(account_id, reference_mana_cost); } - if !options.allow_additional_transaction_builder { + if !options.allow_additional_input_selection { transaction_builder = transaction_builder.disable_additional_transaction_builder(); } @@ -187,7 +187,7 @@ pub struct TransactionBuilder { mana_allotments: BTreeMap, mana_rewards: HashMap, payload: Option, - allow_additional_transaction_builder: bool, + allow_additional_input_selection: bool, transaction_capabilities: TransactionCapabilities, protocol_parameters: ProtocolParameters, } @@ -256,7 +256,7 @@ impl TransactionBuilder { min_mana_allotment: None, mana_allotments: Default::default(), mana_rewards: Default::default(), - allow_additional_transaction_builder: true, + allow_additional_input_selection: true, transaction_capabilities: Default::default(), payload: None, protocol_parameters, @@ -340,7 +340,7 @@ impl TransactionBuilder { // Fulfill the requirement. let inputs = self.fulfill_requirement(&requirement)?; - if !self.allow_additional_transaction_builder && !inputs.is_empty() { + if !self.allow_additional_input_selection && !inputs.is_empty() { return Err(Error::AdditionalInputsRequired(requirement)); } @@ -539,7 +539,7 @@ impl TransactionBuilder { /// Disables selecting additional inputs. pub fn disable_additional_transaction_builder(mut self) -> Self { - self.allow_additional_transaction_builder = false; + self.allow_additional_input_selection = false; self } diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index 23e16e3987..e100b40f00 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -240,7 +240,7 @@ impl TransactionBuilder { if selected_mana >= required_mana { log::debug!("Mana requirement already fulfilled"); } else { - if !self.allow_additional_transaction_builder { + if !self.allow_additional_input_selection { return Err(Error::AdditionalInputsRequired(Requirement::Mana)); } // TODO we should do as for the amount and have preferences on which inputs to pick. diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index 2feedc01c5..5571500a47 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -312,7 +312,7 @@ where // add additional inputs .chain(possible_additional_inputs.iter().map(|o| o.output_id)) .collect(), - allow_additional_transaction_builder: false, + allow_additional_input_selection: false, ..Default::default() }, ) diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index a6fe8d0fbc..d72a1625d2 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -109,7 +109,7 @@ where .map(|bech32| bech32.into_inner()) .unwrap_or_else(|| wallet_address.into_inner()), ), - allow_additional_transaction_builder: false, + allow_additional_input_selection: false, ..Default::default() }); diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index a8134159b6..f231ff6cda 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -158,7 +158,7 @@ where transaction_builder = transaction_builder.with_min_mana_allotment(account_id, reference_mana_cost); } - if !options.allow_additional_transaction_builder { + if !options.allow_additional_input_selection { transaction_builder = transaction_builder.disable_additional_transaction_builder(); } From b403c92c2a6c51c93af14fe545801cd60db8a68a Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 13:07:44 -0500 Subject: [PATCH 04/23] find/replace mistakes --- sdk/src/client/api/block_builder/options.rs | 2 +- .../client/api/block_builder/transaction_builder/burn.rs | 2 +- .../client/api/block_builder/transaction_builder/error.rs | 8 ++++---- .../client/api/block_builder/transaction_builder/mod.rs | 2 +- sdk/src/wallet/events/mod.rs | 8 ++++---- sdk/src/wallet/events/types.rs | 8 ++++---- sdk/src/wallet/operations/participation/mod.rs | 2 +- .../wallet/operations/transaction/build_transaction.rs | 4 ++-- .../transaction/high_level/burning_melting/mod.rs | 2 +- sdk/tests/wallet/events.rs | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sdk/src/client/api/block_builder/options.rs b/sdk/src/client/api/block_builder/options.rs index fd0fd2f58b..dac635e98d 100644 --- a/sdk/src/client/api/block_builder/options.rs +++ b/sdk/src/client/api/block_builder/options.rs @@ -28,7 +28,7 @@ pub struct TransactionOptions { pub context_inputs: Vec, /// Inputs that must be used for the transaction. pub required_inputs: BTreeSet, - /// Specifies what needs to be burned during iransaction builder. + /// Specifies what needs to be burned in the transaction. pub burn: Option, /// A string attached to the transaction. pub note: Option, diff --git a/sdk/src/client/api/block_builder/transaction_builder/burn.rs b/sdk/src/client/api/block_builder/transaction_builder/burn.rs index 7413ba85d3..ce1c991ada 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/burn.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/burn.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::types::block::output::{AccountId, DelegationId, FoundryId, NativeToken, NftId, TokenId}; -/// A type to specify what needs to be burned during iransaction builder. +/// A type to specify what needs to be burned in a transaction. /// Nothing will be burned that has not been explicitly set with this struct. #[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/sdk/src/client/api/block_builder/transaction_builder/error.rs b/sdk/src/client/api/block_builder/transaction_builder/error.rs index 1d1f935f6a..6688d30fe6 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/error.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/error.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -//! Error handling for iransaction builder. +//! Error handling for transaction builder. use std::fmt::Debug; @@ -10,11 +10,11 @@ use primitive_types::U256; use super::Requirement; use crate::types::block::output::{ChainId, OutputId, TokenId}; -/// Errors related to iransaction builder. +/// Errors related to transaction builder. #[derive(Debug, Eq, PartialEq, thiserror::Error)] #[non_exhaustive] pub enum Error { - #[error("additional inputs required for {0:?}, but additional iransaction builder is disabled")] + #[error("additional inputs required for {0:?}, but additional input selection is disabled")] AdditionalInputsRequired(Requirement), /// Block error. #[error("{0}")] @@ -59,7 +59,7 @@ pub enum Error { /// No input with matching ed25519 address provided. #[error("no input with matching ed25519 address provided")] MissingInputWithEd25519Address, - /// No available inputs were provided to iransaction builder. + /// No available inputs were provided to transaction builder. #[error("no available inputs provided")] NoAvailableInputsProvided, /// Required input is forbidden. diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 644a7d47ed..2f576daf3e 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -168,7 +168,7 @@ impl Client { } } -/// Working state for the iransaction builder algorithm. +/// Working state for the transaction builder algorithm. #[derive(Debug)] pub struct TransactionBuilder { available_inputs: Vec, diff --git a/sdk/src/wallet/events/mod.rs b/sdk/src/wallet/events/mod.rs index c75cc39acc..1335a6dd9d 100644 --- a/sdk/src/wallet/events/mod.rs +++ b/sdk/src/wallet/events/mod.rs @@ -148,7 +148,7 @@ mod tests { // emit events emitter.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )); emitter.emit(WalletEvent::TransactionInclusion(TransactionInclusionEvent { transaction_id: TransactionId::from_str( @@ -164,7 +164,7 @@ mod tests { emitter.clear([WalletEventType::TransactionProgress]); // emit event of removed type emitter.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )); assert_eq!(2, event_counter.load(Ordering::SeqCst)); @@ -173,7 +173,7 @@ mod tests { emitter.clear([]); // emit events emitter.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )); emitter.emit(WalletEvent::TransactionInclusion(TransactionInclusionEvent { transaction_id: TransactionId::from_str( @@ -193,7 +193,7 @@ mod tests { for _ in 0..1_000_000 { emitter.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )); } assert_eq!(1_000_002, event_counter.load(Ordering::SeqCst)); diff --git a/sdk/src/wallet/events/types.rs b/sdk/src/wallet/events/types.rs index 207fc33f29..c2aac02e5d 100644 --- a/sdk/src/wallet/events/types.rs +++ b/sdk/src/wallet/events/types.rs @@ -192,8 +192,8 @@ pub struct TransactionInclusionEvent { #[derive(Clone, Debug, Eq, PartialEq)] #[non_exhaustive] pub enum TransactionProgressEvent { - /// Performing iransaction builder. - SelectingInputs, + /// Building a transaction. + BuildingTransaction, /// Generating remainder value deposit address. GeneratingRemainderDepositAddress(AddressData), /// Prepared transaction. @@ -235,7 +235,7 @@ impl Serialize for TransactionProgressEvent { event: TransactionProgressEvent_<'a>, } let event = match self { - Self::SelectingInputs => TypedTransactionProgressEvent_ { + Self::BuildingTransaction => TypedTransactionProgressEvent_ { kind: 0, event: TransactionProgressEvent_::T0, }, @@ -280,7 +280,7 @@ impl<'de> Deserialize<'de> for TransactionProgressEvent { .ok_or_else(|| serde::de::Error::custom("invalid transaction progress event type"))? as u8 { - 0 => Self::SelectingInputs, + 0 => Self::BuildingTransaction, 1 => Self::GeneratingRemainderDepositAddress(AddressData::deserialize(value).map_err(|e| { serde::de::Error::custom(format!("cannot deserialize GeneratingRemainderDepositAddress: {e}")) })?), diff --git a/sdk/src/wallet/operations/participation/mod.rs b/sdk/src/wallet/operations/participation/mod.rs index b114d755ac..755c6c9bba 100644 --- a/sdk/src/wallet/operations/participation/mod.rs +++ b/sdk/src/wallet/operations/participation/mod.rs @@ -6,7 +6,7 @@ // They become spendable again when the user reduces the “voting power”. // This is done by creating a special “voting output” that adheres to the following rules, NOT by sending to a different // address. -// If the user has designated funds to vote with, the resulting output MUST NOT be used for iransaction builder. +// If the user has designated funds to vote with, the resulting output MUST NOT be used for building the transaction. // pub(crate) mod event; // pub(crate) mod voting; diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index f231ff6cda..6b2c4de387 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -67,7 +67,7 @@ where #[cfg(feature = "events")] self.emit(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )) .await; @@ -181,7 +181,7 @@ where } /// Filter available outputs to only include outputs that can be unlocked forever from this moment. -/// Note: this is only for the default iransaction builder, it's still possible to send these outputs by using +/// Note: this is only for the default transaction builder, it's still possible to send these outputs by using /// `claim_outputs` or providing their OutputId's in the custom_inputs #[allow(clippy::too_many_arguments)] fn filter_inputs<'a>( diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs index 588c8fd64a..b38b368e6d 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs @@ -40,7 +40,7 @@ impl Wallet { options.burn = Some(burn.into()); // The empty list of outputs is used. Outputs will be generated by - // the iransaction builder algorithm based on the content of the [`Burn`] object. + // the transaction builder algorithm based on the content of the [`Burn`] object. self.prepare_transaction([], options).await } } diff --git a/sdk/tests/wallet/events.rs b/sdk/tests/wallet/events.rs index 2293698ee1..06e7993e40 100644 --- a/sdk/tests/wallet/events.rs +++ b/sdk/tests/wallet/events.rs @@ -76,7 +76,7 @@ fn wallet_events_serde() { })); assert_serde_eq(WalletEvent::TransactionProgress( - TransactionProgressEvent::SelectingInputs, + TransactionProgressEvent::BuildingTransaction, )); assert_serde_eq(WalletEvent::TransactionProgress( From 1987e5d84ccf9fa1a4971d9aac410f3432ff3527 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 13:09:14 -0500 Subject: [PATCH 05/23] typo --- sdk/src/client/api/block_builder/transaction_builder/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 2f576daf3e..2d023ace08 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -1,7 +1,7 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -//! Bbuilder for transactions +//! Builder for transactions pub(crate) mod burn; pub(crate) mod error; From 1cbff52d5856d3894ba8e001561d20cabdfa28c6 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Thu, 29 Feb 2024 13:12:39 -0500 Subject: [PATCH 06/23] error swap --- sdk/src/client/api/block_builder/transaction_builder/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 2d023ace08..9e0c17e87d 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -53,7 +53,7 @@ impl Client { addresses: impl IntoIterator, outputs: impl IntoIterator, options: TransactionOptions, - ) -> crate::wallet::Result { + ) -> crate::client::Result { let outputs = outputs.into_iter().collect::>(); let addresses = addresses.into_iter().collect::>(); // Voting output needs to be requested before to prevent a deadlock From 80dd6b5bece90b9049f5a4ea20d7d2b74eb98ee2 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 08:06:26 -0500 Subject: [PATCH 07/23] review --- .../block_builder/transaction_builder/mod.rs | 8 +- .../transaction/build_transaction.rs | 4 +- sdk/tests/client/signing/mod.rs | 2 +- .../transaction_builder/account_outputs.rs | 78 +++++++++---------- .../transaction_builder/basic_outputs.rs | 72 ++++++++--------- sdk/tests/client/transaction_builder/burn.rs | 36 ++++----- .../transaction_builder/delegation_outputs.rs | 2 +- .../client/transaction_builder/expiration.rs | 36 ++++----- .../transaction_builder/foundry_outputs.rs | 36 ++++----- .../transaction_builder/native_tokens.rs | 50 ++++++------ .../client/transaction_builder/nft_outputs.rs | 52 ++++++------- .../client/transaction_builder/outputs.rs | 18 ++--- .../storage_deposit_return.rs | 22 +++--- .../client/transaction_builder/timelock.rs | 10 +-- 14 files changed, 213 insertions(+), 213 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 9e0c17e87d..c687558ee6 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -153,14 +153,14 @@ impl Client { } if !options.allow_additional_input_selection { - transaction_builder = transaction_builder.disable_additional_transaction_builder(); + transaction_builder = transaction_builder.disable_additional_input_selection(); } if let Some(capabilities) = options.capabilities { transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) } - let prepared_transaction_data = transaction_builder.select()?; + let prepared_transaction_data = transaction_builder.build()?; validate_transaction_length(&prepared_transaction_data.transaction)?; @@ -315,7 +315,7 @@ impl TransactionBuilder { /// Selects inputs that meet the requirements of the outputs to satisfy the semantic validation of the overall /// transaction. Also creates a remainder output and chain transition outputs if required. - pub fn select(mut self) -> Result { + pub fn build(mut self) -> Result { if !OUTPUT_COUNT_RANGE.contains(&(self.provided_outputs.len() as u16)) { // If burn or mana allotments are provided, outputs will be added later, in the other cases it will just // create remainder outputs. @@ -538,7 +538,7 @@ impl TransactionBuilder { } /// Disables selecting additional inputs. - pub fn disable_additional_transaction_builder(mut self) -> Self { + pub fn disable_additional_input_selection(mut self) -> Self { self.allow_additional_input_selection = false; self } diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 6b2c4de387..921866936b 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -159,14 +159,14 @@ where } if !options.allow_additional_input_selection { - transaction_builder = transaction_builder.disable_additional_transaction_builder(); + transaction_builder = transaction_builder.disable_additional_input_selection(); } if let Some(capabilities) = options.capabilities { transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) } - let prepared_transaction_data = transaction_builder.select()?; + let prepared_transaction_data = transaction_builder.build()?; validate_transaction_length(&prepared_transaction_data.transaction)?; diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index d1a103bdb9..2e35dbc4f3 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -376,7 +376,7 @@ async fn all_combined() -> Result<()> { slot_commitment_id, protocol_parameters.clone(), ) - .select() + .build() .unwrap(); let transaction = Transaction::builder(protocol_parameters.network_id()) diff --git a/sdk/tests/client/transaction_builder/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs index 949d04fbdb..61f27b62dc 100644 --- a/sdk/tests/client/transaction_builder/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -61,7 +61,7 @@ fn input_account_eq_output_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -103,7 +103,7 @@ fn transition_account_id_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -280,7 +280,7 @@ fn create_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -333,7 +333,7 @@ fn burn_account() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -421,7 +421,7 @@ fn missing_input_for_account_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -478,7 +478,7 @@ fn missing_input_for_account_output_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -522,7 +522,7 @@ fn missing_input_for_account_output_but_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -581,7 +581,7 @@ fn account_in_output_and_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -622,7 +622,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -666,7 +666,7 @@ fn missing_ed25519_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -708,7 +708,7 @@ fn missing_ed25519_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -747,7 +747,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -791,7 +791,7 @@ fn missing_account_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -833,7 +833,7 @@ fn missing_account_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -872,7 +872,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -916,7 +916,7 @@ fn missing_nft_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -958,7 +958,7 @@ fn missing_nft_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -1011,7 +1011,7 @@ fn increase_account_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1066,7 +1066,7 @@ fn decrease_account_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1135,7 +1135,7 @@ fn prefer_basic_to_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1193,7 +1193,7 @@ fn take_amount_from_account_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1266,7 +1266,7 @@ fn account_burn_should_validate_account_sender() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1336,7 +1336,7 @@ fn account_burn_should_validate_account_address() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1391,7 +1391,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1462,7 +1462,7 @@ fn two_accounts_required() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1528,7 +1528,7 @@ fn state_controller_sender_required() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1582,7 +1582,7 @@ fn state_controller_sender_required_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1624,7 +1624,7 @@ fn state_transition_and_required() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1665,7 +1665,7 @@ fn remainder_address_in_state_controller() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1724,7 +1724,7 @@ fn min_allot_account_mana() { protocol_parameters, ) .with_min_mana_allotment(account_id_1, 2) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1795,7 +1795,7 @@ fn min_allot_account_mana_additional() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1862,8 +1862,8 @@ fn min_allot_account_mana_cannot_select_additional() { .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_2, provided_allotment))) .with_required_inputs([*inputs[0].output_id()]) - .disable_additional_transaction_builder() - .select() + .disable_additional_input_selection() + .build() .unwrap_err(); assert!( @@ -1914,7 +1914,7 @@ fn min_allot_account_mana_requirement_twice() { ) .with_min_mana_allotment(account_id_1, 2) .with_required_inputs([*inputs[1].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1995,7 +1995,7 @@ fn min_allot_account_mana_requirement_covered() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2070,7 +2070,7 @@ fn min_allot_account_mana_requirement_covered_2() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2128,7 +2128,7 @@ fn implicit_account_transition() { ) .with_required_inputs(vec![input_output_id]) .with_min_mana_allotment(account_id_1, 2) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2173,7 +2173,7 @@ fn auto_transition_account_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap_err(); let min_amount = AccountOutputBuilder::from(inputs[0].output.as_account()) @@ -2235,7 +2235,7 @@ fn auto_transition_account_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/basic_outputs.rs b/sdk/tests/client/transaction_builder/basic_outputs.rs index 5f5cda1151..e0375b1ba3 100644 --- a/sdk/tests/client/transaction_builder/basic_outputs.rs +++ b/sdk/tests/client/transaction_builder/basic_outputs.rs @@ -63,7 +63,7 @@ fn input_amount_equal_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -107,7 +107,7 @@ fn input_amount_lower_than_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -169,7 +169,7 @@ fn input_amount_lower_than_output_amount_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -217,7 +217,7 @@ fn input_amount_greater_than_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -275,7 +275,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { protocol_parameters, ) .with_remainder_address(remainder_address) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -345,7 +345,7 @@ fn two_same_inputs_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); // One input has enough amount. @@ -416,7 +416,7 @@ fn two_inputs_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data, [inputs[0].clone()]); @@ -474,7 +474,7 @@ fn two_inputs_one_needed_reversed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data, [inputs[1].clone()]); @@ -532,7 +532,7 @@ fn two_inputs_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -590,7 +590,7 @@ fn two_inputs_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -742,7 +742,7 @@ fn ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); // Sender + another for amount @@ -794,7 +794,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -888,7 +888,7 @@ fn account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); // Sender + another for amount @@ -955,7 +955,7 @@ fn account_sender_zero_id() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1006,7 +1006,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1102,7 +1102,7 @@ fn nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); // Sender + another for amount @@ -1172,7 +1172,7 @@ fn nft_sender_zero_id() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1223,7 +1223,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1268,7 +1268,7 @@ fn simple_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1403,7 +1403,7 @@ fn one_provided_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1447,7 +1447,7 @@ fn insufficient_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1509,7 +1509,7 @@ fn two_inputs_remainder_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1579,7 +1579,7 @@ fn two_inputs_remainder_3() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1678,7 +1678,7 @@ fn sender_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1726,7 +1726,7 @@ fn single_mandatory_input() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1774,7 +1774,7 @@ fn too_many_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert_eq!( selected.unwrap_err(), @@ -1841,7 +1841,7 @@ fn more_than_max_inputs_only_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &needed_input)); @@ -1888,7 +1888,7 @@ fn too_many_outputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert_eq!( selected.unwrap_err(), @@ -1937,7 +1937,7 @@ fn too_many_outputs_with_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert_eq!( selected.unwrap_err(), @@ -2035,7 +2035,7 @@ fn restricted_ed25519() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -2097,7 +2097,7 @@ fn restricted_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2157,7 +2157,7 @@ fn restricted_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2257,7 +2257,7 @@ fn restricted_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); // Sender + another for amount @@ -2354,7 +2354,7 @@ fn multi_address_sender_already_fulfilled() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id(), *inputs[1].output_id(), *inputs[2].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2430,7 +2430,7 @@ fn ed25519_backed_available_address() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2478,7 +2478,7 @@ fn automatic_allotment_provided_in_and_output() { protocol_parameters, ) .with_min_mana_allotment(account_id_1, 2) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/burn.rs b/sdk/tests/client/transaction_builder/burn.rs index 10e94f06a8..a998c70359 100644 --- a/sdk/tests/client/transaction_builder/burn.rs +++ b/sdk/tests/client/transaction_builder/burn.rs @@ -76,7 +76,7 @@ fn burn_account_present() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -136,7 +136,7 @@ fn burn_account_present_and_required() { ) .with_burn(Burn::new().add_account(account_id_1)) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -198,7 +198,7 @@ fn burn_account_id_zero() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id)) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -245,7 +245,7 @@ fn burn_account_absent() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -315,7 +315,7 @@ fn burn_accounts_present() { protocol_parameters, ) .with_burn(Burn::new().set_accounts(HashSet::from([account_id_1, account_id_2]))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -382,7 +382,7 @@ fn burn_account_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -443,7 +443,7 @@ fn burn_nft_present() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -505,7 +505,7 @@ fn burn_nft_present_and_required() { ) .with_burn(Burn::new().add_nft(nft_id_1)) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -565,7 +565,7 @@ fn burn_nft_id_zero() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id)) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -612,7 +612,7 @@ fn burn_nft_absent() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -686,7 +686,7 @@ fn burn_nfts_present() { protocol_parameters, ) .with_burn(Burn::new().set_nfts(HashSet::from([nft_id_1, nft_id_2]))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -757,7 +757,7 @@ fn burn_nft_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -826,7 +826,7 @@ fn burn_foundry_present() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[0].output.as_foundry().id())) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -927,7 +927,7 @@ fn burn_foundry_absent() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(foundry_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -997,7 +997,7 @@ fn burn_foundries_present() { inputs[0].output.as_foundry().id(), inputs[1].output.as_foundry().id(), ]))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1080,7 +1080,7 @@ fn burn_foundry_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(foundry_id_1)) - .select(); + .build(); assert!(matches!( selected, @@ -1136,7 +1136,7 @@ fn burn_native_tokens() { (TokenId::from_str(TOKEN_ID_1).unwrap(), 20), (TokenId::from_str(TOKEN_ID_2).unwrap(), 30), ]))) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1221,7 +1221,7 @@ fn burn_foundry_and_its_account() { .add_foundry(inputs[0].output.as_foundry().id()) .add_account(account_id_1), ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); diff --git a/sdk/tests/client/transaction_builder/delegation_outputs.rs b/sdk/tests/client/transaction_builder/delegation_outputs.rs index 9c522ea798..f6b2f1f000 100644 --- a/sdk/tests/client/transaction_builder/delegation_outputs.rs +++ b/sdk/tests/client/transaction_builder/delegation_outputs.rs @@ -83,7 +83,7 @@ fn remainder_needed_for_mana() { ) .with_burn(Burn::from(delegation_id)) .add_mana_rewards(delegation_output_id, mana_rewards) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); diff --git a/sdk/tests/client/transaction_builder/expiration.rs b/sdk/tests/client/transaction_builder/expiration.rs index 579669b73f..b8fa221497 100644 --- a/sdk/tests/client/transaction_builder/expiration.rs +++ b/sdk/tests/client/transaction_builder/expiration.rs @@ -58,7 +58,7 @@ fn one_output_expiration_not_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -100,7 +100,7 @@ fn expiration_equal_timestamp() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -144,7 +144,7 @@ fn one_output_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -202,7 +202,7 @@ fn two_outputs_one_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -261,7 +261,7 @@ fn two_outputs_one_unexpired_one_missing() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -332,7 +332,7 @@ fn two_outputs_two_expired() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -394,7 +394,7 @@ fn two_outputs_two_expired_2() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -438,7 +438,7 @@ fn expiration_expired_with_sdr() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -482,7 +482,7 @@ fn expiration_expired_with_sdr_2() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -526,7 +526,7 @@ fn expiration_expired_with_sdr_and_timelock() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -570,7 +570,7 @@ fn expiration_expired_with_sdr_and_timelock_2() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -667,7 +667,7 @@ fn sender_in_expiration() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -716,7 +716,7 @@ fn sender_in_expiration_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -763,7 +763,7 @@ fn remainder_in_expiration() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -818,7 +818,7 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -876,7 +876,7 @@ fn expiration_expired_only_account_addresses() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -921,7 +921,7 @@ fn one_nft_output_expiration_unexpired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -966,7 +966,7 @@ fn one_nft_output_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/foundry_outputs.rs b/sdk/tests/client/transaction_builder/foundry_outputs.rs index 5eef53bba7..90dbfcbe1c 100644 --- a/sdk/tests/client/transaction_builder/foundry_outputs.rs +++ b/sdk/tests/client/transaction_builder/foundry_outputs.rs @@ -62,7 +62,7 @@ fn missing_input_account_for_foundry() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -156,7 +156,7 @@ fn minted_native_tokens_in_new_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -232,7 +232,7 @@ fn minted_native_tokens_in_provided_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -305,7 +305,7 @@ fn melt_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -366,7 +366,7 @@ fn destroy_foundry_with_account_state_transition() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[1].output.as_foundry().id())) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -427,7 +427,7 @@ fn destroy_foundry_with_account_burn() { .add_foundry(inputs[1].output.as_foundry().id()) .add_account(account_id_2), ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -505,7 +505,7 @@ fn prefer_basic_to_foundry() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -574,7 +574,7 @@ fn simple_foundry_transition_basic_not_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -658,7 +658,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -809,7 +809,7 @@ fn mint_and_burn_at_the_same_time() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id, 10)) - .select(); + .build(); assert!(matches!( selected, @@ -881,7 +881,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -949,7 +949,7 @@ fn create_native_token_but_burn_account() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1016,7 +1016,7 @@ fn melted_tokens_not_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1076,7 +1076,7 @@ fn burned_tokens_not_provided() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id_1, 100)) - .select(); + .build(); assert!(matches!( selected, @@ -1134,7 +1134,7 @@ fn foundry_in_outputs_and_required() { protocol_parameters, ) .with_required_inputs([*inputs[1].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1211,7 +1211,7 @@ fn melt_and_burn_native_tokens() { ) // Burn 456 native tokens .with_burn(Burn::new().add_native_token(token_id, 456)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1272,7 +1272,7 @@ fn auto_transition_foundry_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap_err(); let min_amount = FoundryOutputBuilder::from(inputs[0].output.as_foundry()) @@ -1353,7 +1353,7 @@ fn auto_transition_foundry_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/native_tokens.rs b/sdk/tests/client/transaction_builder/native_tokens.rs index d5f6a1644d..382d073134 100644 --- a/sdk/tests/client/transaction_builder/native_tokens.rs +++ b/sdk/tests/client/transaction_builder/native_tokens.rs @@ -70,7 +70,7 @@ fn two_native_tokens_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data[0], inputs[0]); @@ -140,7 +140,7 @@ fn two_native_tokens_both_needed_plus_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -221,7 +221,7 @@ fn three_inputs_two_needed_plus_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -302,7 +302,7 @@ fn three_inputs_two_needed_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -346,7 +346,7 @@ fn insufficient_native_tokens_one_input() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -420,7 +420,7 @@ fn insufficient_native_tokens_three_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -487,7 +487,7 @@ fn burn_and_send_at_the_same_time() { .add_native_token(TokenId::from_str(TOKEN_ID_1).unwrap(), 10) .add_native_token(TokenId::from_str(TOKEN_ID_2).unwrap(), 100), ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -534,7 +534,7 @@ fn burn_one_input_no_output() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(TokenId::from_str(TOKEN_ID_1).unwrap(), 50)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -598,7 +598,7 @@ fn multiple_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -643,7 +643,7 @@ fn insufficient_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -691,7 +691,7 @@ fn insufficient_native_tokens_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -741,7 +741,7 @@ fn insufficient_amount_for_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert_eq!( selected.unwrap_err(), @@ -789,7 +789,7 @@ fn single_output_native_token_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -833,7 +833,7 @@ fn single_output_native_token_remainder_1() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -884,7 +884,7 @@ fn single_output_native_token_remainder_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -949,7 +949,7 @@ fn two_basic_outputs_1() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1015,7 +1015,7 @@ fn two_basic_outputs_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1081,7 +1081,7 @@ fn two_basic_outputs_3() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1147,7 +1147,7 @@ fn two_basic_outputs_4() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1213,7 +1213,7 @@ fn two_basic_outputs_5() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1279,7 +1279,7 @@ fn two_basic_outputs_6() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1344,7 +1344,7 @@ fn two_basic_outputs_7() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1409,7 +1409,7 @@ fn two_basic_outputs_8() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1471,7 +1471,7 @@ fn two_basic_outputs_native_tokens_not_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1563,7 +1563,7 @@ fn multiple_remainders() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 4); diff --git a/sdk/tests/client/transaction_builder/nft_outputs.rs b/sdk/tests/client/transaction_builder/nft_outputs.rs index c446d4caa1..bb8649b834 100644 --- a/sdk/tests/client/transaction_builder/nft_outputs.rs +++ b/sdk/tests/client/transaction_builder/nft_outputs.rs @@ -62,7 +62,7 @@ fn input_nft_eq_output_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -108,7 +108,7 @@ fn transition_nft_id_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -241,7 +241,7 @@ fn mint_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -296,7 +296,7 @@ fn burn_nft() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_2)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -386,7 +386,7 @@ fn missing_input_for_nft_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -432,7 +432,7 @@ fn missing_input_for_nft_output_but_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -500,7 +500,7 @@ fn nft_in_output_and_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -553,7 +553,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -599,7 +599,7 @@ fn missing_ed25519_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -645,7 +645,7 @@ fn missing_ed25519_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -688,7 +688,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -734,7 +734,7 @@ fn missing_account_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -780,7 +780,7 @@ fn missing_account_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -823,7 +823,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -869,7 +869,7 @@ fn missing_nft_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -915,7 +915,7 @@ fn missing_nft_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(selected.is_ok()); } @@ -972,7 +972,7 @@ fn increase_nft_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1031,7 +1031,7 @@ fn decrease_nft_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1102,7 +1102,7 @@ fn prefer_basic_to_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1162,7 +1162,7 @@ fn take_amount_from_nft_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1235,7 +1235,7 @@ fn nft_burn_should_validate_nft_sender() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1295,7 +1295,7 @@ fn nft_burn_should_validate_nft_address() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1340,7 +1340,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1418,7 +1418,7 @@ fn changed_immutable_metadata() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -1460,7 +1460,7 @@ fn auto_transition_nft_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap_err(); let min_amount = NftOutputBuilder::from(inputs[0].output.as_nft()) @@ -1524,7 +1524,7 @@ fn auto_transition_nft_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/outputs.rs b/sdk/tests/client/transaction_builder/outputs.rs index 35ebec4f0d..c7bbcfcbeb 100644 --- a/sdk/tests/client/transaction_builder/outputs.rs +++ b/sdk/tests/client/transaction_builder/outputs.rs @@ -46,7 +46,7 @@ fn no_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -80,7 +80,7 @@ fn no_outputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::InvalidOutputCount(0)))); } @@ -115,7 +115,7 @@ fn no_outputs_but_required_input() { protocol_parameters, ) .with_required_inputs(HashSet::from([*inputs[0].output_id()])) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data, inputs); @@ -158,7 +158,7 @@ fn no_outputs_but_burn() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data, inputs); @@ -208,7 +208,7 @@ fn no_address_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -250,7 +250,7 @@ fn no_matching_address_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -306,7 +306,7 @@ fn two_addresses_one_missing() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -371,7 +371,7 @@ fn two_addresses() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -433,7 +433,7 @@ fn consolidate_with_min_allotment() { ) .with_min_mana_allotment(account_id_1, 10) .with_required_inputs(inputs.iter().map(|i| *i.output_id())) - .select() + .build() .unwrap(); assert_eq!(selected.transaction.outputs().len(), 1); diff --git a/sdk/tests/client/transaction_builder/storage_deposit_return.rs b/sdk/tests/client/transaction_builder/storage_deposit_return.rs index a84188efe9..ab0eab75f9 100644 --- a/sdk/tests/client/transaction_builder/storage_deposit_return.rs +++ b/sdk/tests/client/transaction_builder/storage_deposit_return.rs @@ -53,7 +53,7 @@ fn sdruc_output_not_provided_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -119,7 +119,7 @@ fn sdruc_output_provided_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -163,7 +163,7 @@ fn sdruc_output_provided_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -232,7 +232,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -301,7 +301,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -371,7 +371,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -452,7 +452,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -508,7 +508,7 @@ fn insufficient_amount_because_of_sdruc() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select(); + .build(); assert!(matches!( selected, @@ -573,7 +573,7 @@ fn useless_sdruc_required_for_sender_feature() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -641,7 +641,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -721,7 +721,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); diff --git a/sdk/tests/client/transaction_builder/timelock.rs b/sdk/tests/client/transaction_builder/timelock.rs index 63e2d00f25..fe64fe4bbf 100644 --- a/sdk/tests/client/transaction_builder/timelock.rs +++ b/sdk/tests/client/transaction_builder/timelock.rs @@ -52,7 +52,7 @@ fn one_output_timelock_not_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select(); + .build(); assert!(matches!(selected, Err(Error::NoAvailableInputsProvided))); } @@ -94,7 +94,7 @@ fn timelock_equal_timestamp() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -152,7 +152,7 @@ fn two_outputs_one_timelock_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -211,7 +211,7 @@ fn two_outputs_one_timelocked_one_missing() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -256,7 +256,7 @@ fn one_output_timelock_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .select() + .build() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); From 898b3323978c40b212924c4fa6623b18e07afd9c Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 09:24:34 -0500 Subject: [PATCH 08/23] finish renaming --- .../block_builder/transaction_builder/mod.rs | 4 +- .../transaction/build_transaction.rs | 2 +- sdk/tests/client/signing/mod.rs | 2 +- .../transaction_builder/account_outputs.rs | 76 +++++++++---------- .../transaction_builder/basic_outputs.rs | 72 +++++++++--------- sdk/tests/client/transaction_builder/burn.rs | 36 ++++----- .../transaction_builder/delegation_outputs.rs | 2 +- .../client/transaction_builder/expiration.rs | 36 ++++----- .../transaction_builder/foundry_outputs.rs | 36 ++++----- .../transaction_builder/native_tokens.rs | 50 ++++++------ .../client/transaction_builder/nft_outputs.rs | 52 ++++++------- .../client/transaction_builder/outputs.rs | 18 ++--- .../storage_deposit_return.rs | 22 +++--- .../client/transaction_builder/timelock.rs | 10 +-- 14 files changed, 209 insertions(+), 209 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index ecf35cac8a..f6040ff7a4 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -160,7 +160,7 @@ impl Client { transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) } - let prepared_transaction_data = transaction_builder.build()?; + let prepared_transaction_data = transaction_builder.finish()?; validate_transaction_length(&prepared_transaction_data.transaction)?; @@ -315,7 +315,7 @@ impl TransactionBuilder { /// Selects inputs that meet the requirements of the outputs to satisfy the semantic validation of the overall /// transaction. Also creates a remainder output and chain transition outputs if required. - pub fn build(mut self) -> Result { + pub fn finish(mut self) -> Result { if !OUTPUT_COUNT_RANGE.contains(&(self.provided_outputs.len() as u16)) { // If burn or mana allotments are provided, outputs will be added later, in the other cases it will just // create remainder outputs. diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 921866936b..1ec6e85597 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -166,7 +166,7 @@ where transaction_builder = transaction_builder.with_transaction_capabilities(capabilities) } - let prepared_transaction_data = transaction_builder.build()?; + let prepared_transaction_data = transaction_builder.finish()?; validate_transaction_length(&prepared_transaction_data.transaction)?; diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 33acbd14db..014718dfb2 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -375,7 +375,7 @@ async fn all_combined() -> Result<(), Box> { slot_commitment_id, protocol_parameters.clone(), ) - .build() + .finish() .unwrap(); let transaction = Transaction::builder(protocol_parameters.network_id()) diff --git a/sdk/tests/client/transaction_builder/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs index a6c8d9317f..7dec6f2c82 100644 --- a/sdk/tests/client/transaction_builder/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -61,7 +61,7 @@ fn input_account_eq_output_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -103,7 +103,7 @@ fn transition_account_id_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -280,7 +280,7 @@ fn create_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -333,7 +333,7 @@ fn burn_account() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -421,7 +421,7 @@ fn missing_input_for_account_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -478,7 +478,7 @@ fn missing_input_for_account_output_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -522,7 +522,7 @@ fn missing_input_for_account_output_but_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -581,7 +581,7 @@ fn account_in_output_and_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -622,7 +622,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -666,7 +666,7 @@ fn missing_ed25519_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -708,7 +708,7 @@ fn missing_ed25519_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -747,7 +747,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -791,7 +791,7 @@ fn missing_account_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -833,7 +833,7 @@ fn missing_account_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -872,7 +872,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -916,7 +916,7 @@ fn missing_nft_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -958,7 +958,7 @@ fn missing_nft_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -1011,7 +1011,7 @@ fn increase_account_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1066,7 +1066,7 @@ fn decrease_account_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1135,7 +1135,7 @@ fn prefer_basic_to_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1193,7 +1193,7 @@ fn take_amount_from_account_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1266,7 +1266,7 @@ fn account_burn_should_validate_account_sender() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1336,7 +1336,7 @@ fn account_burn_should_validate_account_address() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1391,7 +1391,7 @@ fn transitioned_zero_account_id_no_longer_is_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1462,7 +1462,7 @@ fn two_accounts_required() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1528,7 +1528,7 @@ fn state_controller_sender_required() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1582,7 +1582,7 @@ fn state_controller_sender_required_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1624,7 +1624,7 @@ fn state_transition_and_required() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1665,7 +1665,7 @@ fn remainder_address_in_state_controller() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1724,7 +1724,7 @@ fn min_allot_account_mana() { protocol_parameters, ) .with_min_mana_allotment(account_id_1, 2) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1795,7 +1795,7 @@ fn min_allot_account_mana_additional() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1863,7 +1863,7 @@ fn min_allot_account_mana_cannot_select_additional() { .with_mana_allotments(Some((account_id_2, provided_allotment))) .with_required_inputs([*inputs[0].output_id()]) .disable_additional_input_selection() - .build() + .finish() .unwrap_err(); assert!( @@ -1914,7 +1914,7 @@ fn min_allot_account_mana_requirement_twice() { ) .with_min_mana_allotment(account_id_1, 2) .with_required_inputs([*inputs[1].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1995,7 +1995,7 @@ fn min_allot_account_mana_requirement_covered() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2070,7 +2070,7 @@ fn min_allot_account_mana_requirement_covered_2() { ) .with_min_mana_allotment(account_id_1, 2) .with_mana_allotments(Some((account_id_1, provided_allotment))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2128,7 +2128,7 @@ fn implicit_account_transition() { ) .with_required_inputs(vec![input_output_id]) .with_min_mana_allotment(account_id_1, 2) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2173,7 +2173,7 @@ fn auto_transition_account_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap_err(); let min_amount = AccountOutputBuilder::from(inputs[0].output.as_account()) @@ -2235,7 +2235,7 @@ fn auto_transition_account_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/basic_outputs.rs b/sdk/tests/client/transaction_builder/basic_outputs.rs index 270fbc8aa1..56362ea42c 100644 --- a/sdk/tests/client/transaction_builder/basic_outputs.rs +++ b/sdk/tests/client/transaction_builder/basic_outputs.rs @@ -63,7 +63,7 @@ fn input_amount_equal_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -107,7 +107,7 @@ fn input_amount_lower_than_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -169,7 +169,7 @@ fn input_amount_lower_than_output_amount_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -217,7 +217,7 @@ fn input_amount_greater_than_output_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -275,7 +275,7 @@ fn input_amount_greater_than_output_amount_with_remainder_address() { protocol_parameters, ) .with_remainder_address(remainder_address) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -345,7 +345,7 @@ fn two_same_inputs_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); // One input has enough amount. @@ -416,7 +416,7 @@ fn two_inputs_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data, [inputs[0].clone()]); @@ -474,7 +474,7 @@ fn two_inputs_one_needed_reversed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data, [inputs[1].clone()]); @@ -532,7 +532,7 @@ fn two_inputs_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -590,7 +590,7 @@ fn two_inputs_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -742,7 +742,7 @@ fn ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); // Sender + another for amount @@ -794,7 +794,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -888,7 +888,7 @@ fn account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); // Sender + another for amount @@ -955,7 +955,7 @@ fn account_sender_zero_id() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1006,7 +1006,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1102,7 +1102,7 @@ fn nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); // Sender + another for amount @@ -1172,7 +1172,7 @@ fn nft_sender_zero_id() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1223,7 +1223,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1268,7 +1268,7 @@ fn simple_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1403,7 +1403,7 @@ fn one_provided_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1447,7 +1447,7 @@ fn insufficient_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1509,7 +1509,7 @@ fn two_inputs_remainder_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1579,7 +1579,7 @@ fn two_inputs_remainder_3() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1678,7 +1678,7 @@ fn sender_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1726,7 +1726,7 @@ fn single_mandatory_input() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1774,7 +1774,7 @@ fn too_many_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert_eq!( selected.unwrap_err(), @@ -1841,7 +1841,7 @@ fn more_than_max_inputs_only_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &needed_input)); @@ -1888,7 +1888,7 @@ fn too_many_outputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert_eq!( selected.unwrap_err(), @@ -1937,7 +1937,7 @@ fn too_many_outputs_with_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert_eq!( selected.unwrap_err(), @@ -2035,7 +2035,7 @@ fn restricted_ed25519() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -2097,7 +2097,7 @@ fn restricted_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2157,7 +2157,7 @@ fn restricted_account() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2257,7 +2257,7 @@ fn restricted_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); // Sender + another for amount @@ -2354,7 +2354,7 @@ fn multi_address_sender_already_fulfilled() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id(), *inputs[1].output_id(), *inputs[2].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2430,7 +2430,7 @@ fn ed25519_backed_available_address() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -2478,7 +2478,7 @@ fn automatic_allotment_provided_in_and_output() { protocol_parameters, ) .with_min_mana_allotment(account_id_1, 2) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/burn.rs b/sdk/tests/client/transaction_builder/burn.rs index fc7a0d8bdc..3b802bd3dd 100644 --- a/sdk/tests/client/transaction_builder/burn.rs +++ b/sdk/tests/client/transaction_builder/burn.rs @@ -76,7 +76,7 @@ fn burn_account_present() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -136,7 +136,7 @@ fn burn_account_present_and_required() { ) .with_burn(Burn::new().add_account(account_id_1)) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -198,7 +198,7 @@ fn burn_account_id_zero() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id)) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -245,7 +245,7 @@ fn burn_account_absent() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -315,7 +315,7 @@ fn burn_accounts_present() { protocol_parameters, ) .with_burn(Burn::new().set_accounts(HashSet::from([account_id_1, account_id_2]))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -382,7 +382,7 @@ fn burn_account_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -443,7 +443,7 @@ fn burn_nft_present() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -505,7 +505,7 @@ fn burn_nft_present_and_required() { ) .with_burn(Burn::new().add_nft(nft_id_1)) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -565,7 +565,7 @@ fn burn_nft_id_zero() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id)) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -612,7 +612,7 @@ fn burn_nft_absent() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -686,7 +686,7 @@ fn burn_nfts_present() { protocol_parameters, ) .with_burn(Burn::new().set_nfts(HashSet::from([nft_id_1, nft_id_2]))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -757,7 +757,7 @@ fn burn_nft_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -826,7 +826,7 @@ fn burn_foundry_present() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[0].output.as_foundry().id())) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -927,7 +927,7 @@ fn burn_foundry_absent() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(foundry_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -997,7 +997,7 @@ fn burn_foundries_present() { inputs[0].output.as_foundry().id(), inputs[1].output.as_foundry().id(), ]))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1080,7 +1080,7 @@ fn burn_foundry_in_outputs() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(foundry_id_1)) - .build(); + .finish(); assert!(matches!( selected, @@ -1136,7 +1136,7 @@ fn burn_native_tokens() { (TokenId::from_str(TOKEN_ID_1).unwrap(), 20), (TokenId::from_str(TOKEN_ID_2).unwrap(), 30), ]))) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1221,7 +1221,7 @@ fn burn_foundry_and_its_account() { .add_foundry(inputs[0].output.as_foundry().id()) .add_account(account_id_1), ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); diff --git a/sdk/tests/client/transaction_builder/delegation_outputs.rs b/sdk/tests/client/transaction_builder/delegation_outputs.rs index 40a5f72757..bdb63246f4 100644 --- a/sdk/tests/client/transaction_builder/delegation_outputs.rs +++ b/sdk/tests/client/transaction_builder/delegation_outputs.rs @@ -83,7 +83,7 @@ fn remainder_needed_for_mana() { ) .with_burn(Burn::from(delegation_id)) .add_mana_rewards(delegation_output_id, mana_rewards) - .build() + .finish() .unwrap(); let inputs = inputs diff --git a/sdk/tests/client/transaction_builder/expiration.rs b/sdk/tests/client/transaction_builder/expiration.rs index ba57c329e5..45d94865b8 100644 --- a/sdk/tests/client/transaction_builder/expiration.rs +++ b/sdk/tests/client/transaction_builder/expiration.rs @@ -58,7 +58,7 @@ fn one_output_expiration_not_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -103,7 +103,7 @@ fn expiration_equal_timestamp() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -147,7 +147,7 @@ fn one_output_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -205,7 +205,7 @@ fn two_outputs_one_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -264,7 +264,7 @@ fn two_outputs_one_unexpired_one_missing() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -335,7 +335,7 @@ fn two_outputs_two_expired() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -397,7 +397,7 @@ fn two_outputs_two_expired_2() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -441,7 +441,7 @@ fn expiration_expired_with_sdr() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -485,7 +485,7 @@ fn expiration_expired_with_sdr_2() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -529,7 +529,7 @@ fn expiration_expired_with_sdr_and_timelock() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -573,7 +573,7 @@ fn expiration_expired_with_sdr_and_timelock_2() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -670,7 +670,7 @@ fn sender_in_expiration() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -719,7 +719,7 @@ fn sender_in_expiration_already_selected() { protocol_parameters, ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -766,7 +766,7 @@ fn remainder_in_expiration() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -821,7 +821,7 @@ fn expiration_expired_non_ed25519_in_address_unlock_condition() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -879,7 +879,7 @@ fn expiration_expired_only_account_addresses() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -924,7 +924,7 @@ fn one_nft_output_expiration_unexpired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -969,7 +969,7 @@ fn one_nft_output_expiration_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/foundry_outputs.rs b/sdk/tests/client/transaction_builder/foundry_outputs.rs index 93f865f519..f347570e9b 100644 --- a/sdk/tests/client/transaction_builder/foundry_outputs.rs +++ b/sdk/tests/client/transaction_builder/foundry_outputs.rs @@ -62,7 +62,7 @@ fn missing_input_account_for_foundry() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -156,7 +156,7 @@ fn minted_native_tokens_in_new_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -232,7 +232,7 @@ fn minted_native_tokens_in_provided_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -305,7 +305,7 @@ fn melt_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -366,7 +366,7 @@ fn destroy_foundry_with_account_state_transition() { protocol_parameters, ) .with_burn(Burn::new().add_foundry(inputs[1].output.as_foundry().id())) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -427,7 +427,7 @@ fn destroy_foundry_with_account_burn() { .add_foundry(inputs[1].output.as_foundry().id()) .add_account(account_id_2), ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -505,7 +505,7 @@ fn prefer_basic_to_foundry() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -574,7 +574,7 @@ fn simple_foundry_transition_basic_not_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -658,7 +658,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -809,7 +809,7 @@ fn mint_and_burn_at_the_same_time() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id, 10)) - .build(); + .finish(); assert!(matches!( selected, @@ -881,7 +881,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -949,7 +949,7 @@ fn create_native_token_but_burn_account() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_1)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1016,7 +1016,7 @@ fn melted_tokens_not_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1076,7 +1076,7 @@ fn burned_tokens_not_provided() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id_1, 100)) - .build(); + .finish(); assert!(matches!( selected, @@ -1134,7 +1134,7 @@ fn foundry_in_outputs_and_required() { protocol_parameters, ) .with_required_inputs([*inputs[1].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1211,7 +1211,7 @@ fn melt_and_burn_native_tokens() { ) // Burn 456 native tokens .with_burn(Burn::new().add_native_token(token_id, 456)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1272,7 +1272,7 @@ fn auto_transition_foundry_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap_err(); let min_amount = FoundryOutputBuilder::from(inputs[0].output.as_foundry()) @@ -1353,7 +1353,7 @@ fn auto_transition_foundry_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/native_tokens.rs b/sdk/tests/client/transaction_builder/native_tokens.rs index 624ec4a2c4..0eb439a6c3 100644 --- a/sdk/tests/client/transaction_builder/native_tokens.rs +++ b/sdk/tests/client/transaction_builder/native_tokens.rs @@ -70,7 +70,7 @@ fn two_native_tokens_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data[0], inputs[0]); @@ -140,7 +140,7 @@ fn two_native_tokens_both_needed_plus_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -221,7 +221,7 @@ fn three_inputs_two_needed_plus_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -302,7 +302,7 @@ fn three_inputs_two_needed_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); @@ -346,7 +346,7 @@ fn insufficient_native_tokens_one_input() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -420,7 +420,7 @@ fn insufficient_native_tokens_three_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -487,7 +487,7 @@ fn burn_and_send_at_the_same_time() { .add_native_token(TokenId::from_str(TOKEN_ID_1).unwrap(), 10) .add_native_token(TokenId::from_str(TOKEN_ID_2).unwrap(), 100), ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -534,7 +534,7 @@ fn burn_one_input_no_output() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(TokenId::from_str(TOKEN_ID_1).unwrap(), 50)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -598,7 +598,7 @@ fn multiple_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -643,7 +643,7 @@ fn insufficient_native_tokens() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -691,7 +691,7 @@ fn insufficient_native_tokens_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -741,7 +741,7 @@ fn insufficient_amount_for_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert_eq!( selected.unwrap_err(), @@ -789,7 +789,7 @@ fn single_output_native_token_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -833,7 +833,7 @@ fn single_output_native_token_remainder_1() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -884,7 +884,7 @@ fn single_output_native_token_remainder_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -949,7 +949,7 @@ fn two_basic_outputs_1() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1015,7 +1015,7 @@ fn two_basic_outputs_2() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1081,7 +1081,7 @@ fn two_basic_outputs_3() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1147,7 +1147,7 @@ fn two_basic_outputs_4() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1213,7 +1213,7 @@ fn two_basic_outputs_5() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1279,7 +1279,7 @@ fn two_basic_outputs_6() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1344,7 +1344,7 @@ fn two_basic_outputs_7() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1409,7 +1409,7 @@ fn two_basic_outputs_8() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1471,7 +1471,7 @@ fn two_basic_outputs_native_tokens_not_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1563,7 +1563,7 @@ fn multiple_remainders() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 4); diff --git a/sdk/tests/client/transaction_builder/nft_outputs.rs b/sdk/tests/client/transaction_builder/nft_outputs.rs index a0b2748a05..b3ff861139 100644 --- a/sdk/tests/client/transaction_builder/nft_outputs.rs +++ b/sdk/tests/client/transaction_builder/nft_outputs.rs @@ -62,7 +62,7 @@ fn input_nft_eq_output_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -108,7 +108,7 @@ fn transition_nft_id_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -241,7 +241,7 @@ fn mint_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -296,7 +296,7 @@ fn burn_nft() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_2)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -386,7 +386,7 @@ fn missing_input_for_nft_output() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -432,7 +432,7 @@ fn missing_input_for_nft_output_but_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -500,7 +500,7 @@ fn nft_in_output_and_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -553,7 +553,7 @@ fn missing_ed25519_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -599,7 +599,7 @@ fn missing_ed25519_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -645,7 +645,7 @@ fn missing_ed25519_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -688,7 +688,7 @@ fn missing_account_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -734,7 +734,7 @@ fn missing_account_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -780,7 +780,7 @@ fn missing_account_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -823,7 +823,7 @@ fn missing_nft_sender() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -869,7 +869,7 @@ fn missing_nft_issuer_created() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -915,7 +915,7 @@ fn missing_nft_issuer_transition() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(selected.is_ok()); } @@ -972,7 +972,7 @@ fn increase_nft_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1031,7 +1031,7 @@ fn decrease_nft_amount() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1102,7 +1102,7 @@ fn prefer_basic_to_nft() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -1162,7 +1162,7 @@ fn take_amount_from_nft_to_fund_basic() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1235,7 +1235,7 @@ fn nft_burn_should_validate_nft_sender() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1295,7 +1295,7 @@ fn nft_burn_should_validate_nft_address() { protocol_parameters, ) .with_burn(Burn::new().add_nft(nft_id_1)) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1340,7 +1340,7 @@ fn transitioned_zero_nft_id_no_longer_is_zero() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -1418,7 +1418,7 @@ fn changed_immutable_metadata() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -1460,7 +1460,7 @@ fn auto_transition_nft_less_than_min() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap_err(); let min_amount = NftOutputBuilder::from(inputs[0].output.as_nft()) @@ -1524,7 +1524,7 @@ fn auto_transition_nft_less_than_min_additional() { protocol_parameters.clone(), ) .with_required_inputs([*inputs[0].output_id()]) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); diff --git a/sdk/tests/client/transaction_builder/outputs.rs b/sdk/tests/client/transaction_builder/outputs.rs index ef68dbb024..9dadd4c923 100644 --- a/sdk/tests/client/transaction_builder/outputs.rs +++ b/sdk/tests/client/transaction_builder/outputs.rs @@ -46,7 +46,7 @@ fn no_inputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -83,7 +83,7 @@ fn no_outputs() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!(selected, Err(TransactionBuilderError::InvalidOutputCount(0)))); } @@ -118,7 +118,7 @@ fn no_outputs_but_required_input() { protocol_parameters, ) .with_required_inputs(HashSet::from([*inputs[0].output_id()])) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data, inputs); @@ -161,7 +161,7 @@ fn no_outputs_but_burn() { protocol_parameters, ) .with_burn(Burn::new().add_account(account_id_2)) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data, inputs); @@ -211,7 +211,7 @@ fn no_address_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -256,7 +256,7 @@ fn no_matching_address_provided() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -315,7 +315,7 @@ fn two_addresses_one_missing() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -380,7 +380,7 @@ fn two_addresses() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -442,7 +442,7 @@ fn consolidate_with_min_allotment() { ) .with_min_mana_allotment(account_id_1, 10) .with_required_inputs(inputs.iter().map(|i| *i.output_id())) - .build() + .finish() .unwrap(); assert_eq!(selected.transaction.outputs().len(), 1); diff --git a/sdk/tests/client/transaction_builder/storage_deposit_return.rs b/sdk/tests/client/transaction_builder/storage_deposit_return.rs index de95eb87a3..217b2bab1c 100644 --- a/sdk/tests/client/transaction_builder/storage_deposit_return.rs +++ b/sdk/tests/client/transaction_builder/storage_deposit_return.rs @@ -53,7 +53,7 @@ fn sdruc_output_not_provided_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -119,7 +119,7 @@ fn sdruc_output_provided_no_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -163,7 +163,7 @@ fn sdruc_output_provided_remainder() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -232,7 +232,7 @@ fn two_sdrucs_to_the_same_address_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -301,7 +301,7 @@ fn two_sdrucs_to_the_same_address_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -371,7 +371,7 @@ fn two_sdrucs_to_different_addresses_both_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -452,7 +452,7 @@ fn two_sdrucs_to_different_addresses_one_needed() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -508,7 +508,7 @@ fn insufficient_amount_because_of_sdruc() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -573,7 +573,7 @@ fn useless_sdruc_required_for_sender_feature() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -641,7 +641,7 @@ fn sdruc_required_non_ed25519_in_address_unlock() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -721,7 +721,7 @@ fn useless_sdruc_non_ed25519_in_address_unlock() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 2); diff --git a/sdk/tests/client/transaction_builder/timelock.rs b/sdk/tests/client/transaction_builder/timelock.rs index b3c74194f4..328c580ede 100644 --- a/sdk/tests/client/transaction_builder/timelock.rs +++ b/sdk/tests/client/transaction_builder/timelock.rs @@ -52,7 +52,7 @@ fn one_output_timelock_not_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build(); + .finish(); assert!(matches!( selected, @@ -97,7 +97,7 @@ fn timelock_equal_timestamp() { SlotCommitmentHash::null().into_slot_commitment_id(199), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); @@ -155,7 +155,7 @@ fn two_outputs_one_timelock_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -214,7 +214,7 @@ fn two_outputs_one_timelocked_one_missing() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert_eq!(selected.inputs_data.len(), 1); @@ -259,7 +259,7 @@ fn one_output_timelock_expired() { SlotCommitmentHash::null().into_slot_commitment_id(99), protocol_parameters, ) - .build() + .finish() .unwrap(); assert!(unsorted_eq(&selected.inputs_data, &inputs)); From e1b396c3c9d774ce683afde3c2d41361acda9cd8 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 12:12:22 -0500 Subject: [PATCH 09/23] Fix reward context inputs and tests --- bindings/core/src/method_handler/utils.rs | 4 +- .../offline_signing/2_sign_transaction.rs | 7 +- sdk/src/client/api/block_builder/mod.rs | 1 - .../client/api/block_builder/transaction.rs | 125 ++++++---- .../transaction_builder/error.rs | 4 + .../block_builder/transaction_builder/mod.rs | 231 ++++++------------ .../requirement/context_inputs.rs | 27 +- .../transaction_builder/requirement/mana.rs | 2 +- sdk/src/client/secret/mod.rs | 19 +- sdk/src/types/block/semantic/mod.rs | 16 +- .../transaction/build_transaction.rs | 33 ++- sdk/src/wallet/operations/transaction/mod.rs | 10 +- .../transaction/sign_transaction.rs | 6 +- sdk/tests/client/signing/account.rs | 31 +-- sdk/tests/client/signing/basic.rs | 44 +--- sdk/tests/client/signing/delegation.rs | 174 ++++--------- sdk/tests/client/signing/mod.rs | 18 +- sdk/tests/client/signing/nft.rs | 18 +- .../transaction_builder/account_outputs.rs | 23 +- .../transaction_builder/delegation_outputs.rs | 16 +- .../transaction_builder/foundry_outputs.rs | 10 +- .../client/transaction_builder/nft_outputs.rs | 12 +- 22 files changed, 341 insertions(+), 490 deletions(-) diff --git a/bindings/core/src/method_handler/utils.rs b/bindings/core/src/method_handler/utils.rs index 6109531ad6..aee0fdabfd 100644 --- a/bindings/core/src/method_handler/utils.rs +++ b/bindings/core/src/method_handler/utils.rs @@ -129,8 +129,8 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result Result<(), Box> { let signed_transaction = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&signed_transaction)?; + signed_transaction.validate_length()?; let signed_transaction_data = SignedTransactionData { payload: signed_transaction, diff --git a/sdk/src/client/api/block_builder/mod.rs b/sdk/src/client/api/block_builder/mod.rs index dfb3312368..2a9c3cffd1 100644 --- a/sdk/src/client/api/block_builder/mod.rs +++ b/sdk/src/client/api/block_builder/mod.rs @@ -5,7 +5,6 @@ pub mod options; pub mod transaction; pub mod transaction_builder; -pub use self::transaction::verify_semantic; use crate::{ client::{constants::FIVE_MINUTES_IN_NANOSECONDS, Client, Error, Result}, types::block::{ diff --git a/sdk/src/client/api/block_builder/transaction.rs b/sdk/src/client/api/block_builder/transaction.rs index 7fa90e945e..15b3a41268 100644 --- a/sdk/src/client/api/block_builder/transaction.rs +++ b/sdk/src/client/api/block_builder/transaction.rs @@ -3,12 +3,13 @@ //! Transaction preparation and signing -use alloc::collections::BTreeMap; - use packable::PackableExt; use crate::{ - client::{secret::types::InputSigningData, Error}, + client::{ + api::{PreparedTransactionData, SignedTransactionData}, + Error, + }, types::block::{ output::{Output, OutputId}, payload::signed_transaction::{SignedTransactionPayload, Transaction}, @@ -27,63 +28,85 @@ const SINGLE_UNLOCK_LENGTH: usize = 1 + 1 + Ed25519Signature::PUBLIC_KEY_LENGTH // Type + reference index const REFERENCE_ACCOUNT_NFT_UNLOCK_LENGTH: usize = 1 + 2; -/// Verifies the semantic of a prepared transaction. -pub fn verify_semantic( - input_signing_data: &[InputSigningData], - transaction_payload: &SignedTransactionPayload, - mana_rewards: impl Into>>, - protocol_parameters: ProtocolParameters, -) -> Result<(), TransactionFailureReason> { - let inputs = input_signing_data - .iter() - .map(|input| (input.output_id(), &input.output)) - .collect::>(); +impl PreparedTransactionData { + /// Verifies the semantic of a prepared transaction. + pub fn verify_semantic(&self, protocol_parameters: &ProtocolParameters) -> Result<(), TransactionFailureReason> { + let inputs = self + .inputs_data + .iter() + .map(|input| (input.output_id(), &input.output)) + .collect::>(); + + let context = SemanticValidationContext::new( + &self.transaction, + &inputs, + None, + Some(&self.mana_rewards), + protocol_parameters, + ); + + context.validate() + } +} - let context = SemanticValidationContext::new( - transaction_payload.transaction(), - &inputs, - Some(transaction_payload.unlocks()), - mana_rewards.into(), - protocol_parameters, - ); +impl SignedTransactionData { + /// Verifies the semantic of a prepared transaction. + pub fn verify_semantic(&self, protocol_parameters: &ProtocolParameters) -> Result<(), TransactionFailureReason> { + let inputs = self + .inputs_data + .iter() + .map(|input| (input.output_id(), &input.output)) + .collect::>(); - context.validate() + let context = SemanticValidationContext::new( + &self.payload.transaction(), + &inputs, + Some(self.payload.unlocks()), + Some(&self.mana_rewards), + protocol_parameters, + ); + + context.validate() + } } -/// Verifies that the signed transaction payload doesn't exceed the block size limit with 8 parents. -pub fn validate_signed_transaction_payload_length( - signed_transaction_payload: &SignedTransactionPayload, -) -> crate::client::error::Result<()> { - let signed_transaction_payload_bytes = signed_transaction_payload.pack_to_vec(); - if signed_transaction_payload_bytes.len() > MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS { - return Err(Error::InvalidSignedTransactionPayloadLength { - length: signed_transaction_payload_bytes.len(), - max_length: MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS, - }); +impl SignedTransactionPayload { + /// Verifies that the signed transaction payload doesn't exceed the block size limit with 8 parents. + pub fn validate_length(&self) -> crate::client::error::Result<()> { + let signed_transaction_payload_bytes = self.pack_to_vec(); + if signed_transaction_payload_bytes.len() > MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS { + return Err(Error::InvalidSignedTransactionPayloadLength { + length: signed_transaction_payload_bytes.len(), + max_length: MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS, + }); + } + Ok(()) } - Ok(()) } -/// Verifies that the transaction doesn't exceed the block size limit with 8 parents. -/// Assuming one signature unlock and otherwise reference/account/nft unlocks. `validate_transaction_payload_length()` -/// should later be used to check the length again with the correct unlocks. -pub fn validate_transaction_length(transaction: &Transaction) -> crate::client::error::Result<()> { - let transaction_bytes = transaction.pack_to_vec(); +impl Transaction { + /// Verifies that the transaction doesn't exceed the block size limit with 8 parents. + /// Assuming one signature unlock and otherwise reference/account/nft unlocks. + /// `validate_transaction_payload_length()` should later be used to check the length again with the correct + /// unlocks. + pub fn validate_length(&self) -> crate::client::error::Result<()> { + let transaction_bytes = self.pack_to_vec(); - // Assuming there is only 1 signature unlock and the rest is reference/account/nft unlocks - let reference_account_nft_unlocks_amount = transaction.inputs().len() - 1; + // Assuming there is only 1 signature unlock and the rest is reference/account/nft unlocks + let reference_account_nft_unlocks_amount = self.inputs().len() - 1; - // Max tx payload length - length for one signature unlock (there might be more unlocks, we check with them - // later again, when we built the transaction payload) - let max_length = MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS - - SINGLE_UNLOCK_LENGTH - - (reference_account_nft_unlocks_amount * REFERENCE_ACCOUNT_NFT_UNLOCK_LENGTH); + // Max tx payload length - length for one signature unlock (there might be more unlocks, we check with them + // later again, when we built the transaction payload) + let max_length = MAX_TX_LENGTH_FOR_BLOCK_WITH_8_PARENTS + - SINGLE_UNLOCK_LENGTH + - (reference_account_nft_unlocks_amount * REFERENCE_ACCOUNT_NFT_UNLOCK_LENGTH); - if transaction_bytes.len() > max_length { - return Err(Error::InvalidTransactionLength { - length: transaction_bytes.len(), - max_length, - }); + if transaction_bytes.len() > max_length { + return Err(Error::InvalidTransactionLength { + length: transaction_bytes.len(), + max_length, + }); + } + Ok(()) } - Ok(()) } diff --git a/sdk/src/client/api/block_builder/transaction_builder/error.rs b/sdk/src/client/api/block_builder/transaction_builder/error.rs index b407a4093d..f58cf6bcb9 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/error.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/error.rs @@ -13,6 +13,7 @@ use crate::types::block::{ mana::ManaError, output::{ChainId, NativeTokenError, OutputError, OutputId, TokenId}, payload::PayloadError, + semantic::TransactionFailureReason, signature::SignatureError, unlock::UnlockError, BlockError, @@ -104,4 +105,7 @@ pub enum TransactionBuilderError { /// Unlock errors. #[error("{0}")] Unlock(#[from] UnlockError), + /// Semantic errors. + #[error("{0}")] + Semantic(#[from] TransactionFailureReason), } diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index f6040ff7a4..15adf8e223 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -10,18 +10,15 @@ pub(crate) mod requirement; pub(crate) mod transition; use alloc::collections::BTreeMap; -use core::ops::Deref; use std::collections::{HashMap, HashSet}; use packable::PackableExt; -use self::requirement::account::is_account_with_id; pub use self::{burn::Burn, error::TransactionBuilderError, requirement::Requirement}; use crate::{ client::{ api::{ options::{RemainderValueStrategy, TransactionOptions}, - transaction::validate_transaction_length, PreparedTransactionData, RemainderData, }, node_api::indexer::query_parameters::OutputQueryParameters, @@ -30,12 +27,12 @@ use crate::{ }, types::block::{ address::{AccountAddress, Address, NftAddress, ToBech32Ext}, - context_input::ContextInput, + context_input::{BlockIssuanceCreditContextInput, CommitmentContextInput, ContextInput, RewardContextInput}, input::{Input, UtxoInput, INPUT_COUNT_RANGE}, mana::ManaAllotment, output::{ - AccountId, AccountOutput, AccountOutputBuilder, AnchorOutputBuilder, BasicOutputBuilder, FoundryOutput, - NativeTokensBuilder, NftOutput, NftOutputBuilder, Output, OutputId, OUTPUT_COUNT_RANGE, + AccountId, AccountOutputBuilder, AnchorOutputBuilder, BasicOutputBuilder, NftOutputBuilder, Output, + OutputId, OUTPUT_COUNT_RANGE, }, payload::{ signed_transaction::{Transaction, TransactionCapabilities}, @@ -59,7 +56,29 @@ impl Client { // Voting output needs to be requested before to prevent a deadlock let protocol_parameters = self.get_protocol_parameters().await?; let creation_slot = self.get_slot_index().await?; - let slot_commitment_id = self.get_issuance().await?.latest_commitment.id(); + + let (bic_context_inputs, commitment_context_input) = options.context_inputs.into_iter().fold( + (HashSet::new(), None), + |(mut bic_context_inputs, mut commitment_context_input), i| { + match i { + ContextInput::BlockIssuanceCredit(i) => { + bic_context_inputs.insert(i); + } + ContextInput::Commitment(i) => { + commitment_context_input.replace(i); + } + // TODO: It's not really possible to accurately provide a reward context input, + // so should we forbid it in transaction options? + ContextInput::Reward(_) => (), + } + (bic_context_inputs, commitment_context_input) + }, + ); + + let slot_commitment_id = match commitment_context_input { + Some(c) => c.slot_commitment_id(), + None => self.get_issuance().await?.latest_commitment.id(), + }; let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { Some(self.get_account_congestion(&issuer_id, None).await?.reference_mana_cost) } else { @@ -141,7 +160,8 @@ impl Client { protocol_parameters.clone(), ) .with_required_inputs(options.required_inputs) - .with_context_inputs(options.context_inputs) + .with_block_issuance_credit_context_inputs(bic_context_inputs) + .with_commitment_context_input(commitment_context_input) .with_mana_rewards(mana_rewards) .with_payload(options.tagged_data_payload) .with_mana_allotments(options.mana_allotments) @@ -162,7 +182,7 @@ impl Client { let prepared_transaction_data = transaction_builder.finish()?; - validate_transaction_length(&prepared_transaction_data.transaction)?; + prepared_transaction_data.transaction.validate_length()?; Ok(prepared_transaction_data) } @@ -174,7 +194,9 @@ pub struct TransactionBuilder { available_inputs: Vec, required_inputs: HashSet, selected_inputs: Vec, - context_inputs: HashSet, + bic_context_inputs: HashSet, + commitment_context_input: Option, + reward_context_inputs: HashSet, provided_outputs: Vec, added_outputs: Vec, addresses: HashSet
, @@ -244,7 +266,9 @@ impl TransactionBuilder { available_inputs, required_inputs: HashSet::new(), selected_inputs: Vec::new(), - context_inputs: HashSet::new(), + bic_context_inputs: HashSet::new(), + commitment_context_input: None, + reward_context_inputs: HashSet::new(), provided_outputs: outputs.into_iter().collect(), added_outputs: Vec::new(), addresses, @@ -400,8 +424,6 @@ impl TransactionBuilder { return Err(TransactionBuilderError::InvalidOutputCount(outputs.len())); } - Self::validate_transitions(&self.selected_inputs, &outputs)?; - for output_id in self.mana_rewards.keys() { if !self.selected_inputs.iter().any(|i| output_id == i.output_id()) { return Err(TransactionBuilderError::ExtraManaRewards(*output_id)); @@ -415,9 +437,18 @@ impl TransactionBuilder { )?; let mut inputs: Vec = Vec::new(); + let mut context_inputs = self + .bic_context_inputs + .into_iter() + .map(ContextInput::from) + .chain(self.commitment_context_input.map(ContextInput::from)) + .collect::>(); - for input in &inputs_data { + for (idx, input) in inputs_data.iter().enumerate() { inputs.push(Input::Utxo(UtxoInput::from(*input.output_id()))); + if self.reward_context_inputs.contains(input.output_id()) { + context_inputs.push(RewardContextInput::new(idx as u16).unwrap().into()); + } } let mana_allotments = self @@ -432,7 +463,7 @@ impl TransactionBuilder { .with_inputs(inputs) .with_outputs(outputs) .with_mana_allotments(mana_allotments) - .with_context_inputs(self.context_inputs) + .with_context_inputs(context_inputs) .with_creation_slot(self.creation_slot) .with_capabilities(self.transaction_capabilities); @@ -442,12 +473,16 @@ impl TransactionBuilder { let transaction = builder.finish_with_params(&self.protocol_parameters)?; - Ok(PreparedTransactionData { + let data = PreparedTransactionData { transaction, inputs_data, remainders: self.remainders.data, mana_rewards: self.mana_rewards.into_iter().collect(), - }) + }; + + data.verify_semantic(&self.protocol_parameters)?; + + Ok(data) } fn select_input(&mut self, input: InputSigningData) -> Result, TransactionBuilderError> { @@ -485,9 +520,21 @@ impl TransactionBuilder { self } - /// Sets the context inputs of an [`TransactionBuilder`]. - pub fn with_context_inputs(mut self, context_inputs: impl IntoIterator) -> Self { - self.context_inputs = context_inputs.into_iter().collect(); + /// Sets the block issance credit context inputs of an [`TransactionBuilder`]. + pub fn with_block_issuance_credit_context_inputs( + mut self, + bic_context_inputs: impl IntoIterator, + ) -> Self { + self.bic_context_inputs = bic_context_inputs.into_iter().collect(); + self + } + + /// Sets the commitment context input of an [`TransactionBuilder`]. + pub fn with_commitment_context_input( + mut self, + commitment_context_input: impl Into>, + ) -> Self { + self.commitment_context_input = commitment_context_input.into(); self } @@ -568,6 +615,19 @@ impl TransactionBuilder { .chain(&self.remainders.storage_deposit_returns) } + pub(crate) fn context_inputs(&self) -> impl Iterator + '_ { + self.bic_context_inputs + .iter() + .copied() + .map(ContextInput::from) + .chain(self.commitment_context_input.map(ContextInput::from)) + .chain(self.selected_inputs.iter().enumerate().filter_map(|(idx, input)| { + self.reward_context_inputs + .contains(input.output_id()) + .then_some(RewardContextInput::new(idx as u16).unwrap().into()) + })) + } + fn required_account_nft_addresses( &self, input: &InputSigningData, @@ -752,135 +812,4 @@ impl TransactionBuilder { Ok(sorted_inputs) } - - fn validate_transitions(inputs: &[InputSigningData], outputs: &[Output]) -> Result<(), TransactionBuilderError> { - let mut input_native_tokens_builder = NativeTokensBuilder::new(); - let mut output_native_tokens_builder = NativeTokensBuilder::new(); - let mut input_accounts = Vec::new(); - let mut input_chains_foundries = hashbrown::HashMap::new(); - let mut input_foundries = Vec::new(); - let mut input_nfts = Vec::new(); - - for input in inputs { - if let Some(native_token) = input.output.native_token() { - input_native_tokens_builder.add_native_token(*native_token)?; - } - match &input.output { - Output::Basic(basic) => { - if basic.is_implicit_account() { - input_accounts.push(input); - } - } - Output::Account(_) => { - input_accounts.push(input); - } - Output::Foundry(foundry) => { - input_chains_foundries.insert(foundry.chain_id(), (input.output_id(), &input.output)); - input_foundries.push(input); - } - Output::Nft(_) => { - input_nfts.push(input); - } - _ => {} - } - } - - for output in outputs { - if let Some(native_token) = output.native_token() { - output_native_tokens_builder.add_native_token(*native_token)?; - } - } - - // Validate utxo chain transitions - for output in outputs { - match output { - Output::Account(account_output) => { - // Null id outputs are just minted and can't be a transition - if account_output.account_id().is_null() { - continue; - } - - let account_input = input_accounts - .iter() - .find(|i| is_account_with_id(&i.output, account_output.account_id(), i.output_id())) - .expect("ISA is broken because there is no account input"); - - match &account_input.output { - Output::Account(account) => { - if let Err(err) = AccountOutput::transition_inner( - account, - account_output, - &input_chains_foundries, - outputs, - ) { - log::debug!("validate_transitions error {err:?}"); - return Err(TransactionBuilderError::UnfulfillableRequirement(Requirement::Account( - *account_output.account_id(), - ))); - } - } - Output::Basic(_) => { - // TODO https://github.com/iotaledger/iota-sdk/issues/1664 - } - _ => panic!( - "unreachable: \"input_accounts\" only contains account outputs and implicit account (basic) outputs" - ), - } - } - Output::Foundry(foundry_output) => { - let foundry_id = foundry_output.id(); - let foundry_input = input_foundries.iter().find(|i| { - if let Output::Foundry(foundry_input) = &i.output { - foundry_id == foundry_input.id() - } else { - false - } - }); - if let Some(foundry_input) = foundry_input { - if let Err(err) = FoundryOutput::transition_inner( - foundry_input.output.as_foundry(), - foundry_output, - input_native_tokens_builder.deref(), - output_native_tokens_builder.deref(), - // We use `all` capabilities here because this transition may be burning - // native tokens, and validation will fail without the capability. - &TransactionCapabilities::all(), - ) { - log::debug!("validate_transitions error {err:?}"); - return Err(TransactionBuilderError::UnfulfillableRequirement(Requirement::Foundry( - foundry_output.id(), - ))); - } - } - } - Output::Nft(nft_output) => { - // Null id outputs are just minted and can't be a transition - if nft_output.nft_id().is_null() { - continue; - } - - let nft_input = input_nfts - .iter() - .find(|i| { - if let Output::Nft(nft_input) = &i.output { - *nft_output.nft_id() == nft_input.nft_id_non_null(i.output_id()) - } else { - false - } - }) - .expect("ISA is broken because there is no nft input"); - - if let Err(err) = NftOutput::transition_inner(nft_input.output.as_nft(), nft_output) { - log::debug!("validate_transitions error {err:?}"); - return Err(TransactionBuilderError::UnfulfillableRequirement(Requirement::Nft( - *nft_output.nft_id(), - ))); - } - } - // other output types don't do transitions - _ => {} - } - } - Ok(()) - } } diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs index a0738b5f77..a8ddd031ef 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs @@ -5,7 +5,7 @@ use super::{TransactionBuilder, TransactionBuilderError}; use crate::{ client::secret::types::InputSigningData, types::block::{ - context_input::{BlockIssuanceCreditContextInput, CommitmentContextInput, RewardContextInput}, + context_input::{BlockIssuanceCreditContextInput, CommitmentContextInput}, output::{AccountId, DelegationOutputBuilder, Output}, }, }; @@ -16,13 +16,13 @@ impl TransactionBuilder { ) -> Result, TransactionBuilderError> { let mut needs_commitment_context = false; - for (idx, input) in self.selected_inputs.iter().enumerate() { + for input in &self.selected_inputs { match &input.output { // Transitioning an issuer account requires a BlockIssuanceCreditContextInput. Output::Account(account) => { if account.features().block_issuer().is_some() { log::debug!("Adding block issuance context input for transitioned account output"); - self.context_inputs.insert( + self.bic_context_inputs.insert( BlockIssuanceCreditContextInput::from(account.account_id_non_null(input.output_id())) .into(), ); @@ -32,7 +32,7 @@ impl TransactionBuilder { Output::Basic(basic) => { if basic.is_implicit_account() { log::debug!("Adding block issuance context input for transitioned implicit account output"); - self.context_inputs + self.bic_context_inputs .insert(BlockIssuanceCreditContextInput::from(AccountId::from(input.output_id())).into()); } } @@ -51,7 +51,7 @@ impl TransactionBuilder { if self.mana_rewards.get(input.output_id()).is_some() { log::debug!("Adding reward and commitment context input for output claiming mana rewards"); - self.context_inputs.insert(RewardContextInput::new(idx as _)?.into()); + self.reward_context_inputs.insert(*input.output_id()); needs_commitment_context = true; } } @@ -83,25 +83,16 @@ impl TransactionBuilder { needs_commitment_context = true; } // BlockIssuanceCreditContextInput requires a CommitmentContextInput. - if self - .context_inputs - .iter() - .any(|c| c.kind() == BlockIssuanceCreditContextInput::KIND) - { + if !self.bic_context_inputs.is_empty() { // TODO https://github.com/iotaledger/iota-sdk/issues/1740 log::debug!("Adding commitment context input for output with block issuance credit context input"); needs_commitment_context = true; } - if needs_commitment_context - && !self - .context_inputs - .iter() - .any(|c| c.kind() == CommitmentContextInput::KIND) - { + if needs_commitment_context && self.commitment_context_input.is_none() { // TODO https://github.com/iotaledger/iota-sdk/issues/1740 - self.context_inputs - .insert(CommitmentContextInput::new(self.latest_slot_commitment_id).into()); + self.commitment_context_input + .replace(CommitmentContextInput::new(self.latest_slot_commitment_id).into()); } Ok(Vec::new()) } diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index adf15cdfa3..b0ca28a503 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -63,7 +63,7 @@ impl TransactionBuilder { // If the transaction fails to build, just keep going in case another requirement helps let transaction = builder - .with_context_inputs(self.context_inputs.clone()) + .with_context_inputs(self.context_inputs()) .with_mana_allotments( self.mana_allotments .iter() diff --git a/sdk/src/client/secret/mod.rs b/sdk/src/client/secret/mod.rs index 66c63a55ba..27ced12c79 100644 --- a/sdk/src/client/secret/mod.rs +++ b/sdk/src/client/secret/mod.rs @@ -48,10 +48,7 @@ pub use self::types::{GenerateAddressOptions, LedgerNanoStatus}; use crate::client::secret::types::StrongholdDto; use crate::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, transaction_builder::TransactionBuilderError, - verify_semantic, PreparedTransactionData, - }, + api::{transaction_builder::TransactionBuilderError, PreparedTransactionData, SignedTransactionData}, Error, }, types::block::{ @@ -669,13 +666,19 @@ where } = prepared_transaction_data; let tx_payload = SignedTransactionPayload::new(transaction, unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic(&inputs_data, &tx_payload, mana_rewards, protocol_parameters.clone()).inspect_err(|e| { - log::debug!("[sign_transaction] conflict: {e:?} for {tx_payload:#?}"); + let data = SignedTransactionData { + payload: tx_payload, + inputs_data, + mana_rewards, + }; + + data.verify_semantic(protocol_parameters).inspect_err(|e| { + log::debug!("[sign_transaction] conflict: {e:?} for {:#?}", data.payload); })?; - Ok(tx_payload) + Ok(data.payload) } #[async_trait] diff --git a/sdk/src/types/block/semantic/mod.rs b/sdk/src/types/block/semantic/mod.rs index d0400af283..0840359181 100644 --- a/sdk/src/types/block/semantic/mod.rs +++ b/sdk/src/types/block/semantic/mod.rs @@ -30,7 +30,7 @@ pub struct SemanticValidationContext<'a> { pub(crate) unlocks: Option<&'a [Unlock]>, pub(crate) input_amount: u64, pub(crate) input_mana: u64, - pub(crate) mana_rewards: Option>, + pub(crate) mana_rewards: Option<&'a BTreeMap>, pub(crate) commitment_context_input: Option, pub(crate) reward_context_inputs: HashMap, pub(crate) input_native_tokens: BTreeMap, @@ -43,7 +43,7 @@ pub struct SemanticValidationContext<'a> { pub(crate) unlocked_addresses: HashSet
, pub(crate) storage_deposit_returns: HashMap, pub(crate) simple_deposits: HashMap, - pub(crate) protocol_parameters: ProtocolParameters, + pub(crate) protocol_parameters: &'a ProtocolParameters, } impl<'a> SemanticValidationContext<'a> { @@ -52,8 +52,8 @@ impl<'a> SemanticValidationContext<'a> { transaction: &'a Transaction, inputs: &'a [(&'a OutputId, &'a Output)], unlocks: Option<&'a [Unlock]>, - mana_rewards: Option>, - protocol_parameters: ProtocolParameters, + mana_rewards: Option<&'a BTreeMap>, + protocol_parameters: &'a ProtocolParameters, ) -> Self { let transaction_id = transaction.id(); let input_chains = inputs @@ -334,9 +334,11 @@ impl<'a> SemanticValidationContext<'a> { Output::Delegation(output) => (output.amount(), 0, None, None), }; - if let Some(sender) = features.and_then(Features::sender) { - if !self.unlocked_addresses.contains(sender.address()) { - return Err(TransactionFailureReason::SenderFeatureNotUnlocked); + if self.unlocks.is_some() { + if let Some(sender) = features.and_then(Features::sender) { + if !self.unlocked_addresses.contains(sender.address()) { + return Err(TransactionFailureReason::SenderFeatureNotUnlocked); + } } } diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 1ec6e85597..9433aa0b94 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use alloc::collections::BTreeSet; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use crypto::keys::bip44::Bip44; @@ -12,7 +12,6 @@ use crate::{ client::{ api::{ options::{RemainderValueStrategy, TransactionOptions}, - transaction::validate_transaction_length, transaction_builder::TransactionBuilder, PreparedTransactionData, }, @@ -20,6 +19,7 @@ use crate::{ }, types::block::{ address::Bech32Address, + context_input::ContextInput, output::{Output, OutputId}, protocol::CommittableAgeRange, slot::SlotIndex, @@ -44,7 +44,29 @@ where let voting_output = self.get_voting_output().await?; let protocol_parameters = self.client().get_protocol_parameters().await?; let creation_slot = self.client().get_slot_index().await?; - let slot_commitment_id = self.client().get_issuance().await?.latest_commitment.id(); + + let (bic_context_inputs, commitment_context_input) = options.context_inputs.into_iter().fold( + (HashSet::new(), None), + |(mut bic_context_inputs, mut commitment_context_input), i| { + match i { + ContextInput::BlockIssuanceCredit(i) => { + bic_context_inputs.insert(i); + } + ContextInput::Commitment(i) => { + commitment_context_input.replace(i); + } + // TODO: It's not really possible to accurately provide a reward context input, + // so should we forbid it in transaction options? + ContextInput::Reward(_) => (), + } + (bic_context_inputs, commitment_context_input) + }, + ); + + let slot_commitment_id = match commitment_context_input { + Some(c) => c.slot_commitment_id(), + None => self.client().get_issuance().await?.latest_commitment.id(), + }; if options.issuer_id.is_none() { options.issuer_id = self.ledger().await.first_account_id(); } @@ -147,7 +169,8 @@ where protocol_parameters.clone(), ) .with_required_inputs(options.required_inputs) - .with_context_inputs(options.context_inputs) + .with_block_issuance_credit_context_inputs(bic_context_inputs) + .with_commitment_context_input(commitment_context_input) .with_mana_rewards(mana_rewards) .with_payload(options.tagged_data_payload) .with_mana_allotments(options.mana_allotments) @@ -168,7 +191,7 @@ where let prepared_transaction_data = transaction_builder.finish()?; - validate_transaction_length(&prepared_transaction_data.transaction)?; + prepared_transaction_data.transaction.validate_length()?; // lock outputs so they don't get used by another transaction for output in &prepared_transaction_data.inputs_data { diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 8f12179aec..78e54077a0 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -13,7 +13,7 @@ pub(crate) mod submit_transaction; use crate::wallet::core::WalletLedgerDto; use crate::{ client::{ - api::{options::TransactionOptions, verify_semantic, PreparedTransactionData, SignedTransactionData}, + api::{options::TransactionOptions, PreparedTransactionData, SignedTransactionData}, secret::{types::InputSigningData, SecretManage}, }, types::block::{ @@ -113,12 +113,8 @@ where let options = options.into(); // Validate transaction before sending and storing it - if let Err(conflict) = verify_semantic( - &signed_transaction_data.inputs_data, - &signed_transaction_data.payload, - signed_transaction_data.mana_rewards, - self.client().get_protocol_parameters().await?, - ) { + if let Err(conflict) = signed_transaction_data.verify_semantic(&self.client().get_protocol_parameters().await?) + { log::debug!( "[TRANSACTION] conflict: {conflict:?} for {:?}", signed_transaction_data.payload diff --git a/sdk/src/wallet/operations/transaction/sign_transaction.rs b/sdk/src/wallet/operations/transaction/sign_transaction.rs index dfdee16c5b..aa25c762bd 100644 --- a/sdk/src/wallet/operations/transaction/sign_transaction.rs +++ b/sdk/src/wallet/operations/transaction/sign_transaction.rs @@ -14,9 +14,7 @@ use { use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, PreparedTransactionData, SignedTransactionData, - }, + api::{PreparedTransactionData, SignedTransactionData}, secret::SecretManage, }, wallet::{operations::transaction::SignedTransactionPayload, Wallet}, @@ -93,7 +91,7 @@ where log::debug!("[TRANSACTION] signed transaction: {:?}", payload); - validate_signed_transaction_payload_length(&payload)?; + payload.validate_length()?; Ok(SignedTransactionData { payload, diff --git a/sdk/tests/client/signing/account.rs b/sdk/tests/client/signing/account.rs index 37aebc578e..37c8757b27 100644 --- a/sdk/tests/client/signing/account.rs +++ b/sdk/tests/client/signing/account.rs @@ -6,10 +6,7 @@ use std::str::FromStr; use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, verify_semantic, GetAddressesOptions, - PreparedTransactionData, - }, + api::{GetAddressesOptions, PreparedTransactionData}, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, Client, @@ -49,7 +46,7 @@ async fn sign_account_state_transition() -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let account_id = AccountId::from_str(ACCOUNT_ID_1)?; let account_address = Address::Account(AccountAddress::new(account_id)); let slot_index = SlotIndex::from(10); @@ -203,7 +195,7 @@ async fn account_reference_unlocks() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -233,14 +225,9 @@ async fn account_reference_unlocks() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } diff --git a/sdk/tests/client/signing/basic.rs b/sdk/tests/client/signing/basic.rs index 04093f6455..b66af9641f 100644 --- a/sdk/tests/client/signing/basic.rs +++ b/sdk/tests/client/signing/basic.rs @@ -4,10 +4,7 @@ use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, verify_semantic, GetAddressesOptions, - PreparedTransactionData, - }, + api::{GetAddressesOptions, PreparedTransactionData}, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, Client, @@ -41,7 +38,7 @@ async fn single_ed25519_unlock() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_index = SlotIndex::from(10); let inputs = build_inputs( @@ -80,7 +77,7 @@ async fn single_ed25519_unlock() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -98,14 +95,9 @@ async fn single_ed25519_unlock() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } @@ -124,7 +116,7 @@ async fn ed25519_reference_unlocks() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_index = SlotIndex::from(10); let inputs = build_inputs( @@ -189,7 +181,7 @@ async fn ed25519_reference_unlocks() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -219,14 +211,9 @@ async fn ed25519_reference_unlocks() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } @@ -254,7 +241,7 @@ async fn two_signature_unlocks() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_index = SlotIndex::from(10); let inputs = build_inputs( @@ -307,7 +294,7 @@ async fn two_signature_unlocks() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -326,14 +313,9 @@ async fn two_signature_unlocks() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } diff --git a/sdk/tests/client/signing/delegation.rs b/sdk/tests/client/signing/delegation.rs index 1a44d93a26..12646b9b6c 100644 --- a/sdk/tests/client/signing/delegation.rs +++ b/sdk/tests/client/signing/delegation.rs @@ -6,10 +6,7 @@ use std::collections::BTreeMap; use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, verify_semantic, GetAddressesOptions, - PreparedTransactionData, - }, + api::{GetAddressesOptions, PreparedTransactionData}, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, Client, @@ -49,7 +46,7 @@ async fn valid_creation() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id = rand_slot_commitment_id(); let slot_index = slot_commitment_id.slot_index(); @@ -90,7 +87,7 @@ async fn valid_creation() -> Result<(), Box> { .with_creation_slot(slot_index + 1) .with_context_inputs([CommitmentContextInput::new(slot_commitment_id).into()]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -108,14 +105,9 @@ async fn valid_creation() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } @@ -134,7 +126,7 @@ async fn creation_missing_commitment_input() -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id = rand_slot_commitment_id(); let slot_index = slot_commitment_id.slot_index(); @@ -263,7 +250,7 @@ async fn non_null_id_creation() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -281,14 +268,9 @@ async fn non_null_id_creation() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::NewChainOutputHasNonZeroedId)); @@ -309,7 +291,7 @@ async fn mismatch_amount_creation() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id = rand_slot_commitment_id(); let slot_index = slot_commitment_id.slot_index(); @@ -349,7 +331,7 @@ async fn mismatch_amount_creation() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -367,14 +349,9 @@ async fn mismatch_amount_creation() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationAmountMismatch)); @@ -395,7 +372,7 @@ async fn non_zero_end_epoch_creation() -> Result<(), Box> .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id = rand_slot_commitment_id(); let slot_index = slot_commitment_id.slot_index(); @@ -435,7 +412,7 @@ async fn non_zero_end_epoch_creation() -> Result<(), Box> .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -453,14 +430,9 @@ async fn non_zero_end_epoch_creation() -> Result<(), Box> let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationEndEpochNotZero)); @@ -481,7 +453,7 @@ async fn invalid_start_epoch_creation() -> Result<(), Box .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id = rand_slot_commitment_id(); let slot_index = slot_commitment_id.slot_index(); @@ -522,7 +494,7 @@ async fn invalid_start_epoch_creation() -> Result<(), Box .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) .with_context_inputs([CommitmentContextInput::new(slot_commitment_id).into()]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -540,14 +512,9 @@ async fn invalid_start_epoch_creation() -> Result<(), Box let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationStartEpochInvalid)); @@ -568,7 +535,7 @@ async fn delay_not_null_id() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -620,7 +587,7 @@ async fn delay_not_null_id() -> Result<(), Box> { RewardContextInput::new(0)?.into(), ]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -638,14 +605,9 @@ async fn delay_not_null_id() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!( conflict, @@ -669,7 +631,7 @@ async fn delay_modified_amount() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -721,7 +683,7 @@ async fn delay_modified_amount() -> Result<(), Box> { RewardContextInput::new(0)?.into(), ]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -739,14 +701,9 @@ async fn delay_modified_amount() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationModified)); @@ -767,7 +724,7 @@ async fn delay_modified_validator() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -819,7 +776,7 @@ async fn delay_modified_validator() -> Result<(), Box> { RewardContextInput::new(0)?.into(), ]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -837,14 +794,9 @@ async fn delay_modified_validator() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationModified)); @@ -865,7 +817,7 @@ async fn delay_modified_start_epoch() -> Result<(), Box> .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -917,7 +869,7 @@ async fn delay_modified_start_epoch() -> Result<(), Box> RewardContextInput::new(0)?.into(), ]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -935,14 +887,9 @@ async fn delay_modified_start_epoch() -> Result<(), Box> let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationModified)); @@ -963,7 +910,7 @@ async fn delay_pre_registration_slot_end_epoch() -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -1111,7 +1053,7 @@ async fn destroy_null_id() -> Result<(), Box> { RewardContextInput::new(0)?.into(), ]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let mut mana_rewards = BTreeMap::default(); mana_rewards.insert(*inputs[0].output_id(), 0); @@ -1132,14 +1074,9 @@ async fn destroy_null_id() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } @@ -1158,7 +1095,7 @@ async fn destroy_reward_missing() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let slot_commitment_id_1 = rand_slot_commitment_id(); let slot_index_1 = slot_commitment_id_1.slot_index(); let slot_commitment_id_2 = rand_slot_commitment_id() @@ -1205,7 +1142,7 @@ async fn destroy_reward_missing() -> Result<(), Box> { .with_creation_slot(slot_index_2 + 1) .with_context_inputs([CommitmentContextInput::new(slot_commitment_id_2).into()]) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -1223,14 +1160,9 @@ async fn destroy_reward_missing() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - let conflict = verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - ); + let conflict = prepared_transaction_data.verify_semantic(protocol_parameters); assert_eq!(conflict, Err(TransactionFailureReason::DelegationRewardInputMissing)); diff --git a/sdk/tests/client/signing/mod.rs b/sdk/tests/client/signing/mod.rs index 014718dfb2..258fda7eea 100644 --- a/sdk/tests/client/signing/mod.rs +++ b/sdk/tests/client/signing/mod.rs @@ -11,10 +11,7 @@ use std::str::FromStr; use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, transaction_builder::TransactionBuilder, - verify_semantic, GetAddressesOptions, PreparedTransactionData, - }, + api::{transaction_builder::TransactionBuilder, GetAddressesOptions, PreparedTransactionData}, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, }, @@ -44,7 +41,7 @@ async fn all_combined() -> Result<(), Box> { "mirror add nothing long orphan hat this rough scare gallery fork twelve old shrug voyage job table obscure mimic holiday possible proud giraffe fan".to_owned(), )?; - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let ed25519_bech32_addresses = secret_manager .generate_ed25519_addresses( @@ -391,7 +388,7 @@ async fn all_combined() -> Result<(), Box> { ) .with_outputs(outputs) .with_creation_slot(slot_index) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -484,14 +481,9 @@ async fn all_combined() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } diff --git a/sdk/tests/client/signing/nft.rs b/sdk/tests/client/signing/nft.rs index c714c178d4..bb0f1318a0 100644 --- a/sdk/tests/client/signing/nft.rs +++ b/sdk/tests/client/signing/nft.rs @@ -6,10 +6,7 @@ use std::str::FromStr; use crypto::keys::bip44::Bip44; use iota_sdk::{ client::{ - api::{ - transaction::validate_signed_transaction_payload_length, verify_semantic, GetAddressesOptions, - PreparedTransactionData, - }, + api::{GetAddressesOptions, PreparedTransactionData}, constants::SHIMMER_COIN_TYPE, secret::{SecretManage, SecretManager}, Client, @@ -49,7 +46,7 @@ async fn nft_reference_unlocks() -> Result<(), Box> { .clone() .into_inner(); - let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let protocol_parameters = iota_mainnet_protocol_parameters(); let nft_id = NftId::from_str(NFT_ID_1)?; let nft_address = Address::Nft(NftAddress::new(nft_id)); let slot_index = SlotIndex::from(10); @@ -127,7 +124,7 @@ async fn nft_reference_unlocks() -> Result<(), Box> { .with_outputs(outputs) .with_creation_slot(slot_index + 1) .with_capabilities([TransactionCapabilityFlag::BurnMana]) - .finish_with_params(&protocol_parameters)?; + .finish_with_params(protocol_parameters)?; let prepared_transaction_data = PreparedTransactionData { transaction, @@ -157,14 +154,9 @@ async fn nft_reference_unlocks() -> Result<(), Box> { let tx_payload = SignedTransactionPayload::new(prepared_transaction_data.transaction.clone(), unlocks)?; - validate_signed_transaction_payload_length(&tx_payload)?; + tx_payload.validate_length()?; - verify_semantic( - &prepared_transaction_data.inputs_data, - &tx_payload, - prepared_transaction_data.mana_rewards, - protocol_parameters, - )?; + prepared_transaction_data.verify_semantic(protocol_parameters)?; Ok(()) } diff --git a/sdk/tests/client/transaction_builder/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs index 7dec6f2c82..db375c96c4 100644 --- a/sdk/tests/client/transaction_builder/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -12,7 +12,9 @@ use iota_sdk::{ address::{Address, ImplicitAccountCreationAddress}, mana::ManaAllotment, output::{ - unlock_condition::AddressUnlockCondition, AccountId, AccountOutputBuilder, BasicOutputBuilder, Output, + feature::{BlockIssuerFeature, BlockIssuerKeys, Ed25519PublicKeyHashBlockIssuerKey}, + unlock_condition::AddressUnlockCondition, + AccountId, AccountOutputBuilder, BasicOutputBuilder, Output, }, protocol::iota_mainnet_protocol_parameters, rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, @@ -2088,14 +2090,13 @@ fn min_allot_account_mana_requirement_covered_2() { fn implicit_account_transition() { let protocol_parameters = iota_mainnet_protocol_parameters().clone(); let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); + let ed25519_address = Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(); let inputs = [BasicOutputBuilder::new_with_amount(1_000_000) .add_unlock_condition(AddressUnlockCondition::new(Address::ImplicitAccountCreation( - ImplicitAccountCreationAddress::new( - **Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap().as_ed25519(), - ), + ImplicitAccountCreationAddress::new(**ed25519_address.as_ed25519()), ))) - .with_mana(7871) + .with_mana(10000) .finish_output() .unwrap()]; let inputs = inputs @@ -2114,6 +2115,14 @@ fn implicit_account_transition() { .add_unlock_condition(AddressUnlockCondition::new( Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), )) + .with_features([BlockIssuerFeature::new( + u32::MAX, + BlockIssuerKeys::from_vec(vec![ + Ed25519PublicKeyHashBlockIssuerKey::new(**ed25519_address.as_ed25519()).into(), + ]) + .unwrap(), + ) + .unwrap()]) .finish_output() .unwrap(), ]; @@ -2137,10 +2146,10 @@ fn implicit_account_transition() { assert_eq!(selected.transaction.allotments().len(), 1); assert_eq!( selected.transaction.allotments()[0], - ManaAllotment::new(account_id_1, 7870).unwrap() + ManaAllotment::new(account_id_1, 9948).unwrap() ); // One remainder Mana - assert_eq!(selected.transaction.outputs()[0].mana(), 1); + assert_eq!(selected.transaction.outputs()[0].mana(), 52); } #[test] diff --git a/sdk/tests/client/transaction_builder/delegation_outputs.rs b/sdk/tests/client/transaction_builder/delegation_outputs.rs index bdb63246f4..612e6781a7 100644 --- a/sdk/tests/client/transaction_builder/delegation_outputs.rs +++ b/sdk/tests/client/transaction_builder/delegation_outputs.rs @@ -86,7 +86,8 @@ fn remainder_needed_for_mana() { .finish() .unwrap(); - let inputs = inputs + let inputs = selected + .inputs_data .iter() .map(|input| (input.output_id(), &input.output)) .collect::>(); @@ -97,18 +98,7 @@ fn remainder_needed_for_mana() { &inputs, None, None, - protocol_parameters.clone(), - ) - .validate() - .unwrap(); - - // validating with rewards - iota_sdk::types::block::semantic::SemanticValidationContext::new( - &selected.transaction, - &inputs, - None, - Some(std::collections::BTreeMap::from([(delegation_output_id, mana_rewards)])), - protocol_parameters.clone(), + protocol_parameters, ) .validate() .unwrap(); diff --git a/sdk/tests/client/transaction_builder/foundry_outputs.rs b/sdk/tests/client/transaction_builder/foundry_outputs.rs index f347570e9b..403e141077 100644 --- a/sdk/tests/client/transaction_builder/foundry_outputs.rs +++ b/sdk/tests/client/transaction_builder/foundry_outputs.rs @@ -16,6 +16,7 @@ use iota_sdk::{ }, protocol::iota_mainnet_protocol_parameters, rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, + semantic::TransactionFailureReason, }, }; use pretty_assertions::assert_eq; @@ -809,12 +810,13 @@ fn mint_and_burn_at_the_same_time() { protocol_parameters, ) .with_burn(Burn::new().add_native_token(token_id, 10)) - .finish(); + .finish() + .unwrap_err(); - assert!(matches!( + assert_eq!( selected, - Err(TransactionBuilderError::UnfulfillableRequirement(Requirement::Foundry(id))) if id == foundry_id - )); + TransactionBuilderError::Semantic(TransactionFailureReason::NativeTokenSumUnbalanced) + ); } #[test] diff --git a/sdk/tests/client/transaction_builder/nft_outputs.rs b/sdk/tests/client/transaction_builder/nft_outputs.rs index b3ff861139..c4326dcec5 100644 --- a/sdk/tests/client/transaction_builder/nft_outputs.rs +++ b/sdk/tests/client/transaction_builder/nft_outputs.rs @@ -13,6 +13,7 @@ use iota_sdk::{ output::{feature::MetadataFeature, unlock_condition::AddressUnlockCondition, NftId, NftOutputBuilder, Output}, protocol::iota_mainnet_protocol_parameters, rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, + semantic::TransactionFailureReason, }, }; use pretty_assertions::{assert_eq, assert_ne}; @@ -1418,14 +1419,13 @@ fn changed_immutable_metadata() { SLOT_COMMITMENT_ID, protocol_parameters, ) - .finish(); + .finish() + .unwrap_err(); - assert!(matches!( + assert_eq!( selected, - Err(TransactionBuilderError::UnfulfillableRequirement(Requirement::Nft( - nft_id, - ))) if nft_id == nft_id_1 - )); + TransactionBuilderError::Semantic(TransactionFailureReason::ChainOutputImmutableFeaturesChanged) + ); } #[test] From 67f6efb4a998b43df37836b53758a6a89ad9eb29 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 12:52:03 -0500 Subject: [PATCH 10/23] remove context inputs from transaction options --- .../lib/types/wallet/transaction-options.ts | 2 - .../iota_sdk/types/transaction_options.py | 2 - sdk/src/client/api/block_builder/options.rs | 4 -- .../block_builder/transaction_builder/mod.rs | 43 +------------------ .../transaction/build_transaction.rs | 28 +----------- 5 files changed, 3 insertions(+), 76 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/transaction-options.ts b/bindings/nodejs/lib/types/wallet/transaction-options.ts index cbe3f7385b..19801928de 100644 --- a/bindings/nodejs/lib/types/wallet/transaction-options.ts +++ b/bindings/nodejs/lib/types/wallet/transaction-options.ts @@ -19,8 +19,6 @@ export interface TransactionOptions { remainderValueStrategy?: RemainderValueStrategy; /** An optional tagged data payload. */ taggedDataPayload?: TaggedDataPayload; - /** Transaction context inputs to include. */ - contextInputs?: ContextInput[]; /** Inputs that must be used for the transaction. */ requiredInputs?: OutputId[]; /** Specifies what needs to be burned during input selection. */ diff --git a/bindings/python/iota_sdk/types/transaction_options.py b/bindings/python/iota_sdk/types/transaction_options.py index 8aedbc7283..a3ac142ced 100644 --- a/bindings/python/iota_sdk/types/transaction_options.py +++ b/bindings/python/iota_sdk/types/transaction_options.py @@ -49,7 +49,6 @@ class TransactionOptions: Attributes: remainder_value_strategy: The strategy applied for base coin remainders. tagged_data_payload: An optional tagged data payload. - context_inputs: Transaction context inputs to include. required_inputs: Inputs that must be used for the transaction. burn: Specifies what needs to be burned during input selection. note: A string attached to the transaction. @@ -62,7 +61,6 @@ class TransactionOptions: remainder_value_strategy: Optional[Union[RemainderValueStrategy, RemainderValueStrategyCustomAddress]] = None tagged_data_payload: Optional[TaggedDataPayload] = None - context_inputs: Optional[List[ContextInput]] = None required_inputs: Optional[List[OutputId]] = None burn: Optional[Burn] = None note: Optional[str] = None diff --git a/sdk/src/client/api/block_builder/options.rs b/sdk/src/client/api/block_builder/options.rs index dac635e98d..8fa7cbcc55 100644 --- a/sdk/src/client/api/block_builder/options.rs +++ b/sdk/src/client/api/block_builder/options.rs @@ -9,7 +9,6 @@ use crate::{ client::api::transaction_builder::Burn, types::block::{ address::Address, - context_input::ContextInput, output::{AccountId, OutputId}, payload::{signed_transaction::TransactionCapabilities, tagged_data::TaggedDataPayload}, }, @@ -24,8 +23,6 @@ pub struct TransactionOptions { pub remainder_value_strategy: RemainderValueStrategy, /// An optional tagged data payload. pub tagged_data_payload: Option, - /// Transaction context inputs to include. - pub context_inputs: Vec, /// Inputs that must be used for the transaction. pub required_inputs: BTreeSet, /// Specifies what needs to be burned in the transaction. @@ -49,7 +46,6 @@ impl Default for TransactionOptions { Self { remainder_value_strategy: Default::default(), tagged_data_payload: Default::default(), - context_inputs: Default::default(), required_inputs: Default::default(), burn: Default::default(), note: Default::default(), diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 15adf8e223..043c358027 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -57,28 +57,7 @@ impl Client { let protocol_parameters = self.get_protocol_parameters().await?; let creation_slot = self.get_slot_index().await?; - let (bic_context_inputs, commitment_context_input) = options.context_inputs.into_iter().fold( - (HashSet::new(), None), - |(mut bic_context_inputs, mut commitment_context_input), i| { - match i { - ContextInput::BlockIssuanceCredit(i) => { - bic_context_inputs.insert(i); - } - ContextInput::Commitment(i) => { - commitment_context_input.replace(i); - } - // TODO: It's not really possible to accurately provide a reward context input, - // so should we forbid it in transaction options? - ContextInput::Reward(_) => (), - } - (bic_context_inputs, commitment_context_input) - }, - ); - - let slot_commitment_id = match commitment_context_input { - Some(c) => c.slot_commitment_id(), - None => self.get_issuance().await?.latest_commitment.id(), - }; + let slot_commitment_id = self.get_issuance().await?.latest_commitment.id(); let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { Some(self.get_account_congestion(&issuer_id, None).await?.reference_mana_cost) } else { @@ -160,8 +139,6 @@ impl Client { protocol_parameters.clone(), ) .with_required_inputs(options.required_inputs) - .with_block_issuance_credit_context_inputs(bic_context_inputs) - .with_commitment_context_input(commitment_context_input) .with_mana_rewards(mana_rewards) .with_payload(options.tagged_data_payload) .with_mana_allotments(options.mana_allotments) @@ -520,24 +497,6 @@ impl TransactionBuilder { self } - /// Sets the block issance credit context inputs of an [`TransactionBuilder`]. - pub fn with_block_issuance_credit_context_inputs( - mut self, - bic_context_inputs: impl IntoIterator, - ) -> Self { - self.bic_context_inputs = bic_context_inputs.into_iter().collect(); - self - } - - /// Sets the commitment context input of an [`TransactionBuilder`]. - pub fn with_commitment_context_input( - mut self, - commitment_context_input: impl Into>, - ) -> Self { - self.commitment_context_input = commitment_context_input.into(); - self - } - /// Sets the burn of an [`TransactionBuilder`]. pub fn with_burn(mut self, burn: impl Into>) -> Self { self.burn = burn.into(); diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 68a2bfaddd..d678bae9a2 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use alloc::collections::BTreeSet; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use crypto::keys::bip44::Bip44; @@ -19,7 +19,6 @@ use crate::{ }, types::block::{ address::Bech32Address, - context_input::ContextInput, output::{Output, OutputId}, protocol::CommittableAgeRange, slot::SlotIndex, @@ -45,28 +44,7 @@ where let protocol_parameters = self.client().get_protocol_parameters().await?; let creation_slot = self.client().get_slot_index().await?; - let (bic_context_inputs, commitment_context_input) = options.context_inputs.into_iter().fold( - (HashSet::new(), None), - |(mut bic_context_inputs, mut commitment_context_input), i| { - match i { - ContextInput::BlockIssuanceCredit(i) => { - bic_context_inputs.insert(i); - } - ContextInput::Commitment(i) => { - commitment_context_input.replace(i); - } - // TODO: It's not really possible to accurately provide a reward context input, - // so should we forbid it in transaction options? - ContextInput::Reward(_) => (), - } - (bic_context_inputs, commitment_context_input) - }, - ); - - let slot_commitment_id = match commitment_context_input { - Some(c) => c.slot_commitment_id(), - None => self.client().get_issuance().await?.latest_commitment.id(), - }; + let slot_commitment_id = self.client().get_issuance().await?.latest_commitment.id(); if options.issuer_id.is_none() { options.issuer_id = self.ledger().await.first_account_id(); } @@ -169,8 +147,6 @@ where protocol_parameters.clone(), ) .with_required_inputs(options.required_inputs) - .with_block_issuance_credit_context_inputs(bic_context_inputs) - .with_commitment_context_input(commitment_context_input) .with_mana_rewards(mana_rewards) .with_payload(options.tagged_data_payload) .with_mana_allotments(options.mana_allotments) From 200c65fbb68a128864c930416ed6415edcaf1c8e Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 13:20:35 -0500 Subject: [PATCH 11/23] revert merge mistake --- sdk/tests/client/transaction_builder/foundry_outputs.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/tests/client/transaction_builder/foundry_outputs.rs b/sdk/tests/client/transaction_builder/foundry_outputs.rs index 861d2fefb3..d363420fe2 100644 --- a/sdk/tests/client/transaction_builder/foundry_outputs.rs +++ b/sdk/tests/client/transaction_builder/foundry_outputs.rs @@ -17,6 +17,7 @@ use iota_sdk::{ payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, protocol::iota_mainnet_protocol_parameters, rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, + semantic::TransactionFailureReason, }, }; use pretty_assertions::assert_eq; @@ -826,7 +827,7 @@ fn mint_and_burn_at_the_same_time() { assert_eq!( selected, - TransactionBuilderError::UnfulfillableRequirement(Requirement::Foundry(foundry_id)) + TransactionBuilderError::Semantic(TransactionFailureReason::NativeTokenSumUnbalanced) ); } From bec9ba25c93758a388d1a9a442b1652a223a3682 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 13:23:33 -0500 Subject: [PATCH 12/23] remove comments --- .../high_level/minting/create_native_token.rs | 38 +++++++++---------- .../high_level/minting/mint_native_token.rs | 5 +-- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs index 5cbbadb460..16f7549d8c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs @@ -120,28 +120,26 @@ where ); let token_id = TokenId::from(foundry_id); - let outputs = [ - { - let mut foundry_builder = FoundryOutputBuilder::new_with_minimum_amount( - storage_score_params, - account_output.foundry_counter() + 1, - TokenScheme::Simple(SimpleTokenScheme::new( - params.circulating_supply, - 0, - params.maximum_supply, - )?), - ) - .add_unlock_condition(ImmutableAccountAddressUnlockCondition::new(AccountAddress::from( - account_id, - ))); + let outputs = [{ + let mut foundry_builder = FoundryOutputBuilder::new_with_minimum_amount( + storage_score_params, + account_output.foundry_counter() + 1, + TokenScheme::Simple(SimpleTokenScheme::new( + params.circulating_supply, + 0, + params.maximum_supply, + )?), + ) + .add_unlock_condition(ImmutableAccountAddressUnlockCondition::new(AccountAddress::from( + account_id, + ))); - if let Some(foundry_metadata) = params.foundry_metadata { - foundry_builder = foundry_builder.add_immutable_feature(foundry_metadata); - } + if let Some(foundry_metadata) = params.foundry_metadata { + foundry_builder = foundry_builder.add_immutable_feature(foundry_metadata); + } - foundry_builder.finish_output()? - }, // Native Tokens will be added automatically in the remainder output in try_select_inputs() - ]; + foundry_builder.finish_output()? + }]; self.prepare_transaction(outputs, options) .await diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs index 21c75a4484..af3bca6692 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs @@ -119,10 +119,7 @@ where let new_foundry_output_builder = FoundryOutputBuilder::from(foundry_output).with_token_scheme(updated_token_scheme); - let outputs = [ - new_foundry_output_builder.finish_output()?, - // Native Tokens will be added automatically in the remainder output in try_select_inputs() - ]; + let outputs = [new_foundry_output_builder.finish_output()?]; self.prepare_transaction(outputs, options).await } From 999a984267f9069a94708d022655ebace0f0c9d7 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Fri, 1 Mar 2024 13:33:25 -0500 Subject: [PATCH 13/23] usused import --- bindings/python/iota_sdk/types/transaction_options.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/python/iota_sdk/types/transaction_options.py b/bindings/python/iota_sdk/types/transaction_options.py index 7dbcbe319c..2829721411 100644 --- a/bindings/python/iota_sdk/types/transaction_options.py +++ b/bindings/python/iota_sdk/types/transaction_options.py @@ -7,7 +7,6 @@ from iota_sdk.types.address import Address from iota_sdk.types.burn import Burn from iota_sdk.types.common import HexStr, json -from iota_sdk.types.context_input import ContextInput from iota_sdk.types.output_id import OutputId from iota_sdk.types.payload import TaggedDataPayload From bad67a06a66b0cda62b3084608657b134ba45704 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 4 Mar 2024 09:58:04 +0100 Subject: [PATCH 14/23] Remove unused ContextInput --- bindings/nodejs/lib/types/wallet/transaction-options.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/nodejs/lib/types/wallet/transaction-options.ts b/bindings/nodejs/lib/types/wallet/transaction-options.ts index 52c609b28c..252ef0522e 100644 --- a/bindings/nodejs/lib/types/wallet/transaction-options.ts +++ b/bindings/nodejs/lib/types/wallet/transaction-options.ts @@ -6,7 +6,6 @@ import { AccountId, Address, Bech32Address, - ContextInput, OutputId, } from '../block'; import { TaggedDataPayload } from '../block/payload/tagged'; From 88c4b36aae598de65d17f910c938ca65ced58d9d Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 08:35:30 -0500 Subject: [PATCH 15/23] review --- bindings/nodejs/lib/types/wallet/event.ts | 4 +-- .../lib/types/wallet/transaction-options.ts | 2 +- bindings/python/iota_sdk/types/event.py | 19 +++++++++++ .../iota_sdk/types/transaction_options.py | 2 +- .../types/block/semantic/state_transition.rs | 32 ++++++++++++------- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index 10b8884e79..6c48c9cb62 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -115,8 +115,8 @@ class TransactionInclusionWalletEvent extends WalletEvent { * All of the transaction progress types. */ enum TransactionProgressType { - /** Performing input selection. */ - SelectingInputs = 0, + /** Building a transaction. */ + BuildingTransaction = 0, /** Generating remainder value deposit address. */ GeneratingRemainderDepositAddress = 1, /** Prepared transaction. */ diff --git a/bindings/nodejs/lib/types/wallet/transaction-options.ts b/bindings/nodejs/lib/types/wallet/transaction-options.ts index 252ef0522e..2004248bbf 100644 --- a/bindings/nodejs/lib/types/wallet/transaction-options.ts +++ b/bindings/nodejs/lib/types/wallet/transaction-options.ts @@ -20,7 +20,7 @@ export interface TransactionOptions { taggedDataPayload?: TaggedDataPayload; /** Inputs that must be used for the transaction. */ requiredInputs?: OutputId[]; - /** Specifies what needs to be burned during input selection. */ + /** Specifies what needs to be burned in the transaction. */ burn?: Burn; /** Optional note, that is only stored locally. */ note?: string; diff --git a/bindings/python/iota_sdk/types/event.py b/bindings/python/iota_sdk/types/event.py index 75ed34886a..00a8c55475 100644 --- a/bindings/python/iota_sdk/types/event.py +++ b/bindings/python/iota_sdk/types/event.py @@ -19,3 +19,22 @@ class WalletEventType(IntEnum): SpentOutput = 2 TransactionInclusion = 3 TransactionProgress = 4 + + +class TransactionProgressEvent(IntEnum): + """Types of transaction progress events. + + Attributes: + BuildingTransaction (0): Building a transaction. + GeneratingRemainderDepositAddress (1): Generating remainder value deposit address. + PreparedTransaction (2): Prepared transaction. + PreparedTransactionSigningHash (3): Prepared transaction signing hash hex encoded, required for blindsigning with a Ledger Nano. + SigningTransaction (4): Signing the transaction. + Broadcasting (5): Broadcasting. + """ + BuildingTransaction = 0 + GeneratingRemainderDepositAddress = 1 + PreparedTransaction = 2 + PreparedTransactionSigningHash = 3 + SigningTransaction = 4 + Broadcasting = 5 diff --git a/bindings/python/iota_sdk/types/transaction_options.py b/bindings/python/iota_sdk/types/transaction_options.py index 2829721411..aa6eee238d 100644 --- a/bindings/python/iota_sdk/types/transaction_options.py +++ b/bindings/python/iota_sdk/types/transaction_options.py @@ -49,7 +49,7 @@ class TransactionOptions: remainder_value_strategy: The strategy applied for base coin remainders. tagged_data_payload: An optional tagged data payload. required_inputs: Inputs that must be used for the transaction. - burn: Specifies what needs to be burned during input selection. + burn: Specifies what needs to be burned in the transaction. note: A string attached to the transaction. allow_micro_amount: Whether to allow sending a micro amount. allow_additional_input_selection: Whether to allow the selection of additional inputs for this transaction. diff --git a/sdk/src/types/block/semantic/state_transition.rs b/sdk/src/types/block/semantic/state_transition.rs index e420fc7f3c..f2cd780db3 100644 --- a/sdk/src/types/block/semantic/state_transition.rs +++ b/sdk/src/types/block/semantic/state_transition.rs @@ -130,9 +130,11 @@ impl BasicOutput { return Err(TransactionFailureReason::BlockIssuerNotExpired); } - if let Some(issuer) = next_state.immutable_features().issuer() { - if !context.unlocked_addresses.contains(issuer.address()) { - return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + if context.unlocks.is_some() { + if let Some(issuer) = next_state.immutable_features().issuer() { + if !context.unlocked_addresses.contains(issuer.address()) { + return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + } } } @@ -172,9 +174,11 @@ impl StateTransitionVerifier for AccountOutput { } } - if let Some(issuer) = next_state.immutable_features().issuer() { - if !context.unlocked_addresses.contains(issuer.address()) { - return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + if context.unlocks.is_some() { + if let Some(issuer) = next_state.immutable_features().issuer() { + if !context.unlocked_addresses.contains(issuer.address()) { + return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + } } } @@ -351,9 +355,11 @@ impl StateTransitionVerifier for AnchorOutput { return Err(TransactionFailureReason::NewChainOutputHasNonZeroedId); } - if let Some(issuer) = next_state.immutable_features().issuer() { - if !context.unlocked_addresses.contains(issuer.address()) { - return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + if context.unlocks.is_some() { + if let Some(issuer) = next_state.immutable_features().issuer() { + if !context.unlocked_addresses.contains(issuer.address()) { + return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + } } } @@ -487,9 +493,11 @@ impl StateTransitionVerifier for NftOutput { return Err(TransactionFailureReason::NewChainOutputHasNonZeroedId); } - if let Some(issuer) = next_state.immutable_features().issuer() { - if !context.unlocked_addresses.contains(issuer.address()) { - return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + if context.unlocks.is_some() { + if let Some(issuer) = next_state.immutable_features().issuer() { + if !context.unlocked_addresses.contains(issuer.address()) { + return Err(TransactionFailureReason::IssuerFeatureNotUnlocked); + } } } From d948e8ed6e2e7201f4340c81ceb31718c283cacf Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 08:48:30 -0500 Subject: [PATCH 16/23] more ts instances --- bindings/nodejs/examples/wallet/events.ts | 6 ++++-- bindings/nodejs/lib/types/wallet/event.ts | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bindings/nodejs/examples/wallet/events.ts b/bindings/nodejs/examples/wallet/events.ts index d0f8f4f5fd..70b60e2538 100644 --- a/bindings/nodejs/examples/wallet/events.ts +++ b/bindings/nodejs/examples/wallet/events.ts @@ -4,7 +4,7 @@ import { WalletEvent, TransactionProgressWalletEvent, - SelectingInputsProgress, + BuildingTransactionProgress, } from '@iota/sdk'; import { getUnlockedWallet } from './common'; require('dotenv').config({ path: '.env' }); @@ -30,7 +30,9 @@ async function run() { await wallet.listen([], callback); await wallet.emitTestEvent( - new TransactionProgressWalletEvent(new SelectingInputsProgress()), + new TransactionProgressWalletEvent( + new BuildingTransactionProgress(), + ), ); await wallet.destroy(); diff --git a/bindings/nodejs/lib/types/wallet/event.ts b/bindings/nodejs/lib/types/wallet/event.ts index 6c48c9cb62..b94f7b686d 100644 --- a/bindings/nodejs/lib/types/wallet/event.ts +++ b/bindings/nodejs/lib/types/wallet/event.ts @@ -159,11 +159,11 @@ abstract class TransactionProgress { } /** - * A 'selecting inputs' progress. + * A 'building transaction' progress. */ -class SelectingInputsProgress extends TransactionProgress { +class BuildingTransactionProgress extends TransactionProgress { constructor() { - super(TransactionProgressType.SelectingInputs); + super(TransactionProgressType.BuildingTransaction); } } @@ -249,7 +249,7 @@ export { TransactionInclusionWalletEvent, TransactionProgressWalletEvent, TransactionProgress, - SelectingInputsProgress, + BuildingTransactionProgress, GeneratingRemainderDepositAddressProgress, PreparedTransactionProgress, PreparedTransactionSigningHashProgress, From c591188e56d48fb1f47c471f23863b11cfa7fe41 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 10:02:47 -0500 Subject: [PATCH 17/23] review --- sdk/src/client/api/block_builder/transaction_builder/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index 16012df828..a21fe131d2 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -53,7 +53,6 @@ impl Client { ) -> crate::client::Result { let outputs = outputs.into_iter().collect::>(); let addresses = addresses.into_iter().collect::>(); - // Voting output needs to be requested before to prevent a deadlock let protocol_parameters = self.get_protocol_parameters().await?; let creation_slot = self.get_slot_index().await?; @@ -68,7 +67,7 @@ impl Client { RemainderValueStrategy::CustomAddress(address) => Some(address), }; - let hrp = self.get_bech32_hrp().await?; + let hrp = protocol_parameters.bech32_hrp(); let mut available_input_ids = HashSet::new(); for address in &addresses { From 074bc0fa0d6ffe904754ddd9285348f47f0a18ba Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 11:04:37 -0500 Subject: [PATCH 18/23] double copyright --- .../api/block_builder/transaction_builder/requirement/mana.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index 729649e305..9b1002f98a 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -1,8 +1,6 @@ // Copyright 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -// Copyright 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 use std::collections::HashMap; use super::{TransactionBuilder, TransactionBuilderError}; From 2683468a7302380e8415cc29817f35fa426e82d3 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 12:44:02 -0500 Subject: [PATCH 19/23] review --- .../block_builder/transaction_builder/mod.rs | 18 +++++------------- .../requirement/context_inputs.rs | 13 +++++++------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index a21fe131d2..e6159b5107 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -71,19 +71,11 @@ impl Client { let mut available_input_ids = HashSet::new(); for address in &addresses { - let mut cursor = None; - loop { - let mut query = OutputQueryParameters::new().unlockable_by_address(address.clone().to_bech32(hrp)); - if let Some(cursor) = cursor { - query = query.cursor(cursor); - } - let res = self.output_ids(query).await?; - cursor = res.cursor; - available_input_ids.extend(res.items); - if cursor.is_none() { - break; - } - } + available_input_ids.extend( + self.output_ids(OutputQueryParameters::new().unlockable_by_address(address.clone().to_bech32(hrp))) + .await? + .items, + ); } let available_inputs = self .get_outputs_with_metadata(&available_input_ids.into_iter().collect::>()) diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs index a8ddd031ef..8315adf8aa 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/context_inputs.rs @@ -22,10 +22,9 @@ impl TransactionBuilder { Output::Account(account) => { if account.features().block_issuer().is_some() { log::debug!("Adding block issuance context input for transitioned account output"); - self.bic_context_inputs.insert( - BlockIssuanceCreditContextInput::from(account.account_id_non_null(input.output_id())) - .into(), - ); + self.bic_context_inputs.insert(BlockIssuanceCreditContextInput::from( + account.account_id_non_null(input.output_id()), + )); } } // Transitioning an implicit account requires a BlockIssuanceCreditContextInput. @@ -33,7 +32,9 @@ impl TransactionBuilder { if basic.is_implicit_account() { log::debug!("Adding block issuance context input for transitioned implicit account output"); self.bic_context_inputs - .insert(BlockIssuanceCreditContextInput::from(AccountId::from(input.output_id())).into()); + .insert(BlockIssuanceCreditContextInput::from(AccountId::from( + input.output_id(), + ))); } } _ => (), @@ -92,7 +93,7 @@ impl TransactionBuilder { if needs_commitment_context && self.commitment_context_input.is_none() { // TODO https://github.com/iotaledger/iota-sdk/issues/1740 self.commitment_context_input - .replace(CommitmentContextInput::new(self.latest_slot_commitment_id).into()); + .replace(CommitmentContextInput::new(self.latest_slot_commitment_id)); } Ok(Vec::new()) } From 80c18972546a6f39b1b42f7a8a6157bf32b43428 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 12:46:56 -0500 Subject: [PATCH 20/23] fix mana allotment not recalculating after changes are made --- .../transaction_builder/requirement/mana.rs | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index 9b1002f98a..94538ad6ec 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -14,7 +14,7 @@ use crate::{ input::{Input, UtxoInput}, mana::ManaAllotment, output::{AccountOutputBuilder, Output}, - payload::{signed_transaction::Transaction, SignedTransactionPayload}, + payload::{dto::SignedTransactionPayloadDto, signed_transaction::Transaction, SignedTransactionPayload}, signature::Ed25519Signature, unlock::{AccountUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks}, BlockError, @@ -34,6 +34,8 @@ impl TransactionBuilder { return Ok(Vec::new()); }; + let mut should_recalculate = false; + if !self.selected_inputs.is_empty() && self.all_outputs().next().is_some() { self.selected_inputs = Self::sort_input_signing_data( std::mem::take(&mut self.selected_inputs), @@ -59,7 +61,6 @@ impl TransactionBuilder { // Add the empty allotment so the work score includes it self.mana_allotments.entry(issuer_id).or_default(); - // If the transaction fails to build, just keep going in case another requirement helps let transaction = builder .with_context_inputs(self.context_inputs()) .with_mana_allotments( @@ -71,6 +72,11 @@ impl TransactionBuilder { let signed_transaction = SignedTransactionPayload::new(transaction, self.null_transaction_unlocks()?)?; + log::debug!( + "signed_transaction: {}", + serde_json::to_string_pretty(&SignedTransactionPayloadDto::from(&signed_transaction)).unwrap() + ); + let block_work_score = self.protocol_parameters.work_score(&signed_transaction) + self.protocol_parameters.work_score_parameters().block(); @@ -94,14 +100,22 @@ impl TransactionBuilder { *self.mana_allotments.get_mut(issuer_id).unwrap() = required_allotment_mana; log::debug!("Adding {additional_allotment} to allotment debt {allotment_debt}"); *allotment_debt += additional_allotment; + should_recalculate = true; } else { log::debug!("Setting allotment debt to {}", self.mana_allotments[issuer_id]); *allotment_debt = self.mana_allotments[issuer_id]; + // Since the allotment is fine, check if the mana balance is good because + // we can exit early in that case. + let (input_mana, output_mana) = self.mana_sums(true)?; + if input_mana == output_mana { + log::debug!("allotments and mana are both correct, no further action needed"); + return Ok(Vec::new()); + } } - self.reduce_account_output()?; - } else if !self.requirements.contains(&Requirement::Mana) { - self.requirements.push(Requirement::Mana); + should_recalculate |= self.reduce_account_output()?; + } else { + should_recalculate = true; } // Remainders can only be calculated when the input mana is >= the output mana @@ -110,17 +124,16 @@ impl TransactionBuilder { self.update_remainders()?; } - let additional_inputs = self.get_inputs_for_mana_balance()?; - // If we needed more inputs to cover the additional allotment mana - // then update remainders and re-run this requirement - if additional_inputs && !self.requirements.contains(&Requirement::Mana) { + should_recalculate |= self.get_inputs_for_mana_balance()?; + + if should_recalculate && !self.requirements.contains(&Requirement::Mana) { self.requirements.push(Requirement::Mana); } Ok(Vec::new()) } - fn reduce_account_output(&mut self) -> Result<(), TransactionBuilderError> { + fn reduce_account_output(&mut self) -> Result { let MinManaAllotment { issuer_id, allotment_debt, @@ -147,8 +160,9 @@ impl TransactionBuilder { .finish_output()?; *allotment_debt = allotment_debt.saturating_sub(output_mana); log::debug!("Allotment debt after reduction: {}", allotment_debt); + return Ok(true); } - Ok(()) + Ok(false) } pub(crate) fn null_transaction_unlocks(&self) -> Result { From 2efa235c4e8eacc66c52542f215197f1e790713a Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Mon, 4 Mar 2024 12:52:24 -0500 Subject: [PATCH 21/23] remove error variant --- sdk/src/client/api/block_builder/transaction_builder/error.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/error.rs b/sdk/src/client/api/block_builder/transaction_builder/error.rs index f58cf6bcb9..06dfa4c538 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/error.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/error.rs @@ -68,9 +68,6 @@ pub enum TransactionBuilderError { /// No available inputs were provided to transaction builder. #[error("no available inputs provided")] NoAvailableInputsProvided, - /// Required input is forbidden. - #[error("required input {0} is forbidden")] - RequiredInputIsForbidden(OutputId), /// Required input is not available. #[error("required input {0} is not available")] RequiredInputIsNotAvailable(OutputId), From 61e94f2529c271991ed9cadfb0d4395b70ed1660 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Tue, 5 Mar 2024 10:54:39 -0500 Subject: [PATCH 22/23] allow providing chains --- sdk/examples/client/send_all.rs | 21 +++++++--- .../block_builder/transaction_builder/mod.rs | 39 ++++++++++--------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/sdk/examples/client/send_all.rs b/sdk/examples/client/send_all.rs index a5c0dd4f94..0418a151be 100644 --- a/sdk/examples/client/send_all.rs +++ b/sdk/examples/client/send_all.rs @@ -21,6 +21,7 @@ use iota_sdk::{ Client, }, types::block::{ + address::{Address, Ed25519Address, ToBech32Ext}, output::{unlock_condition::AddressUnlockCondition, AccountId, BasicOutputBuilder}, payload::{Payload, SignedTransactionPayload}, }, @@ -47,10 +48,20 @@ async fn main() -> Result<(), Box> { let secret_manager_2 = SecretManager::try_from_mnemonic(std::env::var("MNEMONIC_2").unwrap())?; let issuer_id = std::env::var("ISSUER_ID").unwrap().parse::().unwrap(); - let from_address = secret_manager_1 - .generate_ed25519_addresses(GetAddressesOptions::from_client(&client).await?.with_range(0..1)) - .await?[0] - .clone(); + let chain = Bip44::new(IOTA_COIN_TYPE); + + let from_address = Address::from(Ed25519Address::from_public_key_bytes( + secret_manager_1 + .generate_ed25519_public_keys( + chain.coin_type, + chain.account, + chain.address_index..chain.address_index + 1, + None, + ) + .await?[0] + .to_bytes(), + )) + .to_bech32(client.get_bech32_hrp().await?); // Get output ids of outputs that can be controlled by this address without further unlock constraints let output_ids_response = client @@ -101,7 +112,7 @@ async fn main() -> Result<(), Box> { let prepared_transaction = client .build_transaction( - [from_address.into_inner()], + [(from_address.into_inner(), chain)], outputs, TransactionOptions { required_inputs: inputs, diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index cfd5797133..b883bba1c7 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -12,6 +12,7 @@ pub(crate) mod transition; use alloc::collections::BTreeMap; use std::collections::{HashMap, HashSet}; +use crypto::keys::bip44::Bip44; use packable::PackableExt; pub use self::{burn::Burn, error::TransactionBuilderError, requirement::Requirement}; @@ -47,12 +48,12 @@ impl Client { /// Builds a transaction using the given inputs, outputs, addresses, and options. pub async fn build_transaction( &self, - addresses: impl IntoIterator, + addresses: impl IntoIterator, outputs: impl IntoIterator, options: TransactionOptions, ) -> Result { let outputs = outputs.into_iter().collect::>(); - let addresses = addresses.into_iter().collect::>(); + let addresses = addresses.into_iter().collect::>(); let protocol_parameters = self.get_protocol_parameters().await?; let creation_slot = self.get_slot_index().await?; @@ -69,24 +70,26 @@ impl Client { let hrp = protocol_parameters.bech32_hrp(); - let mut available_input_ids = HashSet::new(); - for address in &addresses { - available_input_ids.extend( - self.output_ids(OutputQueryParameters::new().unlockable_by_address(address.clone().to_bech32(hrp))) + let mut available_inputs = Vec::new(); + for (address, chain) in &addresses { + let output_ids = self + .output_ids(OutputQueryParameters::new().unlockable_by_address(address.clone().to_bech32(hrp))) + .await? + .items; + available_inputs.extend( + self.get_outputs_with_metadata(&output_ids) .await? - .items, + .into_iter() + .map(|res| { + Ok(InputSigningData { + output: res.output, + output_metadata: res.metadata, + chain: Some(*chain), + }) + }) + .collect::, ClientError>>()?, ); } - let available_inputs = self - .get_outputs_with_metadata(&available_input_ids.into_iter().collect::>()) - .await? - .into_iter() - .map(|res| InputSigningData { - output: res.output, - output_metadata: res.metadata, - chain: None, - }) - .collect::>(); let mut mana_rewards = HashMap::new(); @@ -124,7 +127,7 @@ impl Client { let mut transaction_builder = TransactionBuilder::new( available_inputs, outputs, - addresses, + addresses.into_keys(), creation_slot, slot_commitment_id, protocol_parameters.clone(), From d8628819e32bc373ba718d8bf61b6dfcffa3e969 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Tue, 5 Mar 2024 11:11:30 -0500 Subject: [PATCH 23/23] DRY --- .../block_builder/transaction_builder/mod.rs | 51 ++++++--- .../transaction/build_transaction.rs | 100 +++--------------- 2 files changed, 51 insertions(+), 100 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/mod.rs b/sdk/src/client/api/block_builder/transaction_builder/mod.rs index b883bba1c7..f819430c91 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/mod.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/mod.rs @@ -52,21 +52,9 @@ impl Client { outputs: impl IntoIterator, options: TransactionOptions, ) -> Result { - let outputs = outputs.into_iter().collect::>(); let addresses = addresses.into_iter().collect::>(); let protocol_parameters = self.get_protocol_parameters().await?; - let creation_slot = self.get_slot_index().await?; - let slot_commitment_id = self.get_issuance().await?.latest_commitment.id(); - let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { - Some(self.get_account_congestion(&issuer_id, None).await?.reference_mana_cost) - } else { - None - }; - let remainder_address = match options.remainder_value_strategy { - RemainderValueStrategy::ReuseAddress => None, - RemainderValueStrategy::CustomAddress(address) => Some(address), - }; let hrp = protocol_parameters.bech32_hrp(); @@ -91,6 +79,40 @@ impl Client { ); } + self.build_transaction_inner( + addresses.into_keys(), + available_inputs, + outputs, + options, + slot_commitment_id, + protocol_parameters, + ) + .await + } + + /// Builds a transaction using the given inputs, outputs, addresses, and options. + pub(crate) async fn build_transaction_inner( + &self, + addresses: impl IntoIterator, + available_inputs: impl IntoIterator, + outputs: impl IntoIterator, + options: TransactionOptions, + slot_commitment_id: SlotCommitmentId, + protocol_parameters: ProtocolParameters, + ) -> Result { + let outputs = outputs.into_iter().collect::>(); + let creation_slot = self.get_slot_index().await?; + + let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { + Some(self.get_account_congestion(&issuer_id, None).await?.reference_mana_cost) + } else { + None + }; + let remainder_address = match options.remainder_value_strategy { + RemainderValueStrategy::ReuseAddress => None, + RemainderValueStrategy::CustomAddress(address) => Some(address), + }; + let mut mana_rewards = HashMap::new(); if let Some(burn) = &options.burn { @@ -105,7 +127,6 @@ impl Client { } } - // Check that no input got already locked for output_id in &options.required_inputs { let input = self.get_output(output_id).await?; if input.output.can_claim_rewards(outputs.iter().find(|o| { @@ -127,10 +148,10 @@ impl Client { let mut transaction_builder = TransactionBuilder::new( available_inputs, outputs, - addresses.into_keys(), + addresses, creation_slot, slot_commitment_id, - protocol_parameters.clone(), + protocol_parameters, ) .with_required_inputs(options.required_inputs) .with_mana_rewards(mana_rewards) diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index fa373c3a81..72df49b0e3 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 use alloc::collections::BTreeSet; -use std::collections::HashMap; use crypto::keys::bip44::Bip44; @@ -10,11 +9,7 @@ use crypto::keys::bip44::Bip44; use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::{ - api::{ - options::{RemainderValueStrategy, TransactionOptions}, - transaction_builder::TransactionBuilder, - PreparedTransactionData, - }, + api::{options::TransactionOptions, PreparedTransactionData}, secret::{types::InputSigningData, SecretManage}, }, types::block::{ @@ -40,28 +35,11 @@ impl Wallet { #[cfg(feature = "participation")] let voting_output = self.get_voting_output().await; let protocol_parameters = self.client().get_protocol_parameters().await?; - let creation_slot = self.client().get_slot_index().await?; let slot_commitment_id = self.client().get_issuance().await?.latest_commitment.id(); if options.issuer_id.is_none() { options.issuer_id = self.ledger().await.first_account_id(); } - let reference_mana_cost = if let Some(issuer_id) = options.issuer_id { - Some( - self.client() - .get_account_congestion(&issuer_id, None) - .await? - .reference_mana_cost, - ) - } else { - None - }; - let remainder_address = match options.remainder_value_strategy { - RemainderValueStrategy::ReuseAddress => None, - RemainderValueStrategy::CustomAddress(address) => Some(address), - }; - - let wallet_ledger = self.ledger().await; #[cfg(feature = "events")] self.emit(WalletEvent::TransactionProgress( @@ -69,6 +47,8 @@ impl Wallet { )) .await; + let wallet_ledger = self.ledger().await; + #[allow(unused_mut)] let mut forbidden_inputs = wallet_ledger.locked_outputs.clone(); @@ -82,7 +62,7 @@ impl Wallet { // Filter inputs to not include inputs that require additional outputs for storage deposit return or could be // still locked. - let available_outputs_signing_data = filter_inputs( + let available_inputs = filter_inputs( &self.address().await, self.bip_path().await, wallet_ledger @@ -94,22 +74,6 @@ impl Wallet { &options.required_inputs, )?; - let mut mana_rewards = HashMap::new(); - - if let Some(burn) = &options.burn { - for delegation_id in burn.delegations() { - if let Some(output) = wallet_ledger.unspent_delegation_output(delegation_id) { - mana_rewards.insert( - output.output_id, - self.client() - .get_output_mana_rewards(&output.output_id, slot_commitment_id.slot_index()) - .await? - .rewards, - ); - } - } - } - // Check that no input got already locked for output_id in &options.required_inputs { if wallet_ledger.locked_outputs.contains(output_id) { @@ -117,53 +81,19 @@ impl Wallet { "provided custom input {output_id} is already used in another transaction", ))); } - if let Some(input) = wallet_ledger.outputs.get(output_id) { - if input.output.can_claim_rewards(outputs.iter().find(|o| { - input - .output - .chain_id() - .map(|chain_id| chain_id.or_from_output_id(output_id)) - == o.chain_id() - })) { - mana_rewards.insert( - *output_id, - self.client() - .get_output_mana_rewards(output_id, slot_commitment_id.slot_index()) - .await? - .rewards, - ); - } - } - } - - let mut transaction_builder = TransactionBuilder::new( - available_outputs_signing_data, - outputs, - Some(self.address().await.into_inner()), - creation_slot, - slot_commitment_id, - protocol_parameters.clone(), - ) - .with_required_inputs(options.required_inputs) - .with_mana_rewards(mana_rewards) - .with_payload(options.tagged_data_payload) - .with_mana_allotments(options.mana_allotments) - .with_remainder_address(remainder_address) - .with_burn(options.burn); - - if let (Some(account_id), Some(reference_mana_cost)) = (options.issuer_id, reference_mana_cost) { - transaction_builder = transaction_builder.with_min_mana_allotment(account_id, reference_mana_cost); - } - - if !options.allow_additional_input_selection { - transaction_builder = transaction_builder.disable_additional_input_selection(); } - let prepared_transaction_data = transaction_builder.finish()?; - - prepared_transaction_data.transaction.validate_length()?; - - Ok(prepared_transaction_data) + Ok(self + .client() + .build_transaction_inner( + [self.address().await.into_inner()], + available_inputs, + outputs, + options, + slot_commitment_id, + protocol_parameters, + ) + .await?) } }