Skip to content

Commit 4977c30

Browse files
committed
refactor: define a UINT256_ONE global constant
Instead of having a uint256 representations of one scattered throughout where it is used, define it globally in uint256.h
1 parent 415afcc commit 4977c30

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

src/script/interpreter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,13 +1281,11 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn
12811281
return ss.GetHash();
12821282
}
12831283

1284-
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
1285-
12861284
// Check for invalid use of SIGHASH_SINGLE
12871285
if ((nHashType & 0x1f) == SIGHASH_SINGLE) {
12881286
if (nIn >= txTo.vout.size()) {
12891287
// nOut out of range
1290-
return one;
1288+
return UINT256_ONE();
12911289
}
12921290
}
12931291

src/test/sighash_tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ extern UniValue read_json(const std::string& jsondata);
2626
// Old script.cpp SignatureHash function
2727
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
2828
{
29-
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
3029
if (nIn >= txTo.vin.size())
3130
{
32-
return one;
31+
return UINT256_ONE();
3332
}
3433
CMutableTransaction txTmp(txTo);
3534

@@ -59,7 +58,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
5958
unsigned int nOut = nIn;
6059
if (nOut >= txTmp.vout.size())
6160
{
62-
return one;
61+
return UINT256_ONE();
6362
}
6463
txTmp.vout.resize(nOut+1);
6564
for (unsigned int i = 0; i < nOut; i++)

src/uint256.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ template std::string base_blob<256>::GetHex() const;
7575
template std::string base_blob<256>::ToString() const;
7676
template void base_blob<256>::SetHex(const char*);
7777
template void base_blob<256>::SetHex(const std::string&);
78+
79+
uint256& UINT256_ONE() {
80+
static uint256* one = new uint256(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
81+
return *one;
82+
}

src/uint256.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ inline uint256 uint256S(const std::string& str)
144144
return rv;
145145
}
146146

147+
uint256& UINT256_ONE();
148+
147149
#endif // BITCOIN_UINT256_H

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ WalletCreationStatus CreateWallet(interfaces::Chain& chain, const SecureString&
238238
return WalletCreationStatus::SUCCESS;
239239
}
240240

241-
const uint256 CWalletTx::ABANDON_HASH(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
241+
const uint256 CWalletTx::ABANDON_HASH(UINT256_ONE());
242242

243243
/** @defgroup mapWallet
244244
*

0 commit comments

Comments
 (0)