Skip to content
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

Merged
merged 1 commit into from Apr 15, 2019

Conversation

Projects
None yet
4 participants
@moneromooo-monero
Copy link
Contributor

moneromooo-monero commented Apr 5, 2019

This should be friendlier for clients which don't have bignum support

rpc: make wide_difficulty hexadecimal
This should be friendlier for clients which don't have bignum support
@hyc

hyc approved these changes Apr 5, 2019

std::string hex(difficulty_type v)
{
static const char chars[] = "0123456789abcdef";
std::string s;

This comment has been minimized.

Copy link
@vtnerd

vtnerd Apr 8, 2019

Contributor

A call to reserve will constrain the number of allocations.

if (s.empty())
s += "0";
std::reverse(s.begin(), s.end());
return "0x" + s;

This comment has been minimized.

Copy link
@vtnerd

vtnerd Apr 8, 2019

Contributor

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);

This comment has been minimized.

Copy link
@vtnerd

vtnerd Apr 8, 2019

Contributor

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.

@fluffypony
Copy link
Collaborator

fluffypony left a comment

Reviewed

@fluffypony fluffypony merged commit cbf3224 into monero-project:master Apr 15, 2019

1 of 10 checks passed

buildbot/monero-linux-armv7 Build done.
Details
buildbot/monero-static-osx-10.11 Build done.
Details
buildbot/monero-static-osx-10.12 Build done.
Details
buildbot/monero-static-osx-10.13 Build done.
Details
buildbot/monero-static-ubuntu-amd64 Build done.
Details
buildbot/monero-static-ubuntu-i686 Build done.
Details
buildbot/monero-static-win32 Build done.
Details
buildbot/monero-static-win64 Build done.
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
buildbot/monero-linux-armv8 Build done.
Details

fluffypony added a commit that referenced this pull request Apr 15, 2019

Merge pull request #5402
cbf3224 rpc: make wide_difficulty hexadecimal (moneromooo-monero)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.