diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1187,10 +1187,11 @@ // included in a block. As this is best effort, we only check for // output 0 and 1. This works well enough in practice and we get // diminishing returns with 2 onward. + const TxId txid(inv.hash); return recentRejects->contains(inv.hash) || g_mempool.exists(inv.hash) || - pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 0)) || - pcoinsTip->HaveCoinInCache(COutPoint(inv.hash, 1)); + pcoinsTip->HaveCoinInCache(COutPoint(txid, 0)) || + pcoinsTip->HaveCoinInCache(COutPoint(txid, 1)); } case MSG_BLOCK: return LookupBlockIndex(inv.hash) != nullptr; @@ -2477,8 +2478,9 @@ bool fMissingInputs = false; CValidationState state; - pfrom->setAskFor.erase(inv.hash); - mapAlreadyAskedFor.erase(inv.hash); + const TxId txid(inv.hash); + pfrom->setAskFor.erase(txid); + mapAlreadyAskedFor.erase(txid); if (!AlreadyHave(inv) && AcceptToMemoryPool(config, g_mempool, state, ptx, true, @@ -2486,7 +2488,7 @@ g_mempool.check(pcoinsTip.get()); RelayTransaction(tx, connman); for (size_t i = 0; i < tx.vout.size(); i++) { - vWorkQueue.emplace_back(inv.hash, i); + vWorkQueue.emplace_back(txid, i); } pfrom->nLastTXTime = GetTime(); @@ -2511,7 +2513,7 @@ mi != itByPrev->second.end(); ++mi) { const CTransactionRef &porphanTx = (*mi)->second.tx; const CTransaction &orphanTx = *porphanTx; - const uint256 &orphanId = orphanTx.GetId(); + const TxId &orphanId = orphanTx.GetId(); NodeId fromPeer = (*mi)->second.fromPeer; bool fMissingInputs2 = false; // Use a dummy CValidationState so someone can't setup nodes diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -26,7 +26,7 @@ public: COutPoint() : txid(), n(-1) {} - COutPoint(uint256 txidIn, uint32_t nIn) : txid(TxId(txidIn)), n(nIn) {} + COutPoint(TxId txidIn, uint32_t nIn) : txid(txidIn), n(nIn) {} ADD_SERIALIZE_METHODS; diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -490,7 +490,6 @@ } for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++) { - uint256 txid; int32_t nOutput; std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-")); std::string strOutput = @@ -500,8 +499,9 @@ return RESTERR(req, HTTP_BAD_REQUEST, "Parse error"); } + TxId txid; txid.SetHex(strTxid); - vOutPoints.push_back(COutPoint(txid, (uint32_t)nOutput)); + vOutPoints.push_back(COutPoint(txid, uint32_t(nOutput))); } if (vOutPoints.size() > 0) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1158,10 +1158,10 @@ UniValue ret(UniValue::VOBJ); - std::string strHash = request.params[0].get_str(); - uint256 hash(uint256S(strHash)); + std::string strTxId = request.params[0].get_str(); + TxId txid(uint256S(strTxId)); int n = request.params[1].get_int(); - COutPoint out(hash, n); + COutPoint out(txid, n); bool fMempool = true; if (!request.params[2].isNull()) { fMempool = request.params[2].get_bool(); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -485,7 +485,7 @@ const UniValue &input = inputs[idx]; const UniValue &o = input.get_obj(); - uint256 txid = ParseHashO(o, "txid"); + TxId txid(ParseHashO(o, "txid")); const UniValue &vout_v = find_value(o, "vout"); if (vout_v.isNull()) { @@ -868,7 +868,7 @@ // (which are valid JSON) }); - uint256 txid = ParseHashO(prevOut, "txid"); + TxId txid(ParseHashO(prevOut, "txid")); int nOut = find_value(prevOut, "vout").get_int(); if (nOut < 0) { @@ -1311,7 +1311,7 @@ } CTransactionRef tx(MakeTransactionRef(std::move(mtx))); - const uint256 &txid = tx->GetId(); + const TxId &txid = tx->GetId(); Amount nMaxRawTxFee = maxTxFee; if (request.params.size() > 1 && request.params[1].get_bool()) { 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 @@ -143,7 +143,7 @@ // Do a random modification. { // txid we're going to modify in this iteration. - TxId txid = txids[InsecureRandRange(txids.size())]; + const TxId txid = txids[InsecureRandRange(txids.size())]; Coin &coin = result[COutPoint(txid, 0)]; // Determine whether to test HaveCoin before or after Access* (or // both). As these functions can influence each other's behaviour by @@ -276,7 +276,7 @@ UtxoData::iterator FindRandomFrom(const std::set &utxoSet) { assert(utxoSet.size()); - auto utxoSetIt = utxoSet.lower_bound(COutPoint(InsecureRand256(), 0)); + auto utxoSetIt = utxoSet.lower_bound(COutPoint(TxId(InsecureRand256()), 0)); if (utxoSetIt == utxoSet.end()) { utxoSetIt = utxoSet.begin(); } diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -359,7 +359,7 @@ for (int i = 0; i < 50; i++) { CMutableTransaction tx; tx.vin.resize(1); - tx.vin[0].prevout = COutPoint(InsecureRand256(), 0); + tx.vin[0].prevout = COutPoint(TxId(InsecureRand256()), 0); tx.vin[0].scriptSig << OP_1; tx.vout.resize(1); tx.vout[0].nValue = 1 * CENT; diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -107,7 +107,7 @@ for (int in = 0; in < ins; in++) { tx.vin.push_back(CTxIn()); CTxIn &txin = tx.vin.back(); - txin.prevout = COutPoint(InsecureRand256(), InsecureRandBits(2)); + txin.prevout = COutPoint(TxId(InsecureRand256()), InsecureRandBits(2)); RandomScript(txin.scriptSig); txin.nSequence = InsecureRandBool() ? InsecureRand32() diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -256,7 +256,7 @@ CMutableTransaction tx; tx.nVersion = 1; tx.vin.resize(1); - tx.vin[0].prevout = COutPoint(InsecureRand256(), 0); + tx.vin[0].prevout = COutPoint(TxId(InsecureRand256()), 0); tx.vin[0].scriptSig = CScript(); tx.vout.resize(1); tx.vout[0].nValue = SATOSHI; diff --git a/src/test/undo_tests.cpp b/src/test/undo_tests.cpp --- a/src/test/undo_tests.cpp +++ b/src/test/undo_tests.cpp @@ -39,7 +39,7 @@ ApplyBlockUndo(blockUndo, block, &pindex, view); } -static bool HasSpendableCoin(const CCoinsViewCache &view, const uint256 &txid) { +static bool HasSpendableCoin(const CCoinsViewCache &view, const TxId &txid) { return !view.AccessCoin(COutPoint(txid, 0)).IsSpent(); } @@ -67,7 +67,7 @@ block.vtx[0] = MakeTransactionRef(tx); tx.vout[0].scriptPubKey = CScript() << OP_TRUE; - tx.vin[0].prevout = COutPoint(InsecureRand256(), 0); + tx.vin[0].prevout = COutPoint(TxId(InsecureRand256()), 0); tx.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; tx.vin[0].scriptSig.resize(0); tx.nVersion = 2; diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -92,7 +92,7 @@ CMutableTransaction coinbase_spend; coinbase_spend.vin.push_back( - CTxIn(COutPoint(pblock->vtx[0]->GetHash(), 0), CScript(), 0)); + CTxIn(COutPoint(pblock->vtx[0]->GetId(), 0), CScript(), 0)); coinbase_spend.vout.push_back(pblock->vtx[0]->vout[0]); CTransactionRef tx = MakeTransactionRef(coinbase_spend); diff --git a/src/txdb.cpp b/src/txdb.cpp --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -46,7 +46,7 @@ template void Unserialize(Stream &s) { s >> key; - uint256 id; + TxId id; s >> id; uint32_t n = 0; s >> VARINT(n);