From 6436bd08fb665485b04eb83eb467f9d139a04d41 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 5 Dec 2023 09:40:57 +0100 Subject: [PATCH] Set issuer of sent blocks (#1738) * Set issuer of sent blocks * Add link to TODO --- bindings/core/src/method_handler/wallet.rs | 3 ++- .../wallet/offline_signing/3_send_transaction.rs | 2 +- sdk/src/wallet/operations/block.rs | 12 +++++++++--- sdk/src/wallet/operations/output_claiming.rs | 4 +++- sdk/src/wallet/operations/output_consolidation.rs | 4 +++- sdk/src/wallet/operations/participation/voting.rs | 4 ++-- .../wallet/operations/participation/voting_power.rs | 4 ++-- sdk/src/wallet/operations/syncing/transactions.rs | 4 +++- sdk/src/wallet/operations/transaction/account.rs | 3 +++ .../high_level/burning_melting/melt_native_token.rs | 3 ++- .../transaction/high_level/burning_melting/mod.rs | 2 +- .../transaction/high_level/create_account.rs | 3 ++- .../high_level/minting/create_native_token.rs | 2 +- .../high_level/minting/mint_native_token.rs | 2 +- .../transaction/high_level/minting/mint_nfts.rs | 3 ++- .../operations/transaction/high_level/send.rs | 3 ++- .../transaction/high_level/send_native_tokens.rs | 3 ++- .../operations/transaction/high_level/send_nft.rs | 3 ++- sdk/src/wallet/operations/transaction/mod.rs | 13 +++++++++---- .../operations/transaction/submit_transaction.rs | 5 +++-- 20 files changed, 55 insertions(+), 27 deletions(-) diff --git a/bindings/core/src/method_handler/wallet.rs b/bindings/core/src/method_handler/wallet.rs index 2b3910ea0c..3b088222e0 100644 --- a/bindings/core/src/method_handler/wallet.rs +++ b/bindings/core/src/method_handler/wallet.rs @@ -381,6 +381,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM &wallet.client().get_protocol_parameters().await?, )?, None, + None, ) .await?; Response::SentTransaction(TransactionWithMetadataDto::from(&transaction)) @@ -401,7 +402,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM &wallet.client().get_protocol_parameters().await?, )?; let transaction = wallet - .submit_and_store_transaction(signed_transaction_data, None) + .submit_and_store_transaction(signed_transaction_data, None, None) .await?; Response::SentTransaction(TransactionWithMetadataDto::from(&transaction)) } diff --git a/sdk/examples/wallet/offline_signing/3_send_transaction.rs b/sdk/examples/wallet/offline_signing/3_send_transaction.rs index 5a108b9fbc..9763aec488 100644 --- a/sdk/examples/wallet/offline_signing/3_send_transaction.rs +++ b/sdk/examples/wallet/offline_signing/3_send_transaction.rs @@ -43,7 +43,7 @@ async fn main() -> Result<()> { // Sends offline signed transaction online. let transaction = wallet - .submit_and_store_transaction(signed_transaction_data, None) + .submit_and_store_transaction(signed_transaction_data, None, None) .await?; wait_for_inclusion(&transaction.transaction_id, &wallet).await?; diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 93f1a63914..d0e988ab60 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -12,13 +12,19 @@ where crate::wallet::Error: From, crate::client::Error: From, { - pub(crate) async fn submit_basic_block(&self, payload: Option) -> Result { + pub(crate) async fn submit_basic_block( + &self, + payload: Option, + issuer_id: impl Into> + Send, + ) -> Result { log::debug!("submit_basic_block"); + // TODO https://github.com/iotaledger/iota-sdk/issues/1741 + let issuer_id = issuer_id.into().unwrap_or(AccountId::null()); + let block = self .client() - // TODO https://github.com/iotaledger/iota-sdk/issues/1665 to set AccountId - .build_basic_block(AccountId::null(), payload) + .build_basic_block(issuer_id, payload) .await? .sign_ed25519( &*self.get_secret_manager().read().await, diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index f966eee27e..fa64145091 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -203,7 +203,9 @@ where } })?; - let claim_tx = self.sign_and_submit_transaction(prepared_transaction, None).await?; + let claim_tx = self + .sign_and_submit_transaction(prepared_transaction, None, None) + .await?; log::debug!( "[OUTPUT_CLAIMING] Claiming transaction created: block_id: {:?} tx_id: {:?}", diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index c07c70195f..fdb29b815b 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -105,7 +105,9 @@ where /// transaction. pub async fn consolidate_outputs(&self, params: ConsolidationParams) -> Result { let prepared_transaction = self.prepare_consolidate_outputs(params).await?; - let consolidation_tx = self.sign_and_submit_transaction(prepared_transaction, None).await?; + let consolidation_tx = self + .sign_and_submit_transaction(prepared_transaction, None, None) + .await?; log::debug!( "[OUTPUT_CONSOLIDATION] consolidation transaction created: block_id: {:?} tx_id: {:?}", diff --git a/sdk/src/wallet/operations/participation/voting.rs b/sdk/src/wallet/operations/participation/voting.rs index 5da86d003a..b8642af3c6 100644 --- a/sdk/src/wallet/operations/participation/voting.rs +++ b/sdk/src/wallet/operations/participation/voting.rs @@ -41,7 +41,7 @@ where ) -> Result { let prepared = self.prepare_vote(event_id, answers).await?; - self.sign_and_submit_transaction(prepared, None).await + self.sign_and_submit_transaction(prepared, None, None).await } /// Prepares the transaction for [Wallet::vote()]. @@ -131,7 +131,7 @@ where pub async fn stop_participating(&self, event_id: ParticipationEventId) -> Result { let prepared = self.prepare_stop_participating(event_id).await?; - self.sign_and_submit_transaction(prepared, None).await + self.sign_and_submit_transaction(prepared, None, None).await } /// Prepares the transaction for [Wallet::stop_participating()]. diff --git a/sdk/src/wallet/operations/participation/voting_power.rs b/sdk/src/wallet/operations/participation/voting_power.rs index 4bf3a8c88b..550ffe64d9 100644 --- a/sdk/src/wallet/operations/participation/voting_power.rs +++ b/sdk/src/wallet/operations/participation/voting_power.rs @@ -44,7 +44,7 @@ where pub async fn increase_voting_power(&self, amount: u64) -> Result { let prepared = self.prepare_increase_voting_power(amount).await?; - self.sign_and_submit_transaction(prepared, None).await + self.sign_and_submit_transaction(prepared, None, None).await } /// Prepares the transaction for [Wallet::increase_voting_power()]. @@ -92,7 +92,7 @@ where pub async fn decrease_voting_power(&self, amount: u64) -> Result { let prepared = self.prepare_decrease_voting_power(amount).await?; - self.sign_and_submit_transaction(prepared, None).await + self.sign_and_submit_transaction(prepared, None, None).await } /// Prepares the transaction for [Wallet::decrease_voting_power()]. diff --git a/sdk/src/wallet/operations/syncing/transactions.rs b/sdk/src/wallet/operations/syncing/transactions.rs index 890e78e041..609dff8c62 100644 --- a/sdk/src/wallet/operations/syncing/transactions.rs +++ b/sdk/src/wallet/operations/syncing/transactions.rs @@ -202,7 +202,9 @@ where for mut transaction in transactions_to_reissue { log::debug!("[SYNC] reissue transaction"); - let reissued_block = self.submit_signed_transaction(transaction.payload.clone()).await?; + let reissued_block = self + .submit_signed_transaction(transaction.payload.clone(), None) + .await?; transaction.block_id.replace(reissued_block); updated_transactions.push(transaction); } diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 5e0138dc42..4e4800b4fa 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -31,8 +31,11 @@ where output_id: &OutputId, key_source: Option>, ) -> Result { + let issuer_id = AccountId::from(output_id); + self.sign_and_submit_transaction( self.prepare_implicit_account_transition(output_id, key_source).await?, + issuer_id, None, ) .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 9aafc1c92c..70cde54392 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 @@ -37,7 +37,8 @@ where .prepare_melt_native_token(token_id, melt_amount, options.clone()) .await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::melt_native_token()]. 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 809a4ee45e..3909c7c7f7 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 @@ -22,7 +22,7 @@ impl Wallet { let options = options.into(); let prepared = self.prepare_burn(burn, options.clone()).await?; - self.sign_and_submit_transaction(prepared, options).await + self.sign_and_submit_transaction(prepared, None, options).await } /// A generic `prepare_burn()` function that can be used to prepare the burn of native tokens, nfts, foundries and 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 944e0dd351..9ae930a68f 100644 --- a/sdk/src/wallet/operations/transaction/high_level/create_account.rs +++ b/sdk/src/wallet/operations/transaction/high_level/create_account.rs @@ -62,7 +62,8 @@ where let options = options.into(); let prepared_transaction = self.prepare_create_account_output(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::create_account_output()]. 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 554ecb6ac3..e74dbc10f4 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 @@ -117,7 +117,7 @@ where let options = options.into(); let prepared = self.prepare_create_native_token(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared.transaction, options) + self.sign_and_submit_transaction(prepared.transaction, None, options) .await .map(|transaction| CreateNativeTokenTransaction { token_id: prepared.token_id, 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 6288c1837b..4342e48b97 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 @@ -41,7 +41,7 @@ where let prepared = self .prepare_mint_native_token(token_id, mint_amount, options.clone()) .await?; - let transaction = self.sign_and_submit_transaction(prepared, options).await?; + let transaction = self.sign_and_submit_transaction(prepared, None, options).await?; Ok(transaction) } 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 28542e2503..613fd48d19 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 @@ -147,7 +147,8 @@ where let options = options.into(); let prepared_transaction = self.prepare_mint_nfts(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::mint_nfts()]. diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index 4f03b7a35b..f51d01afaf 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -121,7 +121,8 @@ where let options = options.into(); let prepared_transaction = self.prepare_send(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::send()]. 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 56a89ef771..255931a5f3 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 @@ -111,7 +111,8 @@ where let options = options.into(); let prepared_transaction = self.prepare_send_native_tokens(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::send_native_tokens()]. 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 b62a24b139..995de07b89 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -79,7 +79,8 @@ where let options = options.into(); let prepared_transaction = self.prepare_send_nft(params, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction, options).await + self.sign_and_submit_transaction(prepared_transaction, None, options) + .await } /// Prepares the transaction for [Wallet::send_nft()]. diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 82221ec46d..84fb9a78b2 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -20,7 +20,10 @@ use crate::{ }, types::{ api::core::OutputWithMetadataResponse, - block::{output::Output, payload::signed_transaction::SignedTransactionPayload}, + block::{ + output::{AccountId, Output}, + payload::signed_transaction::SignedTransactionPayload, + }, }, wallet::{ types::{InclusionState, TransactionWithMetadata}, @@ -89,7 +92,7 @@ where let prepared_transaction_data = self.prepare_transaction(outputs, options.clone()).await?; - self.sign_and_submit_transaction(prepared_transaction_data, options) + self.sign_and_submit_transaction(prepared_transaction_data, None, options) .await } @@ -97,6 +100,7 @@ where pub async fn sign_and_submit_transaction( &self, prepared_transaction_data: PreparedTransactionData, + issuer_id: impl Into> + Send, options: impl Into> + Send, ) -> crate::wallet::Result { log::debug!("[TRANSACTION] sign_and_submit_transaction"); @@ -110,7 +114,7 @@ where } }; - self.submit_and_store_transaction(signed_transaction_data, options) + self.submit_and_store_transaction(signed_transaction_data, issuer_id, options) .await } @@ -118,6 +122,7 @@ where pub async fn submit_and_store_transaction( &self, signed_transaction_data: SignedTransactionData, + issuer_id: impl Into> + Send, options: impl Into> + Send, ) -> crate::wallet::Result { log::debug!( @@ -141,7 +146,7 @@ where // Ignore errors from sending, we will try to send it again during [`sync_pending_transactions`] let block_id = match self - .submit_signed_transaction(signed_transaction_data.payload.clone()) + .submit_signed_transaction(signed_transaction_data.payload.clone(), issuer_id) .await { Ok(block_id) => Some(block_id), diff --git a/sdk/src/wallet/operations/transaction/submit_transaction.rs b/sdk/src/wallet/operations/transaction/submit_transaction.rs index bf202b44f8..3fffb31b7e 100644 --- a/sdk/src/wallet/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/operations/transaction/submit_transaction.rs @@ -5,7 +5,7 @@ use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::secret::SecretManage, - types::block::{payload::Payload, BlockId}, + types::block::{output::AccountId, payload::Payload, BlockId}, wallet::{operations::transaction::SignedTransactionPayload, Wallet}, }; @@ -18,6 +18,7 @@ where pub(crate) async fn submit_signed_transaction( &self, payload: SignedTransactionPayload, + issuer_id: impl Into> + Send, ) -> crate::wallet::Result { log::debug!("[TRANSACTION] submit_signed_transaction"); @@ -25,6 +26,6 @@ where self.emit(WalletEvent::TransactionProgress(TransactionProgressEvent::Broadcasting)) .await; - self.submit_basic_block(Some(Payload::from(payload))).await + self.submit_basic_block(Some(Payload::from(payload)), issuer_id).await } }