1212
1313#include < future>
1414
15- const char * TransactionErrorString (const TransactionError err)
15+ std::string TransactionErrorString (const TransactionError err)
1616{
1717 switch (err) {
1818 case TransactionError::OK:
@@ -33,22 +33,16 @@ const char* TransactionErrorString(const TransactionError err)
3333 return " PSBTs not compatible (different transactions)" ;
3434 case TransactionError::SIGHASH_MISMATCH:
3535 return " Specified sighash value does not match existing value" ;
36-
37- case TransactionError::UNKNOWN_ERROR:
38- default : break ;
36+ // no default case, so the compiler can warn about missing cases
3937 }
40- return " Unknown error " ;
38+ assert ( false ) ;
4139}
4240
43- bool BroadcastTransaction (const CTransactionRef tx, uint256& hashTx, TransactionError& error, std::string& err_string, const bool allowhighfees )
41+ TransactionError BroadcastTransaction (const CTransactionRef tx, uint256& hashTx, std::string& err_string, const CAmount& highfee )
4442{
4543 std::promise<void > promise;
4644 hashTx = tx->GetHash ();
4745
48- CAmount nMaxRawTxFee = maxTxFee;
49- if (allowhighfees)
50- nMaxRawTxFee = 0 ;
51-
5246 { // cs_main scope
5347 LOCK (cs_main);
5448 CCoinsViewCache &view = *pcoinsTip;
@@ -63,19 +57,16 @@ bool BroadcastTransaction(const CTransactionRef tx, uint256& hashTx, Transaction
6357 CValidationState state;
6458 bool fMissingInputs ;
6559 if (!AcceptToMemoryPool (mempool, state, std::move (tx), &fMissingInputs ,
66- nullptr /* plTxnReplaced */ , false /* bypass_limits */ , nMaxRawTxFee )) {
60+ nullptr /* plTxnReplaced */ , false /* bypass_limits */ , highfee )) {
6761 if (state.IsInvalid ()) {
6862 err_string = FormatStateMessage (state);
69- error = TransactionError::MEMPOOL_REJECTED;
70- return false ;
63+ return TransactionError::MEMPOOL_REJECTED;
7164 } else {
7265 if (fMissingInputs ) {
73- error = TransactionError::MISSING_INPUTS;
74- return false ;
66+ return TransactionError::MISSING_INPUTS;
7567 }
7668 err_string = FormatStateMessage (state);
77- error = TransactionError::MEMPOOL_ERROR;
78- return false ;
69+ return TransactionError::MEMPOOL_ERROR;
7970 }
8071 } else {
8172 // If wallet is enabled, ensure that the wallet has been made aware
@@ -88,8 +79,7 @@ bool BroadcastTransaction(const CTransactionRef tx, uint256& hashTx, Transaction
8879 });
8980 }
9081 } else if (fHaveChain ) {
91- error = TransactionError::ALREADY_IN_CHAIN;
92- return false ;
82+ return TransactionError::ALREADY_IN_CHAIN;
9383 } else {
9484 // Make sure we don't block forever if re-sending
9585 // a transaction already in mempool.
@@ -100,16 +90,14 @@ bool BroadcastTransaction(const CTransactionRef tx, uint256& hashTx, Transaction
10090
10191 promise.get_future ().wait ();
10292
103- if (!g_connman) {
104- error = TransactionError::P2P_DISABLED;
105- return false ;
93+ if (!g_connman) {
94+ return TransactionError::P2P_DISABLED;
10695 }
10796
10897 CInv inv (MSG_TX, hashTx);
109- g_connman->ForEachNode ([&inv](CNode* pnode)
110- {
98+ g_connman->ForEachNode ([&inv](CNode* pnode) {
11199 pnode->PushInventory (inv);
112100 });
113101
114- return true ;
115- }
102+ return TransactionError::OK ;
103+ }
0 commit comments