Skip to content

Commit

Permalink
Set issuer of sent blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Dec 4, 2023
1 parent 5b36631 commit 0677426
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 29 deletions.
3 changes: 2 additions & 1 deletion bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,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))
Expand All @@ -388,7 +389,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))
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/examples/wallet/offline_signing/3_send_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
12 changes: 9 additions & 3 deletions sdk/src/wallet/operations/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ where
crate::wallet::Error: From<S::Error>,
crate::client::Error: From<S::Error>,
{
pub(crate) async fn submit_basic_block(&self, payload: Option<Payload>) -> Result<BlockId> {
pub(crate) async fn submit_basic_block(
&self,
payload: Option<Payload>,
issuer_id: impl Into<Option<AccountId>> + Send,
) -> Result<BlockId> {
log::debug!("submit_basic_block");

// TODO
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,
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/wallet/operations/output_claiming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {:?}",
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/wallet/operations/output_consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ where
/// transaction.
pub async fn consolidate_outputs(&self, params: ConsolidationParams) -> Result<TransactionWithMetadata> {
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: {:?}",
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/wallet/operations/participation/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
) -> Result<TransactionWithMetadata> {
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()].
Expand Down Expand Up @@ -131,7 +131,7 @@ where
pub async fn stop_participating(&self, event_id: ParticipationEventId) -> Result<TransactionWithMetadata> {
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()].
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/wallet/operations/participation/voting_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
pub async fn increase_voting_power(&self, amount: u64) -> Result<TransactionWithMetadata> {
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()].
Expand Down Expand Up @@ -92,7 +92,7 @@ where
pub async fn decrease_voting_power(&self, amount: u64) -> Result<TransactionWithMetadata> {
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()].
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/wallet/operations/syncing/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/src/wallet/operations/transaction/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ where
{
/// Transitions an implicit account to an account.
pub async fn implicit_account_transition(&self, output_id: &OutputId) -> Result<TransactionWithMetadata> {
self.sign_and_submit_transaction(self.prepare_implicit_account_transition(output_id).await?, None)
.await
let issuer_id = AccountId::from(output_id);

self.sign_and_submit_transaction(
self.prepare_implicit_account_transition(output_id).await?,
issuer_id,
None,
)
.await
}

/// Prepares to transition an implicit account to an account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/wallet/operations/transaction/high_level/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/wallet/operations/transaction/high_level/send_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()].
Expand Down
13 changes: 9 additions & 4 deletions sdk/src/wallet/operations/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -89,14 +92,15 @@ 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
}

/// Signs a transaction, submit it to a node and store it in the wallet
pub async fn sign_and_submit_transaction(
&self,
prepared_transaction_data: PreparedTransactionData,
issuer_id: impl Into<Option<AccountId>> + Send,
options: impl Into<Option<TransactionOptions>> + Send,
) -> crate::wallet::Result<TransactionWithMetadata> {
log::debug!("[TRANSACTION] sign_and_submit_transaction");
Expand All @@ -110,14 +114,15 @@ where
}
};

self.submit_and_store_transaction(signed_transaction_data, options)
self.submit_and_store_transaction(signed_transaction_data, issuer_id, options)
.await
}

/// Validates the transaction, submit it to a node and store it in the wallet
pub async fn submit_and_store_transaction(
&self,
signed_transaction_data: SignedTransactionData,
issuer_id: impl Into<Option<AccountId>> + Send,
options: impl Into<Option<TransactionOptions>> + Send,
) -> crate::wallet::Result<TransactionWithMetadata> {
log::debug!(
Expand All @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/wallet/operations/transaction/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -18,13 +18,14 @@ where
pub(crate) async fn submit_signed_transaction(
&self,
payload: SignedTransactionPayload,
issuer_id: impl Into<Option<AccountId>> + Send,
) -> crate::wallet::Result<BlockId> {
log::debug!("[TRANSACTION] submit_signed_transaction");

#[cfg(feature = "events")]
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
}
}

0 comments on commit 0677426

Please sign in to comment.