Skip to content

Commit 4f15249

Browse files
committed
Replace direct use of 0 with SetNull and IsNull
Replace x=0 with .SetNull(), x==0 with IsNull(), x!=0 with !IsNull(). Replace uses of uint256(0) with uint256().
1 parent 5d3064b commit 4f15249

28 files changed

+68
-68
lines changed

src/bitcoin-tx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static bool findSighashFlags(int& flags, const string& flagStr)
315315
uint256 ParseHashUO(map<string,UniValue>& o, string strKey)
316316
{
317317
if (!o.count(strKey))
318-
return 0;
318+
return uint256();
319319
return ParseHashUV(o[strKey], strKey);
320320
}
321321

@@ -485,7 +485,7 @@ static void MutateTx(CMutableTransaction& tx, const string& command,
485485
static void OutputTxJSON(const CTransaction& tx)
486486
{
487487
UniValue entry(UniValue::VOBJ);
488-
TxToUniv(tx, 0, entry);
488+
TxToUniv(tx, uint256(), entry);
489489

490490
string jsonOutput = entry.write(4);
491491
fprintf(stdout, "%s\n", jsonOutput.c_str());

src/chain.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ class CBlockIndex
150150
nFile = 0;
151151
nDataPos = 0;
152152
nUndoPos = 0;
153-
nChainWork = 0;
153+
nChainWork = uint256();
154154
nTx = 0;
155155
nChainTx = 0;
156156
nStatus = 0;
157157
nSequenceId = 0;
158158

159159
nVersion = 0;
160-
hashMerkleRoot = 0;
160+
hashMerkleRoot = uint256();
161161
nTime = 0;
162162
nBits = 0;
163163
nNonce = 0;
@@ -282,11 +282,11 @@ class CDiskBlockIndex : public CBlockIndex
282282
uint256 hashPrev;
283283

284284
CDiskBlockIndex() {
285-
hashPrev = 0;
285+
hashPrev = uint256();
286286
}
287287

288288
explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) {
289-
hashPrev = (pprev ? pprev->GetBlockHash() : 0);
289+
hashPrev = (pprev ? pprev->GetBlockHash() : uint256());
290290
}
291291

292292
ADD_SERIALIZE_METHODS;

src/chainparams.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CMainParams : public CChainParams {
141141
txNew.vout[0].nValue = 50 * COIN;
142142
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
143143
genesis.vtx.push_back(txNew);
144-
genesis.hashPrevBlock = 0;
144+
genesis.hashPrevBlock.SetNull();
145145
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
146146
genesis.nVersion = 1;
147147
genesis.nTime = 1231006505;

src/coins.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool CCoins::Spend(uint32_t nPos)
4242

4343
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
4444
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
45-
uint256 CCoinsView::GetBestBlock() const { return uint256(0); }
45+
uint256 CCoinsView::GetBestBlock() const { return uint256(); }
4646
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
4747
bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
4848

@@ -57,7 +57,7 @@ bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStat
5757

5858
CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
5959

60-
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false), hashBlock(0) { }
60+
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false) { }
6161

6262
CCoinsViewCache::~CCoinsViewCache()
6363
{
@@ -128,7 +128,7 @@ bool CCoinsViewCache::HaveCoins(const uint256 &txid) const {
128128
}
129129

130130
uint256 CCoinsViewCache::GetBestBlock() const {
131-
if (hashBlock == uint256(0))
131+
if (hashBlock.IsNull())
132132
hashBlock = base->GetBestBlock();
133133
return hashBlock;
134134
}

src/coins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ struct CCoinsStats
297297
uint256 hashSerialized;
298298
CAmount nTotalAmount;
299299

300-
CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
300+
CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), nTotalAmount(0) {}
301301
};
302302

303303

src/core_write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
127127
}
128128
entry.pushKV("vout", vout);
129129

130-
if (hashBlock != 0)
130+
if (!hashBlock.IsNull())
131131
entry.pushKV("blockhash", hashBlock.GetHex());
132132

133133
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".

src/key.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_
8484
nonce += test_case;
8585
int nSigLen = 72;
8686
int ret = secp256k1_ecdsa_sign((const unsigned char*)&hash, (unsigned char*)&vchSig[0], &nSigLen, begin(), (unsigned char*)&nonce);
87-
nonce = 0;
87+
nonce = uint256();
8888
if (ret) {
8989
vchSig.resize(nSigLen);
9090
return true;
@@ -116,7 +116,7 @@ bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig)
116116
uint256 nonce;
117117
prng.Generate((unsigned char*)&nonce, 32);
118118
int ret = secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, &vchSig[1], begin(), (unsigned char*)&nonce, &rec);
119-
nonce = 0;
119+
nonce = uint256();
120120
if (ret)
121121
break;
122122
} while(true);

src/main.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct CNodeState {
261261
nMisbehavior = 0;
262262
fShouldBan = false;
263263
pindexBestKnownBlock = NULL;
264-
hashLastUnknownBlock = uint256(0);
264+
hashLastUnknownBlock.SetNull();
265265
pindexLastCommonBlock = NULL;
266266
fSyncStarted = false;
267267
nStallingSince = 0;
@@ -349,12 +349,12 @@ void ProcessBlockAvailability(NodeId nodeid) {
349349
CNodeState *state = State(nodeid);
350350
assert(state != NULL);
351351

352-
if (state->hashLastUnknownBlock != 0) {
352+
if (!state->hashLastUnknownBlock.IsNull()) {
353353
BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
354354
if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) {
355355
if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
356356
state->pindexBestKnownBlock = itOld->second;
357-
state->hashLastUnknownBlock = uint256(0);
357+
state->hashLastUnknownBlock.SetNull();
358358
}
359359
}
360360
}
@@ -1712,7 +1712,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17121712
return false;
17131713

17141714
// verify that the view's current state corresponds to the previous block
1715-
uint256 hashPrevBlock = pindex->pprev == NULL ? uint256(0) : pindex->pprev->GetBlockHash();
1715+
uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash();
17161716
assert(hashPrevBlock == view.GetBestBlock());
17171717

17181718
// Special case for the genesis block, skipping connection of its transactions
@@ -2835,7 +2835,7 @@ boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char
28352835

28362836
CBlockIndex * InsertBlockIndex(uint256 hash)
28372837
{
2838-
if (hash == 0)
2838+
if (hash.IsNull())
28392839
return NULL;
28402840

28412841
// Return existing
@@ -3369,7 +3369,7 @@ void static ProcessGetData(CNode* pfrom)
33693369
vector<CInv> vInv;
33703370
vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
33713371
pfrom->PushMessage("inv", vInv);
3372-
pfrom->hashContinue = 0;
3372+
pfrom->hashContinue.SetNull();
33733373
}
33743374
}
33753375
}
@@ -3604,7 +3604,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
36043604
// Use deterministic randomness to send to the same nodes for 24 hours
36053605
// at a time so the setAddrKnowns of the chosen nodes prevent repeats
36063606
static uint256 hashSalt;
3607-
if (hashSalt == 0)
3607+
if (hashSalt.IsNull())
36083608
hashSalt = GetRandHash();
36093609
uint64_t hashAddr = addr.GetHash();
36103610
uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60));
@@ -3738,7 +3738,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
37383738
if (pindex)
37393739
pindex = chainActive.Next(pindex);
37403740
int nLimit = 500;
3741-
LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop==uint256(0) ? "end" : hashStop.ToString(), nLimit, pfrom->id);
3741+
LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->id);
37423742
for (; pindex; pindex = chainActive.Next(pindex))
37433743
{
37443744
if (pindex->GetBlockHash() == hashStop)
@@ -3954,7 +3954,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
39543954
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
39553955
// from there instead.
39563956
LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight);
3957-
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256(0));
3957+
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256());
39583958
}
39593959
}
39603960

@@ -4452,7 +4452,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
44524452
nSyncStarted++;
44534453
CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader;
44544454
LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight);
4455-
pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256(0));
4455+
pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256());
44564456
}
44574457
}
44584458

@@ -4483,7 +4483,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
44834483
{
44844484
// 1/4 of tx invs blast to all immediately
44854485
static uint256 hashSalt;
4486-
if (hashSalt == 0)
4486+
if (hashSalt.IsNull())
44874487
hashSalt = GetRandHash();
44884488
uint256 hashRand = inv.hash ^ hashSalt;
44894489
hashRand = Hash(BEGIN(hashRand), END(hashRand));

src/merkleblock.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns
7676
if (nBitsUsed >= vBits.size()) {
7777
// overflowed the bits array - failure
7878
fBad = true;
79-
return 0;
79+
return uint256();
8080
}
8181
bool fParentOfMatch = vBits[nBitsUsed++];
8282
if (height==0 || !fParentOfMatch) {
8383
// if at height 0, or nothing interesting below, use stored hash and do not descend
8484
if (nHashUsed >= vHash.size()) {
8585
// overflowed the hash array - failure
8686
fBad = true;
87-
return 0;
87+
return uint256();
8888
}
8989
const uint256 &hash = vHash[nHashUsed++];
9090
if (height==0 && fParentOfMatch) // in case of height 0, we have a matched txid
@@ -128,16 +128,16 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
128128
vMatch.clear();
129129
// An empty set will not work
130130
if (nTransactions == 0)
131-
return 0;
131+
return uint256();
132132
// check for excessively high numbers of transactions
133133
if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
134-
return 0;
134+
return uint256();
135135
// there can never be more hashes provided than one for every txid
136136
if (vHash.size() > nTransactions)
137-
return 0;
137+
return uint256();
138138
// there must be at least one bit per node in the partial tree, and at least one node per hash
139139
if (vBits.size() < vHash.size())
140-
return 0;
140+
return uint256();
141141
// calculate height of tree
142142
int nHeight = 0;
143143
while (CalcTreeWidth(nHeight) > 1)
@@ -147,12 +147,12 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
147147
uint256 hashMerkleRoot = TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch);
148148
// verify that no problems occured during the tree traversal
149149
if (fBad)
150-
return 0;
150+
return uint256();
151151
// verify that all bits were consumed (except for the padding caused by serializing it as a byte sequence)
152152
if ((nBitsUsed+7)/8 != (vBits.size()+7)/8)
153-
return 0;
153+
return uint256();
154154
// verify that all hashes were consumed
155155
if (nHashUsed != vHash.size())
156-
return 0;
156+
return uint256();
157157
return hashMerkleRoot;
158158
}

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ CNode::CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn, bool fIn
19491949
nRefCount = 0;
19501950
nSendSize = 0;
19511951
nSendOffset = 0;
1952-
hashContinue = 0;
1952+
hashContinue = uint256();
19531953
nStartingHeight = -1;
19541954
fGetAddr = false;
19551955
fRelayTxes = false;

0 commit comments

Comments
 (0)