Skip to content

Commit 9e58c5b

Browse files
committed
Use Txid in COutpoint
1 parent d752349 commit 9e58c5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+124
-114
lines changed

src/bench/disconnected_transactions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ReorgTxns {
2828
static BlockTxns CreateRandomTransactions(size_t num_txns)
2929
{
3030
// Ensure every transaction has a different txid by having each one spend the previous one.
31-
static uint256 prevout_hash{uint256::ZERO};
31+
static Txid prevout_hash{};
3232

3333
BlockTxns txns;
3434
txns.reserve(num_txns);

src/bench/duplicate_inputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void DuplicateInputs(benchmark::Bench& bench)
4747

4848
uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100;
4949
for (uint64_t x = 0; x < (n_inputs - 1); ++x) {
50-
naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0);
50+
naughtyTx.vin.emplace_back(Txid::FromUint256(GetRandHash()), 0, CScript(), 0);
5151
}
5252
naughtyTx.vin.emplace_back(naughtyTx.vin.back());
5353

src/bench/mempool_stress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static std::vector<CTransactionRef> CreateOrderedCoins(FastRandomContext& det_ra
5656
for (size_t ancestor = 0; ancestor < n_ancestors && !available_coins.empty(); ++ancestor){
5757
size_t idx = det_rand.randrange(available_coins.size());
5858
Available coin = available_coins[idx];
59-
uint256 hash = coin.ref->GetHash();
59+
Txid hash = coin.ref->GetHash();
6060
// biased towards taking min_ancestors parents, but maybe more
6161
size_t n_to_take = det_rand.randrange(2) == 0 ?
6262
min_ancestors :

src/bitcoin-tx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
280280
}
281281

282282
// append to transaction input list
283-
CTxIn txin(txid, vout, CScript(), nSequenceIn);
283+
CTxIn txin(Txid::FromUint256(txid), vout, CScript(), nSequenceIn);
284284
tx.vin.push_back(txin);
285285
}
286286

@@ -629,7 +629,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
629629
if (nOut < 0)
630630
throw std::runtime_error("vout cannot be negative");
631631

632-
COutPoint out(txid, nOut);
632+
COutPoint out(Txid::FromUint256(txid), nOut);
633633
std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
634634
CScript scriptPubKey(pkData.begin(), pkData.end());
635635

src/coins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CCoinsViewCache::EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coi
116116

117117
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check_for_overwrite) {
118118
bool fCoinbase = tx.IsCoinBase();
119-
const uint256& txid = tx.GetHash();
119+
const Txid& txid = tx.GetHash();
120120
for (size_t i = 0; i < tx.vout.size(); ++i) {
121121
bool overwrite = check_for_overwrite ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
122122
// Coinbase transactions can always be overwritten, in order to correctly
@@ -341,7 +341,7 @@ void CCoinsViewCache::SanityCheck() const
341341
static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut());
342342
static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
343343

344-
const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
344+
const Coin& AccessByTxid(const CCoinsViewCache& view, const Txid& txid)
345345
{
346346
COutPoint iter(txid, 0);
347347
while (iter.n < MAX_OUTPUTS_PER_BLOCK) {

src/coins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool
364364
//! This function can be quite expensive because in the event of a transaction
365365
//! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK
366366
//! lookups to database, so it should be used with care.
367-
const Coin& AccessByTxid(const CCoinsViewCache& cache, const uint256& txid);
367+
const Coin& AccessByTxid(const CCoinsViewCache& cache, const Txid& txid);
368368

369369
/**
370370
* This is a minimally invasive approach to shutdown on LevelDB read errors from the

src/common/bloom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
9898
// for finding tx when they appear in a block
9999
if (vData.empty()) // zero-size = "match-all" filter
100100
return true;
101-
const uint256& hash = tx.GetHash();
102-
if (contains(hash))
101+
const Txid& hash = tx.GetHash();
102+
if (contains(hash.ToUint256()))
103103
fFound = true;
104104

105105
for (unsigned int i = 0; i < tx.vout.size(); i++)

src/kernel/coinstats.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void ApplyCoinHash(std::nullptr_t, const COutPoint& outpoint, const Coin&
8989
//! construction could cause a previously invalid (and potentially malicious)
9090
//! UTXO snapshot to be considered valid.
9191
template <typename T>
92-
static void ApplyHash(T& hash_obj, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
92+
static void ApplyHash(T& hash_obj, const Txid& hash, const std::map<uint32_t, Coin>& outputs)
9393
{
9494
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
9595
COutPoint outpoint = COutPoint(hash, it->first);
@@ -118,7 +118,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
118118
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
119119
assert(pcursor);
120120

121-
uint256 prevkey;
121+
Txid prevkey;
122122
std::map<uint32_t, Coin> outputs;
123123
while (pcursor->Valid()) {
124124
if (interruption_point) interruption_point();

src/node/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
4040
assert(node.peerman);
4141

4242
std::promise<void> promise;
43-
uint256 txid = tx->GetHash();
43+
Txid txid = tx->GetHash();
4444
uint256 wtxid = tx->GetWitnessHash();
4545
bool callback_set = false;
4646

src/primitives/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, uint32_t nSequenceIn)
2929
nSequence = nSequenceIn;
3030
}
3131

32-
CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
32+
CTxIn::CTxIn(Txid hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
3333
{
3434
prevout = COutPoint(hashPrevTx, nOut);
3535
scriptSig = scriptSigIn;

0 commit comments

Comments
 (0)