aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-04-05 16:28:15 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-04-05 16:30:16 +0000
commitcbf3224180380d7ff2b4fc28b3800486f22a1cc7 (patch)
tree9f2d6b4de0d6e2dc3e2e30c4472fe1d19d97a4ed /src
parentMerge pull request #5390 (diff)
downloadmonero-cbf3224180380d7ff2b4fc28b3800486f22a1cc7.tar.xz
rpc: make wide_difficulty hexadecimal
This should be friendlier for clients which don't have bignum support
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_basic/difficulty.cpp15
-rw-r--r--src/cryptonote_basic/difficulty.h3
-rw-r--r--src/rpc/core_rpc_server.cpp2
3 files changed, 19 insertions, 1 deletions
diff --git a/src/cryptonote_basic/difficulty.cpp b/src/cryptonote_basic/difficulty.cpp
index 5162e53e6..859173aa5 100644
--- a/src/cryptonote_basic/difficulty.cpp
+++ b/src/cryptonote_basic/difficulty.cpp
@@ -239,4 +239,19 @@ namespace cryptonote {
return res.convert_to<difficulty_type>();
}
+ std::string hex(difficulty_type v)
+ {
+ static const char chars[] = "0123456789abcdef";
+ std::string s;
+ while (v > 0)
+ {
+ s.push_back(chars[(v & 0xf).convert_to<unsigned>()]);
+ v >>= 4;
+ }
+ if (s.empty())
+ s += "0";
+ std::reverse(s.begin(), s.end());
+ return "0x" + s;
+ }
+
}
diff --git a/src/cryptonote_basic/difficulty.h b/src/cryptonote_basic/difficulty.h
index f7a9376fb..02ed89e5a 100644
--- a/src/cryptonote_basic/difficulty.h
+++ b/src/cryptonote_basic/difficulty.h
@@ -32,6 +32,7 @@
#include <cstdint>
#include <vector>
+#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include "crypto/hash.h"
@@ -58,4 +59,6 @@ namespace cryptonote
bool check_hash_128(const crypto::hash &hash, difficulty_type difficulty);
bool check_hash(const crypto::hash &hash, difficulty_type difficulty);
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds);
+
+ std::string hex(difficulty_type v);
}
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index f5f1a2f9a..8c201097e 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -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);
stop64 = (difficulty >> 64).convert_to<uint64_t>();
}
}