Skip to content

Commit fa9b60c

Browse files
author
MarcoFalke
committed
Remove unused TransactionError constants
1 parent 38989ab commit fa9b60c

File tree

9 files changed

+45
-70
lines changed

9 files changed

+45
-70
lines changed

src/node/transaction.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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+
}

src/node/transaction.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
// Copyright (c) 2017-2018 The Bitcoin Core developers
1+
// Copyright (c) 2017-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#ifndef BITCOIN_NODE_TRANSACTION_H
66
#define BITCOIN_NODE_TRANSACTION_H
77

8+
#include <attributes.h>
89
#include <primitives/transaction.h>
910
#include <uint256.h>
1011

1112
enum class TransactionError {
12-
OK = 0,
13-
UNKNOWN_ERROR,
14-
13+
OK, //!< No error
1514
MISSING_INPUTS,
1615
ALREADY_IN_CHAIN,
1716
P2P_DISABLED,
@@ -20,24 +19,19 @@ enum class TransactionError {
2019
INVALID_PSBT,
2120
PSBT_MISMATCH,
2221
SIGHASH_MISMATCH,
23-
24-
ERROR_COUNT
2522
};
2623

27-
#define TRANSACTION_ERR_LAST TransactionError::ERROR_COUNT
28-
29-
const char* TransactionErrorString(const TransactionError error);
24+
std::string TransactionErrorString(const TransactionError error);
3025

3126
/**
3227
* Broadcast a transaction
3328
*
3429
* @param[in] tx the transaction to broadcast
3530
* @param[out] &txid the txid of the transaction, if successfully broadcast
36-
* @param[out] &error reference to UniValue to fill with error info on failure
3731
* @param[out] &err_string reference to std::string to fill with error string if available
38-
* @param[in] allowhighfees whether to allow fees exceeding maxTxFee
39-
* return true on success, false on error (and fills in `error`)
32+
* @param[in] highfee Reject txs with fees higher than this (if 0, accept any fee)
33+
* return error
4034
*/
41-
bool BroadcastTransaction(CTransactionRef tx, uint256& txid, TransactionError& error, std::string& err_string, bool allowhighfees = false);
35+
NODISCARD TransactionError BroadcastTransaction(CTransactionRef tx, uint256& txid, std::string& err_string, const CAmount& highfee);
4236

4337
#endif // BITCOIN_NODE_TRANSACTION_H

src/psbt.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,19 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
263263
return true;
264264
}
265265

266-
bool CombinePSBTs(PartiallySignedTransaction& out, TransactionError& error, const std::vector<PartiallySignedTransaction>& psbtxs)
266+
TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs)
267267
{
268268
out = psbtxs[0]; // Copy the first one
269269

270270
// Merge
271271
for (auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
272272
if (!out.Merge(*it)) {
273-
error = TransactionError::PSBT_MISMATCH;
274-
return false;
273+
return TransactionError::PSBT_MISMATCH;
275274
}
276275
}
277276
if (!out.IsSane()) {
278-
error = TransactionError::INVALID_PSBT;
279-
return false;
277+
return TransactionError::INVALID_PSBT;
280278
}
281279

282-
return true;
280+
return TransactionError::OK;
283281
}

src/psbt.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2009-2018 The Bitcoin Core developers
1+
// Copyright (c) 2009-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -565,10 +565,9 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
565565
* Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial signatures from each input.
566566
*
567567
* @param[out] &out the combined PSBT, if successful
568-
* @param[out] &error reference to TransactionError to fill with error info on failure
569568
* @param[in] psbtxs the PSBTs to combine
570-
* @return True if we successfully combined the transactions, false if they were not compatible
569+
* @return error (OK if we successfully combined the transactions, other error if they were not compatible)
571570
*/
572-
bool CombinePSBTs(PartiallySignedTransaction& out, TransactionError& error, const std::vector<PartiallySignedTransaction>& psbtxs);
571+
NODISCARD TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector<PartiallySignedTransaction>& psbtxs);
573572

574573
#endif // BITCOIN_PSBT_H

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,10 +1050,11 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10501050

10511051
bool allowhighfees = false;
10521052
if (!request.params[1].isNull()) allowhighfees = request.params[1].get_bool();
1053+
const CAmount highfee{allowhighfees ? 0 : ::maxTxFee};
10531054
uint256 txid;
1054-
TransactionError err;
10551055
std::string err_string;
1056-
if (!BroadcastTransaction(tx, txid, err, err_string, allowhighfees)) {
1056+
const TransactionError err = BroadcastTransaction(tx, txid, err_string, highfee);
1057+
if (TransactionError::OK != err) {
10571058
throw JSONRPCTransactionError(err, err_string);
10581059
}
10591060

@@ -1478,8 +1479,8 @@ UniValue combinepsbt(const JSONRPCRequest& request)
14781479
}
14791480

14801481
PartiallySignedTransaction merged_psbt;
1481-
TransactionError error;
1482-
if (!CombinePSBTs(merged_psbt, error, psbtxs)) {
1482+
const TransactionError error = CombinePSBTs(merged_psbt, psbtxs);
1483+
if (error != TransactionError::OK) {
14831484
throw JSONRPCTransactionError(error);
14841485
}
14851486

src/wallet/psbtwallet.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <wallet/psbtwallet.h>
66

7-
bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, TransactionError& error, bool& complete, int sighash_type, bool sign, bool bip32derivs)
7+
TransactionError FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, bool& complete, int sighash_type, bool sign, bool bip32derivs)
88
{
99
LOCK(pwallet->cs_wallet);
1010
// Get all of the previous transactions
@@ -19,8 +19,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, Transac
1919

2020
// Verify input looks sane. This will check that we have at most one uxto, witness or non-witness.
2121
if (!input.IsSane()) {
22-
error = TransactionError::INVALID_PSBT;
23-
return false;
22+
return TransactionError::INVALID_PSBT;
2423
}
2524

2625
// If we have no utxo, grab it from the wallet.
@@ -37,8 +36,7 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, Transac
3736

3837
// Get the Sighash type
3938
if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) {
40-
error = TransactionError::SIGHASH_MISMATCH;
41-
return false;
39+
return TransactionError::SIGHASH_MISMATCH;
4240
}
4341

4442
complete &= SignPSBTInput(HidingSigningProvider(pwallet, !sign, !bip32derivs), psbtx, i, sighash_type);
@@ -58,5 +56,5 @@ bool FillPSBT(const CWallet* pwallet, PartiallySignedTransaction& psbtx, Transac
5856
psbt_out.FromSignatureData(sigdata);
5957
}
6058

61-
return true;
59+
return TransactionError::OK;
6260
}

src/wallet/psbtwallet.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2009-2018 The Bitcoin Core developers
1+
// Copyright (c) 2009-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -18,16 +18,14 @@
1818
*
1919
* @param[in] pwallet pointer to a wallet
2020
* @param[in] &psbtx reference to PartiallySignedTransaction to fill in
21-
* @param[out] &error reference to UniValue to fill with error info on failure
2221
* @param[out] &complete indicates whether the PSBT is now complete
2322
* @param[in] sighash_type the sighash type to use when signing (if PSBT does not specify)
2423
* @param[in] sign whether to sign or not
2524
* @param[in] bip32derivs whether to fill in bip32 derivation information if available
26-
* return true on success, false on error (and fills in `error`)
25+
* return error
2726
*/
28-
bool FillPSBT(const CWallet* pwallet,
27+
NODISCARD TransactionError FillPSBT(const CWallet* pwallet,
2928
PartiallySignedTransaction& psbtx,
30-
TransactionError& error,
3129
bool& complete,
3230
int sighash_type = 1 /* SIGHASH_ALL */,
3331
bool sign = true,

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,8 +3995,8 @@ UniValue walletprocesspsbt(const JSONRPCRequest& request)
39953995
bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
39963996
bool bip32derivs = request.params[3].isNull() ? false : request.params[3].get_bool();
39973997
bool complete = true;
3998-
TransactionError err;
3999-
if (!FillPSBT(pwallet, psbtx, err, complete, nHashType, sign, bip32derivs)) {
3998+
const TransactionError err = FillPSBT(pwallet, psbtx, complete, nHashType, sign, bip32derivs);
3999+
if (err != TransactionError::OK) {
40004000
throw JSONRPCTransactionError(err);
40014001
}
40024002

@@ -4113,8 +4113,8 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
41134113
// Fill transaction with out data but don't sign
41144114
bool bip32derivs = request.params[4].isNull() ? false : request.params[4].get_bool();
41154115
bool complete = true;
4116-
TransactionError err;
4117-
if (!FillPSBT(pwallet, psbtx, err, complete, 1, false, bip32derivs)) {
4116+
const TransactionError err = FillPSBT(pwallet, psbtx, complete, 1, false, bip32derivs);
4117+
if (err != TransactionError::OK) {
41184118
throw JSONRPCTransactionError(err);
41194119
}
41204120

src/wallet/test/psbt_wallet_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test)
6161
ssData >> psbtx;
6262

6363
// Fill transaction with our data
64-
TransactionError err;
6564
bool complete = true;
66-
FillPSBT(&m_wallet, psbtx, err, complete, SIGHASH_ALL, false, true);
65+
BOOST_REQUIRE_EQUAL(TransactionError::OK, FillPSBT(&m_wallet, psbtx, complete, SIGHASH_ALL, false, true));
6766

6867
// Get the final tx
6968
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);

0 commit comments

Comments
 (0)