This commit is contained in:
marcofleon 2025-04-29 11:49:19 +02:00 committed by GitHub
commit 6b24ce176c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 155 additions and 150 deletions

View file

@ -14,6 +14,7 @@
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
#include <util/fs.h> #include <util/fs.h>
#include <util/result.h> #include <util/result.h>
#include <util/transaction_identifier.h>
#include <util/ui_change_type.h> #include <util/ui_change_type.h>
#include <cstdint> #include <cstdint>
@ -159,16 +160,16 @@ public:
WalletOrderForm order_form) = 0; WalletOrderForm order_form) = 0;
//! Return whether transaction can be abandoned. //! Return whether transaction can be abandoned.
virtual bool transactionCanBeAbandoned(const uint256& txid) = 0; virtual bool transactionCanBeAbandoned(const Txid& txid) = 0;
//! Abandon transaction. //! Abandon transaction.
virtual bool abandonTransaction(const uint256& txid) = 0; virtual bool abandonTransaction(const Txid& txid) = 0;
//! Return whether transaction can be bumped. //! Return whether transaction can be bumped.
virtual bool transactionCanBeBumped(const uint256& txid) = 0; virtual bool transactionCanBeBumped(const Txid& txid) = 0;
//! Create bump transaction. //! Create bump transaction.
virtual bool createBumpTransaction(const uint256& txid, virtual bool createBumpTransaction(const Txid& txid,
const wallet::CCoinControl& coin_control, const wallet::CCoinControl& coin_control,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
CAmount& old_fee, CAmount& old_fee,
@ -179,28 +180,28 @@ public:
virtual bool signBumpTransaction(CMutableTransaction& mtx) = 0; virtual bool signBumpTransaction(CMutableTransaction& mtx) = 0;
//! Commit bump transaction. //! Commit bump transaction.
virtual bool commitBumpTransaction(const uint256& txid, virtual bool commitBumpTransaction(const Txid& txid,
CMutableTransaction&& mtx, CMutableTransaction&& mtx,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
uint256& bumped_txid) = 0; Txid& bumped_txid) = 0;
//! Get a transaction. //! Get a transaction.
virtual CTransactionRef getTx(const uint256& txid) = 0; virtual CTransactionRef getTx(const Txid& txid) = 0;
//! Get transaction information. //! Get transaction information.
virtual WalletTx getWalletTx(const uint256& txid) = 0; virtual WalletTx getWalletTx(const Txid& txid) = 0;
//! Get list of all wallet transactions. //! Get list of all wallet transactions.
virtual std::set<WalletTx> getWalletTxs() = 0; virtual std::set<WalletTx> getWalletTxs() = 0;
//! Try to get updated status for a particular transaction, if possible without blocking. //! Try to get updated status for a particular transaction, if possible without blocking.
virtual bool tryGetTxStatus(const uint256& txid, virtual bool tryGetTxStatus(const Txid& txid,
WalletTxStatus& tx_status, WalletTxStatus& tx_status,
int& num_blocks, int& num_blocks,
int64_t& block_time) = 0; int64_t& block_time) = 0;
//! Get transaction details. //! Get transaction details.
virtual WalletTx getWalletTxDetails(const uint256& txid, virtual WalletTx getWalletTxDetails(const Txid& txid,
WalletTxStatus& tx_status, WalletTxStatus& tx_status,
WalletOrderForm& order_form, WalletOrderForm& order_form,
bool& in_mempool, bool& in_mempool,
@ -306,7 +307,7 @@ public:
virtual std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) = 0; virtual std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) = 0;
//! Register handler for transaction changed messages. //! Register handler for transaction changed messages.
using TransactionChangedFn = std::function<void(const uint256& txid, ChangeType status)>; using TransactionChangedFn = std::function<void(const Txid& txid, ChangeType status)>;
virtual std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) = 0; virtual std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) = 0;
//! Register handler for watchonly changed messages. //! Register handler for watchonly changed messages.

View file

@ -7,6 +7,7 @@
#include <qt/clientmodel.h> #include <qt/clientmodel.h>
#include <qt/walletmodel.h> #include <qt/walletmodel.h>
#include <util/transaction_identifier.h>
#include <QDialog> #include <QDialog>
#include <QMessageBox> #include <QMessageBox>
@ -61,7 +62,7 @@ public Q_SLOTS:
void setBalance(const interfaces::WalletBalances& balances); void setBalance(const interfaces::WalletBalances& balances);
Q_SIGNALS: Q_SIGNALS:
void coinsSent(const uint256& txid); void coinsSent(const Txid& txid);
private: private:
Ui::SendCoinsDialog *ui; Ui::SendCoinsDialog *ui;

View file

@ -75,7 +75,7 @@ void ConfirmSend(QString* text = nullptr, QMessageBox::StandardButton confirm_ty
} }
//! Send coins to address and return txid. //! Send coins to address and return txid.
uint256 SendCoins(CWallet& wallet, SendCoinsDialog& sendCoinsDialog, const CTxDestination& address, CAmount amount, bool rbf, Txid SendCoins(CWallet& wallet, SendCoinsDialog& sendCoinsDialog, const CTxDestination& address, CAmount amount, bool rbf,
QMessageBox::StandardButton confirm_type = QMessageBox::Yes) QMessageBox::StandardButton confirm_type = QMessageBox::Yes)
{ {
QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries"); QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries");
@ -86,8 +86,8 @@ uint256 SendCoins(CWallet& wallet, SendCoinsDialog& sendCoinsDialog, const CTxDe
->findChild<QFrame*>("frameFeeSelection") ->findChild<QFrame*>("frameFeeSelection")
->findChild<QCheckBox*>("optInRBF") ->findChild<QCheckBox*>("optInRBF")
->setCheckState(rbf ? Qt::Checked : Qt::Unchecked); ->setCheckState(rbf ? Qt::Checked : Qt::Unchecked);
uint256 txid; Txid txid;
boost::signals2::scoped_connection c(wallet.NotifyTransactionChanged.connect([&txid](const uint256& hash, ChangeType status) { boost::signals2::scoped_connection c(wallet.NotifyTransactionChanged.connect([&txid](const Txid& hash, ChangeType status) {
if (status == CT_NEW) txid = hash; if (status == CT_NEW) txid = hash;
})); }));
ConfirmSend(/*text=*/nullptr, confirm_type); ConfirmSend(/*text=*/nullptr, confirm_type);
@ -97,7 +97,7 @@ uint256 SendCoins(CWallet& wallet, SendCoinsDialog& sendCoinsDialog, const CTxDe
} }
//! Find index of txid in transaction list. //! Find index of txid in transaction list.
QModelIndex FindTx(const QAbstractItemModel& model, const uint256& txid) QModelIndex FindTx(const QAbstractItemModel& model, const Txid& txid)
{ {
QString hash = QString::fromStdString(txid.ToString()); QString hash = QString::fromStdString(txid.ToString());
int rows = model.rowCount({}); int rows = model.rowCount({});
@ -111,7 +111,7 @@ QModelIndex FindTx(const QAbstractItemModel& model, const uint256& txid)
} }
//! Invoke bumpfee on txid and check results. //! Invoke bumpfee on txid and check results.
void BumpFee(TransactionView& view, const uint256& txid, bool expectDisabled, std::string expectError, bool cancel) void BumpFee(TransactionView& view, const Txid& txid, bool expectDisabled, std::string expectError, bool cancel)
{ {
QTableView* table = view.findChild<QTableView*>("transactionView"); QTableView* table = view.findChild<QTableView*>("transactionView");
QModelIndex index = FindTx(*table->selectionModel()->model(), txid); QModelIndex index = FindTx(*table->selectionModel()->model(), txid);
@ -285,8 +285,8 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
// Send two transactions, and verify they are added to transaction list. // Send two transactions, and verify they are added to transaction list.
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel(); TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
QCOMPARE(transactionTableModel->rowCount({}), 105); QCOMPARE(transactionTableModel->rowCount({}), 105);
uint256 txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, /*rbf=*/false); Txid txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, /*rbf=*/false);
uint256 txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN, /*rbf=*/true); Txid txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN, /*rbf=*/true);
// Transaction table model updates on a QueuedConnection, so process events to ensure it's updated. // Transaction table model updates on a QueuedConnection, so process events to ensure it's updated.
qApp->processEvents(); qApp->processEvents();
QCOMPARE(transactionTableModel->rowCount({}), 107); QCOMPARE(transactionTableModel->rowCount({}), 107);

View file

@ -37,7 +37,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interface
CAmount nCredit = wtx.credit; CAmount nCredit = wtx.credit;
CAmount nDebit = wtx.debit; CAmount nDebit = wtx.debit;
CAmount nNet = nCredit - nDebit; CAmount nNet = nCredit - nDebit;
uint256 hash = wtx.tx->GetHash(); Txid hash = wtx.tx->GetHash();
std::map<std::string, std::string> mapValue = wtx.value_map; std::map<std::string, std::string> mapValue = wtx.value_map;
bool involvesWatchAddress = false; bool involvesWatchAddress = false;

View file

@ -7,6 +7,7 @@
#include <consensus/amount.h> #include <consensus/amount.h>
#include <uint256.h> #include <uint256.h>
#include <util/transaction_identifier.h>
#include <QList> #include <QList>
#include <QString> #include <QString>
@ -79,13 +80,13 @@ public:
{ {
} }
TransactionRecord(uint256 _hash, qint64 _time): TransactionRecord(Txid _hash, qint64 _time):
hash(_hash), time(_time), type(Other), debit(0), hash(_hash), time(_time), type(Other), debit(0),
credit(0), idx(0) credit(0), idx(0)
{ {
} }
TransactionRecord(uint256 _hash, qint64 _time, TransactionRecord(Txid _hash, qint64 _time,
Type _type, const std::string &_address, Type _type, const std::string &_address,
const CAmount& _debit, const CAmount& _credit): const CAmount& _debit, const CAmount& _credit):
hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit), hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit),
@ -100,7 +101,7 @@ public:
/** @name Immutable transaction attributes /** @name Immutable transaction attributes
@{*/ @{*/
uint256 hash; Txid hash;
qint64 time; qint64 time;
Type type; Type type;
std::string address; std::string address;

View file

@ -49,11 +49,11 @@ struct TxLessThan
{ {
return a.hash < b.hash; return a.hash < b.hash;
} }
bool operator()(const TransactionRecord &a, const uint256 &b) const bool operator()(const TransactionRecord &a, const Txid &b) const
{ {
return a.hash < b; return a.hash < b;
} }
bool operator()(const uint256 &a, const TransactionRecord &b) const bool operator()(const Txid &a, const TransactionRecord &b) const
{ {
return a < b.hash; return a < b.hash;
} }
@ -64,7 +64,7 @@ struct TransactionNotification
{ {
public: public:
TransactionNotification() = default; TransactionNotification() = default;
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction): TransactionNotification(Txid _hash, ChangeType _status, bool _showTransaction):
hash(_hash), status(_status), showTransaction(_showTransaction) {} hash(_hash), status(_status), showTransaction(_showTransaction) {}
void invoke(QObject *ttm) void invoke(QObject *ttm)
@ -78,7 +78,7 @@ public:
assert(invoked); assert(invoked);
} }
private: private:
uint256 hash; Txid hash;
ChangeType status; ChangeType status;
bool showTransaction; bool showTransaction;
}; };
@ -103,7 +103,7 @@ public:
bool m_loading = false; bool m_loading = false;
std::vector< TransactionNotification > vQueueNotifications; std::vector< TransactionNotification > vQueueNotifications;
void NotifyTransactionChanged(const uint256 &hash, ChangeType status); void NotifyTransactionChanged(const Txid& hash, ChangeType status);
void DispatchNotifications(); void DispatchNotifications();
/* Query entire wallet anew from core. /* Query entire wallet anew from core.
@ -127,7 +127,7 @@ public:
Call with transaction that was added, removed or changed. Call with transaction that was added, removed or changed.
*/ */
void updateWallet(interfaces::Wallet& wallet, const uint256 &hash, int status, bool showTransaction) void updateWallet(interfaces::Wallet& wallet, const Txid& hash, int status, bool showTransaction)
{ {
qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status); qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);
@ -699,7 +699,7 @@ void TransactionTableModel::updateDisplayUnit()
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount)); Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
} }
void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeType status) void TransactionTablePriv::NotifyTransactionChanged(const Txid& hash, ChangeType status)
{ {
// Find transaction in wallet // Find transaction in wallet
// Determine whether to show transaction or not (determine this here so that no relocking is needed in GUI thread) // Determine whether to show transaction or not (determine this here so that no relocking is needed in GUI thread)

View file

@ -193,7 +193,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
// Double-clicking on a transaction on the transaction history page shows details // Double-clicking on a transaction on the transaction history page shows details
connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails); connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails);
// Highlight transaction after fee bump // Highlight transaction after fee bump
connect(this, &TransactionView::bumpedFee, [this](const uint256& txid) { connect(this, &TransactionView::bumpedFee, [this](const Txid& txid) {
focusTransaction(txid); focusTransaction(txid);
}); });
} }
@ -436,7 +436,7 @@ void TransactionView::bumpFee([[maybe_unused]] bool checked)
Txid hash = Txid::FromHex(hashQStr.toStdString()).value(); Txid hash = Txid::FromHex(hashQStr.toStdString()).value();
// Bump tx fee over the walletModel // Bump tx fee over the walletModel
uint256 newHash; Txid newHash;
if (model->bumpFee(hash, newHash)) { if (model->bumpFee(hash, newHash)) {
// Update the table // Update the table
transactionView->selectionModel()->clearSelection(); transactionView->selectionModel()->clearSelection();
@ -604,7 +604,7 @@ void TransactionView::focusTransaction(const QModelIndex &idx)
transactionView->setFocus(); transactionView->setFocus();
} }
void TransactionView::focusTransaction(const uint256& txid) void TransactionView::focusTransaction(const Txid& txid)
{ {
if (!transactionProxyModel) if (!transactionProxyModel)
return; return;

View file

@ -8,6 +8,7 @@
#include <qt/guiutil.h> #include <qt/guiutil.h>
#include <uint256.h> #include <uint256.h>
#include <util/transaction_identifier.h>
#include <QWidget> #include <QWidget>
#include <QKeyEvent> #include <QKeyEvent>
@ -115,7 +116,7 @@ Q_SIGNALS:
/** Fired when a message should be reported to the user */ /** Fired when a message should be reported to the user */
void message(const QString &title, const QString &message, unsigned int style); void message(const QString &title, const QString &message, unsigned int style);
void bumpedFee(const uint256& txid); void bumpedFee(const Txid& txid);
public Q_SLOTS: public Q_SLOTS:
void chooseDate(int idx); void chooseDate(int idx);
@ -126,7 +127,7 @@ public Q_SLOTS:
void exportClicked(); void exportClicked();
void closeOpenedDialogs(); void closeOpenedDialogs();
void focusTransaction(const QModelIndex&); void focusTransaction(const QModelIndex&);
void focusTransaction(const uint256& txid); void focusTransaction(const Txid& txid);
}; };
#endif // BITCOIN_QT_TRANSACTIONVIEW_H #endif // BITCOIN_QT_TRANSACTIONVIEW_H

View file

@ -388,7 +388,7 @@ static void NotifyAddressBookChanged(WalletModel *walletmodel,
assert(invoked); assert(invoked);
} }
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status) static void NotifyTransactionChanged(WalletModel *walletmodel, const Txid& hash, ChangeType status)
{ {
Q_UNUSED(hash); Q_UNUSED(hash);
Q_UNUSED(status); Q_UNUSED(status);
@ -479,7 +479,7 @@ WalletModel::UnlockContext::~UnlockContext()
} }
} }
bool WalletModel::bumpFee(uint256 hash, uint256& new_hash) bool WalletModel::bumpFee(Txid hash, Txid& new_hash)
{ {
CCoinControl coin_control; CCoinControl coin_control;
coin_control.m_signal_bip125_rbf = true; coin_control.m_signal_bip125_rbf = true;

View file

@ -11,6 +11,7 @@
#include <interfaces/wallet.h> #include <interfaces/wallet.h>
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
#include <util/transaction_identifier.h>
#include <vector> #include <vector>
@ -129,7 +130,7 @@ public:
UnlockContext requestUnlock(); UnlockContext requestUnlock();
bool bumpFee(uint256 hash, uint256& new_hash); bool bumpFee(Txid hash, Txid& new_hash);
void displayAddress(std::string sAddress) const; void displayAddress(std::string sAddress) const;
static bool isWalletEnabled(); static bool isWalletEnabled();

View file

@ -82,7 +82,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, this, &WalletView::coinsSent); connect(sendCoinsPage, &SendCoinsDialog::coinsSent, this, &WalletView::coinsSent);
// Highlight transaction after send // Highlight transaction after send
connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const uint256&>(&TransactionView::focusTransaction)); connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const Txid&>(&TransactionView::focusTransaction));
// Clicking on "Export" allows to export the transaction list // Clicking on "Export" allows to export the transaction list
connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked); connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);

View file

@ -146,7 +146,7 @@ static CFeeRate EstimateFeeRate(const CWallet& wallet, const CWalletTx& wtx, con
namespace feebumper { namespace feebumper {
bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid) bool TransactionCanBeBumped(const CWallet& wallet, const Txid& txid)
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
const CWalletTx* wtx = wallet.GetWalletTx(txid); const CWalletTx* wtx = wallet.GetWalletTx(txid);
@ -157,7 +157,7 @@ bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid)
return res == feebumper::Result::OK; return res == feebumper::Result::OK;
} }
Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCoinControl& coin_control, std::vector<bilingual_str>& errors, Result CreateRateBumpTransaction(CWallet& wallet, const Txid& txid, const CCoinControl& coin_control, std::vector<bilingual_str>& errors,
CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx, bool require_mine, const std::vector<CTxOut>& outputs, std::optional<uint32_t> original_change_index) CAmount& old_fee, CAmount& new_fee, CMutableTransaction& mtx, bool require_mine, const std::vector<CTxOut>& outputs, std::optional<uint32_t> original_change_index)
{ {
// For now, cannot specify both new outputs to use and an output index to send change // For now, cannot specify both new outputs to use and an output index to send change
@ -348,7 +348,7 @@ bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx) {
} }
} }
Result CommitTransaction(CWallet& wallet, const uint256& txid, CMutableTransaction&& mtx, std::vector<bilingual_str>& errors, uint256& bumped_txid) Result CommitTransaction(CWallet& wallet, const Txid& txid, CMutableTransaction&& mtx, std::vector<bilingual_str>& errors, Txid& bumped_txid)
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
if (!errors.empty()) { if (!errors.empty()) {

View file

@ -31,7 +31,7 @@ enum class Result
}; };
//! Return whether transaction can be bumped. //! Return whether transaction can be bumped.
bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid); bool TransactionCanBeBumped(const CWallet& wallet, const Txid& txid);
/** Create bumpfee transaction based on feerate estimates. /** Create bumpfee transaction based on feerate estimates.
* *
@ -47,7 +47,7 @@ bool TransactionCanBeBumped(const CWallet& wallet, const uint256& txid);
* @param[in] original_change_index The position of the change output to deduct the fee from in the transaction being bumped * @param[in] original_change_index The position of the change output to deduct the fee from in the transaction being bumped
*/ */
Result CreateRateBumpTransaction(CWallet& wallet, Result CreateRateBumpTransaction(CWallet& wallet,
const uint256& txid, const Txid& txid,
const CCoinControl& coin_control, const CCoinControl& coin_control,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
CAmount& old_fee, CAmount& old_fee,
@ -67,10 +67,10 @@ bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx);
//! but sets errors if the tx could not be added to the mempool (will try later) //! but sets errors if the tx could not be added to the mempool (will try later)
//! or if the old transaction could not be marked as replaced. //! or if the old transaction could not be marked as replaced.
Result CommitTransaction(CWallet& wallet, Result CommitTransaction(CWallet& wallet,
const uint256& txid, const Txid& txid,
CMutableTransaction&& mtx, CMutableTransaction&& mtx,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
uint256& bumped_txid); Txid& bumped_txid);
struct SignatureWeights struct SignatureWeights
{ {

View file

@ -299,17 +299,17 @@ public:
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form)); m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
} }
bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); } bool transactionCanBeAbandoned(const Txid& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
bool abandonTransaction(const uint256& txid) override bool abandonTransaction(const Txid& txid) override
{ {
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
return m_wallet->AbandonTransaction(txid); return m_wallet->AbandonTransaction(txid);
} }
bool transactionCanBeBumped(const uint256& txid) override bool transactionCanBeBumped(const Txid& txid) override
{ {
return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid); return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid);
} }
bool createBumpTransaction(const uint256& txid, bool createBumpTransaction(const Txid& txid,
const CCoinControl& coin_control, const CCoinControl& coin_control,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
CAmount& old_fee, CAmount& old_fee,
@ -320,15 +320,15 @@ public:
return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx, /* require_mine= */ true, outputs) == feebumper::Result::OK; return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx, /* require_mine= */ true, outputs) == feebumper::Result::OK;
} }
bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); } bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
bool commitBumpTransaction(const uint256& txid, bool commitBumpTransaction(const Txid& txid,
CMutableTransaction&& mtx, CMutableTransaction&& mtx,
std::vector<bilingual_str>& errors, std::vector<bilingual_str>& errors,
uint256& bumped_txid) override Txid& bumped_txid) override
{ {
return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) == return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
feebumper::Result::OK; feebumper::Result::OK;
} }
CTransactionRef getTx(const uint256& txid) override CTransactionRef getTx(const Txid& txid) override
{ {
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
auto mi = m_wallet->mapWallet.find(txid); auto mi = m_wallet->mapWallet.find(txid);
@ -337,7 +337,7 @@ public:
} }
return {}; return {};
} }
WalletTx getWalletTx(const uint256& txid) override WalletTx getWalletTx(const Txid& txid) override
{ {
LOCK(m_wallet->cs_wallet); LOCK(m_wallet->cs_wallet);
auto mi = m_wallet->mapWallet.find(txid); auto mi = m_wallet->mapWallet.find(txid);
@ -355,7 +355,7 @@ public:
} }
return result; return result;
} }
bool tryGetTxStatus(const uint256& txid, bool tryGetTxStatus(const Txid& txid,
interfaces::WalletTxStatus& tx_status, interfaces::WalletTxStatus& tx_status,
int& num_blocks, int& num_blocks,
int64_t& block_time) override int64_t& block_time) override
@ -374,7 +374,7 @@ public:
tx_status = MakeWalletTxStatus(*m_wallet, mi->second); tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
return true; return true;
} }
WalletTx getWalletTxDetails(const uint256& txid, WalletTx getWalletTxDetails(const Txid& txid,
WalletTxStatus& tx_status, WalletTxStatus& tx_status,
WalletOrderForm& order_form, WalletOrderForm& order_form,
bool& in_mempool, bool& in_mempool,
@ -548,7 +548,7 @@ public:
std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
{ {
return MakeSignalHandler(m_wallet->NotifyTransactionChanged.connect( return MakeSignalHandler(m_wallet->NotifyTransactionChanged.connect(
[fn](const uint256& txid, ChangeType status) { fn(txid, status); })); [fn](const Txid& txid, ChangeType status) { fn(txid, status); }));
} }
std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
{ {

View file

@ -254,7 +254,7 @@ bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminef
} }
// NOLINTNEXTLINE(misc-no-recursion) // NOLINTNEXTLINE(misc-no-recursion)
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents) bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<Txid>& trusted_parents)
{ {
AssertLockHeld(wallet.cs_wallet); AssertLockHeld(wallet.cs_wallet);
if (wtx.isConfirmed()) return true; if (wtx.isConfirmed()) return true;
@ -285,7 +285,7 @@ bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uin
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx) bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx)
{ {
std::set<uint256> trusted_parents; std::set<Txid> trusted_parents;
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
return CachedTxIsTrusted(wallet, wtx, trusted_parents); return CachedTxIsTrusted(wallet, wtx, trusted_parents);
} }
@ -296,7 +296,7 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse)
isminefilter reuse_filter = avoid_reuse ? ISMINE_NO : ISMINE_USED; isminefilter reuse_filter = avoid_reuse ? ISMINE_NO : ISMINE_USED;
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
std::set<uint256> trusted_parents; std::set<Txid> trusted_parents;
for (const auto& entry : wallet.mapWallet) for (const auto& entry : wallet.mapWallet)
{ {
const CWalletTx& wtx = entry.second; const CWalletTx& wtx = entry.second;
@ -325,7 +325,7 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
{ {
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
std::set<uint256> trusted_parents; std::set<Txid> trusted_parents;
for (const auto& walletEntry : wallet.mapWallet) for (const auto& walletEntry : wallet.mapWallet)
{ {
const CWalletTx& wtx = walletEntry.second; const CWalletTx& wtx = walletEntry.second;
@ -348,7 +348,7 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
if(!ExtractDestination(output.scriptPubKey, addr)) if(!ExtractDestination(output.scriptPubKey, addr))
continue; continue;
CAmount n = wallet.IsSpent(COutPoint(Txid::FromUint256(walletEntry.first), i)) ? 0 : output.nValue; CAmount n = wallet.IsSpent(COutPoint(walletEntry.first, i)) ? 0 : output.nValue;
balances[addr] += n; balances[addr] += n;
} }
} }

View file

@ -6,6 +6,7 @@
#define BITCOIN_WALLET_RECEIVE_H #define BITCOIN_WALLET_RECEIVE_H
#include <consensus/amount.h> #include <consensus/amount.h>
#include <util/transaction_identifier.h>
#include <wallet/transaction.h> #include <wallet/transaction.h>
#include <wallet/types.h> #include <wallet/types.h>
#include <wallet/wallet.h> #include <wallet/wallet.h>
@ -45,7 +46,7 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
CAmount& nFee, const isminefilter& filter, CAmount& nFee, const isminefilter& filter,
bool include_change); bool include_change);
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter); bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminefilter& filter);
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<Txid>& trusted_parents) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx); bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx);
struct Balance { struct Balance {

View file

@ -337,7 +337,6 @@ RPCHelpMan importprunedfunds()
if (!DecodeHexTx(tx, request.params[0].get_str())) { if (!DecodeHexTx(tx, request.params[0].get_str())) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input."); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
} }
uint256 hashTx = tx.GetHash();
DataStream ssMB{ParseHexV(request.params[1], "proof")}; DataStream ssMB{ParseHexV(request.params[1], "proof")};
CMerkleBlock merkleBlock; CMerkleBlock merkleBlock;
@ -357,7 +356,7 @@ RPCHelpMan importprunedfunds()
} }
std::vector<uint256>::const_iterator it; std::vector<uint256>::const_iterator it;
if ((it = std::find(vMatch.begin(), vMatch.end(), hashTx)) == vMatch.end()) { if ((it = std::find(vMatch.begin(), vMatch.end(), tx.GetHash())) == vMatch.end()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction given doesn't exist in proof"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction given doesn't exist in proof");
} }
@ -394,8 +393,8 @@ RPCHelpMan removeprunedfunds()
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
uint256 hash(ParseHashV(request.params[0], "txid")); Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
std::vector<uint256> vHash; std::vector<Txid> vHash;
vHash.push_back(hash); vHash.push_back(hash);
if (auto res = pwallet->RemoveTxs(vHash); !res) { if (auto res = pwallet->RemoveTxs(vHash); !res) {
throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(res).original); throw JSONRPCError(RPC_WALLET_ERROR, util::ErrorString(res).original);

View file

@ -56,8 +56,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
// Tally // Tally
CAmount amount = 0; CAmount amount = 0;
for (const std::pair<const uint256, CWalletTx>& wtx_pair : wallet.mapWallet) { for (const auto& [_, wtx] : wallet.mapWallet) {
const CWalletTx& wtx = wtx_pair.second;
int depth{wallet.GetTxDepthInMainChain(wtx)}; int depth{wallet.GetTxDepthInMainChain(wtx)};
if (depth < min_depth if (depth < min_depth
// Coinbase with less than 1 confirmation is no longer in the main chain // Coinbase with less than 1 confirmation is no longer in the main chain

View file

@ -1068,7 +1068,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
throw JSONRPCError(RPC_WALLET_ERROR, "bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead."); throw JSONRPCError(RPC_WALLET_ERROR, "bumpfee is not available with wallets that have private keys disabled. Use psbtbumpfee instead.");
} }
uint256 hash(ParseHashV(request.params[0], "txid")); Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
CCoinControl coin_control; CCoinControl coin_control;
coin_control.fAllowWatchOnly = pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); coin_control.fAllowWatchOnly = pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
@ -1166,7 +1166,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction."); throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");
} }
uint256 txid; Txid txid;
if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) { if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original); throw JSONRPCError(RPC_WALLET_ERROR, errors[0].original);
} }

View file

@ -7,6 +7,7 @@
#include <policy/rbf.h> #include <policy/rbf.h>
#include <rpc/util.h> #include <rpc/util.h>
#include <rpc/blockchain.h> #include <rpc/blockchain.h>
#include <util/transaction_identifier.h>
#include <util/vector.h> #include <util/vector.h>
#include <wallet/receive.h> #include <wallet/receive.h>
#include <wallet/rpc/util.h> #include <wallet/rpc/util.h>
@ -34,11 +35,10 @@ static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue
} else { } else {
entry.pushKV("trusted", CachedTxIsTrusted(wallet, wtx)); entry.pushKV("trusted", CachedTxIsTrusted(wallet, wtx));
} }
uint256 hash = wtx.GetHash(); entry.pushKV("txid", wtx.GetHash().GetHex());
entry.pushKV("txid", hash.GetHex());
entry.pushKV("wtxid", wtx.GetWitnessHash().GetHex()); entry.pushKV("wtxid", wtx.GetWitnessHash().GetHex());
UniValue conflicts(UniValue::VARR); UniValue conflicts(UniValue::VARR);
for (const uint256& conflict : wallet.GetTxConflicts(wtx)) for (const Txid& conflict : wallet.GetTxConflicts(wtx))
conflicts.push_back(conflict.GetHex()); conflicts.push_back(conflict.GetHex());
entry.pushKV("walletconflicts", std::move(conflicts)); entry.pushKV("walletconflicts", std::move(conflicts));
UniValue mempool_conflicts(UniValue::VARR); UniValue mempool_conflicts(UniValue::VARR);
@ -67,7 +67,7 @@ struct tallyitem
{ {
CAmount nAmount{0}; CAmount nAmount{0};
int nConf{std::numeric_limits<int>::max()}; int nConf{std::numeric_limits<int>::max()};
std::vector<uint256> txids; std::vector<Txid> txids;
bool fIsWatchonly{false}; bool fIsWatchonly{false};
tallyitem() = default; tallyitem() = default;
}; };
@ -100,8 +100,7 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
// Tally // Tally
std::map<CTxDestination, tallyitem> mapTally; std::map<CTxDestination, tallyitem> mapTally;
for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) { for (const auto& [_, wtx] : wallet.mapWallet) {
const CWalletTx& wtx = pairWtx.second;
int nDepth = wallet.GetTxDepthInMainChain(wtx); int nDepth = wallet.GetTxDepthInMainChain(wtx);
if (nDepth < nMinDepth) if (nDepth < nMinDepth)
@ -169,7 +168,7 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
obj.pushKV("label", label); obj.pushKV("label", label);
UniValue transactions(UniValue::VARR); UniValue transactions(UniValue::VARR);
if (it != mapTally.end()) { if (it != mapTally.end()) {
for (const uint256& _item : (*it).second.txids) { for (const Txid& _item : (*it).second.txids) {
transactions.push_back(_item.GetHex()); transactions.push_back(_item.GetHex());
} }
} }
@ -650,8 +649,7 @@ RPCHelpMan listsinceblock()
UniValue transactions(UniValue::VARR); UniValue transactions(UniValue::VARR);
for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet) { for (const auto& [_, tx] : wallet.mapWallet) {
const CWalletTx& tx = pairWtx.second;
if (depth == -1 || abs(wallet.GetTxDepthInMainChain(tx)) < depth) { if (depth == -1 || abs(wallet.GetTxDepthInMainChain(tx)) < depth) {
ListTransactions(wallet, tx, 0, true, transactions, filter, filter_label, include_change); ListTransactions(wallet, tx, 0, true, transactions, filter, filter_label, include_change);
@ -760,7 +758,7 @@ RPCHelpMan gettransaction()
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
uint256 hash(ParseHashV(request.params[0], "txid")); Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
isminefilter filter = ISMINE_SPENDABLE; isminefilter filter = ISMINE_SPENDABLE;
@ -833,7 +831,7 @@ RPCHelpMan abandontransaction()
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
uint256 hash(ParseHashV(request.params[0], "txid")); Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
if (!pwallet->mapWallet.count(hash)) { if (!pwallet->mapWallet.count(hash)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");

View file

@ -21,6 +21,7 @@
#include <util/rbf.h> #include <util/rbf.h>
#include <util/trace.h> #include <util/trace.h>
#include <util/translation.h> #include <util/translation.h>
#include <util/transaction_identifier.h>
#include <wallet/coincontrol.h> #include <wallet/coincontrol.h>
#include <wallet/fees.h> #include <wallet/fees.h>
#include <wallet/receive.h> #include <wallet/receive.h>
@ -328,10 +329,10 @@ CoinsResult AvailableCoins(const CWallet& wallet,
const bool can_grind_r = wallet.CanGrindR(); const bool can_grind_r = wallet.CanGrindR();
std::vector<COutPoint> outpoints; std::vector<COutPoint> outpoints;
std::set<uint256> trusted_parents; std::set<Txid> trusted_parents;
for (const auto& entry : wallet.mapWallet) for (const auto& entry : wallet.mapWallet)
{ {
const uint256& txid = entry.first; const Txid& txid = entry.first;
const CWalletTx& wtx = entry.second; const CWalletTx& wtx = entry.second;
if (wallet.IsTxImmatureCoinBase(wtx) && !params.include_immature_coinbase) if (wallet.IsTxImmatureCoinBase(wtx) && !params.include_immature_coinbase)
@ -391,7 +392,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
const CTxOut& output = wtx.tx->vout[i]; const CTxOut& output = wtx.tx->vout[i];
const COutPoint outpoint(Txid::FromUint256(txid), i); const COutPoint outpoint(txid, i);
if (output.nValue < params.min_amount || output.nValue > params.max_amount) if (output.nValue < params.min_amount || output.nValue > params.max_amount)
continue; continue;

View file

@ -80,7 +80,7 @@ static void add_coin(CoinsResult& available_coins, CWallet& wallet, const CAmoun
if (spendable) { if (spendable) {
tx.vout[nInput].scriptPubKey = GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, ""))); tx.vout[nInput].scriptPubKey = GetScriptForDestination(*Assert(wallet.GetNewDestination(OutputType::BECH32, "")));
} }
uint256 txid = tx.GetHash(); Txid txid = tx.GetHash();
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{})); auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{}));

View file

@ -40,7 +40,7 @@ static void addCoin(CoinsResult& coins,
tx.vout[0].nValue = nValue; tx.vout[0].nValue = nValue;
tx.vout[0].scriptPubKey = GetScriptForDestination(dest); tx.vout[0].scriptPubKey = GetScriptForDestination(dest);
const auto txid{tx.GetHash().ToUint256()}; const auto txid{tx.GetHash()};
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{})); auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{}));
assert(ret.second); assert(ret.second);

View file

@ -726,7 +726,7 @@ BOOST_FIXTURE_TEST_CASE(RemoveTxs, TestChain100Setup)
BOOST_CHECK(wallet->HasWalletSpend(prev_tx)); BOOST_CHECK(wallet->HasWalletSpend(prev_tx));
BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1u); BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_hash), 1u);
std::vector<uint256> vHashIn{ block_hash }; std::vector<Txid> vHashIn{ block_hash };
BOOST_CHECK(wallet->RemoveTxs(vHashIn)); BOOST_CHECK(wallet->RemoveTxs(vHashIn));
BOOST_CHECK(!wallet->HasWalletSpend(prev_tx)); BOOST_CHECK(!wallet->HasWalletSpend(prev_tx));
@ -776,7 +776,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_sync_tx_invalid_state_test, TestingSetup)
{ {
// Verify balance update for the new tx and the old one // Verify balance update for the new tx and the old one
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);
const CWalletTx* new_wtx = wallet.GetWalletTx(good_tx_id.ToUint256()); const CWalletTx* new_wtx = wallet.GetWalletTx(good_tx_id);
BOOST_CHECK_EQUAL(CachedTxGetAvailableCredit(wallet, *new_wtx), 1 * COIN); BOOST_CHECK_EQUAL(CachedTxGetAvailableCredit(wallet, *new_wtx), 1 * COIN);
// Now the old wtx // Now the old wtx

View file

@ -539,7 +539,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& b
* @{ * @{
*/ */
const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const const CWalletTx* CWallet::GetWalletTx(const Txid& hash) const
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
const auto it = mapWallet.find(hash); const auto it = mapWallet.find(hash);
@ -676,9 +676,9 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
} }
} }
std::set<uint256> CWallet::GetConflicts(const uint256& txid) const std::set<Txid> CWallet::GetConflicts(const Txid& txid) const
{ {
std::set<uint256> result; std::set<Txid> result;
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
const auto it = mapWallet.find(txid); const auto it = mapWallet.find(txid);
@ -744,7 +744,7 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
// Now copy data from copyFrom to rest: // Now copy data from copyFrom to rest:
for (TxSpends::iterator it = range.first; it != range.second; ++it) for (TxSpends::iterator it = range.first; it != range.second; ++it)
{ {
const uint256& hash = it->second; const Txid& hash = it->second;
CWalletTx* copyTo = &mapWallet.at(hash); CWalletTx* copyTo = &mapWallet.at(hash);
if (copyFrom == copyTo) continue; if (copyFrom == copyTo) continue;
assert(copyFrom && "Oldest wallet transaction in range assumed to have been found."); assert(copyFrom && "Oldest wallet transaction in range assumed to have been found.");
@ -770,8 +770,8 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
range = mapTxSpends.equal_range(outpoint); range = mapTxSpends.equal_range(outpoint);
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) { for (TxSpends::const_iterator it = range.first; it != range.second; ++it) {
const uint256& wtxid = it->second; const Txid& txid = it->second;
const auto mit = mapWallet.find(wtxid); const auto mit = mapWallet.find(txid);
if (mit != mapWallet.end()) { if (mit != mapWallet.end()) {
const auto& wtx = mit->second; const auto& wtx = mit->second;
if (!wtx.isAbandoned() && !wtx.isBlockConflicted() && !wtx.isMempoolConflicted()) if (!wtx.isAbandoned() && !wtx.isBlockConflicted() && !wtx.isMempoolConflicted())
@ -781,9 +781,9 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
return false; return false;
} }
void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch) void CWallet::AddToSpends(const COutPoint& outpoint, const Txid& txid, WalletBatch* batch)
{ {
mapTxSpends.insert(std::make_pair(outpoint, wtxid)); mapTxSpends.insert(std::make_pair(outpoint, txid));
if (batch) { if (batch) {
UnlockCoin(outpoint, batch); UnlockCoin(outpoint, batch);
@ -983,12 +983,12 @@ void CWallet::MarkDirty()
{ {
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
for (std::pair<const uint256, CWalletTx>& item : mapWallet) for (auto& [_, wtx] : mapWallet)
item.second.MarkDirty(); wtx.MarkDirty();
} }
} }
bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash) bool CWallet::MarkReplaced(const Txid& originalHash, const Txid& newHash)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1020,7 +1020,7 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
return success; return success;
} }
void CWallet::SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) void CWallet::SetSpentKeyState(WalletBatch& batch, const Txid& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations)
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
const CWalletTx* srctx = GetWalletTx(hash); const CWalletTx* srctx = GetWalletTx(hash);
@ -1075,7 +1075,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
WalletBatch batch(GetDatabase(), fFlushOnClose); WalletBatch batch(GetDatabase(), fFlushOnClose);
uint256 hash = tx->GetHash(); Txid hash = tx->GetHash();
if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
// Mark used destinations // Mark used destinations
@ -1197,7 +1197,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
return &wtx; return &wtx;
} }
bool CWallet::LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx) bool CWallet::LoadToWallet(const Txid& hash, const UpdateWalletTxFn& fill_wtx)
{ {
const auto& ins = mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(hash), std::forward_as_tuple(nullptr, TxStateInactive{})); const auto& ins = mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(hash), std::forward_as_tuple(nullptr, TxStateInactive{}));
CWalletTx& wtx = ins.first->second; CWalletTx& wtx = ins.first->second;
@ -1295,7 +1295,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxS
return false; return false;
} }
bool CWallet::TransactionCanBeAbandoned(const uint256& hashTx) const bool CWallet::TransactionCanBeAbandoned(const Txid& hashTx) const
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
const CWalletTx* wtx = GetWalletTx(hashTx); const CWalletTx* wtx = GetWalletTx(hashTx);
@ -1312,7 +1312,7 @@ void CWallet::MarkInputsDirty(const CTransactionRef& tx)
} }
} }
bool CWallet::AbandonTransaction(const uint256& hashTx) bool CWallet::AbandonTransaction(const Txid& hashTx)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
auto it = mapWallet.find(hashTx); auto it = mapWallet.find(hashTx);
@ -1350,7 +1350,7 @@ bool CWallet::AbandonTransaction(CWalletTx& tx)
return true; return true;
} }
void CWallet::MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx) void CWallet::MarkConflicted(const uint256& hashBlock, int conflicting_height, const Txid& hashTx)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1380,20 +1380,20 @@ void CWallet::MarkConflicted(const uint256& hashBlock, int conflicting_height, c
} }
void CWallet::RecursiveUpdateTxState(const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) { void CWallet::RecursiveUpdateTxState(const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) {
// Do not flush the wallet here for performance reasons // Do not flush the wallet here for performance reasons
WalletBatch batch(GetDatabase(), false); WalletBatch batch(GetDatabase(), false);
RecursiveUpdateTxState(&batch, tx_hash, try_updating_state); RecursiveUpdateTxState(&batch, tx_hash, try_updating_state);
} }
void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) { void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) {
std::set<uint256> todo; std::set<Txid> todo;
std::set<uint256> done; std::set<Txid> done;
todo.insert(tx_hash); todo.insert(tx_hash);
while (!todo.empty()) { while (!todo.empty()) {
uint256 now = *todo.begin(); Txid now = *todo.begin();
todo.erase(now); todo.erase(now);
done.insert(now); done.insert(now);
auto it = mapWallet.find(now); auto it = mapWallet.find(now);
@ -1406,7 +1406,7 @@ void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const uint256& tx_hash,
if (batch) batch->WriteTx(wtx); if (batch) batch->WriteTx(wtx);
// Iterate over all its outputs, and update those tx states as well (if applicable) // Iterate over all its outputs, and update those tx states as well (if applicable)
for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) { for (unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(COutPoint(Txid::FromUint256(now), i)); std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(COutPoint(now, i));
for (TxSpends::const_iterator iter = range.first; iter != range.second; ++iter) { for (TxSpends::const_iterator iter = range.first; iter != range.second; ++iter) {
if (!done.count(iter->second)) { if (!done.count(iter->second)) {
todo.insert(iter->second); todo.insert(iter->second);
@ -1450,7 +1450,7 @@ void CWallet::transactionAddedToMempool(const CTransactionRef& tx) {
for (const CTxIn& tx_in : tx->vin) { for (const CTxIn& tx_in : tx->vin) {
// For each wallet transaction spending this prevout.. // For each wallet transaction spending this prevout..
for (auto range = mapTxSpends.equal_range(tx_in.prevout); range.first != range.second; range.first++) { for (auto range = mapTxSpends.equal_range(tx_in.prevout); range.first != range.second; range.first++) {
const uint256& spent_id = range.first->second; const Txid& spent_id = range.first->second;
// Skip the recently added tx // Skip the recently added tx
if (spent_id == txid) continue; if (spent_id == txid) continue;
RecursiveUpdateTxState(/*batch=*/nullptr, spent_id, [&txid](CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { RecursiveUpdateTxState(/*batch=*/nullptr, spent_id, [&txid](CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {
@ -1503,7 +1503,7 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe
// and recursively mark them as no longer conflicting with // and recursively mark them as no longer conflicting with
// txid // txid
for (auto range = mapTxSpends.equal_range(tx_in.prevout); range.first != range.second; range.first++) { for (auto range = mapTxSpends.equal_range(tx_in.prevout); range.first != range.second; range.first++) {
const uint256& spent_id = range.first->second; const Txid& spent_id = range.first->second;
RecursiveUpdateTxState(/*batch=*/nullptr, spent_id, [&txid](CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { RecursiveUpdateTxState(/*batch=*/nullptr, spent_id, [&txid](CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {
return wtx.mempool_conflicts.erase(txid) ? TxUpdate::CHANGED : TxUpdate::UNCHANGED; return wtx.mempool_conflicts.erase(txid) ? TxUpdate::CHANGED : TxUpdate::UNCHANGED;
@ -2072,12 +2072,12 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string
return ret; return ret;
} }
std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const std::set<Txid> CWallet::GetTxConflicts(const CWalletTx& wtx) const
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
const uint256 myHash{wtx.GetHash()}; const Txid myHash{wtx.GetHash()};
std::set<uint256> result{GetConflicts(myHash)}; std::set<Txid> result{GetConflicts(myHash)};
result.erase(myHash); result.erase(myHash);
return result; return result;
} }
@ -2228,7 +2228,7 @@ std::optional<PSBTError> CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bo
// If we have no utxo, grab it from the wallet. // If we have no utxo, grab it from the wallet.
if (!input.non_witness_utxo) { if (!input.non_witness_utxo) {
const uint256& txhash = txin.prevout.hash; const Txid& txhash = txin.prevout.hash;
const auto it = mapWallet.find(txhash); const auto it = mapWallet.find(txhash);
if (it != mapWallet.end()) { if (it != mapWallet.end()) {
const CWalletTx& wtx = it->second; const CWalletTx& wtx = it->second;
@ -2405,7 +2405,7 @@ DBErrors CWallet::LoadWallet()
return nLoadWalletRet; return nLoadWalletRet;
} }
util::Result<void> CWallet::RemoveTxs(std::vector<uint256>& txs_to_remove) util::Result<void> CWallet::RemoveTxs(std::vector<Txid>& txs_to_remove)
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
bilingual_str str_err; // future: make RunWithinTxn return a util::Result bilingual_str str_err; // future: make RunWithinTxn return a util::Result
@ -2419,16 +2419,15 @@ util::Result<void> CWallet::RemoveTxs(std::vector<uint256>& txs_to_remove)
return {}; // all good return {}; // all good
} }
util::Result<void> CWallet::RemoveTxs(WalletBatch& batch, std::vector<uint256>& txs_to_remove) util::Result<void> CWallet::RemoveTxs(WalletBatch& batch, std::vector<Txid>& txs_to_remove)
{ {
AssertLockHeld(cs_wallet); AssertLockHeld(cs_wallet);
if (!batch.HasActiveTxn()) return util::Error{strprintf(_("The transactions removal process can only be executed within a db txn"))}; if (!batch.HasActiveTxn()) return util::Error{strprintf(_("The transactions removal process can only be executed within a db txn"))};
// Check for transaction existence and remove entries from disk // Check for transaction existence and remove entries from disk
using TxIterator = std::unordered_map<uint256, CWalletTx, SaltedTxidHasher>::const_iterator; std::vector<decltype(mapWallet)::const_iterator> erased_txs;
std::vector<TxIterator> erased_txs;
bilingual_str str_err; bilingual_str str_err;
for (const uint256& hash : txs_to_remove) { for (const Txid& hash : txs_to_remove) {
auto it_wtx = mapWallet.find(hash); auto it_wtx = mapWallet.find(hash);
if (it_wtx == mapWallet.end()) { if (it_wtx == mapWallet.end()) {
return util::Error{strprintf(_("Transaction %s does not belong to this wallet"), hash.GetHex())}; return util::Error{strprintf(_("Transaction %s does not belong to this wallet"), hash.GetHex())};
@ -2443,7 +2442,7 @@ util::Result<void> CWallet::RemoveTxs(WalletBatch& batch, std::vector<uint256>&
batch.RegisterTxnListener({.on_commit=[&, erased_txs]() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { batch.RegisterTxnListener({.on_commit=[&, erased_txs]() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {
// Update the in-memory state and notify upper layers about the removals // Update the in-memory state and notify upper layers about the removals
for (const auto& it : erased_txs) { for (const auto& it : erased_txs) {
const uint256 hash{it->first}; const Txid hash{it->first};
wtxOrdered.erase(it->second.m_it_wtxOrdered); wtxOrdered.erase(it->second.m_it_wtxOrdered);
for (const auto& txin : it->second.tx->vin) for (const auto& txin : it->second.tx->vin)
mapTxSpends.erase(txin.prevout); mapTxSpends.erase(txin.prevout);
@ -4164,7 +4163,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
// Check if the transactions in the wallet are still ours. Either they belong here, or they belong in the watchonly wallet. // Check if the transactions in the wallet are still ours. Either they belong here, or they belong in the watchonly wallet.
// We need to go through these in the tx insertion order so that lookups to spends works. // We need to go through these in the tx insertion order so that lookups to spends works.
std::vector<uint256> txids_to_delete; std::vector<Txid> txids_to_delete;
std::unique_ptr<WalletBatch> watchonly_batch; std::unique_ptr<WalletBatch> watchonly_batch;
if (data.watchonly_wallet) { if (data.watchonly_wallet) {
watchonly_batch = std::make_unique<WalletBatch>(data.watchonly_wallet->GetDatabase()); watchonly_batch = std::make_unique<WalletBatch>(data.watchonly_wallet->GetDatabase());
@ -4195,7 +4194,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
LOCK(data.watchonly_wallet->cs_wallet); LOCK(data.watchonly_wallet->cs_wallet);
if (data.watchonly_wallet->IsMine(*wtx->tx) || data.watchonly_wallet->IsFromMe(*wtx->tx)) { if (data.watchonly_wallet->IsMine(*wtx->tx) || data.watchonly_wallet->IsFromMe(*wtx->tx)) {
// Add to watchonly wallet // Add to watchonly wallet
const uint256& hash = wtx->GetHash(); const Txid& hash = wtx->GetHash();
const CWalletTx& to_copy_wtx = *wtx; const CWalletTx& to_copy_wtx = *wtx;
if (!data.watchonly_wallet->LoadToWallet(hash, [&](CWalletTx& ins_wtx, bool new_tx) EXCLUSIVE_LOCKS_REQUIRED(data.watchonly_wallet->cs_wallet) { if (!data.watchonly_wallet->LoadToWallet(hash, [&](CWalletTx& ins_wtx, bool new_tx) EXCLUSIVE_LOCKS_REQUIRED(data.watchonly_wallet->cs_wallet) {
if (!new_tx) return false; if (!new_tx) return false;

View file

@ -26,6 +26,7 @@
#include <util/result.h> #include <util/result.h>
#include <util/string.h> #include <util/string.h>
#include <util/time.h> #include <util/time.h>
#include <util/transaction_identifier.h>
#include <util/ui_change_type.h> #include <util/ui_change_type.h>
#include <wallet/crypter.h> #include <wallet/crypter.h>
#include <wallet/db.h> #include <wallet/db.h>
@ -331,9 +332,9 @@ private:
* detect and report conflicts (double-spends or * detect and report conflicts (double-spends or
* mutated transactions where the mutant gets mined). * mutated transactions where the mutant gets mined).
*/ */
typedef std::unordered_multimap<COutPoint, uint256, SaltedOutpointHasher> TxSpends; typedef std::unordered_multimap<COutPoint, Txid, SaltedOutpointHasher> TxSpends;
TxSpends mapTxSpends GUARDED_BY(cs_wallet); TxSpends mapTxSpends GUARDED_BY(cs_wallet);
void AddToSpends(const COutPoint& outpoint, const uint256& wtxid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void AddToSpends(const COutPoint& outpoint, const Txid& txid, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void AddToSpends(const CWalletTx& wtx, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void AddToSpends(const CWalletTx& wtx, WalletBatch* batch = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** /**
@ -355,15 +356,15 @@ private:
bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool AddToWalletIfInvolvingMe(const CTransactionRef& tx, const SyncTxState& state, bool fUpdate, bool rescanning_old_block) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */ /** Mark a transaction (and its in-wallet descendants) as conflicting with a particular block. */
void MarkConflicted(const uint256& hashBlock, int conflicting_height, const uint256& hashTx); void MarkConflicted(const uint256& hashBlock, int conflicting_height, const Txid& hashTx);
enum class TxUpdate { UNCHANGED, CHANGED, NOTIFY_CHANGED }; enum class TxUpdate { UNCHANGED, CHANGED, NOTIFY_CHANGED };
using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>; using TryUpdatingStateFn = std::function<TxUpdate(CWalletTx& wtx)>;
/** Mark a transaction (and its in-wallet descendants) as a particular tx state. */ /** Mark a transaction (and its in-wallet descendants) as a particular tx state. */
void RecursiveUpdateTxState(const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void RecursiveUpdateTxState(const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void RecursiveUpdateTxState(WalletBatch* batch, const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */ /** Mark a transaction's inputs dirty, thus forcing the outputs to be recomputed */
void MarkInputsDirty(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void MarkInputsDirty(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@ -481,7 +482,7 @@ public:
/** Map from txid to CWalletTx for all transactions this wallet is /** Map from txid to CWalletTx for all transactions this wallet is
* interested in, including received and sent transactions. */ * interested in, including received and sent transactions. */
std::unordered_map<uint256, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet); std::unordered_map<Txid, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet);
typedef std::multimap<int64_t, CWalletTx*> TxItems; typedef std::multimap<int64_t, CWalletTx*> TxItems;
TxItems wtxOrdered; TxItems wtxOrdered;
@ -503,9 +504,9 @@ public:
/** Interface for accessing chain state. */ /** Interface for accessing chain state. */
interfaces::Chain& chain() const { assert(m_chain); return *m_chain; } interfaces::Chain& chain() const { assert(m_chain); return *m_chain; }
const CWalletTx* GetWalletTx(const uint256& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); const CWalletTx* GetWalletTx(const Txid& hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
std::set<uint256> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::set<Txid> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** /**
* Return depth of transaction in blockchain: * Return depth of transaction in blockchain:
@ -537,7 +538,7 @@ public:
// Whether this or any known scriptPubKey with the same single key has been spent. // Whether this or any known scriptPubKey with the same single key has been spent.
bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool IsSpentKey(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void SetSpentKeyState(WalletBatch& batch, const uint256& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void SetSpentKeyState(WalletBatch& batch, const Txid& hash, unsigned int n, bool used, std::set<CTxDestination>& tx_destinations) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** Display address on an external signer. */ /** Display address on an external signer. */
util::Result<void> DisplayAddress(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); util::Result<void> DisplayAddress(const CTxDestination& dest) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@ -608,7 +609,7 @@ public:
* @return the recently added wtx pointer or nullptr if there was a db write error. * @return the recently added wtx pointer or nullptr if there was a db write error.
*/ */
CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block = false); CWalletTx* AddToWallet(CTransactionRef tx, const TxState& state, const UpdateWalletTxFn& update_wtx=nullptr, bool fFlushOnClose=true, bool rescanning_old_block = false);
bool LoadToWallet(const uint256& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool LoadToWallet(const Txid& hash, const UpdateWalletTxFn& fill_wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
void transactionAddedToMempool(const CTransactionRef& tx) override; void transactionAddedToMempool(const CTransactionRef& tx) override;
void blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) override; void blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) override;
void blockDisconnected(const interfaces::BlockInfo& block) override; void blockDisconnected(const interfaces::BlockInfo& block) override;
@ -793,8 +794,8 @@ public:
DBErrors LoadWallet(); DBErrors LoadWallet();
/** Erases the provided transactions from the wallet. */ /** Erases the provided transactions from the wallet. */
util::Result<void> RemoveTxs(std::vector<uint256>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); util::Result<void> RemoveTxs(std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
util::Result<void> RemoveTxs(WalletBatch& batch, std::vector<uint256>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); util::Result<void> RemoveTxs(WalletBatch& batch, std::vector<Txid>& txs_to_remove) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose); bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::optional<AddressPurpose>& purpose);
@ -817,7 +818,7 @@ public:
int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; } int GetVersion() const { LOCK(cs_wallet); return nWalletVersion; }
//! Get wallet transactions that conflict with given transaction (spend same outputs) //! Get wallet transactions that conflict with given transaction (spend same outputs)
std::set<uint256> GetConflicts(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); std::set<Txid> GetConflicts(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Check if a given transaction has any of its outputs spent by another transaction in the wallet //! Check if a given transaction has any of its outputs spent by another transaction in the wallet
bool HasWalletSpend(const CTransactionRef& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool HasWalletSpend(const CTransactionRef& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
@ -844,7 +845,7 @@ public:
* Wallet transaction added, removed or updated. * Wallet transaction added, removed or updated.
* @note called with lock cs_wallet held. * @note called with lock cs_wallet held.
*/ */
boost::signals2::signal<void(const uint256& hashTx, ChangeType status)> NotifyTransactionChanged; boost::signals2::signal<void(const Txid& hashTx, ChangeType status)> NotifyTransactionChanged;
/** Show progress e.g. for rescan */ /** Show progress e.g. for rescan */
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress; boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
@ -867,14 +868,14 @@ public:
void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; } void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
/** Return whether transaction can be abandoned */ /** Return whether transaction can be abandoned */
bool TransactionCanBeAbandoned(const uint256& hashTx) const; bool TransactionCanBeAbandoned(const Txid& hashTx) const;
/* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */ /* Mark a transaction (and it in-wallet descendants) as abandoned so its inputs may be respent. */
bool AbandonTransaction(const uint256& hashTx); bool AbandonTransaction(const Txid& hashTx);
bool AbandonTransaction(CWalletTx& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); bool AbandonTransaction(CWalletTx& tx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** Mark a transaction as replaced by another transaction. */ /** Mark a transaction as replaced by another transaction. */
bool MarkReplaced(const uint256& originalHash, const uint256& newHash); bool MarkReplaced(const Txid& originalHash, const Txid& newHash);
/* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */ /* Initializes the wallet, returns a new CWallet instance or a null pointer in case of an error */
static std::shared_ptr<CWallet> Create(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings); static std::shared_ptr<CWallet> Create(WalletContext& context, const std::string& name, std::unique_ptr<WalletDatabase> database, uint64_t wallet_creation_flags, bilingual_str& error, std::vector<bilingual_str>& warnings);

View file

@ -16,6 +16,7 @@
#include <util/bip32.h> #include <util/bip32.h>
#include <util/check.h> #include <util/check.h>
#include <util/fs.h> #include <util/fs.h>
#include <util/transaction_identifier.h>
#include <util/time.h> #include <util/time.h>
#include <util/translation.h> #include <util/translation.h>
#ifdef USE_BDB #ifdef USE_BDB
@ -96,9 +97,9 @@ bool WalletBatch::WriteTx(const CWalletTx& wtx)
return WriteIC(std::make_pair(DBKeys::TX, wtx.GetHash()), wtx); return WriteIC(std::make_pair(DBKeys::TX, wtx.GetHash()), wtx);
} }
bool WalletBatch::EraseTx(uint256 hash) bool WalletBatch::EraseTx(Txid hash)
{ {
return EraseIC(std::make_pair(DBKeys::TX, hash)); return EraseIC(std::make_pair(DBKeys::TX, hash.ToUint256()));
} }
bool WalletBatch::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite) bool WalletBatch::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite)
@ -1048,7 +1049,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E
return result; return result;
} }
static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vector<uint256>& upgraded_txs, bool& any_unordered) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vector<Txid>& upgraded_txs, bool& any_unordered) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{ {
AssertLockHeld(pwallet->cs_wallet); AssertLockHeld(pwallet->cs_wallet);
DBErrors result = DBErrors::LOAD_OK; DBErrors result = DBErrors::LOAD_OK;
@ -1058,7 +1059,7 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
LoadResult tx_res = LoadRecords(pwallet, batch, DBKeys::TX, LoadResult tx_res = LoadRecords(pwallet, batch, DBKeys::TX,
[&any_unordered, &upgraded_txs] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { [&any_unordered, &upgraded_txs] (CWallet* pwallet, DataStream& key, DataStream& value, std::string& err) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) {
DBErrors result = DBErrors::LOAD_OK; DBErrors result = DBErrors::LOAD_OK;
uint256 hash; Txid hash;
key >> hash; key >> hash;
// LoadToWallet call below creates a new CWalletTx that fill_wtx // LoadToWallet call below creates a new CWalletTx that fill_wtx
// callback fills with transaction metadata. // callback fills with transaction metadata.
@ -1192,7 +1193,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
{ {
DBErrors result = DBErrors::LOAD_OK; DBErrors result = DBErrors::LOAD_OK;
bool any_unordered = false; bool any_unordered = false;
std::vector<uint256> upgraded_txs; std::vector<Txid> upgraded_txs;
LOCK(pwallet->cs_wallet); LOCK(pwallet->cs_wallet);
@ -1247,7 +1248,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
if (result != DBErrors::LOAD_OK) if (result != DBErrors::LOAD_OK)
return result; return result;
for (const uint256& hash : upgraded_txs) for (const Txid& hash : upgraded_txs)
WriteTx(pwallet->mapWallet.at(hash)); WriteTx(pwallet->mapWallet.at(hash));
if (!has_last_client || last_client != CLIENT_VERSION) // Update if (!has_last_client || last_client != CLIENT_VERSION) // Update

View file

@ -7,6 +7,7 @@
#define BITCOIN_WALLET_WALLETDB_H #define BITCOIN_WALLET_WALLETDB_H
#include <script/sign.h> #include <script/sign.h>
#include <util/transaction_identifier.h>
#include <wallet/db.h> #include <wallet/db.h>
#include <wallet/walletutil.h> #include <wallet/walletutil.h>
#include <key.h> #include <key.h>
@ -238,7 +239,7 @@ public:
bool ErasePurpose(const std::string& strAddress); bool ErasePurpose(const std::string& strAddress);
bool WriteTx(const CWalletTx& wtx); bool WriteTx(const CWalletTx& wtx);
bool EraseTx(uint256 hash); bool EraseTx(Txid hash);
bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite); bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite);
bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta); bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);