diff --git a/src/coins.h b/src/coins.h --- a/src/coins.h +++ b/src/coins.h @@ -304,6 +304,6 @@ bool check = false); //! Utility function to find any unspent output with a given txid. -const Coin &AccessByTxid(const CCoinsViewCache &cache, const uint256 &txid); +const Coin &AccessByTxid(const CCoinsViewCache &cache, const TxId &txid); #endif // BITCOIN_COINS_H diff --git a/src/coins.cpp b/src/coins.cpp --- a/src/coins.cpp +++ b/src/coins.cpp @@ -131,13 +131,14 @@ void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check) { bool fCoinbase = tx.IsCoinBase(); - const uint256 &txid = tx.GetHash(); + const TxId txid = tx.GetId(); for (size_t i = 0; i < tx.vout.size(); ++i) { - bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase; + const COutPoint outpoint(txid, i); + bool overwrite = check ? cache.HaveCoin(outpoint) : fCoinbase; // Always set the possible_overwrite flag to AddCoin for coinbase txn, // in order to correctly deal with the pre-BIP30 occurrences of // duplicate coinbase transactions. - cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), + cache.AddCoin(outpoint, Coin(tx.vout[i], nHeight, fCoinbase), overwrite); } } @@ -331,7 +332,7 @@ static const size_t MAX_OUTPUTS_PER_TX = MAX_TX_SIZE / ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION); -const Coin &AccessByTxid(const CCoinsViewCache &view, const uint256 &txid) { +const Coin &AccessByTxid(const CCoinsViewCache &view, const TxId &txid) { for (uint32_t n = 0; n < MAX_OUTPUTS_PER_TX; n++) { const Coin &alternate = view.AccessCoin(COutPoint(txid, n)); if (!alternate.IsSpent()) { diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -398,9 +398,11 @@ return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); } + const TxId txid(hash); + CTransactionRef tx; uint256 hashBlock = uint256(); - if (!GetTransaction(config, hash, tx, hashBlock, true)) { + if (!GetTransaction(config, txid, tx, hashBlock, true)) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -214,7 +214,7 @@ LOCK(cs_main); - uint256 hash = ParseHashV(request.params[0], "parameter 1"); + TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); // Accept either a bool (true) or a num (>=1) to indicate verbose output. bool fVerbose = false; @@ -236,7 +236,7 @@ CTransactionRef tx; uint256 hashBlock; - if (!GetTransaction(config, hash, tx, hashBlock, true)) { + if (!GetTransaction(config, txid, tx, hashBlock, true)) { throw JSONRPCError( RPC_INVALID_ADDRESS_OR_KEY, std::string(fTxIndex ? "No such mempool or blockchain transaction" diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -135,17 +135,17 @@ // Use a limited set of random transaction ids, so we do test overwriting // entries. - std::vector txids; + std::vector txids; txids.resize(NUM_SIMULATION_ITERATIONS / 8); for (size_t i = 0; i < txids.size(); i++) { - txids[i] = InsecureRand256(); + txids[i] = TxId(InsecureRand256()); } for (unsigned int i = 0; i < NUM_SIMULATION_ITERATIONS; i++) { // Do a random modification. { // txid we're going to modify in this iteration. - uint256 txid = txids[InsecureRandRange(txids.size())]; + TxId txid = txids[InsecureRandRange(txids.size())]; Coin &coin = result[COutPoint(txid, 0)]; const Coin &entry = (InsecureRandRange(500) == 0) diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -400,9 +400,8 @@ /** * Retrieve a transaction (from memory pool, or from disk, if possible). */ -bool GetTransaction(const Config &config, const uint256 &hash, - CTransactionRef &tx, uint256 &hashBlock, - bool fAllowSlow = false); +bool GetTransaction(const Config &config, const TxId &txid, CTransactionRef &tx, + uint256 &hashBlock, bool fAllowSlow = false); /** * Find the best known block, and make it the active tip of the block chain. diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1120,9 +1120,11 @@ fOverrideMempoolLimit, nAbsurdFee); } -/** Return transaction in txOut, and if it was found inside a block, its hash is - * placed in hashBlock */ -bool GetTransaction(const Config &config, const uint256 &txid, +/** + * Return transaction in txOut, and if it was found inside a block, its hash is + * placed in hashBlock. + */ +bool GetTransaction(const Config &config, const TxId &txid, CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow) { CBlockIndex *pindexSlow = nullptr;