From 4554d4c3d995b0be347b96f342657730148838f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 5 Mar 2024 10:44:31 +0100 Subject: [PATCH 1/4] Rename prepare_transaction() to prepare_send_outputs() --- bindings/core/src/method/wallet.rs | 4 +-- bindings/core/src/method_handler/wallet.rs | 4 +-- bindings/core/src/response.rs | 2 +- .../nodejs/lib/types/wallet/bridge/wallet.ts | 4 +-- bindings/nodejs/lib/wallet/wallet.ts | 35 +++---------------- bindings/python/iota_sdk/wallet/wallet.py | 12 +++---- sdk/src/wallet/operations/output_claiming.rs | 2 +- .../wallet/operations/output_consolidation.rs | 2 +- .../wallet/operations/participation/voting.rs | 4 +-- .../operations/participation/voting_power.rs | 4 +-- .../wallet/operations/transaction/account.rs | 2 +- .../transaction/high_level/allot_mana.rs | 2 +- .../burning_melting/melt_native_token.rs | 2 +- .../high_level/burning_melting/mod.rs | 2 +- .../transaction/high_level/create_account.rs | 2 +- .../high_level/delegation/create.rs | 2 +- .../high_level/delegation/delay.rs | 2 +- .../high_level/minting/create_native_token.rs | 4 +-- .../high_level/minting/mint_native_token.rs | 2 +- .../high_level/minting/mint_nfts.rs | 4 +-- .../operations/transaction/high_level/send.rs | 2 +- .../transaction/high_level/send_mana.rs | 2 +- .../high_level/send_native_tokens.rs | 2 +- .../transaction/high_level/send_nft.rs | 4 +-- .../transaction/high_level/staking/begin.rs | 2 +- .../transaction/high_level/staking/end.rs | 2 +- .../transaction/high_level/staking/extend.rs | 2 +- sdk/src/wallet/operations/transaction/mod.rs | 6 ++-- ...transaction.rs => prepare_send_outputs.rs} | 10 +++--- 29 files changed, 52 insertions(+), 77 deletions(-) rename sdk/src/wallet/operations/transaction/{prepare_transaction.rs => prepare_send_outputs.rs} (84%) diff --git a/bindings/core/src/method/wallet.rs b/bindings/core/src/method/wallet.rs index ab248beceb..2fc2bb1867 100644 --- a/bindings/core/src/method/wallet.rs +++ b/bindings/core/src/method/wallet.rs @@ -385,9 +385,9 @@ pub enum WalletMethod { // #[cfg_attr(docsrs, doc(cfg(feature = "participation")))] // #[serde(rename_all = "camelCase")] // PrepareStopParticipating { event_id: ParticipationEventId }, - /// Prepare transaction. + /// Prepare to send outputs. /// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction) - PrepareTransaction { + PrepareSendOutputs { outputs: Vec, #[serde(default)] options: Option, diff --git a/bindings/core/src/method_handler/wallet.rs b/bindings/core/src/method_handler/wallet.rs index 9bfc823d3b..a1e051ae4e 100644 --- a/bindings/core/src/method_handler/wallet.rs +++ b/bindings/core/src/method_handler/wallet.rs @@ -363,8 +363,8 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM // let data = wallet.prepare_stop_participating(event_id).await?; // Response::PreparedTransaction(data) // } - WalletMethod::PrepareTransaction { outputs, options } => { - let data = wallet.prepare_transaction(outputs, options).await?; + WalletMethod::PrepareSendOutputs { outputs, options } => { + let data = wallet.prepare_send_outputs(outputs, options).await?; Response::PreparedTransaction(data) } // #[cfg(feature = "participation")] diff --git a/bindings/core/src/response.rs b/bindings/core/src/response.rs index 1c125938b3..372741e172 100644 --- a/bindings/core/src/response.rs +++ b/bindings/core/src/response.rs @@ -337,7 +337,7 @@ pub enum Response { /// - [`PrepareSendNativeTokens`](crate::method::WalletMethod::PrepareSendNativeTokens), /// - [`PrepareSendNft`](crate::method::WalletMethod::PrepareSendNft), /// - [`PrepareStopParticipating`](crate::method::WalletMethod::PrepareStopParticipating) - /// - [`PrepareTransaction`](crate::method::WalletMethod::PrepareTransaction) + /// - [`PrepareSendOutputs`](crate::method::WalletMethod::PrepareSendOutputs) /// - [`PrepareVote`](crate::method::WalletMethod::PrepareVote) /// - [`PrepareImplicitAccountTransition`](crate::method::WalletMethod::PrepareImplicitAccountTransition) PreparedTransaction(PreparedTransactionData), diff --git a/bindings/nodejs/lib/types/wallet/bridge/wallet.ts b/bindings/nodejs/lib/types/wallet/bridge/wallet.ts index 6baa05d442..baff7e5311 100644 --- a/bindings/nodejs/lib/types/wallet/bridge/wallet.ts +++ b/bindings/nodejs/lib/types/wallet/bridge/wallet.ts @@ -351,8 +351,8 @@ export type __PrepareSendMethod__ = { }; }; -export type __PrepareTransactionMethod__ = { - name: 'prepareTransaction'; +export type __PrepareSendOutputsMethod__ = { + name: 'prepareSendOutputs'; data: { outputs: Output[]; options?: TransactionOptions; diff --git a/bindings/nodejs/lib/wallet/wallet.ts b/bindings/nodejs/lib/wallet/wallet.ts index 0d43e63b47..e1d83e5ae9 100644 --- a/bindings/nodejs/lib/wallet/wallet.ts +++ b/bindings/nodejs/lib/wallet/wallet.ts @@ -1463,17 +1463,17 @@ export class Wallet { } /** - * Send a transaction. + * Send outputs. * * @param outputs Outputs to use in the transaction. * @param options Additional transaction options. * @returns The transaction data. */ - async sendTransaction( + async sendOutputs( outputs: Output[], options?: TransactionOptions, ): Promise { - return (await this.prepareTransaction(outputs, options)).send(); + return (await this.prepareSendOutputs(outputs, options)).send(); } /** @@ -1483,12 +1483,12 @@ export class Wallet { * @param options Additional transaction options. * @returns The prepared transaction data. */ - async prepareTransaction( + async prepareSendOutputs( outputs: Output[], options?: TransactionOptions, ): Promise { const response = await this.methodHandler.callMethod({ - name: 'prepareTransaction', + name: 'prepareSendOutputs', data: { outputs, options, @@ -1682,31 +1682,6 @@ export class Wallet { ); } - /** - * Send outputs in a transaction. - * - * @param outputs The outputs to send. - * @param transactionOptions Additional transaction options. - * @returns The sent transaction. - */ - async sendOutputs( - outputs: Output[], - transactionOptions?: TransactionOptions, - ): Promise { - const response = await this.methodHandler.callMethod({ - name: 'sendOutputs', - data: { - outputs, - options: transactionOptions, - }, - }); - - const parsed = JSON.parse( - response, - ) as Response; - return plainToInstance(TransactionWithMetadata, parsed.payload); - } - /** * Send mana. * diff --git a/bindings/python/iota_sdk/wallet/wallet.py b/bindings/python/iota_sdk/wallet/wallet.py index d83d2dc1c3..913266c607 100644 --- a/bindings/python/iota_sdk/wallet/wallet.py +++ b/bindings/python/iota_sdk/wallet/wallet.py @@ -701,18 +701,18 @@ def announce_candidacy(self, account_id: HexStr) -> BlockId: } )) - def send_transaction( + def send_outputs( self, outputs: List[Output], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata: - """Send a transaction. + """Send outputs. """ - return self.prepare_transaction(outputs, options).send() + return self.prepare_send_outputs(outputs, options).send() - def prepare_transaction( + def prepare_send_outputs( self, outputs: List[Output], options: Optional[TransactionOptions] = None) -> PreparedTransaction: - """Prepare transaction. + """Prepare to send outputs. """ prepared = PreparedTransactionData.from_dict(self._call_method( - 'prepareTransaction', { + 'prepareSendOutputs', { 'outputs': outputs, 'options': options } diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index dfdf141174..859f54cd42 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -284,7 +284,7 @@ where } } - self.prepare_transaction( + self.prepare_send_outputs( // We only need to provide the NFT outputs, ISA automatically creates basic outputs as remainder outputs nft_outputs_to_send, TransactionOptions { diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index e9e970fcd1..2fa9cf035e 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -107,7 +107,7 @@ where ..Default::default() }); - self.prepare_transaction([], options).await + self.prepare_send_outputs([], options).await } /// Determines whether an output should be consolidated or not. diff --git a/sdk/src/wallet/operations/participation/voting.rs b/sdk/src/wallet/operations/participation/voting.rs index 0979b21adf..efcf27f4a3 100644 --- a/sdk/src/wallet/operations/participation/voting.rs +++ b/sdk/src/wallet/operations/participation/voting.rs @@ -106,7 +106,7 @@ where ]) .finish_output()?; - self.prepare_transaction( + self.prepare_send_outputs( [new_output], Some(TransactionOptions { // Only use previous voting output as input. @@ -177,7 +177,7 @@ where ]) .finish_output()?; - self.prepare_transaction( + self.prepare_send_outputs( [new_output], Some(TransactionOptions { // Only use previous voting output as input. diff --git a/sdk/src/wallet/operations/participation/voting_power.rs b/sdk/src/wallet/operations/participation/voting_power.rs index 5514929c87..d9cf5958f9 100644 --- a/sdk/src/wallet/operations/participation/voting_power.rs +++ b/sdk/src/wallet/operations/participation/voting_power.rs @@ -77,7 +77,7 @@ where ), }; - self.prepare_transaction([new_output], tx_options).await + self.prepare_send_outputs([new_output], tx_options).await } /// Reduces an account's "voting power" by a given amount. @@ -114,7 +114,7 @@ where (new_output, Some(tagged_data_payload)) }; - self.prepare_transaction( + self.prepare_send_outputs( [new_output], Some(TransactionOptions { // Use the previous voting output and additionally others for possible additional required amount for diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 2141dd7dd4..6f2f7e7b56 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -103,7 +103,7 @@ where ..Default::default() }; - self.prepare_transaction(vec![account], transaction_options.clone()) + self.prepare_send_outputs(vec![account], transaction_options.clone()) .await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/allot_mana.rs b/sdk/src/wallet/operations/transaction/high_level/allot_mana.rs index d379a611e2..ed058556a1 100644 --- a/sdk/src/wallet/operations/transaction/high_level/allot_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/allot_mana.rs @@ -41,6 +41,6 @@ where *options.mana_allotments.entry(account_id).or_default() += mana; } - self.prepare_transaction([], options).await + self.prepare_send_outputs([], options).await } } 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..fdefd5f638 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 @@ -78,7 +78,7 @@ where )?)) .finish_output()?]; // Input selection will detect that we're melting native tokens and add the required inputs if available - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } /// Find and return unspent `OutputData` for given `account_id` and `foundry_id` 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..3e95f7da5f 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 @@ -41,6 +41,6 @@ impl Wallet { // The empty list of outputs is used. Outputs will be generated by // the input selection algorithm based on the content of the [`Burn`] object. - self.prepare_transaction([], options).await + self.prepare_send_outputs([], options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/create_account.rs b/sdk/src/wallet/operations/transaction/high_level/create_account.rs index 652da2da0d..e370b6d8ea 100644 --- a/sdk/src/wallet/operations/transaction/high_level/create_account.rs +++ b/sdk/src/wallet/operations/transaction/high_level/create_account.rs @@ -100,7 +100,7 @@ where let outputs = [account_output_builder.finish_output()?]; - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } /// Gets an existing account output. diff --git a/sdk/src/wallet/operations/transaction/high_level/delegation/create.rs b/sdk/src/wallet/operations/transaction/high_level/delegation/create.rs index e2b91ee592..8ea3dd5a99 100644 --- a/sdk/src/wallet/operations/transaction/high_level/delegation/create.rs +++ b/sdk/src/wallet/operations/transaction/high_level/delegation/create.rs @@ -104,7 +104,7 @@ where .add_unlock_condition(AddressUnlockCondition::new(address)) .finish_output()?; - let transaction = self.prepare_transaction([output], options).await?; + let transaction = self.prepare_send_outputs([output], options).await?; Ok(PreparedCreateDelegationTransaction { delegation_id: DelegationId::from(&transaction.transaction.id().into_output_id(0)), diff --git a/sdk/src/wallet/operations/transaction/high_level/delegation/delay.rs b/sdk/src/wallet/operations/transaction/high_level/delegation/delay.rs index ca4f9ea80a..4ae61d17fb 100644 --- a/sdk/src/wallet/operations/transaction/high_level/delegation/delay.rs +++ b/sdk/src/wallet/operations/transaction/high_level/delegation/delay.rs @@ -87,6 +87,6 @@ where } }; - self.prepare_transaction(outputs, None).await + self.prepare_send_outputs(outputs, None).await } } 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..327a2cc4cb 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 @@ -54,7 +54,7 @@ where { /// Creates a new foundry output with minted native tokens. /// - /// Calls [Wallet::prepare_transaction()](crate::wallet::Wallet::prepare_transaction) internally, the options may + /// Calls [Wallet::prepare_send_outputs()](crate::wallet::Wallet::prepare_send_outputs) internally, the options may /// define the remainder value strategy or custom inputs. /// ```ignore /// let params = CreateNativeTokenParams { @@ -143,7 +143,7 @@ where }, // Native Tokens will be added automatically in the remainder output in try_select_inputs() ]; - self.prepare_transaction(outputs, options) + self.prepare_send_outputs(outputs, options) .await .map(|transaction| PreparedCreateNativeTokenTransaction { token_id, transaction }) } else { 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..f66a98f4be 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 @@ -124,6 +124,6 @@ where // Native Tokens will be added automatically in the remainder output in try_select_inputs() ]; - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs index 3c91e692df..9ed458fc5c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs @@ -114,7 +114,7 @@ where { /// Mints NFTs. /// - /// Calls [Wallet::prepare_transaction()](crate::wallet::Wallet::prepare_transaction) internally. The options may + /// Calls [Wallet::prepare_send_outputs()](crate::wallet::Wallet::prepare_send_outputs) internally. The options may /// define the remainder value strategy or custom inputs. Note that addresses need to be bech32-encoded. /// ```ignore /// let nft_id: [u8; 38] = @@ -207,6 +207,6 @@ where outputs.push(nft_builder.finish_output()?); } - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index a177927306..c0f01ba382 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -198,6 +198,6 @@ where } } - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs index cad5629277..622e150478 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_mana.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_mana.rs @@ -90,6 +90,6 @@ where let output = output_builder.finish_output()?; - self.prepare_transaction(vec![output], options).await + self.prepare_send_outputs(vec![output], options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs index c1c153447c..a83aa8ebe8 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs @@ -173,6 +173,6 @@ where ) } - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, options).await } } diff --git a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs index ffc86ba9ae..eaaf057e73 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -48,7 +48,7 @@ where crate::client::Error: From, { /// Sends an NFT to the provided address. - /// Calls [Wallet::prepare_transaction()](crate::wallet::Wallet::prepare_transaction) internally. The + /// Calls [Wallet::prepare_send_outputs()](crate::wallet::Wallet::prepare_send_outputs) internally. The /// options may define the remainder value strategy. Note that custom inputs will be replaced with the required /// nft inputs and addresses need to be bech32-encoded. /// ```ignore @@ -109,6 +109,6 @@ where }; } - self.prepare_transaction(outputs, options).await + self.prepare_send_outputs(outputs, 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..109638ed8c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs @@ -98,7 +98,7 @@ where )) .finish_output()?; - let transaction = self.prepare_transaction([output], options).await?; + let transaction = self.prepare_send_outputs([output], options).await?; Ok(transaction) } 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..047bcce903 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/end.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/end.rs @@ -70,7 +70,7 @@ where .with_features(features) .finish_output()?; - let transaction = self.prepare_transaction([output], options).await?; + let transaction = self.prepare_send_outputs([output], options).await?; Ok(transaction) } 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..ff8871d663 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs @@ -85,7 +85,7 @@ where let output = output_builder.finish_output()?; - let transaction = self.prepare_transaction([output], options).await?; + let transaction = self.prepare_send_outputs([output], options).await?; Ok(transaction) } diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index c3a84671a5..4fbf4a432a 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -6,7 +6,7 @@ pub(crate) mod high_level; mod input_selection; mod options; pub(crate) mod prepare_output; -mod prepare_transaction; +mod prepare_send_outputs; mod sign_transaction; pub(crate) mod submit_transaction; @@ -67,7 +67,7 @@ where ) -> crate::wallet::Result { let outputs = outputs.into(); let options = options.into(); - // here to check before syncing, how to prevent duplicated verification (also in prepare_transaction())? + // here to check before syncing, how to prevent duplicated verification (also in prepare_send_outputs())? // Checking it also here is good to return earlier if something is invalid let protocol_parameters = self.client().get_protocol_parameters().await?; @@ -76,7 +76,7 @@ where output.verify_storage_deposit(protocol_parameters.storage_score_parameters())?; } - let prepared_transaction_data = self.prepare_transaction(outputs, options.clone()).await?; + let prepared_transaction_data = self.prepare_send_outputs(outputs, options.clone()).await?; self.sign_and_submit_transaction(prepared_transaction_data, options) .await diff --git a/sdk/src/wallet/operations/transaction/prepare_transaction.rs b/sdk/src/wallet/operations/transaction/prepare_send_outputs.rs similarity index 84% rename from sdk/src/wallet/operations/transaction/prepare_transaction.rs rename to sdk/src/wallet/operations/transaction/prepare_send_outputs.rs index 5deee7be6e..fee680e904 100644 --- a/sdk/src/wallet/operations/transaction/prepare_transaction.rs +++ b/sdk/src/wallet/operations/transaction/prepare_send_outputs.rs @@ -16,15 +16,15 @@ where crate::client::Error: From, { /// Get inputs and build the transaction - pub async fn prepare_transaction( + pub async fn prepare_send_outputs( &self, outputs: impl Into> + Send, options: impl Into> + Send, ) -> crate::wallet::Result { - log::debug!("[TRANSACTION] prepare_transaction"); + log::debug!("[TRANSACTION] prepare_send_outputs"); let options = options.into().unwrap_or_default(); let outputs = outputs.into(); - let prepare_transaction_start_time = Instant::now(); + let prepare_send_outputs_start_time = Instant::now(); let storage_score_params = self.client().get_storage_score_parameters().await?; // Check if the outputs have enough amount to cover the storage deposit @@ -41,8 +41,8 @@ where let prepared_transaction_data = self.select_inputs(outputs, options).await?; log::debug!( - "[TRANSACTION] finished prepare_transaction in {:.2?}", - prepare_transaction_start_time.elapsed() + "[TRANSACTION] finished prepare_send_outputs in {:.2?}", + prepare_send_outputs_start_time.elapsed() ); Ok(prepared_transaction_data) } From 71e61c46cbe7771eb0b3a3b85b06eda4e1c2194c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 5 Mar 2024 10:48:28 +0100 Subject: [PATCH 2/4] Remove duplicate --- bindings/python/iota_sdk/wallet/wallet.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/bindings/python/iota_sdk/wallet/wallet.py b/bindings/python/iota_sdk/wallet/wallet.py index 913266c607..eb8c8e6913 100644 --- a/bindings/python/iota_sdk/wallet/wallet.py +++ b/bindings/python/iota_sdk/wallet/wallet.py @@ -792,17 +792,6 @@ def prepare_send_nft(self, params: List[SendNftParams], )) return PreparedTransaction(self, prepared) - def send_outputs( - self, outputs: List[Output], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata: - """Send outputs in a transaction. - """ - return TransactionWithMetadata.from_dict(self._call_method( - 'sendOutputs', { - 'outputs': outputs, - 'options': options, - } - )) - def send_mana( self, params: SendManaParams, options: Optional[TransactionOptions] = None) -> TransactionWithMetadata: """Send mana. From 4fd26f3bd824d52eee364ae2366a539e3211cc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 5 Mar 2024 10:56:24 +0100 Subject: [PATCH 3/4] Fix export --- bindings/nodejs/lib/types/wallet/bridge/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/nodejs/lib/types/wallet/bridge/index.ts b/bindings/nodejs/lib/types/wallet/bridge/index.ts index 0c7628c57d..00e935d384 100644 --- a/bindings/nodejs/lib/types/wallet/bridge/index.ts +++ b/bindings/nodejs/lib/types/wallet/bridge/index.ts @@ -31,7 +31,7 @@ import type { __PrepareBeginStakingMethod__, __PrepareExtendStakingMethod__, __PrepareEndStakingMethod__, - __PrepareTransactionMethod__, + __PrepareSendOutputsMethod__, __RegisterParticipationEventsMethod__, __WaitForTransactionAcceptanceMethod__, __SendMethod__, @@ -112,7 +112,7 @@ export type __WalletMethod__ = | __PrepareBeginStakingMethod__ | __PrepareExtendStakingMethod__ | __PrepareEndStakingMethod__ - | __PrepareTransactionMethod__ + | __PrepareSendOutputsMethod__ | __RegisterParticipationEventsMethod__ | __WaitForTransactionAcceptanceMethod__ | __SendMethod__ From 23b540316fbdc3473c5b134981a766ce8b80c78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Tue, 5 Mar 2024 12:15:25 +0100 Subject: [PATCH 4/4] Rename file and move send_outputs() --- sdk/src/wallet/operations/transaction/mod.rs | 55 +---------- .../transaction/prepare_send_outputs.rs | 45 --------- .../operations/transaction/send_outputs.rs | 97 +++++++++++++++++++ 3 files changed, 99 insertions(+), 98 deletions(-) delete mode 100644 sdk/src/wallet/operations/transaction/prepare_send_outputs.rs create mode 100644 sdk/src/wallet/operations/transaction/send_outputs.rs diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 4f35dc946f..01131871b8 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -6,7 +6,7 @@ pub(crate) mod high_level; mod input_selection; mod options; pub(crate) mod prepare_output; -mod prepare_send_outputs; +mod send_outputs; mod sign_transaction; pub(crate) mod submit_transaction; @@ -19,10 +19,7 @@ use crate::{ secret::SecretManage, ClientError, }, - types::block::{ - output::{Output, OutputWithMetadata}, - payload::signed_transaction::SignedTransactionPayload, - }, + types::block::{output::OutputWithMetadata, payload::signed_transaction::SignedTransactionPayload}, wallet::{ types::{InclusionState, TransactionWithMetadata}, Wallet, WalletError, @@ -34,54 +31,6 @@ where WalletError: From, ClientError: From, { - /// Sends a transaction by specifying its outputs. - /// - /// Note that, if sending a block fails, the method will return `None` for the block id, but the wallet - /// will reissue the transaction during syncing. - /// ```ignore - /// let outputs = [ - /// BasicOutputBuilder::new_with_amount(1_000_000)? - /// .add_unlock_condition(AddressUnlockCondition::new( - /// Address::try_from_bech32("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu")?, - /// )) - /// .finish_output(account.client.get_token_supply().await?;)?, - /// ]; - /// let tx = account - /// .send_outputs( - /// outputs, - /// Some(TransactionOptions { - /// remainder_value_strategy: RemainderValueStrategy::ReuseAddress, - /// ..Default::default() - /// }), - /// ) - /// .await?; - /// println!("Transaction created: {}", tx.transaction_id); - /// if let Some(block_id) = tx.block_id { - /// println!("Block sent: {}", block_id); - /// } - /// ``` - pub async fn send_outputs( - &self, - outputs: impl Into> + Send, - options: impl Into> + Send, - ) -> Result { - let outputs = outputs.into(); - let options = options.into(); - // here to check before syncing, how to prevent duplicated verification (also in prepare_send_outputs())? - // Checking it also here is good to return earlier if something is invalid - let protocol_parameters = self.client().get_protocol_parameters().await?; - - // Check if the outputs have enough amount to cover the storage deposit - for output in &outputs { - output.verify_storage_deposit(protocol_parameters.storage_score_parameters())?; - } - - let prepared_transaction_data = self.prepare_send_outputs(outputs, options.clone()).await?; - - self.sign_and_submit_transaction(prepared_transaction_data, options) - .await - } - /// Signs a transaction, submit it to a node and store it in the wallet pub async fn sign_and_submit_transaction( &self, diff --git a/sdk/src/wallet/operations/transaction/prepare_send_outputs.rs b/sdk/src/wallet/operations/transaction/prepare_send_outputs.rs deleted file mode 100644 index ea83f0ebe7..0000000000 --- a/sdk/src/wallet/operations/transaction/prepare_send_outputs.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2024 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use instant::Instant; -use packable::bounded::TryIntoBoundedU16Error; - -use crate::{ - client::{api::PreparedTransactionData, secret::SecretManage}, - types::block::{input::INPUT_COUNT_MAX, output::Output, payload::PayloadError}, - wallet::{operations::transaction::TransactionOptions, Wallet, WalletError}, -}; - -impl Wallet { - /// Get inputs and build the transaction - pub async fn prepare_send_outputs( - &self, - outputs: impl Into> + Send, - options: impl Into> + Send, - ) -> Result { - log::debug!("[TRANSACTION] prepare_send_outputs"); - let options = options.into().unwrap_or_default(); - let outputs = outputs.into(); - let prepare_send_outputs_start_time = Instant::now(); - let storage_score_params = self.client().get_storage_score_parameters().await?; - - // Check if the outputs have enough amount to cover the storage deposit - for output in &outputs { - output.verify_storage_deposit(storage_score_params)?; - } - - if options.required_inputs.len() as u16 > INPUT_COUNT_MAX { - return Err(PayloadError::InputCount(TryIntoBoundedU16Error::Truncated( - options.required_inputs.len(), - )))?; - } - - let prepared_transaction_data = self.select_inputs(outputs, options).await?; - - log::debug!( - "[TRANSACTION] finished prepare_send_outputs in {:.2?}", - prepare_send_outputs_start_time.elapsed() - ); - Ok(prepared_transaction_data) - } -} diff --git a/sdk/src/wallet/operations/transaction/send_outputs.rs b/sdk/src/wallet/operations/transaction/send_outputs.rs new file mode 100644 index 0000000000..8f32a81c21 --- /dev/null +++ b/sdk/src/wallet/operations/transaction/send_outputs.rs @@ -0,0 +1,97 @@ +// Copyright 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use instant::Instant; +use packable::bounded::TryIntoBoundedU16Error; + +use crate::{ + client::{api::PreparedTransactionData, secret::SecretManage, ClientError}, + types::block::{input::INPUT_COUNT_MAX, output::Output, payload::PayloadError}, + wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Wallet, WalletError}, +}; + +impl Wallet +where + WalletError: From, + ClientError: From, +{ + /// Sends a transaction by specifying its outputs. + /// + /// Note that, if sending a block fails, the method will return `None` for the block id, but the wallet + /// will reissue the transaction during syncing. + /// ```ignore + /// let outputs = [ + /// BasicOutputBuilder::new_with_amount(1_000_000)? + /// .add_unlock_condition(AddressUnlockCondition::new( + /// Address::try_from_bech32("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu")?, + /// )) + /// .finish_output(account.client.get_token_supply().await?;)?, + /// ]; + /// let tx = account + /// .send_outputs( + /// outputs, + /// Some(TransactionOptions { + /// remainder_value_strategy: RemainderValueStrategy::ReuseAddress, + /// ..Default::default() + /// }), + /// ) + /// .await?; + /// println!("Transaction created: {}", tx.transaction_id); + /// if let Some(block_id) = tx.block_id { + /// println!("Block sent: {}", block_id); + /// } + /// ``` + pub async fn send_outputs( + &self, + outputs: impl Into> + Send, + options: impl Into> + Send, + ) -> Result { + let outputs = outputs.into(); + let options = options.into(); + // here to check before syncing, how to prevent duplicated verification (also in prepare_send_outputs())? + // Checking it also here is good to return earlier if something is invalid + let protocol_parameters = self.client().get_protocol_parameters().await?; + + // Check if the outputs have enough amount to cover the storage deposit + for output in &outputs { + output.verify_storage_deposit(protocol_parameters.storage_score_parameters())?; + } + + let prepared_transaction_data = self.prepare_send_outputs(outputs, options.clone()).await?; + + self.sign_and_submit_transaction(prepared_transaction_data, options) + .await + } + + /// Get inputs and build the transaction + pub async fn prepare_send_outputs( + &self, + outputs: impl Into> + Send, + options: impl Into> + Send, + ) -> Result { + log::debug!("[TRANSACTION] prepare_send_outputs"); + let options = options.into().unwrap_or_default(); + let outputs = outputs.into(); + let prepare_send_outputs_start_time = Instant::now(); + let storage_score_params = self.client().get_storage_score_parameters().await?; + + // Check if the outputs have enough amount to cover the storage deposit + for output in &outputs { + output.verify_storage_deposit(storage_score_params)?; + } + + if options.required_inputs.len() as u16 > INPUT_COUNT_MAX { + return Err(PayloadError::InputCount(TryIntoBoundedU16Error::Truncated( + options.required_inputs.len(), + )))?; + } + + let prepared_transaction_data = self.select_inputs(outputs, options).await?; + + log::debug!( + "[TRANSACTION] finished prepare_send_outputs in {:.2?}", + prepare_send_outputs_start_time.elapsed() + ); + Ok(prepared_transaction_data) + } +}