Permalink
Browse files

Replace calls to GetHash() with GetTxid() for transaction objects.

Where the caller intends to receive a transaction id and not a double
SHA256 hash.
  • Loading branch information...
bitcartel committed Jul 25, 2016
1 parent 1e84d84 commit 10d2c57c0dffaaf872ff7f322887ef055bc65f0a
@@ -498,7 +498,7 @@ static void OutputTxJSON(const CTransaction& tx)

static void OutputTxHash(const CTransaction& tx)
{
string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
string strHexHash = tx.GetTxid().GetHex(); // the hex-encoded transaction hash (aka the transaction id)

fprintf(stdout, "%s\n", strHexHash.c_str());
}
@@ -142,7 +142,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
return true;
if (isEmpty)
return false;
const uint256& hash = tx.GetHash();
const uint256& hash = tx.GetTxid();
if (contains(hash))
fFound = true;

@@ -88,7 +88,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
{
entry.pushKV("txid", tx.GetHash().GetHex());
entry.pushKV("txid", tx.GetTxid().GetHex());
entry.pushKV("version", tx.nVersion);
entry.pushKV("locktime", (int64_t)tx.nLockTime);

@@ -1384,7 +1384,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)

BOOST_FOREACH(const CWalletTx& wtxOld, vWtx)
{
uint256 hash = wtxOld.GetHash();
uint256 hash = wtxOld.GetTxid();
std::map<uint256, CWalletTx>::iterator mi = pwalletMain->mapWallet.find(hash);
if (mi != pwalletMain->mapWallet.end())
{
@@ -553,7 +553,7 @@ CBlockTreeDB *pblocktree = NULL;

bool AddOrphanTx(const CTransaction& tx, NodeId peer)
{
uint256 hash = tx.GetHash();
uint256 hash = tx.GetTxid();
if (mapOrphanTransactions.count(hash))
return false;

@@ -607,7 +607,7 @@ void EraseOrphansFor(NodeId peer)
map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
if (maybeErase->second.fromPeer == peer)
{
EraseOrphanTx(maybeErase->second.tx.GetHash());
EraseOrphanTx(maybeErase->second.tx.GetTxid());
++nErased;
}
}
@@ -1033,7 +1033,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
{
{
LOCK(mempool.cs);
uint256 hash = tx.GetHash();
uint256 hash = tx.GetTxid();
double dPriorityDelta = 0;
CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
@@ -1088,7 +1088,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
return state.DoS(0, false, REJECT_NONSTANDARD, "non-final");

// is it already in the memory pool?
uint256 hash = tx.GetHash();
uint256 hash = tx.GetTxid();
if (pool.exists(hash))
return false;

@@ -1280,7 +1280,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
hashBlock = header.GetHash();
if (txOut.GetHash() != hash)
if (txOut.GetTxid() != hash)
return error("%s: txid mismatch", __func__);
return true;
}
@@ -1302,7 +1302,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
CBlock block;
if (ReadBlockFromDisk(block, pindexSlow)) {
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
if (tx.GetHash() == hash) {
if (tx.GetTxid() == hash) {
txOut = tx;
hashBlock = pindexSlow->GetBlockHash();
return true;
@@ -1593,7 +1593,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
}

// add outputs
inputs.ModifyCoins(tx.GetHash())->FromTx(tx, nHeight);
inputs.ModifyCoins(tx.GetTxid())->FromTx(tx, nHeight);
}

void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, int nHeight)
@@ -1605,7 +1605,7 @@ void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCach
bool CScriptCheck::operator()() {
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
if (!VerifyScript(scriptSig, scriptPubKey, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, cacheStore), &error)) {
return ::error("CScriptCheck(): %s:%d VerifySignature failed: %s", ptxTo->GetHash().ToString(), nIn, ScriptErrorString(error));
return ::error("CScriptCheck(): %s:%d VerifySignature failed: %s", ptxTo->GetTxid().ToString(), nIn, ScriptErrorString(error));
}
return true;
}
@@ -1620,11 +1620,11 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
// for an attacker to attempt to split the network.
if (!inputs.HaveInputs(tx))
return state.Invalid(error("CheckInputs(): %s inputs unavailable", tx.GetHash().ToString()));
return state.Invalid(error("CheckInputs(): %s inputs unavailable", tx.GetTxid().ToString()));

// are the JoinSplit's requirements met?
if (!inputs.HaveJoinSplitRequirements(tx))
return state.Invalid(error("CheckInputs(): %s JoinSplit requirements not met", tx.GetHash().ToString()));
return state.Invalid(error("CheckInputs(): %s JoinSplit requirements not met", tx.GetTxid().ToString()));

CAmount nValueIn = 0;
CAmount nFees = 0;
@@ -1661,13 +1661,13 @@ bool NonContextualCheckInputs(const CTransaction& tx, CValidationState &state, c

if (nValueIn < tx.GetValueOut())
return state.DoS(100, error("CheckInputs(): %s value in (%s) < value out (%s)",
tx.GetHash().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())),
tx.GetTxid().ToString(), FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())),
REJECT_INVALID, "bad-txns-in-belowout");

// Tally transaction fees
CAmount nTxFee = nValueIn - tx.GetValueOut();
if (nTxFee < 0)
return state.DoS(100, error("CheckInputs(): %s nTxFee < 0", tx.GetHash().ToString()),
return state.DoS(100, error("CheckInputs(): %s nTxFee < 0", tx.GetTxid().ToString()),
REJECT_INVALID, "bad-txns-fee-negative");
nFees += nTxFee;
if (!MoneyRange(nFees))
@@ -1886,7 +1886,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
// undo transactions in reverse order
for (int i = block.vtx.size() - 1; i >= 0; i--) {
const CTransaction &tx = block.vtx[i];
uint256 hash = tx.GetHash();
uint256 hash = tx.GetTxid();

// Check that all outputs are available and match the outputs in the block itself
// exactly.
@@ -2067,7 +2067,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
// unless those are already completely spent.
BOOST_FOREACH(const CTransaction& tx, block.vtx) {
const CCoins* coins = view.AccessCoins(tx.GetHash());
const CCoins* coins = view.AccessCoins(tx.GetTxid());
if (coins && !coins->IsPruned())
return state.DoS(100, error("ConnectBlock(): tried to overwrite transaction"),
REJECT_INVALID, "bad-txns-BIP30");
@@ -2165,7 +2165,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
}

vPos.push_back(std::make_pair(tx.GetHash(), pos));
vPos.push_back(std::make_pair(tx.GetTxid(), pos));
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
}

@@ -2222,7 +2222,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// Watch for changes to the previous coinbase transaction.
static uint256 hashPrevBestCoinBase;
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
hashPrevBestCoinBase = block.vtx[0].GetHash();
hashPrevBestCoinBase = block.vtx[0].GetTxid();

int64_t nTime4 = GetTimeMicros(); nTimeCallbacks += nTime4 - nTime3;
LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001);
@@ -4654,7 +4654,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CTransaction tx;
vRecv >> tx;

CInv inv(MSG_TX, tx.GetHash());
CInv inv(MSG_TX, tx.GetTxid());
pfrom->AddInventoryKnown(inv);

LOCK(cs_main);
@@ -4676,7 +4676,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

LogPrint("mempool", "AcceptToMemoryPool: peer=%d %s: accepted %s (poolsz %u)\n",
pfrom->id, pfrom->cleanSubVer,
tx.GetHash().ToString(),
tx.GetTxid().ToString(),
mempool.mapTx.size());

// Recursively process any orphan transactions that depended on this one
@@ -4745,7 +4745,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
} else {
assert(recentRejects);
recentRejects->insert(tx.GetHash());
recentRejects->insert(tx.GetTxid());

if (pfrom->fWhitelisted) {
// Always relay transactions received from whitelisted peers, even
@@ -4761,7 +4761,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
int nDoS = 0;
if (state.IsInvalid(nDoS))
{
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetHash().ToString(),
LogPrint("mempool", "%s from peer=%d %s was not accepted into the memory pool: %s\n", tx.GetTxid().ToString(),
pfrom->id, pfrom->cleanSubVer,
state.GetRejectReason());
pfrom->PushMessage("reject", strCommand, state.GetRejectCode(),
@@ -23,7 +23,7 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)

for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const uint256& hash = block.vtx[i].GetHash();
const uint256& hash = block.vtx[i].GetTxid();
if (filter.IsRelevantAndUpdate(block.vtx[i]))
{
vMatch.push_back(true);
@@ -49,7 +49,7 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, const std::set<uint256>& txids)

for (unsigned int i = 0; i < block.vtx.size(); i++)
{
const uint256& hash = block.vtx[i].GetHash();
const uint256& hash = block.vtx[i].GetTxid();
if (txids.count(hash))
vMatch.push_back(true);
else
@@ -211,7 +211,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
dPriority = tx.ComputePriority(dPriority, nTxSize);

uint256 hash = tx.GetHash();
uint256 hash = tx.GetTxid();
mempool.ApplyDeltas(hash, dPriority, nTotalIn);

CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
@@ -255,7 +255,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
continue;

// Skip free transactions if we're past the minimum block size:
const uint256& hash = tx.GetHash();
const uint256& hash = tx.GetTxid();
double dPriorityDelta = 0;
CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
@@ -302,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (fPrintPriority)
{
LogPrintf("priority %.1f fee %s txid %s\n",
dPriority, feeRate.ToString(), tx.GetHash().ToString());
dPriority, feeRate.ToString(), tx.GetTxid().ToString());
}

// Add transactions that depend on this one to the priority queue
@@ -1751,7 +1751,7 @@ void RelayTransaction(const CTransaction& tx)

void RelayTransaction(const CTransaction& tx, const CDataStream& ss)
{
CInv inv(MSG_TX, tx.GetHash());
CInv inv(MSG_TX, tx.GetTxid());
{
LOCK(cs_mapRelay);
// Expire old relay messages
@@ -344,7 +344,7 @@ bool CBlockPolicyEstimator::isPriDataPoint(const CFeeRate &fee, double pri)
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool fCurrentEstimate)
{
unsigned int txHeight = entry.GetHeight();
uint256 hash = entry.GetTx().GetHash();
uint256 hash = entry.GetTx().GetTxid();
if (mapMemPoolTxs[hash].stats != NULL) {
LogPrint("estimatefee", "Blockpolicy error mempool tx %s already being tracked\n",
hash.ToString().c_str());
@@ -55,7 +55,7 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
vMerkleTree.clear();
vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
for (std::vector<CTransaction>::const_iterator it(vtx.begin()); it != vtx.end(); ++it)
vMerkleTree.push_back(it->GetHash());
vMerkleTree.push_back(it->GetTxid());
int j = 0;
bool mutated = false;
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
@@ -496,7 +496,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
{
// unselect already spent, very unlikely scenario, this could happen
// when selected are spent elsewhere, like rpc or another computer
uint256 txhash = out.tx->GetHash();
uint256 txhash = out.tx->GetTxid();
COutPoint outpt(txhash, out.i);
if (model->isSpent(outpt))
{
@@ -782,7 +782,7 @@ void CoinControlDialog::updateView()
nInputSum += nInputSize;

// transaction hash
uint256 txhash = out.tx->GetHash();
uint256 txhash = out.tx->GetTxid();
itemOutput->setText(COLUMN_TXHASH, QString::fromStdString(txhash.GetHex()));

// vout index
@@ -240,7 +240,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
if (wtx.mapValue.count("comment") && !wtx.mapValue["comment"].empty())
strHTML += "<br><b>" + tr("Comment") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "<br>";

strHTML += "<b>" + tr("Transaction ID") + ":</b> " + TransactionRecord::formatSubTxId(wtx.GetHash(), rec->idx) + "<br>";
strHTML += "<b>" + tr("Transaction ID") + ":</b> " + TransactionRecord::formatSubTxId(wtx.GetTxid(), rec->idx) + "<br>";

// Message from normal bitcoin:URI (bitcoin:123...?message=example)
Q_FOREACH (const PAIRTYPE(string, string)& r, wtx.vOrderForm)
@@ -39,7 +39,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
CAmount nCredit = wtx.GetCredit(ISMINE_ALL);
CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
CAmount nNet = nCredit - nDebit;
uint256 hash = wtx.GetHash();
uint256 hash = wtx.GetTxid();
std::map<std::string, std::string> mapValue = wtx.mapValue;

if (nNet > 0 || wtx.IsCoinBase())
@@ -80,7 +80,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
txs.push_back(objTx);
}
else
txs.push_back(tx.GetHash().GetHex());
txs.push_back(tx.GetTxid().GetHex());
}
result.push_back(Pair("tx", txs));
result.push_back(Pair("time", block.GetBlockTime()));
@@ -567,7 +567,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
int i = 0;
BOOST_FOREACH (CTransaction& tx, pblock->vtx)
{
uint256 txHash = tx.GetHash();
uint256 txHash = tx.GetTxid();
setTxIndex[txHash] = i++;

if (tx.IsCoinBase())
@@ -57,7 +57,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH

void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
{
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("txid", tx.GetTxid().GetHex()));
entry.push_back(Pair("version", tx.nVersion));
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
Array vin;
@@ -307,7 +307,7 @@ Value gettxoutproof(const Array& params, bool fHelp)

unsigned int ntxFound = 0;
BOOST_FOREACH(const CTransaction&tx, block.vtx)
if (setTxids.count(tx.GetHash()))
if (setTxids.count(tx.GetTxid()))
ntxFound++;
if (ntxFound != setTxids.size())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "(Not all) transactions not found in specified block");
@@ -818,7 +818,7 @@ Value sendrawtransaction(const Array& params, bool fHelp)
CTransaction tx;
if (!DecodeHexTx(tx, params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
uint256 hashTx = tx.GetHash();
uint256 hashTx = tx.GetTxid();

bool fOverrideFees = false;
if (params.size() > 1)
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
CMutableTransaction tx;
tx.vin.resize(1);
tx.vin[0].prevout.n = 0;
tx.vin[0].prevout.hash = txPrev.GetHash();
tx.vin[0].prevout.hash = txPrev.GetTxid();
tx.vout.resize(1);
tx.vout[0].nValue = 1*CENT;
tx.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
for (unsigned int j = 0; j < tx.vin.size(); j++)
{
tx.vin[j].prevout.n = j;
tx.vin[j].prevout.hash = txPrev.GetHash();
tx.vin[j].prevout.hash = txPrev.GetTxid();
}
SignSignature(keystore, txPrev, tx, 0);
// Re-use same signature for other inputs
Oops, something went wrong.

0 comments on commit 10d2c57

Please sign in to comment.