-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: make wide_difficulty hexadecimal #5402
Conversation
This should be friendlier for clients which don't have bignum support
std::string hex(difficulty_type v) | ||
{ | ||
static const char chars[] = "0123456789abcdef"; | ||
std::string s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A call to reserve
will constrain the number of allocations.
if (s.empty()) | ||
s += "0"; | ||
std::reverse(s.begin(), s.end()); | ||
return "0x" + s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do this before the while loop, to prevent another possible allocation to handle the front insertion. Then do a if (s.size() == 2) s += "0"; std::reverse(s.begin() + 2, s.end());
.
@@ -74,7 +74,7 @@ namespace | |||
void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64) | |||
{ | |||
sdiff = (difficulty << 64 >> 64).convert_to<uint64_t>(); | |||
swdiff = difficulty.convert_to<std::string>(); | |||
swdiff = cryptonote::hex(difficulty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type has a built-in function difficulty.str(0, std::ios_base::hex);
which looks to have the same output, except the characters are upper case. The leading "0x" is also output. It does not use a std::stringstream
internally, and the implementation looks to be similar in performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
cbf3224 rpc: make wide_difficulty hexadecimal (moneromooo-monero)
This should be friendlier for clients which don't have bignum support