Skip to content

Commit 464796c

Browse files
committed
Refactor for Bitcoin's newer uint256 and arith_uint256 types
1 parent 00b91bb commit 464796c

29 files changed

+234
-228
lines changed

src/addrman.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
1212
CDataStream ss1(SER_GETHASH, 0);
1313
std::vector<unsigned char> vchKey = GetKey();
1414
ss1 << nKey << vchKey;
15-
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
15+
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetUint64();
1616

1717
CDataStream ss2(SER_GETHASH, 0);
1818
std::vector<unsigned char> vchGroupKey = GetGroup();
1919
ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP);
20-
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
20+
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetUint64();
2121
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
2222
}
2323

@@ -27,11 +27,11 @@ int CAddrInfo::GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAd
2727
std::vector<unsigned char> vchGroupKey = GetGroup();
2828
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
2929
ss1 << nKey << vchGroupKey << vchSourceGroupKey;
30-
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
30+
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetUint64();
3131

3232
CDataStream ss2(SER_GETHASH, 0);
3333
ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP);
34-
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
34+
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetUint64();
3535
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
3636
}
3737

src/bignum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ class CBigNum : public CBigNumBase
286286
{
287287
unsigned int nSize = BN_bn2mpi(pbn, NULL);
288288
if (nSize < 4)
289-
return 0;
289+
return uint256();
290290
std::vector<unsigned char> vch(nSize);
291291
BN_bn2mpi(pbn, &vch[0]);
292292
if (vch.size() > 4)
293293
vch[4] &= 0x7f;
294-
uint256 n = 0;
294+
uint256 n = uint256();
295295
for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
296296
((unsigned char*)&n)[i] = vch[j];
297297
return n;

src/checkpoints.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@ namespace Checkpoints
2828
static MapCheckpoints mapCheckpoints =
2929
boost::assign::map_list_of
3030
( 0, hashGenesisBlock )
31-
( 40, uint256("0x0000002c305541bceb763e6f7fce2f111cb752acf9777e64c6f02fab5ef4778c") )
32-
( 50, uint256("0x000000415ff618b8e72eda69e87dc2f2ff8798a5032babbef36b089da0ae2278") )
33-
( 6000, uint256("0x5976ff9d0da7626badf301a9e038ec05d776e5e50839e2505357512945d53b04") )
34-
( 17000, uint256("0x92fe9bafd6c9c1acbe8565ade79460505a70180ac5c3b360489037ef7a4aed42") )
35-
( 27000, uint256("0x1521cd45d0564cb016e816581dd6e2d030f6333a1dac5b79bea71ca8b0186e8d") )
36-
( 36500, uint256("0xcf26a63e66ca95bc7c0189a5239128fd983ef978088f187bd30817aebb2c8424") )
37-
( 67000, uint256("0x429a4ed792c6270a263fa679946ff2c510e55e9a3b7234fa789d66bacd3068a0") )
38-
( 70000, uint256("0x829c215851d7cdf756e7ba9e2c8eeef61e503b15488ffa4becab77c7961d30c5") )
39-
( 71000, uint256("0x708c3319912b19c3547fd9a9a2aa6426c3a4543e84f972b3070a24200bd4fcd3") )
40-
( 85000, uint256("0x928f0669b1f036561a2d53b7588b10c5ea2fcb9e2960a9be593b508a7fcceec1") )
41-
( 91000, uint256("0x8ed361fa50f6c16fbda4f2c7454dd818f2278151987324825bc1ec1eacfa9be2") )
42-
(101000, uint256("0x578efd18f7cd5191be3463a2b0db985375f48ee6e8a8940cc6b91d6847fa3614") )
43-
(118000, uint256("0x8f8ea6eaeae707ab935b517f1c334e6324df75ad8e5f9fbc4d9fb3cc7aa2e69f") )
44-
(120000, uint256("0xe64d19e39d564cc66e931e88c03207c19e4c9a873ca68ccef16ad712830da726") )
45-
(122000, uint256("0xb35d4f385bba3c3cb3f9b6914edd6621bde8f78c8c42f58ec47131ed6aac82a9") )
46-
(124392, uint256("0x1496cd55d7adad1ada774542165a04102a91f8f80c6e894c05f1d0c2ff7e5a39") )
47-
(145000, uint256("0x99f5d7166ad55d6d0e1ac5c7fffaee1d1dd1ff1409738e0d4f13ac1ae38234cc") )
48-
(278000, uint256("0x8066e63198c44b9840f664e795b0315d9b752773b267d6212f35593bc0e3b6f4") )
49-
(361800, uint256("0x801981d8a8f5809e34a2881ea97600259e1d9d778fa21752a5f6cff4defcd08d") )
50-
(500000, uint256("0x3916b53eaa0eb392ce5d7e4eaf7db4f745187743f167539ffa4dc1a30c06acbd") )
51-
(700000, uint256("0x2e45c8a834675b505b96792d198c2dc970f560429c635479c347204044acc59b") )
52-
(770000, uint256("0xfc13a63162bc0a5a09acc3f284cf959d6812a027bb54b342a0e1ccaaca8627ce") )
53-
(850000, uint256("0xc78b15f25ad990d02256907fab92ab37301d129eaea177fd04acacd56c0cbd22") )
54-
(950000, uint256("0x4be0afdb9273d232de0bc75b572d8bcfaa146d9efdbe4a4f1ab775334f175b0f") )
55-
(1050000, uint256("0x0753b624cc0ab39d8745b436012ce53c087f7b2e077099e746a9557f569a80f3") )
56-
(1150000, uint256("0x0264545b51389faea32ac54bf76cd6efb65701d777e7fa1007584114897067f5") )
57-
(1250000, uint256("0x452467f2f74580176375f99dd38e9119d564985ba639fa1303718a51351823ab") )
58-
(1350000, uint256("0x813725a075bc3cc254742557ce6d3a680cb97ee863f65c5d9a386c1ac9a8e792") )
59-
(1450000, uint256("0x5744777ad775063a3e0b9b9c40ac205e8948904e340d11c3c449fb13914c962b") )
60-
(1550000, uint256("0xa37ab3260678f6e7f009b2c11fee14bef6add481b411516201cc35b397859bfb") )
61-
(1700000, uint256("0x831a655dd58599fda1815f7275194ff69ca53341694ba81f9941eede25c40885") )
31+
( 40, uint256S("0x0000002c305541bceb763e6f7fce2f111cb752acf9777e64c6f02fab5ef4778c") )
32+
( 50, uint256S("0x000000415ff618b8e72eda69e87dc2f2ff8798a5032babbef36b089da0ae2278") )
33+
( 6000, uint256S("0x5976ff9d0da7626badf301a9e038ec05d776e5e50839e2505357512945d53b04") )
34+
( 17000, uint256S("0x92fe9bafd6c9c1acbe8565ade79460505a70180ac5c3b360489037ef7a4aed42") )
35+
( 27000, uint256S("0x1521cd45d0564cb016e816581dd6e2d030f6333a1dac5b79bea71ca8b0186e8d") )
36+
( 36500, uint256S("0xcf26a63e66ca95bc7c0189a5239128fd983ef978088f187bd30817aebb2c8424") )
37+
( 67000, uint256S("0x429a4ed792c6270a263fa679946ff2c510e55e9a3b7234fa789d66bacd3068a0") )
38+
( 70000, uint256S("0x829c215851d7cdf756e7ba9e2c8eeef61e503b15488ffa4becab77c7961d30c5") )
39+
( 71000, uint256S("0x708c3319912b19c3547fd9a9a2aa6426c3a4543e84f972b3070a24200bd4fcd3") )
40+
( 85000, uint256S("0x928f0669b1f036561a2d53b7588b10c5ea2fcb9e2960a9be593b508a7fcceec1") )
41+
( 91000, uint256S("0x8ed361fa50f6c16fbda4f2c7454dd818f2278151987324825bc1ec1eacfa9be2") )
42+
(101000, uint256S("0x578efd18f7cd5191be3463a2b0db985375f48ee6e8a8940cc6b91d6847fa3614") )
43+
(118000, uint256S("0x8f8ea6eaeae707ab935b517f1c334e6324df75ad8e5f9fbc4d9fb3cc7aa2e69f") )
44+
(120000, uint256S("0xe64d19e39d564cc66e931e88c03207c19e4c9a873ca68ccef16ad712830da726") )
45+
(122000, uint256S("0xb35d4f385bba3c3cb3f9b6914edd6621bde8f78c8c42f58ec47131ed6aac82a9") )
46+
(124392, uint256S("0x1496cd55d7adad1ada774542165a04102a91f8f80c6e894c05f1d0c2ff7e5a39") )
47+
(145000, uint256S("0x99f5d7166ad55d6d0e1ac5c7fffaee1d1dd1ff1409738e0d4f13ac1ae38234cc") )
48+
(278000, uint256S("0x8066e63198c44b9840f664e795b0315d9b752773b267d6212f35593bc0e3b6f4") )
49+
(361800, uint256S("0x801981d8a8f5809e34a2881ea97600259e1d9d778fa21752a5f6cff4defcd08d") )
50+
(500000, uint256S("0x3916b53eaa0eb392ce5d7e4eaf7db4f745187743f167539ffa4dc1a30c06acbd") )
51+
(700000, uint256S("0x2e45c8a834675b505b96792d198c2dc970f560429c635479c347204044acc59b") )
52+
(770000, uint256S("0xfc13a63162bc0a5a09acc3f284cf959d6812a027bb54b342a0e1ccaaca8627ce") )
53+
(850000, uint256S("0xc78b15f25ad990d02256907fab92ab37301d129eaea177fd04acacd56c0cbd22") )
54+
(950000, uint256S("0x4be0afdb9273d232de0bc75b572d8bcfaa146d9efdbe4a4f1ab775334f175b0f") )
55+
(1050000, uint256S("0x0753b624cc0ab39d8745b436012ce53c087f7b2e077099e746a9557f569a80f3") )
56+
(1150000, uint256S("0x0264545b51389faea32ac54bf76cd6efb65701d777e7fa1007584114897067f5") )
57+
(1250000, uint256S("0x452467f2f74580176375f99dd38e9119d564985ba639fa1303718a51351823ab") )
58+
(1350000, uint256S("0x813725a075bc3cc254742557ce6d3a680cb97ee863f65c5d9a386c1ac9a8e792") )
59+
(1450000, uint256S("0x5744777ad775063a3e0b9b9c40ac205e8948904e340d11c3c449fb13914c962b") )
60+
(1550000, uint256S("0xa37ab3260678f6e7f009b2c11fee14bef6add481b411516201cc35b397859bfb") )
61+
(1700000, uint256S("0x831a655dd58599fda1815f7275194ff69ca53341694ba81f9941eede25c40885") )
6262
;
6363

6464
// TestNet has no checkpoints

src/contract/polls.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,16 @@ double ReturnVerifiedVotingBalance(std::string sXML, bool bCreatedAfterSecurityU
389389
{
390390
// Prove the contents of the XML as a 3rd party
391391
CTransaction tx2;
392-
uint256 hashBlock = 0;
393-
uint256 uTXID(ExtractXML(vXML[x],"<TXID>","</TXID>"));
392+
uint256 hashBlock;
393+
uint256 uTXID = uint256S(ExtractXML(vXML[x],"<TXID>","</TXID>"));
394394
std::string sAmt = ExtractXML(vXML[x],"<AMOUNT>","</AMOUNT>");
395395
std::string sPos = ExtractXML(vXML[x],"<POS>","</POS>");
396396
std::string sXmlSig = ExtractXML(vXML[x],"<SIG>","</SIG>");
397397
std::string sXmlMsg = ExtractXML(vXML[x],"<MESSAGE>","</MESSAGE>");
398398
std::string sScriptPubKeyXml = ExtractXML(vXML[x],"<SCRIPTPUBKEY>","</SCRIPTPUBKEY>");
399399
int32_t iPos = RoundFromString(sPos,0);
400400
std::string sPubKey = ExtractXML(vXML[x],"<PUBKEY>","</PUBKEY>");
401-
if (!sPubKey.empty() && !sAmt.empty() && !sPos.empty() && uTXID > 0)
401+
if (!sPubKey.empty() && !sAmt.empty() && !sPos.empty() && !uTXID.IsNull())
402402
{
403403
if (GetTransaction(uTXID, tx2, hashBlock))
404404
{
@@ -448,7 +448,7 @@ double ReturnVerifiedVotingMagnitude(std::string sXML, bool bCreatedAfterSecurit
448448
std::string sXmlCPID = ExtractXML(sMagXML,"<CPID>","</CPID>");
449449
if (!sXmlBlockHash.empty() && !sMagnitude.empty() && !sXmlSigned.empty())
450450
{
451-
CBlockIndex* pblockindexMagnitude = mapBlockIndex[uint256(sXmlBlockHash)];
451+
CBlockIndex* pblockindexMagnitude = mapBlockIndex[uint256S(sXmlBlockHash)];
452452
if (pblockindexMagnitude)
453453
{
454454
bool fResult = VerifyCPIDSignature(sXmlCPID, sXmlBlockHash, sXmlSigned);

src/gridcoin.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ namespace
66
{
77
static const std::set<uint256> bad_blocks =
88
{
9-
uint256("58b2d6d0ff7e3ebcaca1058be7574a87efadd4b7f5c661f9e14255f851a6185e"), //P1144550 S
10-
uint256("471292b59e5f3ad94c39b3784a9a3f7a8324b9b56ff0ad00bd48c31658537c30"), //P1146939 S
11-
uint256("5b63d4edbdec06ddc2182703ce45a3ced70db0d813e329070e83bf37347a6c2c"), //P1152917 S
12-
uint256("e9035d821668a0563b632e9c84bc5af73f53eafcca1e053ac6da53907c7f6940"), //P1154121 S
13-
uint256("1d30c6d4dce377d69c037f1a725aabbc6bafa72a95456dbe2b2538bc1da115bd"), //P1168122 S
14-
uint256("934c6291209d90bb5d3987885b413c18e39f0e28430e8d302f20888d2a35e725"), //P1168193 S
15-
uint256("58282559939ced7ebed7d390559c7ac821932958f8f2399ad40d1188eb0a57f9"), //P1170167 S
16-
uint256("946996f693a33fa1334c1f068574238a463d438b1a3d2cd6d1dd51404a99c73d") //P1176436 S
9+
uint256S("58b2d6d0ff7e3ebcaca1058be7574a87efadd4b7f5c661f9e14255f851a6185e"), //P1144550 S
10+
uint256S("471292b59e5f3ad94c39b3784a9a3f7a8324b9b56ff0ad00bd48c31658537c30"), //P1146939 S
11+
uint256S("5b63d4edbdec06ddc2182703ce45a3ced70db0d813e329070e83bf37347a6c2c"), //P1152917 S
12+
uint256S("e9035d821668a0563b632e9c84bc5af73f53eafcca1e053ac6da53907c7f6940"), //P1154121 S
13+
uint256S("1d30c6d4dce377d69c037f1a725aabbc6bafa72a95456dbe2b2538bc1da115bd"), //P1168122 S
14+
uint256S("934c6291209d90bb5d3987885b413c18e39f0e28430e8d302f20888d2a35e725"), //P1168193 S
15+
uint256S("58282559939ced7ebed7d390559c7ac821932958f8f2399ad40d1188eb0a57f9"), //P1170167 S
16+
uint256S("946996f693a33fa1334c1f068574238a463d438b1a3d2cd6d1dd51404a99c73d") //P1176436 S
1717
};
1818

1919
static const std::set<uint256> bad_blocks_testnet
2020
{
2121
// Invalid claims
22-
uint256("129ae6779d620ec189f8e5148e205efca2dfe31d9f88004b918da3342157b7ff"), //T407024
23-
uint256("c3f85818ba5290aaea1bcbd25b4e136f83acc93999942942bbb25aee2c655f7a"), //T407068
24-
uint256("cf7f1316f92547f611852cf738fc7a4a643a2bb5b9290a33cd2f9425f44cc3f9"), //T407099
25-
uint256("b47085beb075672c6f20d059633d0cad4dba9c5c20f1853d35455b75dc5d54a9"), //T407117
26-
uint256("5a7d437d15bccc41ee8e39143e77960781f3dcf08697a888fa8c4af8a4965682"), //T407161
27-
uint256("aeb3c24277ae1047bda548975a515e9d353d6e12a2952fb733da03f92438fb0f"), //T407181
28-
uint256("fc584b18239f3e3ea78afbbd33af7c6a29bb518b8299f01c1ed4b52d19413d4f"), //T407214
29-
uint256("d5441f7c35eb9ea1b786bbbed820b7f327504301ae70ef2ac3ca3cbc7106236b"), //T479114
30-
uint256("18e2ed822c4c5686c0189f60ffbe828fa51e90873cc1ed3e534a257d2f09c360"), //T479282
31-
uint256("7cb49bc17ecdb7b3a56e1290496d4866330fc9c7974c65b2034e1c6b951ea0fe"), //T511839
32-
uint256("c1aa0511add3bed3f2e366d38b954285a7602cae10a7244e7fe35e4002e90cd5"), //T629408
33-
uint256("639756cf39bf12a4a0ab4ea5ec10938fd0f463cc7bc1bd2916529a445ceba2ab"), //T680406
22+
uint256S("129ae6779d620ec189f8e5148e205efca2dfe31d9f88004b918da3342157b7ff"), //T407024
23+
uint256S("c3f85818ba5290aaea1bcbd25b4e136f83acc93999942942bbb25aee2c655f7a"), //T407068
24+
uint256S("cf7f1316f92547f611852cf738fc7a4a643a2bb5b9290a33cd2f9425f44cc3f9"), //T407099
25+
uint256S("b47085beb075672c6f20d059633d0cad4dba9c5c20f1853d35455b75dc5d54a9"), //T407117
26+
uint256S("5a7d437d15bccc41ee8e39143e77960781f3dcf08697a888fa8c4af8a4965682"), //T407161
27+
uint256S("aeb3c24277ae1047bda548975a515e9d353d6e12a2952fb733da03f92438fb0f"), //T407181
28+
uint256S("fc584b18239f3e3ea78afbbd33af7c6a29bb518b8299f01c1ed4b52d19413d4f"), //T407214
29+
uint256S("d5441f7c35eb9ea1b786bbbed820b7f327504301ae70ef2ac3ca3cbc7106236b"), //T479114
30+
uint256S("18e2ed822c4c5686c0189f60ffbe828fa51e90873cc1ed3e534a257d2f09c360"), //T479282
31+
uint256S("7cb49bc17ecdb7b3a56e1290496d4866330fc9c7974c65b2034e1c6b951ea0fe"), //T511839
32+
uint256S("c1aa0511add3bed3f2e366d38b954285a7602cae10a7244e7fe35e4002e90cd5"), //T629408
33+
uint256S("639756cf39bf12a4a0ab4ea5ec10938fd0f463cc7bc1bd2916529a445ceba2ab"), //T680406
3434
};
3535
}
3636

src/kernel.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT/X11 software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include "arith_uint256.h"
67
#include "kernel.h"
78
#include "txdb.h"
89
#include "main.h"
@@ -112,7 +113,7 @@ static bool SelectBlockFromCandidates(vector<pair<int64_t, uint256> >& vSortedBy
112113
int64_t nSelectionIntervalStop, uint64_t nStakeModifierPrev, const CBlockIndex** pindexSelected)
113114
{
114115
bool fSelected = false;
115-
uint256 hashBest = 0;
116+
arith_uint256 hashBest = 0;
116117
*pindexSelected = (const CBlockIndex*) 0;
117118
for (auto const& item : vSortedByTimestamp)
118119
{
@@ -128,7 +129,7 @@ static bool SelectBlockFromCandidates(vector<pair<int64_t, uint256> >& vSortedBy
128129
// previous proof-of-stake modifier
129130
CDataStream ss(SER_GETHASH, 0);
130131
ss << pindex->hashProof << nStakeModifierPrev;
131-
uint256 hashSelection = Hash(ss.begin(), ss.end());
132+
arith_uint256 hashSelection = UintToArith256(Hash(ss.begin(), ss.end()));
132133
// the selection hash is divided by 2**32 so that proof-of-stake block
133134
// is always favored over proof-of-work block. this is to preserve
134135
// the energy efficiency property
@@ -185,7 +186,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
185186
if (nModifierTime / nModifierInterval >= pindexPrev->GetBlockTime() / nModifierInterval)
186187
return true;
187188

188-
const uint256 ModifGlitch_hash("439b96fd59c3d585a6b93ee63b6e1d78361d7eb9b299657dee6a2c5400ccba29");
189+
const uint256 ModifGlitch_hash = uint256S("439b96fd59c3d585a6b93ee63b6e1d78361d7eb9b299657dee6a2c5400ccba29");
189190
const uint64_t ModifGlitch_correct=0xdf209a3032807577;
190191
if(pindexPrev->GetBlockHash()==ModifGlitch_hash)
191192
{
@@ -301,10 +302,10 @@ unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex)
301302
CDataStream ss(SER_GETHASH, 0);
302303
if (pindex->pprev)
303304
ss << pindex->pprev->nStakeModifierChecksum;
304-
ss << pindex->nFlags << (pindex->IsProofOfStake() ? pindex->hashProof : 0) << pindex->nStakeModifier;
305-
uint256 hashChecksum = Hash(ss.begin(), ss.end());
305+
ss << pindex->nFlags << (pindex->IsProofOfStake() ? pindex->hashProof : uint256()) << pindex->nStakeModifier;
306+
arith_uint256 hashChecksum = UintToArith256(Hash(ss.begin(), ss.end()));
306307
hashChecksum >>= (256 - 32);
307-
return hashChecksum.Get64();
308+
return hashChecksum.GetLow64();
308309
}
309310

310311
// Check stake modifier hard checkpoints

src/key.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ class key_error : public std::runtime_error
4848
class CKeyID : public uint160
4949
{
5050
public:
51-
CKeyID() : uint160(0) { }
51+
CKeyID() : uint160() { }
5252
CKeyID(const uint160 &in) : uint160(in) { }
5353
};
5454

5555
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
5656
class CScriptID : public uint160
5757
{
5858
public:
59-
CScriptID() : uint160(0) { }
59+
CScriptID() : uint160() { }
6060
CScriptID(const uint160 &in) : uint160(in) { }
6161
};
6262

0 commit comments

Comments
 (0)