diff --git a/src/node/transaction.h b/src/node/transaction.h --- a/src/node/transaction.h +++ b/src/node/transaction.h @@ -1,10 +1,11 @@ -// Copyright (c) 2017-2018 The Bitcoin Core developers +// Copyright (c) 2017-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_NODE_TRANSACTION_H #define BITCOIN_NODE_TRANSACTION_H +#include #include #include @@ -16,14 +17,15 @@ * * @param[in] tx the transaction to broadcast * @param[out] &txid the txid of the transaction, if successfully broadcast - * @param[out] &error reference to UniValue to fill with error info on failure - * @param[out] &err_string reference to std::string to fill with error string if - * available - * @param[in] allowhighfees whether to allow fees exceeding maxTxFee - * return true on success, false on error (and fills in `error`) + * @param[out] &err_string reference to std::string to fill with error string + * if available + * @param[in] highfee Reject txs with fees higher than this (if 0, accept any + * fee) + * @return error */ -bool BroadcastTransaction(const Config &config, CTransactionRef tx, TxId &txid, - TransactionError &error, std::string &err_string, - bool allowhighfees = false); +NODISCARD TransactionError BroadcastTransaction(const Config &config, + CTransactionRef tx, TxId &txid, + std::string &err_string, + Amount highfee); #endif // BITCOIN_NODE_TRANSACTION_H diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -16,17 +16,13 @@ #include -bool BroadcastTransaction(const Config &config, const CTransactionRef tx, - TxId &txid, TransactionError &error, - std::string &err_string, const bool allowhighfees) { +TransactionError BroadcastTransaction(const Config &config, + const CTransactionRef tx, TxId &txid, + std::string &err_string, + const Amount highFee) { std::promise promise; txid = tx->GetId(); - Amount nMaxRawTxFee = maxTxFee; - if (allowhighfees) { - nMaxRawTxFee = Amount::zero(); - } - { // cs_main scope LOCK(cs_main); CCoinsViewCache &view = *pcoinsTip; @@ -43,21 +39,18 @@ bool fMissingInputs; if (!AcceptToMemoryPool(config, g_mempool, state, std::move(tx), &fMissingInputs, false /* bypass_limits */, - nMaxRawTxFee)) { + highFee)) { if (state.IsInvalid()) { err_string = FormatStateMessage(state); - error = TransactionError::MEMPOOL_REJECTED; - return false; + return TransactionError::MEMPOOL_REJECTED; } if (fMissingInputs) { - error = TransactionError::MISSING_INPUTS; - return false; + return TransactionError::MISSING_INPUTS; } err_string = FormatStateMessage(state); - error = TransactionError::MEMPOOL_ERROR; - return false; + return TransactionError::MEMPOOL_ERROR; } else { // If wallet is enabled, ensure that the wallet has been made // aware of the new transaction prior to returning. This @@ -69,8 +62,7 @@ [&promise] { promise.set_value(); }); } } else if (fHaveChain) { - error = TransactionError::ALREADY_IN_CHAIN; - return false; + return TransactionError::ALREADY_IN_CHAIN; } else { // Make sure we don't block forever if re-sending a transaction // already in mempool. @@ -81,12 +73,11 @@ promise.get_future().wait(); if (!g_connman) { - error = TransactionError::P2P_DISABLED; - return false; + return TransactionError::P2P_DISABLED; } CInv inv(MSG_TX, txid); g_connman->ForEachNode([&inv](CNode *pnode) { pnode->PushInventory(inv); }); - return true; + return TransactionError::OK; } diff --git a/src/psbt.h b/src/psbt.h --- a/src/psbt.h +++ b/src/psbt.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2018 The Bitcoin Core developers +// Copyright (c) 2009-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -507,13 +507,12 @@ * PSBT with all partial signatures from each input. * * @param[out] &out the combined PSBT, if successful - * @param[out] &error reference to TransactionError to fill with error info on - * failure * @param[in] psbtxs the PSBTs to combine - * @return True if we successfully combined the transactions, false if they were - * not compatible + * @return error (OK if we successfully combined the transactions, other error + * if they were not compatible) */ -bool CombinePSBTs(PartiallySignedTransaction &out, TransactionError &error, - const std::vector &psbtxs); +NODISCARD TransactionError +CombinePSBTs(PartiallySignedTransaction &out, + const std::vector &psbtxs); #endif // BITCOIN_PSBT_H diff --git a/src/psbt.cpp b/src/psbt.cpp --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -208,22 +208,21 @@ return true; } -bool CombinePSBTs(PartiallySignedTransaction &out, TransactionError &error, - const std::vector &psbtxs) { +TransactionError +CombinePSBTs(PartiallySignedTransaction &out, + const std::vector &psbtxs) { // Copy the first one out = psbtxs[0]; // Merge for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) { if (!out.Merge(*it)) { - error = TransactionError::PSBT_MISMATCH; - return false; + return TransactionError::PSBT_MISMATCH; } } if (!out.IsSane()) { - error = TransactionError::INVALID_PSBT; - return false; + return TransactionError::INVALID_PSBT; } - return true; + return TransactionError::OK; } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -29,6 +29,7 @@ #include