node: change a tx-relay on/off flag to enum

Previously the `bool relay` argument to `BroadcastTransaction()`
designated:

```
relay=true: add to the mempool and broadcast to all peers
relay=false: add to the mempool
```

Change this to an `enum`, so it is more readable and easier to extend
with a 3rd option. Consider these example call sites:

```cpp
Paint(true);
// Or
Paint(/*is_red=*/true);
```

vs

```cpp
Paint(RED);
```

The idea for putting `TxBroadcastMethod` into `node/types.h` by Ryan.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
Vasil Dimov
2024-01-25 17:06:30 +01:00
parent 919e6d01e9
commit 07a926474b
10 changed files with 116 additions and 44 deletions

View File

@@ -363,7 +363,12 @@ public:
}
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);
return BroadcastTransaction(*m_context,
std::move(tx),
err_string,
max_tx_fee,
TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL,
/*wait_callback=*/false);
}
WalletLoader& walletLoader() override
{
@@ -672,10 +677,10 @@ public:
}
bool broadcastTransaction(const CTransactionRef& tx,
const CAmount& max_tx_fee,
bool relay,
TxBroadcast broadcast_method,
std::string& err_string) override
{
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback=*/false);
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, broadcast_method, /*wait_callback=*/false);
// Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
// Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
// that Chain clients do not need to know about.