util: add TransactionError includes and namespace declarations

Add TransactionError to node namespace and include it directly instead of
relying on indirect include through common/messages.h

This is a followup to a previous commit which moved the TransactionError enum.
These changes were done in a separate followup just to keep the previous commit
more minimal and easy to review.
This commit is contained in:
Ryan Ofsky 2023-12-07 17:11:27 -05:00
parent 680eafdc74
commit 4d05d3f3b4
26 changed files with 48 additions and 8 deletions

View file

@ -7,6 +7,7 @@
#include <common/types.h> #include <common/types.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <node/types.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <util/strencodings.h> #include <util/strencodings.h>
#include <util/string.h> #include <util/string.h>
@ -18,6 +19,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
using node::TransactionError;
namespace common { namespace common {
std::string StringForFeeReason(FeeReason reason) std::string StringForFeeReason(FeeReason reason)
{ {

View file

@ -11,13 +11,15 @@
#ifndef BITCOIN_COMMON_MESSAGES_H #ifndef BITCOIN_COMMON_MESSAGES_H
#define BITCOIN_COMMON_MESSAGES_H #define BITCOIN_COMMON_MESSAGES_H
#include <node/types.h>
#include <string> #include <string>
struct bilingual_str; struct bilingual_str;
enum class FeeEstimateMode; enum class FeeEstimateMode;
enum class FeeReason; enum class FeeReason;
namespace node {
enum class TransactionError;
} // namespace node
namespace common { namespace common {
enum class PSBTError; enum class PSBTError;
@ -26,7 +28,7 @@ std::string StringForFeeReason(FeeReason reason);
std::string FeeModes(const std::string& delimiter); std::string FeeModes(const std::string& delimiter);
std::string InvalidEstimateModeErrorMessage(); std::string InvalidEstimateModeErrorMessage();
bilingual_str PSBTErrorString(PSBTError error); bilingual_str PSBTErrorString(PSBTError error);
bilingual_str TransactionErrorString(const TransactionError error); bilingual_str TransactionErrorString(const node::TransactionError error);
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind); bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind);
bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& strPort); bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& strPort);
bilingual_str AmountHighWarn(const std::string& optname); bilingual_str AmountHighWarn(const std::string& optname);

View file

@ -30,10 +30,10 @@ class RPCTimerInterface;
class UniValue; class UniValue;
class Proxy; class Proxy;
enum class SynchronizationState; enum class SynchronizationState;
enum class TransactionError;
struct CNodeStateStats; struct CNodeStateStats;
struct bilingual_str; struct bilingual_str;
namespace node { namespace node {
enum class TransactionError;
struct NodeContext; struct NodeContext;
} // namespace node } // namespace node
namespace wallet { namespace wallet {
@ -208,7 +208,7 @@ public:
virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0; virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0;
//! Broadcast transaction. //! Broadcast transaction.
virtual TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0; virtual node::TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0;
//! Get wallet loader. //! Get wallet loader.
virtual WalletLoader& walletLoader() = 0; virtual WalletLoader& walletLoader() = 0;

View file

@ -35,6 +35,9 @@ struct bilingual_str;
namespace common { namespace common {
enum class PSBTError; enum class PSBTError;
} // namespace common } // namespace common
namespace node {
enum class TransactionError;
} // namespace node
namespace wallet { namespace wallet {
class CCoinControl; class CCoinControl;
class CWallet; class CWallet;

View file

@ -31,6 +31,7 @@
#include <node/interface_ui.h> #include <node/interface_ui.h>
#include <node/mini_miner.h> #include <node/mini_miner.h>
#include <node/transaction.h> #include <node/transaction.h>
#include <node/types.h>
#include <policy/feerate.h> #include <policy/feerate.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>

View file

@ -9,6 +9,7 @@
#include <net_processing.h> #include <net_processing.h>
#include <node/blockstorage.h> #include <node/blockstorage.h>
#include <node/context.h> #include <node/context.h>
#include <node/types.h>
#include <txmempool.h> #include <txmempool.h>
#include <validation.h> #include <validation.h>
#include <validationinterface.h> #include <validationinterface.h>

View file

@ -13,6 +13,7 @@
#ifndef BITCOIN_NODE_TYPES_H #ifndef BITCOIN_NODE_TYPES_H
#define BITCOIN_NODE_TYPES_H #define BITCOIN_NODE_TYPES_H
namespace node {
enum class TransactionError { enum class TransactionError {
OK, //!< No error OK, //!< No error
MISSING_INPUTS, MISSING_INPUTS,
@ -23,5 +24,6 @@ enum class TransactionError {
MAX_BURN_EXCEEDED, MAX_BURN_EXCEEDED,
INVALID_PACKAGE, INVALID_PACKAGE,
}; };
} // namespace node
#endif // BITCOIN_NODE_TYPES_H #endif // BITCOIN_NODE_TYPES_H

View file

@ -4,12 +4,12 @@
#include <psbt.h> #include <psbt.h>
#include <node/types.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <script/signingprovider.h> #include <script/signingprovider.h>
#include <util/check.h> #include <util/check.h>
#include <util/strencodings.h> #include <util/strencodings.h>
PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx) PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx)
{ {
inputs.resize(tx.vin.size()); inputs.resize(tx.vin.size());

View file

@ -17,6 +17,10 @@
#include <optional> #include <optional>
namespace node {
enum class TransactionError;
} // namespace node
// Magic bytes // Magic bytes
static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};

View file

@ -9,6 +9,7 @@
#include <interfaces/node.h> #include <interfaces/node.h>
#include <key_io.h> #include <key_io.h>
#include <node/psbt.h> #include <node/psbt.h>
#include <node/types.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <qt/bitcoinunits.h> #include <qt/bitcoinunits.h>
#include <qt/forms/ui_psbtoperationsdialog.h> #include <qt/forms/ui_psbtoperationsdialog.h>
@ -25,6 +26,7 @@ using common::TransactionErrorString;
using node::AnalyzePSBT; using node::AnalyzePSBT;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE; using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::PSBTAnalysis; using node::PSBTAnalysis;
using node::TransactionError;
PSBTOperationsDialog::PSBTOperationsDialog( PSBTOperationsDialog::PSBTOperationsDialog(
QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags), QWidget* parent, WalletModel* wallet_model, ClientModel* client_model) : QDialog(parent, GUIUtil::dialog_flags),

View file

@ -20,6 +20,7 @@
#include <interfaces/node.h> #include <interfaces/node.h>
#include <key_io.h> #include <key_io.h>
#include <node/interface_ui.h> #include <node/interface_ui.h>
#include <node/types.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <txmempool.h> #include <txmempool.h>
#include <validation.h> #include <validation.h>

View file

@ -19,6 +19,7 @@
#include <interfaces/node.h> #include <interfaces/node.h>
#include <key_io.h> #include <key_io.h>
#include <node/interface_ui.h> #include <node/interface_ui.h>
#include <node/types.h>
#include <psbt.h> #include <psbt.h>
#include <util/translation.h> #include <util/translation.h>
#include <wallet/coincontrol.h> #include <wallet/coincontrol.h>

View file

@ -11,6 +11,7 @@
#include <core_io.h> #include <core_io.h>
#include <kernel/mempool_entry.h> #include <kernel/mempool_entry.h>
#include <node/mempool_persist_args.h> #include <node/mempool_persist_args.h>
#include <node/types.h>
#include <policy/rbf.h> #include <policy/rbf.h>
#include <policy/settings.h> #include <policy/settings.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -32,6 +33,7 @@ using node::DEFAULT_MAX_BURN_AMOUNT;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE; using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::MempoolPath; using node::MempoolPath;
using node::NodeContext; using node::NodeContext;
using node::TransactionError;
static RPCHelpMan sendrawtransaction() static RPCHelpMan sendrawtransaction()
{ {

View file

@ -16,6 +16,7 @@
#include <node/context.h> #include <node/context.h>
#include <node/psbt.h> #include <node/psbt.h>
#include <node/transaction.h> #include <node/transaction.h>
#include <node/types.h>
#include <policy/packages.h> #include <policy/packages.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <policy/rbf.h> #include <policy/rbf.h>

View file

@ -12,6 +12,7 @@
#include <consensus/amount.h> #include <consensus/amount.h>
#include <script/interpreter.h> #include <script/interpreter.h>
#include <key_io.h> #include <key_io.h>
#include <node/types.h>
#include <outputtype.h> #include <outputtype.h>
#include <rpc/util.h> #include <rpc/util.h>
#include <script/descriptor.h> #include <script/descriptor.h>
@ -35,6 +36,7 @@
using common::PSBTError; using common::PSBTError;
using common::PSBTErrorString; using common::PSBTErrorString;
using common::TransactionErrorString; using common::TransactionErrorString;
using node::TransactionError;
const std::string UNIX_EPOCH_TIME = "UNIX epoch time"; const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"}; const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};

View file

@ -34,12 +34,14 @@
class JSONRPCRequest; class JSONRPCRequest;
enum ServiceFlags : uint64_t; enum ServiceFlags : uint64_t;
enum class OutputType; enum class OutputType;
enum class TransactionError;
struct FlatSigningProvider; struct FlatSigningProvider;
struct bilingual_str; struct bilingual_str;
namespace common { namespace common {
enum class PSBTError; enum class PSBTError;
} // namespace common } // namespace common
namespace node {
enum class TransactionError;
} // namespace node
static constexpr bool DEFAULT_RPC_DOC_CHECK{ static constexpr bool DEFAULT_RPC_DOC_CHECK{
#ifdef RPC_DOC_CHECK #ifdef RPC_DOC_CHECK
@ -130,9 +132,9 @@ int ParseSighashString(const UniValue& sighash);
//! Parse a confirm target option and raise an RPC error if it is invalid. //! Parse a confirm target option and raise an RPC error if it is invalid.
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target); unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr); RPCErrorCode RPCErrorFromTransactionError(node::TransactionError terr);
UniValue JSONRPCPSBTError(common::PSBTError err); UniValue JSONRPCPSBTError(common::PSBTError err);
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string = ""); UniValue JSONRPCTransactionError(node::TransactionError terr, const std::string& err_string = "");
//! Parse a JSON range specified as int64, or [int64, int64] //! Parse a JSON range specified as int64, or [int64, int64]
std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value); std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value);

View file

@ -4,6 +4,7 @@
#include <common/messages.h> #include <common/messages.h>
#include <merkleblock.h> #include <merkleblock.h>
#include <node/types.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <rpc/util.h> #include <rpc/util.h>
#include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/FuzzedDataProvider.h>
@ -17,6 +18,7 @@
#include <vector> #include <vector>
using common::TransactionErrorString; using common::TransactionErrorString;
using node::TransactionError;
namespace { namespace {
constexpr TransactionError ALL_TRANSACTION_ERROR[] = { constexpr TransactionError ALL_TRANSACTION_ERROR[] = {

View file

@ -6,6 +6,7 @@
#include <common/args.h> #include <common/args.h>
#include <common/system.h> #include <common/system.h>
#include <external_signer.h> #include <external_signer.h>
#include <node/types.h>
#include <wallet/external_signer_scriptpubkeyman.h> #include <wallet/external_signer_scriptpubkeyman.h>
#include <iostream> #include <iostream>

View file

@ -5,6 +5,7 @@
#include <common/system.h> #include <common/system.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <node/types.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <util/moneystr.h> #include <util/moneystr.h>

View file

@ -8,6 +8,7 @@
#include <consensus/amount.h> #include <consensus/amount.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/handler.h> #include <interfaces/handler.h>
#include <node/types.h>
#include <policy/fees.h> #include <policy/fees.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <rpc/server.h> #include <rpc/server.h>

View file

@ -6,6 +6,7 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <core_io.h> #include <core_io.h>
#include <key_io.h> #include <key_io.h>
#include <node/types.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <rpc/rawtransaction_util.h> #include <rpc/rawtransaction_util.h>
#include <rpc/util.h> #include <rpc/util.h>
@ -27,6 +28,7 @@ using common::FeeModes;
using common::InvalidEstimateModeErrorMessage; using common::InvalidEstimateModeErrorMessage;
using common::StringForFeeReason; using common::StringForFeeReason;
using common::TransactionErrorString; using common::TransactionErrorString;
using node::TransactionError;
namespace wallet { namespace wallet {
std::vector<CRecipient> CreateRecipients(const std::vector<std::pair<CTxDestination, CAmount>>& outputs, const std::set<int>& subtract_fee_outputs) std::vector<CRecipient> CreateRecipients(const std::vector<std::pair<CTxDestination, CAmount>>& outputs, const std::set<int>& subtract_fee_outputs)

View file

@ -5,6 +5,7 @@
#include <hash.h> #include <hash.h>
#include <key_io.h> #include <key_io.h>
#include <logging.h> #include <logging.h>
#include <node/types.h>
#include <outputtype.h> #include <outputtype.h>
#include <script/descriptor.h> #include <script/descriptor.h>
#include <script/script.h> #include <script/script.h>

View file

@ -10,6 +10,7 @@
#include <common/signmessage.h> #include <common/signmessage.h>
#include <common/types.h> #include <common/types.h>
#include <logging.h> #include <logging.h>
#include <node/types.h>
#include <psbt.h> #include <psbt.h>
#include <script/descriptor.h> #include <script/descriptor.h>
#include <script/script.h> #include <script/script.h>

View file

@ -9,6 +9,7 @@
#include <consensus/amount.h> #include <consensus/amount.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <node/types.h>
#include <numeric> #include <numeric>
#include <policy/policy.h> #include <policy/policy.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -32,6 +33,7 @@
using common::StringForFeeReason; using common::StringForFeeReason;
using common::TransactionErrorString; using common::TransactionErrorString;
using interfaces::FoundBlock; using interfaces::FoundBlock;
using node::TransactionError;
namespace wallet { namespace wallet {
static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES{100}; static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES{100};

View file

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <key_io.h> #include <key_io.h>
#include <node/types.h>
#include <util/bip32.h> #include <util/bip32.h>
#include <util/strencodings.h> #include <util/strencodings.h>
#include <wallet/wallet.h> #include <wallet/wallet.h>

View file

@ -27,6 +27,7 @@
#include <key.h> #include <key.h>
#include <key_io.h> #include <key_io.h>
#include <logging.h> #include <logging.h>
#include <node/types.h>
#include <outputtype.h> #include <outputtype.h>
#include <policy/feerate.h> #include <policy/feerate.h>
#include <primitives/block.h> #include <primitives/block.h>