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().
This commit is contained in:
Wladimir J. van der Laan 2014-12-15 09:11:16 +01:00
parent 5d3064bc44
commit 4f1524966a
28 changed files with 68 additions and 68 deletions

View File

@ -315,7 +315,7 @@ static bool findSighashFlags(int& flags, const string& flagStr)
uint256 ParseHashUO(map<string,UniValue>& o, string strKey) uint256 ParseHashUO(map<string,UniValue>& o, string strKey)
{ {
if (!o.count(strKey)) if (!o.count(strKey))
return 0; return uint256();
return ParseHashUV(o[strKey], strKey); return ParseHashUV(o[strKey], strKey);
} }
@ -485,7 +485,7 @@ static void MutateTx(CMutableTransaction& tx, const string& command,
static void OutputTxJSON(const CTransaction& tx) static void OutputTxJSON(const CTransaction& tx)
{ {
UniValue entry(UniValue::VOBJ); UniValue entry(UniValue::VOBJ);
TxToUniv(tx, 0, entry); TxToUniv(tx, uint256(), entry);
string jsonOutput = entry.write(4); string jsonOutput = entry.write(4);
fprintf(stdout, "%s\n", jsonOutput.c_str()); fprintf(stdout, "%s\n", jsonOutput.c_str());

View File

@ -150,14 +150,14 @@ public:
nFile = 0; nFile = 0;
nDataPos = 0; nDataPos = 0;
nUndoPos = 0; nUndoPos = 0;
nChainWork = 0; nChainWork = uint256();
nTx = 0; nTx = 0;
nChainTx = 0; nChainTx = 0;
nStatus = 0; nStatus = 0;
nSequenceId = 0; nSequenceId = 0;
nVersion = 0; nVersion = 0;
hashMerkleRoot = 0; hashMerkleRoot = uint256();
nTime = 0; nTime = 0;
nBits = 0; nBits = 0;
nNonce = 0; nNonce = 0;
@ -282,11 +282,11 @@ public:
uint256 hashPrev; uint256 hashPrev;
CDiskBlockIndex() { CDiskBlockIndex() {
hashPrev = 0; hashPrev = uint256();
} }
explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) { explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex) {
hashPrev = (pprev ? pprev->GetBlockHash() : 0); hashPrev = (pprev ? pprev->GetBlockHash() : uint256());
} }
ADD_SERIALIZE_METHODS; ADD_SERIALIZE_METHODS;

View File

@ -141,7 +141,7 @@ public:
txNew.vout[0].nValue = 50 * COIN; txNew.vout[0].nValue = 50 * COIN;
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
genesis.vtx.push_back(txNew); genesis.vtx.push_back(txNew);
genesis.hashPrevBlock = 0; genesis.hashPrevBlock.SetNull();
genesis.hashMerkleRoot = genesis.BuildMerkleTree(); genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.nVersion = 1; genesis.nVersion = 1;
genesis.nTime = 1231006505; genesis.nTime = 1231006505;

View File

@ -42,7 +42,7 @@ bool CCoins::Spend(uint32_t nPos)
bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; } bool CCoinsView::GetCoins(const uint256 &txid, CCoins &coins) const { return false; }
bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; } bool CCoinsView::HaveCoins(const uint256 &txid) const { return false; }
uint256 CCoinsView::GetBestBlock() const { return uint256(0); } uint256 CCoinsView::GetBestBlock() const { return uint256(); }
bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; } bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; } bool CCoinsView::GetStats(CCoinsStats &stats) const { return false; }
@ -57,7 +57,7 @@ bool CCoinsViewBacked::GetStats(CCoinsStats &stats) const { return base->GetStat
CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {} CCoinsKeyHasher::CCoinsKeyHasher() : salt(GetRandHash()) {}
CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false), hashBlock(0) { } CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), hasModifier(false) { }
CCoinsViewCache::~CCoinsViewCache() CCoinsViewCache::~CCoinsViewCache()
{ {
@ -128,7 +128,7 @@ bool CCoinsViewCache::HaveCoins(const uint256 &txid) const {
} }
uint256 CCoinsViewCache::GetBestBlock() const { uint256 CCoinsViewCache::GetBestBlock() const {
if (hashBlock == uint256(0)) if (hashBlock.IsNull())
hashBlock = base->GetBestBlock(); hashBlock = base->GetBestBlock();
return hashBlock; return hashBlock;
} }

View File

@ -297,7 +297,7 @@ struct CCoinsStats
uint256 hashSerialized; uint256 hashSerialized;
CAmount nTotalAmount; CAmount nTotalAmount;
CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {} CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), nTotalAmount(0) {}
}; };

View File

@ -127,7 +127,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
} }
entry.pushKV("vout", vout); entry.pushKV("vout", vout);
if (hashBlock != 0) if (!hashBlock.IsNull())
entry.pushKV("blockhash", hashBlock.GetHex()); entry.pushKV("blockhash", hashBlock.GetHex());
entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction". entry.pushKV("hex", EncodeHexTx(tx)); // the hex-encoded transaction. used the name "hex" to be consistent with the verbose output of "getrawtransaction".

View File

@ -84,7 +84,7 @@ bool CKey::Sign(const uint256 &hash, std::vector<unsigned char>& vchSig, uint32_
nonce += test_case; nonce += test_case;
int nSigLen = 72; int nSigLen = 72;
int ret = secp256k1_ecdsa_sign((const unsigned char*)&hash, (unsigned char*)&vchSig[0], &nSigLen, begin(), (unsigned char*)&nonce); int ret = secp256k1_ecdsa_sign((const unsigned char*)&hash, (unsigned char*)&vchSig[0], &nSigLen, begin(), (unsigned char*)&nonce);
nonce = 0; nonce = uint256();
if (ret) { if (ret) {
vchSig.resize(nSigLen); vchSig.resize(nSigLen);
return true; return true;
@ -116,7 +116,7 @@ bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig)
uint256 nonce; uint256 nonce;
prng.Generate((unsigned char*)&nonce, 32); prng.Generate((unsigned char*)&nonce, 32);
int ret = secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, &vchSig[1], begin(), (unsigned char*)&nonce, &rec); int ret = secp256k1_ecdsa_sign_compact((const unsigned char*)&hash, &vchSig[1], begin(), (unsigned char*)&nonce, &rec);
nonce = 0; nonce = uint256();
if (ret) if (ret)
break; break;
} while(true); } while(true);

View File

@ -261,7 +261,7 @@ struct CNodeState {
nMisbehavior = 0; nMisbehavior = 0;
fShouldBan = false; fShouldBan = false;
pindexBestKnownBlock = NULL; pindexBestKnownBlock = NULL;
hashLastUnknownBlock = uint256(0); hashLastUnknownBlock.SetNull();
pindexLastCommonBlock = NULL; pindexLastCommonBlock = NULL;
fSyncStarted = false; fSyncStarted = false;
nStallingSince = 0; nStallingSince = 0;
@ -349,12 +349,12 @@ void ProcessBlockAvailability(NodeId nodeid) {
CNodeState *state = State(nodeid); CNodeState *state = State(nodeid);
assert(state != NULL); assert(state != NULL);
if (state->hashLastUnknownBlock != 0) { if (!state->hashLastUnknownBlock.IsNull()) {
BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock);
if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) {
if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork)
state->pindexBestKnownBlock = itOld->second; state->pindexBestKnownBlock = itOld->second;
state->hashLastUnknownBlock = uint256(0); state->hashLastUnknownBlock.SetNull();
} }
} }
} }
@ -1712,7 +1712,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return false; return false;
// verify that the view's current state corresponds to the previous block // verify that the view's current state corresponds to the previous block
uint256 hashPrevBlock = pindex->pprev == NULL ? uint256(0) : pindex->pprev->GetBlockHash(); uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash();
assert(hashPrevBlock == view.GetBestBlock()); assert(hashPrevBlock == view.GetBestBlock());
// Special case for the genesis block, skipping connection of its transactions // Special case for the genesis block, skipping connection of its transactions
@ -2835,7 +2835,7 @@ boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char
CBlockIndex * InsertBlockIndex(uint256 hash) CBlockIndex * InsertBlockIndex(uint256 hash)
{ {
if (hash == 0) if (hash.IsNull())
return NULL; return NULL;
// Return existing // Return existing
@ -3369,7 +3369,7 @@ void static ProcessGetData(CNode* pfrom)
vector<CInv> vInv; vector<CInv> vInv;
vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash())); vInv.push_back(CInv(MSG_BLOCK, chainActive.Tip()->GetBlockHash()));
pfrom->PushMessage("inv", vInv); pfrom->PushMessage("inv", vInv);
pfrom->hashContinue = 0; pfrom->hashContinue.SetNull();
} }
} }
} }
@ -3604,7 +3604,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Use deterministic randomness to send to the same nodes for 24 hours // Use deterministic randomness to send to the same nodes for 24 hours
// at a time so the setAddrKnowns of the chosen nodes prevent repeats // at a time so the setAddrKnowns of the chosen nodes prevent repeats
static uint256 hashSalt; static uint256 hashSalt;
if (hashSalt == 0) if (hashSalt.IsNull())
hashSalt = GetRandHash(); hashSalt = GetRandHash();
uint64_t hashAddr = addr.GetHash(); uint64_t hashAddr = addr.GetHash();
uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60)); uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60));
@ -3738,7 +3738,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if (pindex) if (pindex)
pindex = chainActive.Next(pindex); pindex = chainActive.Next(pindex);
int nLimit = 500; int nLimit = 500;
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); LogPrint("net", "getblocks %d to %s limit %d from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), nLimit, pfrom->id);
for (; pindex; pindex = chainActive.Next(pindex)) for (; pindex; pindex = chainActive.Next(pindex))
{ {
if (pindex->GetBlockHash() == hashStop) if (pindex->GetBlockHash() == hashStop)
@ -3954,7 +3954,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
// from there instead. // from there instead.
LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight);
pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256(0)); pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256());
} }
} }
@ -4452,7 +4452,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
nSyncStarted++; nSyncStarted++;
CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader;
LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight);
pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256(0)); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256());
} }
} }
@ -4483,7 +4483,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
{ {
// 1/4 of tx invs blast to all immediately // 1/4 of tx invs blast to all immediately
static uint256 hashSalt; static uint256 hashSalt;
if (hashSalt == 0) if (hashSalt.IsNull())
hashSalt = GetRandHash(); hashSalt = GetRandHash();
uint256 hashRand = inv.hash ^ hashSalt; uint256 hashRand = inv.hash ^ hashSalt;
hashRand = Hash(BEGIN(hashRand), END(hashRand)); hashRand = Hash(BEGIN(hashRand), END(hashRand));

View File

@ -76,7 +76,7 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns
if (nBitsUsed >= vBits.size()) { if (nBitsUsed >= vBits.size()) {
// overflowed the bits array - failure // overflowed the bits array - failure
fBad = true; fBad = true;
return 0; return uint256();
} }
bool fParentOfMatch = vBits[nBitsUsed++]; bool fParentOfMatch = vBits[nBitsUsed++];
if (height==0 || !fParentOfMatch) { if (height==0 || !fParentOfMatch) {
@ -84,7 +84,7 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns
if (nHashUsed >= vHash.size()) { if (nHashUsed >= vHash.size()) {
// overflowed the hash array - failure // overflowed the hash array - failure
fBad = true; fBad = true;
return 0; return uint256();
} }
const uint256 &hash = vHash[nHashUsed++]; const uint256 &hash = vHash[nHashUsed++];
if (height==0 && fParentOfMatch) // in case of height 0, we have a matched txid 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) {
vMatch.clear(); vMatch.clear();
// An empty set will not work // An empty set will not work
if (nTransactions == 0) if (nTransactions == 0)
return 0; return uint256();
// check for excessively high numbers of transactions // check for excessively high numbers of transactions
if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction if (nTransactions > MAX_BLOCK_SIZE / 60) // 60 is the lower bound for the size of a serialized CTransaction
return 0; return uint256();
// there can never be more hashes provided than one for every txid // there can never be more hashes provided than one for every txid
if (vHash.size() > nTransactions) if (vHash.size() > nTransactions)
return 0; return uint256();
// there must be at least one bit per node in the partial tree, and at least one node per hash // there must be at least one bit per node in the partial tree, and at least one node per hash
if (vBits.size() < vHash.size()) if (vBits.size() < vHash.size())
return 0; return uint256();
// calculate height of tree // calculate height of tree
int nHeight = 0; int nHeight = 0;
while (CalcTreeWidth(nHeight) > 1) while (CalcTreeWidth(nHeight) > 1)
@ -147,12 +147,12 @@ uint256 CPartialMerkleTree::ExtractMatches(std::vector<uint256> &vMatch) {
uint256 hashMerkleRoot = TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch); uint256 hashMerkleRoot = TraverseAndExtract(nHeight, 0, nBitsUsed, nHashUsed, vMatch);
// verify that no problems occured during the tree traversal // verify that no problems occured during the tree traversal
if (fBad) if (fBad)
return 0; return uint256();
// verify that all bits were consumed (except for the padding caused by serializing it as a byte sequence) // verify that all bits were consumed (except for the padding caused by serializing it as a byte sequence)
if ((nBitsUsed+7)/8 != (vBits.size()+7)/8) if ((nBitsUsed+7)/8 != (vBits.size()+7)/8)
return 0; return uint256();
// verify that all hashes were consumed // verify that all hashes were consumed
if (nHashUsed != vHash.size()) if (nHashUsed != vHash.size())
return 0; return uint256();
return hashMerkleRoot; return hashMerkleRoot;
} }

View File

@ -1949,7 +1949,7 @@ CNode::CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn, bool fIn
nRefCount = 0; nRefCount = 0;
nSendSize = 0; nSendSize = 0;
nSendOffset = 0; nSendOffset = 0;
hashContinue = 0; hashContinue = uint256();
nStartingHeight = -1; nStartingHeight = -1;
fGetAddr = false; fGetAddr = false;
fRelayTxes = false; fRelayTxes = false;

View File

@ -74,7 +74,7 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
if (fMutated) { if (fMutated) {
*fMutated = mutated; *fMutated = mutated;
} }
return (vMerkleTree.empty() ? 0 : vMerkleTree.back()); return (vMerkleTree.empty() ? uint256() : vMerkleTree.back());
} }
std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const
@ -96,7 +96,7 @@ std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const
uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex) uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
{ {
if (nIndex == -1) if (nIndex == -1)
return 0; return uint256();
for (std::vector<uint256>::const_iterator it(vMerkleBranch.begin()); it != vMerkleBranch.end(); ++it) for (std::vector<uint256>::const_iterator it(vMerkleBranch.begin()); it != vMerkleBranch.end(); ++it)
{ {
if (nIndex & 1) if (nIndex & 1)

View File

@ -53,8 +53,8 @@ public:
void SetNull() void SetNull()
{ {
nVersion = CBlockHeader::CURRENT_VERSION; nVersion = CBlockHeader::CURRENT_VERSION;
hashPrevBlock = 0; hashPrevBlock.SetNull();
hashMerkleRoot = 0; hashMerkleRoot.SetNull();
nTime = 0; nTime = 0;
nBits = 0; nBits = 0;
nNonce = 0; nNonce = 0;

View File

@ -72,7 +72,7 @@ void CTransaction::UpdateHash() const
*const_cast<uint256*>(&hash) = SerializeHash(*this); *const_cast<uint256*>(&hash) = SerializeHash(*this);
} }
CTransaction::CTransaction() : hash(0), nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { } CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { }
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) { CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {
UpdateHash(); UpdateHash();

View File

@ -28,8 +28,8 @@ public:
READWRITE(FLATDATA(*this)); READWRITE(FLATDATA(*this));
} }
void SetNull() { hash = 0; n = (uint32_t) -1; } void SetNull() { hash.SetNull(); n = (uint32_t) -1; }
bool IsNull() const { return (hash == 0 && n == (uint32_t) -1); } bool IsNull() const { return (hash.IsNull() && n == (uint32_t) -1); }
friend bool operator<(const COutPoint& a, const COutPoint& b) friend bool operator<(const COutPoint& a, const COutPoint& b)
{ {

View File

@ -96,7 +96,7 @@ void CAddress::Init()
CInv::CInv() CInv::CInv()
{ {
type = 0; type = 0;
hash = 0; hash.SetNull();
} }
CInv::CInv(int typeIn, const uint256& hashIn) CInv::CInv(int typeIn, const uint256& hashIn)

View File

@ -27,7 +27,7 @@
class CKeyID : public uint160 class CKeyID : public uint160
{ {
public: public:
CKeyID() : uint160(0) {} CKeyID() : uint160() {}
CKeyID(const uint160& in) : uint160(in) {} CKeyID(const uint160& in) : uint160(in) {}
}; };

View File

@ -240,7 +240,7 @@ static bool rest_tx(AcceptedConnection* conn,
throw RESTERR(HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); throw RESTERR(HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
CTransaction tx; CTransaction tx;
uint256 hashBlock = 0; uint256 hashBlock = uint256();
if (!GetTransaction(hash, tx, hashBlock, true)) if (!GetTransaction(hash, tx, hashBlock, true))
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found"); throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");

View File

@ -70,7 +70,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
if(txDetails) if(txDetails)
{ {
Object objTx; Object objTx;
TxToJSON(tx, uint256(0), objTx); TxToJSON(tx, uint256(), objTx);
txs.push_back(objTx); txs.push_back(objTx);
} }
else else

View File

@ -89,7 +89,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
} }
entry.push_back(Pair("vout", vout)); entry.push_back(Pair("vout", vout));
if (hashBlock != 0) { if (!hashBlock.IsNull()) {
entry.push_back(Pair("blockhash", hashBlock.GetHex())); entry.push_back(Pair("blockhash", hashBlock.GetHex()));
BlockMap::iterator mi = mapBlockIndex.find(hashBlock); BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second) { if (mi != mapBlockIndex.end() && (*mi).second) {
@ -178,7 +178,7 @@ Value getrawtransaction(const Array& params, bool fHelp)
fVerbose = (params[1].get_int() != 0); fVerbose = (params[1].get_int() != 0);
CTransaction tx; CTransaction tx;
uint256 hashBlock = 0; uint256 hashBlock;
if (!GetTransaction(hash, tx, hashBlock, true)) if (!GetTransaction(hash, tx, hashBlock, true))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
@ -438,7 +438,7 @@ Value decoderawtransaction(const Array& params, bool fHelp)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
Object result; Object result;
TxToJSON(tx, 0, result); TxToJSON(tx, uint256(), result);
return result; return result;
} }

View File

@ -1477,7 +1477,7 @@ Value listsinceblock(const Array& params, bool fHelp)
if (params.size() > 0) if (params.size() > 0)
{ {
uint256 blockId = 0; uint256 blockId;
blockId.SetHex(params[0].get_str()); blockId.SetHex(params[0].get_str());
BlockMap::iterator it = mapBlockIndex.find(blockId); BlockMap::iterator it = mapBlockIndex.find(blockId);
@ -1510,7 +1510,7 @@ Value listsinceblock(const Array& params, bool fHelp)
} }
CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms]; CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : 0; uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : uint256();
Object ret; Object ret;
ret.push_back(Pair("transactions", transactions)); ret.push_back(Pair("transactions", transactions));

View File

@ -20,7 +20,7 @@ class CScript;
class CScriptID : public uint160 class CScriptID : public uint160
{ {
public: public:
CScriptID() : uint160(0) {} CScriptID() : uint160() {}
CScriptID(const CScript& in); CScriptID(const CScript& in);
CScriptID(const uint160& in) : uint160(in) {} CScriptID(const uint160& in) : uint160(in) {}
}; };

View File

@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
// calculate actual merkle root and height // calculate actual merkle root and height
uint256 merkleRoot1 = block.BuildMerkleTree(); uint256 merkleRoot1 = block.BuildMerkleTree();
std::vector<uint256> vTxid(nTx, 0); std::vector<uint256> vTxid(nTx, uint256());
for (unsigned int j=0; j<nTx; j++) for (unsigned int j=0; j<nTx; j++)
vTxid[j] = block.vtx[j].GetHash(); vTxid[j] = block.vtx[j].GetHash();
int nHeight = 1, nTx_ = nTx; int nHeight = 1, nTx_ = nTx;
@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
// check that it has the same merkle root as the original, and a valid one // check that it has the same merkle root as the original, and a valid one
BOOST_CHECK(merkleRoot1 == merkleRoot2); BOOST_CHECK(merkleRoot1 == merkleRoot2);
BOOST_CHECK(merkleRoot2 != 0); BOOST_CHECK(!merkleRoot2.IsNull());
// check that it contains the matched transactions (in the same order!) // check that it contains the matched transactions (in the same order!)
BOOST_CHECK(vMatchTxid1 == vMatchTxid2); BOOST_CHECK(vMatchTxid1 == vMatchTxid2);
@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(pmt_malleability)
CPartialMerkleTree tree(vTxid, vMatch); CPartialMerkleTree tree(vTxid, vMatch);
std::vector<uint256> vTxid2; std::vector<uint256> vTxid2;
BOOST_CHECK(tree.ExtractMatches(vTxid) == 0); BOOST_CHECK(tree.ExtractMatches(vTxid).IsNull());
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(set)
BOOST_AUTO_TEST_CASE(is) BOOST_AUTO_TEST_CASE(is)
{ {
// Test CScript::IsPayToScriptHash() // Test CScript::IsPayToScriptHash()
uint160 dummy(0); uint160 dummy;
CScript p2sh; CScript p2sh;
p2sh << OP_HASH160 << ToByteVector(dummy) << OP_EQUAL; p2sh << OP_HASH160 << ToByteVector(dummy) << OP_EQUAL;
BOOST_CHECK(p2sh.IsPayToScriptHash()); BOOST_CHECK(p2sh.IsPayToScriptHash());

View File

@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U); BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U); BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
uint160 dummy(0); uint160 dummy;
s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG; s1 << OP_1 << ToByteVector(dummy) << ToByteVector(dummy) << OP_2 << OP_CHECKMULTISIG;
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U); BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
s1 << OP_IF << OP_CHECKSIG << OP_ENDIF; s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;

View File

@ -39,7 +39,7 @@ bool CCoinsViewDB::HaveCoins(const uint256 &txid) const {
uint256 CCoinsViewDB::GetBestBlock() const { uint256 CCoinsViewDB::GetBestBlock() const {
uint256 hashBestChain; uint256 hashBestChain;
if (!db.Read('B', hashBestChain)) if (!db.Read('B', hashBestChain))
return uint256(0); return uint256();
return hashBestChain; return hashBestChain;
} }
@ -56,7 +56,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
CCoinsMap::iterator itOld = it++; CCoinsMap::iterator itOld = it++;
mapCoins.erase(itOld); mapCoins.erase(itOld);
} }
if (hashBlock != uint256(0)) if (!hashBlock.IsNull())
BatchWriteHashBestChain(batch, hashBlock); BatchWriteHashBestChain(batch, hashBlock);
LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count); LogPrint("coindb", "Committing %u changed transactions (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
@ -179,7 +179,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator()); boost::scoped_ptr<leveldb::Iterator> pcursor(NewIterator());
CDataStream ssKeySet(SER_DISK, CLIENT_VERSION); CDataStream ssKeySet(SER_DISK, CLIENT_VERSION);
ssKeySet << make_pair('b', uint256(0)); ssKeySet << make_pair('b', uint256());
pcursor->Seek(ssKeySet.str()); pcursor->Seek(ssKeySet.str());
// Load mapBlockIndex // Load mapBlockIndex

View File

@ -579,7 +579,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
wtx.nOrderPos = IncOrderPosNext(); wtx.nOrderPos = IncOrderPosNext();
wtx.nTimeSmart = wtx.nTimeReceived; wtx.nTimeSmart = wtx.nTimeReceived;
if (wtxIn.hashBlock != 0) if (!wtxIn.hashBlock.IsNull())
{ {
if (mapBlockIndex.count(wtxIn.hashBlock)) if (mapBlockIndex.count(wtxIn.hashBlock))
{ {
@ -630,7 +630,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
if (!fInsertedNew) if (!fInsertedNew)
{ {
// Merge // Merge
if (wtxIn.hashBlock != 0 && wtxIn.hashBlock != wtx.hashBlock) if (!wtxIn.hashBlock.IsNull() && wtxIn.hashBlock != wtx.hashBlock)
{ {
wtx.hashBlock = wtxIn.hashBlock; wtx.hashBlock = wtxIn.hashBlock;
fUpdated = true; fUpdated = true;
@ -795,7 +795,7 @@ int CWalletTx::GetRequestCount() const
if (IsCoinBase()) if (IsCoinBase())
{ {
// Generated block // Generated block
if (hashBlock != 0) if (!hashBlock.IsNull())
{ {
map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
if (mi != pwallet->mapRequestCount.end()) if (mi != pwallet->mapRequestCount.end())
@ -811,7 +811,7 @@ int CWalletTx::GetRequestCount() const
nRequests = (*mi).second; nRequests = (*mi).second;
// How about the block it's in? // How about the block it's in?
if (nRequests == 0 && hashBlock != 0) if (nRequests == 0 && !hashBlock.IsNull())
{ {
map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); map<uint256, int>::const_iterator mi = pwallet->mapRequestCount.find(hashBlock);
if (mi != pwallet->mapRequestCount.end()) if (mi != pwallet->mapRequestCount.end())
@ -2317,7 +2317,7 @@ int CMerkleTx::SetMerkleBranch(const CBlock& block)
int CMerkleTx::GetDepthInMainChainINTERNAL(const CBlockIndex* &pindexRet) const int CMerkleTx::GetDepthInMainChainINTERNAL(const CBlockIndex* &pindexRet) const
{ {
if (hashBlock == 0 || nIndex == -1) if (hashBlock.IsNull() || nIndex == -1)
return 0; return 0;
AssertLockHeld(cs_main); AssertLockHeld(cs_main);

View File

@ -519,7 +519,7 @@ public:
void Init() void Init()
{ {
hashBlock = 0; hashBlock = uint256();
nIndex = -1; nIndex = -1;
fMerkleVerified = false; fMerkleVerified = false;
} }

View File

@ -439,7 +439,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
} }
CKey key; CKey key;
CPrivKey pkey; CPrivKey pkey;
uint256 hash = 0; uint256 hash;
if (strType == "key") if (strType == "key")
{ {
@ -464,7 +464,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
bool fSkipCheck = false; bool fSkipCheck = false;
if (hash != 0) if (!hash.IsNull())
{ {
// hash pubkey/privkey to accelerate wallet load // hash pubkey/privkey to accelerate wallet load
std::vector<unsigned char> vchKey; std::vector<unsigned char> vchKey;