multiprocess: Add interfaces::Node::broadCastTransaction method

This fixes a null pointer crash in the bitcoin-gui PSBT dialog. The
bitcoin-gui interfaces::Node object has a null NodeContext pointer, and
can't broadcast transactions directly. It needs to broadcast
transactions through the bitcoin-node process instead.
This commit is contained in:
Russell Yanofsky 2021-11-12 15:20:53 -05:00
parent c9dd5c8d6e
commit 0e0f4fdd89
3 changed files with 10 additions and 2 deletions

View file

@ -31,6 +31,7 @@ class RPCTimerInterface;
class UniValue; class UniValue;
class proxyType; class proxyType;
enum class SynchronizationState; enum class SynchronizationState;
enum class TransactionError;
struct CNodeStateStats; struct CNodeStateStats;
struct NodeContext; struct NodeContext;
struct bilingual_str; struct bilingual_str;
@ -174,6 +175,9 @@ public:
//! Get unspent outputs associated with a transaction. //! Get unspent outputs associated with a transaction.
virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0; virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
//! Broadcast transaction.
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
//! Get wallet client. //! Get wallet client.
virtual WalletClient& walletClient() = 0; virtual WalletClient& walletClient() = 0;

View file

@ -261,6 +261,10 @@ public:
LOCK(::cs_main); LOCK(::cs_main);
return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin); return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin);
} }
TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) override
{
return BroadcastTransaction(*m_context, std::move(tx), err_string, max_tx_fee, /*relay=*/ true, /*wait_callback=*/ false);
}
WalletClient& walletClient() override WalletClient& walletClient() override
{ {
return *Assert(m_context->wallet_client); return *Assert(m_context->wallet_client);

View file

@ -110,8 +110,8 @@ void PSBTOperationsDialog::broadcastTransaction()
CTransactionRef tx = MakeTransactionRef(mtx); CTransactionRef tx = MakeTransactionRef(mtx);
std::string err_string; std::string err_string;
TransactionError error = BroadcastTransaction( TransactionError error =
*m_client_model->node().context(), tx, err_string, DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK(), /* relay */ true, /* await_callback */ false); m_client_model->node().broadcastTransaction(tx, DEFAULT_MAX_RAW_TX_FEE_RATE.GetFeePerK(), err_string);
if (error == TransactionError::OK) { if (error == TransactionError::OK) {
showStatus(tr("Transaction broadcast successfully! Transaction ID: %1") showStatus(tr("Transaction broadcast successfully! Transaction ID: %1")