Skip to content

Commit

Permalink
Merge pull request #1690 from mintlayer/fix/gui-wallet-tx-broadcast
Browse files Browse the repository at this point in the history
fix broadcast function used by the gui wallet
  • Loading branch information
TheQuantumPhysicist authored Mar 23, 2024
2 parents 5ac6177 + 57272d1 commit 3f5a870
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions wallet/wallet-controller/src/synced_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,20 +860,31 @@ impl<'a, T: NodeInterface, W: WalletEvents> SyncedController<'a, T, W> {
&mut self,
tx: SignedTransaction,
) -> Result<SignedTransaction, ControllerError<T>> {
if self.config.broadcast_to_mempool {
self.wallet
.add_account_unconfirmed_tx(self.account_index, tx.clone(), self.wallet_events)
.map_err(ControllerError::WalletError)?;

self.rpc_client
.submit_transaction(tx.clone(), Default::default())
.await
.map_err(ControllerError::NodeCallError)?;
}
self.wallet
.add_account_unconfirmed_tx(self.account_index, tx.clone(), self.wallet_events)
.map_err(ControllerError::WalletError)?;

self.rpc_client
.submit_transaction(tx.clone(), Default::default())
.await
.map_err(ControllerError::NodeCallError)?;

Ok(tx)
}

/// Broadcast to the mempool if specified by the controller config
/// sometimes broadcasting is disabled when a prior confirmation is needed
async fn broadcast_to_mempool_if_needed(
&mut self,
tx: SignedTransaction,
) -> Result<SignedTransaction, ControllerError<T>> {
if self.config.broadcast_to_mempool {
self.broadcast_to_mempool(tx).await
} else {
Ok(tx)
}
}

/// Create a transaction and broadcast it
async fn create_and_send_tx<
F: FnOnce(FeeRate, FeeRate, &mut DefaultWallet, U31) -> WalletResult<SignedTransaction>,
Expand All @@ -892,7 +903,7 @@ impl<'a, T: NodeInterface, W: WalletEvents> SyncedController<'a, T, W> {
)
.map_err(ControllerError::WalletError)?;

self.broadcast_to_mempool(tx).await
self.broadcast_to_mempool_if_needed(tx).await
}

/// Create and broadcast a transaction that uses token,
Expand Down Expand Up @@ -933,7 +944,7 @@ impl<'a, T: NodeInterface, W: WalletEvents> SyncedController<'a, T, W> {
)
.map_err(ControllerError::WalletError)?;

self.broadcast_to_mempool(tx).await
self.broadcast_to_mempool_if_needed(tx).await
}

/// Similar to create_and_send_tx but some transactions also create an ID
Expand All @@ -956,7 +967,7 @@ impl<'a, T: NodeInterface, W: WalletEvents> SyncedController<'a, T, W> {
)
.map_err(ControllerError::WalletError)?;

let tx_id = self.broadcast_to_mempool(tx).await?;
let tx_id = self.broadcast_to_mempool_if_needed(tx).await?;
Ok((tx_id, id))
}

Expand Down

0 comments on commit 3f5a870

Please sign in to comment.