File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ double AddrInfo::GetChance(NodeSeconds now) const
108
108
109
109
AddrManImpl::AddrManImpl (const NetGroupManager& netgroupman, bool deterministic, int32_t consistency_check_ratio)
110
110
: insecure_rand{deterministic}
111
- , nKey{deterministic ? uint256{1 } : insecure_rand.rand256 ()}
111
+ , nKey{deterministic ? uint256{1ULL } : insecure_rand.rand256 ()}
112
112
, m_consistency_check_ratio{consistency_check_ratio}
113
113
, m_netgroupman{netgroupman}
114
114
{
Original file line number Diff line number Diff line change @@ -31,5 +31,5 @@ template std::string base_blob<160>::ToString() const;
31
31
template std::string base_blob<256 >::GetHex() const ;
32
32
template std::string base_blob<256 >::ToString() const ;
33
33
34
- const uint256 uint256::ZERO (0 );
35
- const uint256 uint256::ONE (1 );
34
+ const uint256 uint256::ZERO (0ULL );
35
+ const uint256 uint256::ONE (1ULL );
Original file line number Diff line number Diff line change @@ -198,8 +198,22 @@ class uint256 : public base_blob<256> {
198
198
static std::optional<uint256> FromHex (std::string_view str) { return detail::FromHex<uint256>(str); }
199
199
static std::optional<uint256> FromUserHex (std::string_view str) { return detail::FromUserHex<uint256>(str); }
200
200
constexpr uint256 () = default;
201
- consteval explicit uint256 (std::string_view hex_str) : base_blob<256>(hex_str) {}
201
+ constexpr explicit uint256 (uint64_t val) : base_blob<256>() {
202
+ for (size_t i = 0 ; i < 8 ; ++i) {
203
+ m_data[i] = (val >> (i * 8 )) & 0xFF ;
204
+ }
205
+ }
202
206
constexpr explicit uint256 (uint8_t v) : base_blob<256>(v) {}
207
+ consteval explicit uint256 (std::string_view hex_str) : base_blob<256>() {
208
+ if (hex_str.size () > 64 ) {
209
+ throw " Invalid hex string size in consteval uint256" ;
210
+ }
211
+ for (size_t i = 0 ; i < 32 ; ++i) {
212
+ unsigned char high = util::ConstevalHexDigit (hex_str[2 * i]);
213
+ unsigned char low = util::ConstevalHexDigit (hex_str[2 * i + 1 ]);
214
+ m_data[31 - i] = (high << 4 ) | low;
215
+ }
216
+ }
203
217
constexpr explicit uint256 (std::span<const unsigned char > vch) : base_blob<256>(vch) {}
204
218
static const uint256 ZERO;
205
219
static const uint256 ONE;
You can’t perform that action at this time.
0 commit comments