Skip to content

Commit

Permalink
Add src/wallet/* code to wallet:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanofsky committed Jan 7, 2022
1 parent 90fc8b0 commit f7086fd
Show file tree
Hide file tree
Showing 94 changed files with 293 additions and 74 deletions.
11 changes: 11 additions & 0 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
#include <set>

using node::NodeContext;
using wallet::AttemptSelection;
using wallet::CInputCoin;
using wallet::COutput;
using wallet::CWallet;
using wallet::CWalletTx;
using wallet::CoinEligibilityFilter;
using wallet::CoinSelectionParams;
using wallet::CreateDummyWalletDatabase;
using wallet::OutputGroup;
using wallet::SelectCoinsBnB;
using wallet::TxStateInactive;

static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<std::unique_ptr<CWalletTx>>& wtxs)
{
Expand Down
6 changes: 6 additions & 0 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

#include <optional>

using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::DBErrors;
using wallet::GetBalance;
using wallet::WALLET_FLAG_DESCRIPTORS;

static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ int main(int argc, char* argv[])

ECCVerifyHandle globalVerifyHandle;
ECC_Start();
if (!WalletTool::ExecuteWalletToolFunc(args, command->command)) {
if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
return EXIT_FAILURE;
}
ECC_Stop();
Expand Down
6 changes: 0 additions & 6 deletions src/dummywallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <walletinitinterface.h>

class ArgsManager;
class CWallet;

namespace interfaces {
class Chain;
Expand Down Expand Up @@ -59,11 +58,6 @@ const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();

namespace interfaces {

std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet)
{
throw std::logic_error("Wallet function called in non-wallet build.");
}

std::unique_ptr<WalletLoader> MakeWalletLoader(Chain& chain, ArgsManager& args)
{
throw std::logic_error("Wallet function called in non-wallet build.");
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <vector>

class BanMan;
class CCoinControl;
class CFeeRate;
class CNodeStats;
class Coin;
Expand All @@ -36,6 +35,9 @@ struct bilingual_str;
namespace node {
struct NodeContext;
} // namespace node
namespace wallet {
class CCoinControl;
} // namespace wallet

namespace interfaces {
class Handler;
Expand Down
46 changes: 24 additions & 22 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@
#include <utility>
#include <vector>

class CCoinControl;
class CFeeRate;
class CKey;
class CWallet;
enum class FeeReason;
enum class OutputType;
enum class TransactionError;
struct PartiallySignedTransaction;
struct bilingual_str;
namespace wallet {
class CCoinControl;
class CWallet;
enum isminetype : unsigned int;
struct CRecipient;
struct PartiallySignedTransaction;
struct WalletContext;
struct bilingual_str;
using isminefilter = std::underlying_type<isminetype>::type;
} // namespace wallet

namespace interfaces {

Expand Down Expand Up @@ -107,7 +109,7 @@ class Wallet
//! Look up address in wallet, return whether exists.
virtual bool getAddress(const CTxDestination& dest,
std::string* name,
isminetype* is_mine,
wallet::isminetype* is_mine,
std::string* purpose) = 0;

//! Get wallet address list.
Expand Down Expand Up @@ -135,8 +137,8 @@ class Wallet
virtual void listLockedCoins(std::vector<COutPoint>& outputs) = 0;

//! Create transaction.
virtual CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
const CCoinControl& coin_control,
virtual CTransactionRef createTransaction(const std::vector<wallet::CRecipient>& recipients,
const wallet::CCoinControl& coin_control,
bool sign,
int& change_pos,
CAmount& fee,
Expand All @@ -158,7 +160,7 @@ class Wallet

//! Create bump transaction.
virtual bool createBumpTransaction(const uint256& txid,
const CCoinControl& coin_control,
const wallet::CCoinControl& coin_control,
std::vector<bilingual_str>& errors,
CAmount& old_fee,
CAmount& new_fee,
Expand Down Expand Up @@ -213,19 +215,19 @@ class Wallet
virtual CAmount getBalance() = 0;

//! Get available balance.
virtual CAmount getAvailableBalance(const CCoinControl& coin_control) = 0;
virtual CAmount getAvailableBalance(const wallet::CCoinControl& coin_control) = 0;

//! Return whether transaction input belongs to wallet.
virtual isminetype txinIsMine(const CTxIn& txin) = 0;
virtual wallet::isminetype txinIsMine(const CTxIn& txin) = 0;

//! Return whether transaction output belongs to wallet.
virtual isminetype txoutIsMine(const CTxOut& txout) = 0;
virtual wallet::isminetype txoutIsMine(const CTxOut& txout) = 0;

//! Return debit amount if transaction input belongs to wallet.
virtual CAmount getDebit(const CTxIn& txin, isminefilter filter) = 0;
virtual CAmount getDebit(const CTxIn& txin, wallet::isminefilter filter) = 0;

//! Return credit amount if transaction input belongs to wallet.
virtual CAmount getCredit(const CTxOut& txout, isminefilter filter) = 0;
virtual CAmount getCredit(const CTxOut& txout, wallet::isminefilter filter) = 0;

//! Return AvailableCoins + LockedCoins grouped by wallet address.
//! (put change in one group with wallet address)
Expand All @@ -240,7 +242,7 @@ class Wallet

//! Get minimum fee.
virtual CAmount getMinimumFee(unsigned int tx_bytes,
const CCoinControl& coin_control,
const wallet::CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) = 0;

Expand Down Expand Up @@ -307,7 +309,7 @@ class Wallet
virtual std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0;

//! Return pointer to internal wallet class, useful for testing.
virtual CWallet* wallet() { return nullptr; }
virtual wallet::CWallet* wallet() { return nullptr; }
};

//! Wallet chain client that in addition to having chain client methods for
Expand Down Expand Up @@ -341,18 +343,18 @@ class WalletLoader : public ChainClient
virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;

//! Return pointer to internal context, useful for testing.
virtual WalletContext* context() { return nullptr; }
virtual wallet::WalletContext* context() { return nullptr; }
};

//! Information about one wallet address.
struct WalletAddress
{
CTxDestination dest;
isminetype is_mine;
wallet::isminetype is_mine;
std::string name;
std::string purpose;

WalletAddress(CTxDestination dest, isminetype is_mine, std::string name, std::string purpose)
WalletAddress(CTxDestination dest, wallet::isminetype is_mine, std::string name, std::string purpose)
: dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose))
{
}
Expand Down Expand Up @@ -382,10 +384,10 @@ struct WalletBalances
struct WalletTx
{
CTransactionRef tx;
std::vector<isminetype> txin_is_mine;
std::vector<isminetype> txout_is_mine;
std::vector<wallet::isminetype> txin_is_mine;
std::vector<wallet::isminetype> txout_is_mine;
std::vector<CTxDestination> txout_address;
std::vector<isminetype> txout_address_is_mine;
std::vector<wallet::isminetype> txout_address_is_mine;
CAmount credit;
CAmount debit;
CAmount change;
Expand Down Expand Up @@ -420,7 +422,7 @@ struct WalletTxOut

//! Return implementation of Wallet interface. This function is defined in
//! dummywallet.cpp and throws if the wallet component is not compiled.
std::unique_ptr<Wallet> MakeWallet(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
std::unique_ptr<Wallet> MakeWallet(wallet::WalletContext& context, const std::shared_ptr<wallet::CWallet>& wallet);

//! Return implementation of ChainClient interface for a wallet loader. This
//! function will be undefined in builds where ENABLE_WALLET is false.
Expand Down
3 changes: 3 additions & 0 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <QSettings>
#include <QTreeWidget>

using wallet::CCoinControl;
using wallet::MIN_CHANGE;

QList<CAmount> CoinControlDialog::payAmounts;
bool CoinControlDialog::fSubtractFeeFromAmount = false;

Expand Down
8 changes: 5 additions & 3 deletions src/qt/coincontroldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class PlatformStyle;
class WalletModel;

namespace wallet {
class CCoinControl;
} // namespace wallet

namespace Ui {
class CoinControlDialog;
Expand All @@ -42,11 +44,11 @@ class CoinControlDialog : public QDialog
Q_OBJECT

public:
explicit CoinControlDialog(CCoinControl& coin_control, WalletModel* model, const PlatformStyle *platformStyle, QWidget *parent = nullptr);
explicit CoinControlDialog(wallet::CCoinControl& coin_control, WalletModel* model, const PlatformStyle *platformStyle, QWidget *parent = nullptr);
~CoinControlDialog();

// static because also called from sendcoinsdialog
static void updateLabels(CCoinControl& m_coin_control, WalletModel*, QDialog*);
static void updateLabels(wallet::CCoinControl& m_coin_control, WalletModel*, QDialog*);

static QList<CAmount> payAmounts;
static bool fSubtractFeeFromAmount;
Expand All @@ -56,7 +58,7 @@ class CoinControlDialog : public QDialog

private:
Ui::CoinControlDialog *ui;
CCoinControl& m_coin_control;
wallet::CCoinControl& m_coin_control;
WalletModel *model;
int sortColumn;
Qt::SortOrder sortOrder;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <QSettings>
#include <QTextDocument>

using wallet::CCoinControl;
using wallet::DEFAULT_PAY_TX_FEE;

static constexpr std::array confTargets{2, 4, 6, 12, 24, 48, 144, 504, 1008};
int getConfTargetForIndex(int index) {
if (index+1 > static_cast<int>(confTargets.size())) {
Expand Down
6 changes: 4 additions & 2 deletions src/qt/sendcoinsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include <QString>
#include <QTimer>

class CCoinControl;
class ClientModel;
class PlatformStyle;
class SendCoinsEntry;
class SendCoinsRecipient;
enum class SynchronizationState;
namespace wallet {
class CCoinControl;
} // namespace wallet

namespace Ui {
class SendCoinsDialog;
Expand Down Expand Up @@ -62,7 +64,7 @@ public Q_SLOTS:
Ui::SendCoinsDialog *ui;
ClientModel *clientModel;
WalletModel *model;
std::unique_ptr<CCoinControl> m_coin_control;
std::unique_ptr<wallet::CCoinControl> m_coin_control;
std::unique_ptr<WalletModelTransaction> m_current_transaction;
bool fNewRecipientAllowed;
bool fFeeMinimized;
Expand Down
7 changes: 7 additions & 0 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#include <QTimer>
#include <QMessageBox>

using wallet::AddWallet;
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;

namespace
{

Expand Down
9 changes: 9 additions & 0 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include <QListView>
#include <QDialogButtonBox>

using wallet::AddWallet;
using wallet::CWallet;
using wallet::CreateMockWalletDatabase;
using wallet::RemoveWallet;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WalletContext;
using wallet::WalletDescriptor;
using wallet::WalletRescanReserver;

namespace
{
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.
Expand Down
5 changes: 5 additions & 0 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

#include <QLatin1String>

using wallet::ISMINE_ALL;
using wallet::ISMINE_SPENDABLE;
using wallet::ISMINE_WATCH_ONLY;
using wallet::isminetype;

QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
{
if (!status.is_final)
Expand Down
4 changes: 4 additions & 0 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

#include <QDateTime>

using wallet::ISMINE_SPENDABLE;
using wallet::ISMINE_WATCH_ONLY;
using wallet::isminetype;

/* Return positive answer if transaction should be shown in list.
*/
bool TransactionRecord::showTransaction()
Expand Down
5 changes: 5 additions & 0 deletions src/qt/walletcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <QTimer>
#include <QWindow>

using wallet::WALLET_FLAG_BLANK_WALLET;
using wallet::WALLET_FLAG_DESCRIPTORS;
using wallet::WALLET_FLAG_DISABLE_PRIVATE_KEYS;
using wallet::WALLET_FLAG_EXTERNAL_SIGNER;

WalletController::WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent)
: QObject(parent)
, m_activity_thread(new QThread(this))
Expand Down
3 changes: 3 additions & 0 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <QSet>
#include <QTimer>

using wallet::CCoinControl;
using wallet::CRecipient;
using wallet::DEFAULT_DISABLE_WALLET;

WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) :
QObject(parent),
Expand Down
Loading

0 comments on commit f7086fd

Please sign in to comment.