File tree 3 files changed +17
-11
lines changed
3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -278,4 +278,10 @@ BOOST_AUTO_TEST_CASE( operator_with_self )
278
278
BOOST_CHECK (v == UintToArith256 (uint256S (" 0" )));
279
279
}
280
280
281
+ BOOST_AUTO_TEST_CASE ( check_ONE )
282
+ {
283
+ uint256 one = uint256S (" 0000000000000000000000000000000000000000000000000000000000000001" );
284
+ BOOST_CHECK_EQUAL (one, uint256::ONE);
285
+ }
286
+
281
287
BOOST_AUTO_TEST_SUITE_END ()
Original file line number Diff line number Diff line change @@ -80,7 +80,4 @@ template std::string base_blob<256>::ToString() const;
80
80
template void base_blob<256 >::SetHex(const char *);
81
81
template void base_blob<256 >::SetHex(const std::string&);
82
82
83
- uint256& UINT256_ONE () {
84
- static uint256* one = new uint256 (uint256S (" 0000000000000000000000000000000000000000000000000000000000000001" ));
85
- return *one;
86
- }
83
+ const uint256 uint256::ONE (1 );
Original file line number Diff line number Diff line change @@ -20,10 +20,11 @@ class base_blob
20
20
static constexpr int WIDTH = BITS / 8 ;
21
21
uint8_t m_data[WIDTH];
22
22
public:
23
- base_blob ()
24
- {
25
- memset (m_data, 0 , sizeof (m_data));
26
- }
23
+ /* construct 0 value by default */
24
+ constexpr base_blob () : m_data() {}
25
+
26
+ /* constructor for constants between 1 and 255 */
27
+ constexpr explicit base_blob (uint8_t v) : m_data{v} {}
27
28
28
29
explicit base_blob (const std::vector<unsigned char >& vch);
29
30
@@ -111,7 +112,7 @@ class base_blob
111
112
*/
112
113
class uint160 : public base_blob <160 > {
113
114
public:
114
- uint160 () {}
115
+ constexpr uint160 () {}
115
116
explicit uint160 (const std::vector<unsigned char >& vch) : base_blob<160>(vch) {}
116
117
};
117
118
@@ -122,8 +123,10 @@ class uint160 : public base_blob<160> {
122
123
*/
123
124
class uint256 : public base_blob <256 > {
124
125
public:
125
- uint256 () {}
126
+ constexpr uint256 () {}
127
+ constexpr explicit uint256 (uint8_t v) : base_blob<256>(v) {}
126
128
explicit uint256 (const std::vector<unsigned char >& vch) : base_blob<256>(vch) {}
129
+ static const uint256 ONE;
127
130
};
128
131
129
132
/* uint256 from const char *.
@@ -147,6 +150,6 @@ inline uint256 uint256S(const std::string& str)
147
150
return rv;
148
151
}
149
152
150
- uint256& UINT256_ONE ();
153
+ inline const uint256& UINT256_ONE () { return uint256::ONE; }
151
154
152
155
#endif // BITCOIN_UINT256_H
You can’t perform that action at this time.
0 commit comments