mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Merge bitcoin/bitcoin#32238: qt, wallet: Convert uint256 to Txid
0671d66a8ewallet, refactor: Convert uint256 to Txid in wallet (marcofleon)c8ed51e62bwallet, refactor: Convert uint256 to Txid in wallet interfaces (marcofleon)b3214cefe6qt, refactor: Convert uint256 to Txid in the GUI (marcofleon) Pull request description: This is part of https://github.com/bitcoin/bitcoin/pull/32189. Converts all instances of transactions from `uint256` to `Txid` in the wallet, GUI, and related interfaces. ACKs for top commit: stickies-v: re-ACK0671d66a8e, no changes since 65fcfbb2b38bef20a58daa6c828c51890180611d except rebase. achow101: ACK0671d66a8efurszy: Code review ACK0671d66a8eTree-SHA512: 9fd4675db63195c4eed2d14c25015a1821fb597f51404674e4879a44a9cf18f475021a97c5f62f3926b7783ade5a38567386f663acba9f5861f1f59c1309ed60
This commit is contained in:
@@ -535,7 +535,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);
|
||||
const auto it = mapWallet.find(hash);
|
||||
@@ -680,9 +680,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);
|
||||
|
||||
const auto it = mapWallet.find(txid);
|
||||
@@ -743,7 +743,7 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
|
||||
// Now copy data from copyFrom to rest:
|
||||
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);
|
||||
if (copyFrom == copyTo) continue;
|
||||
assert(copyFrom && "Oldest wallet transaction in range assumed to have been found.");
|
||||
@@ -768,8 +768,8 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
|
||||
range = mapTxSpends.equal_range(outpoint);
|
||||
|
||||
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) {
|
||||
const uint256& wtxid = it->second;
|
||||
const auto mit = mapWallet.find(wtxid);
|
||||
const Txid& txid = it->second;
|
||||
const auto mit = mapWallet.find(txid);
|
||||
if (mit != mapWallet.end()) {
|
||||
const auto& wtx = mit->second;
|
||||
if (!wtx.isAbandoned() && !wtx.isBlockConflicted() && !wtx.isMempoolConflicted())
|
||||
@@ -779,9 +779,9 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
|
||||
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) {
|
||||
UnlockCoin(outpoint, batch);
|
||||
@@ -953,12 +953,12 @@ void CWallet::MarkDirty()
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
|
||||
item.second.MarkDirty();
|
||||
for (auto& [_, wtx] : mapWallet)
|
||||
wtx.MarkDirty();
|
||||
}
|
||||
}
|
||||
|
||||
bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
|
||||
bool CWallet::MarkReplaced(const Txid& originalHash, const Txid& newHash)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
|
||||
@@ -990,7 +990,7 @@ bool CWallet::MarkReplaced(const uint256& originalHash, const uint256& newHash)
|
||||
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);
|
||||
const CWalletTx* srctx = GetWalletTx(hash);
|
||||
@@ -1028,7 +1028,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
|
||||
|
||||
WalletBatch batch(GetDatabase());
|
||||
|
||||
uint256 hash = tx->GetHash();
|
||||
Txid hash = tx->GetHash();
|
||||
|
||||
if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
|
||||
// Mark used destinations
|
||||
@@ -1150,7 +1150,7 @@ CWalletTx* CWallet::AddToWallet(CTransactionRef tx, const TxState& state, const
|
||||
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{}));
|
||||
CWalletTx& wtx = ins.first->second;
|
||||
@@ -1248,7 +1248,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxS
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CWallet::TransactionCanBeAbandoned(const uint256& hashTx) const
|
||||
bool CWallet::TransactionCanBeAbandoned(const Txid& hashTx) const
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
const CWalletTx* wtx = GetWalletTx(hashTx);
|
||||
@@ -1265,7 +1265,7 @@ void CWallet::MarkInputsDirty(const CTransactionRef& tx)
|
||||
}
|
||||
}
|
||||
|
||||
bool CWallet::AbandonTransaction(const uint256& hashTx)
|
||||
bool CWallet::AbandonTransaction(const Txid& hashTx)
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
auto it = mapWallet.find(hashTx);
|
||||
@@ -1303,7 +1303,7 @@ bool CWallet::AbandonTransaction(CWalletTx& tx)
|
||||
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);
|
||||
|
||||
@@ -1333,19 +1333,19 @@ 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) {
|
||||
WalletBatch batch(GetDatabase());
|
||||
RecursiveUpdateTxState(&batch, tx_hash, try_updating_state);
|
||||
}
|
||||
|
||||
void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const uint256& tx_hash, const TryUpdatingStateFn& try_updating_state) {
|
||||
std::set<uint256> todo;
|
||||
std::set<uint256> done;
|
||||
void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const Txid& tx_hash, const TryUpdatingStateFn& try_updating_state) {
|
||||
std::set<Txid> todo;
|
||||
std::set<Txid> done;
|
||||
|
||||
todo.insert(tx_hash);
|
||||
|
||||
while (!todo.empty()) {
|
||||
uint256 now = *todo.begin();
|
||||
Txid now = *todo.begin();
|
||||
todo.erase(now);
|
||||
done.insert(now);
|
||||
auto it = mapWallet.find(now);
|
||||
@@ -1358,7 +1358,7 @@ void CWallet::RecursiveUpdateTxState(WalletBatch* batch, const uint256& tx_hash,
|
||||
if (batch) batch->WriteTx(wtx);
|
||||
// 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) {
|
||||
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) {
|
||||
if (!done.count(iter->second)) {
|
||||
todo.insert(iter->second);
|
||||
@@ -1402,7 +1402,7 @@ void CWallet::transactionAddedToMempool(const CTransactionRef& tx) {
|
||||
for (const CTxIn& tx_in : tx->vin) {
|
||||
// For each wallet transaction spending this prevout..
|
||||
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
|
||||
if (spent_id == txid) continue;
|
||||
RecursiveUpdateTxState(/*batch=*/nullptr, spent_id, [&txid](CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {
|
||||
@@ -1455,7 +1455,7 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe
|
||||
// and recursively mark them as no longer conflicting with
|
||||
// txid
|
||||
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) {
|
||||
return wtx.mempool_conflicts.erase(txid) ? TxUpdate::CHANGED : TxUpdate::UNCHANGED;
|
||||
@@ -1966,12 +1966,12 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::set<uint256> CWallet::GetTxConflicts(const CWalletTx& wtx) const
|
||||
std::set<Txid> CWallet::GetTxConflicts(const CWalletTx& wtx) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
|
||||
const uint256 myHash{wtx.GetHash()};
|
||||
std::set<uint256> result{GetConflicts(myHash)};
|
||||
const Txid myHash{wtx.GetHash()};
|
||||
std::set<Txid> result{GetConflicts(myHash)};
|
||||
result.erase(myHash);
|
||||
return result;
|
||||
}
|
||||
@@ -2117,7 +2117,7 @@ std::optional<PSBTError> CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bo
|
||||
|
||||
// If we have no utxo, grab it from the wallet.
|
||||
if (!input.non_witness_utxo) {
|
||||
const uint256& txhash = txin.prevout.hash;
|
||||
const Txid& txhash = txin.prevout.hash;
|
||||
const auto it = mapWallet.find(txhash);
|
||||
if (it != mapWallet.end()) {
|
||||
const CWalletTx& wtx = it->second;
|
||||
@@ -2293,7 +2293,7 @@ DBErrors CWallet::LoadWallet()
|
||||
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);
|
||||
bilingual_str str_err; // future: make RunWithinTxn return a util::Result
|
||||
@@ -2307,16 +2307,15 @@ util::Result<void> CWallet::RemoveTxs(std::vector<uint256>& txs_to_remove)
|
||||
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);
|
||||
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
|
||||
using TxIterator = std::unordered_map<uint256, CWalletTx, SaltedTxidHasher>::const_iterator;
|
||||
std::vector<TxIterator> erased_txs;
|
||||
std::vector<decltype(mapWallet)::const_iterator> erased_txs;
|
||||
bilingual_str str_err;
|
||||
for (const uint256& hash : txs_to_remove) {
|
||||
for (const Txid& hash : txs_to_remove) {
|
||||
auto it_wtx = mapWallet.find(hash);
|
||||
if (it_wtx == mapWallet.end()) {
|
||||
return util::Error{strprintf(_("Transaction %s does not belong to this wallet"), hash.GetHex())};
|
||||
@@ -2331,7 +2330,7 @@ util::Result<void> CWallet::RemoveTxs(WalletBatch& batch, std::vector<uint256>&
|
||||
batch.RegisterTxnListener({.on_commit=[&, erased_txs]() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) {
|
||||
// Update the in-memory state and notify upper layers about the removals
|
||||
for (const auto& it : erased_txs) {
|
||||
const uint256 hash{it->first};
|
||||
const Txid hash{it->first};
|
||||
wtxOrdered.erase(it->second.m_it_wtxOrdered);
|
||||
for (const auto& txin : it->second.tx->vin)
|
||||
mapTxSpends.erase(txin.prevout);
|
||||
@@ -3929,7 +3928,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.
|
||||
// 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;
|
||||
if (data.watchonly_wallet) {
|
||||
watchonly_batch = std::make_unique<WalletBatch>(data.watchonly_wallet->GetDatabase());
|
||||
@@ -3960,7 +3959,7 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
|
||||
LOCK(data.watchonly_wallet->cs_wallet);
|
||||
if (data.watchonly_wallet->IsMine(*wtx->tx) || data.watchonly_wallet->IsFromMe(*wtx->tx)) {
|
||||
// Add to watchonly wallet
|
||||
const uint256& hash = wtx->GetHash();
|
||||
const Txid& hash = wtx->GetHash();
|
||||
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 (!new_tx) return false;
|
||||
|
||||
Reference in New Issue
Block a user