From 5424d869fa578d95db5e6af901f427b9cbfc8801 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Thu, 7 Mar 2019 15:44:38 -0800 Subject: [PATCH] WIP: fixed getblocktemplate. --- src/rpc/mining.cpp | 4 ++-- src/util.cpp | 4 ++-- src/util.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 11e20a23f..beeba7404 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -952,12 +952,12 @@ UniValue getblocktemplate(const JSONRPCRequest& request) std::string kevaBlockData = HexStr(stream.begin(), stream.end()); cryptonote::tx_extra_keva_block extra_keva_block; extra_keva_block.keva_block = kevaBlockData; - if (cryptonote::append_keva_block_to_extra(cn_block.miner_tx.extra, extra_keva_block)) { + if (!cryptonote::append_keva_block_to_extra(cn_block.miner_tx.extra, extra_keva_block)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal error: failed to add block"); } UniValue result(UniValue::VOBJ); - const double difficulty = ConvertNBitsToDiff(pblock->nBits); + const uint64_t difficulty = ConvertNBitsToDiff(pblock->nBits); result.push_back(Pair("blocktemplate_blob", pblock->hashPrevBlock.GetHex())); result.push_back(Pair("difficulty", (double)difficulty)); result.push_back(Pair("height", (uint64_t)height)); diff --git a/src/util.cpp b/src/util.cpp index 266265084..568d39cdc 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -962,7 +962,7 @@ int64_t GetStartupTime() return nStartupTime; } -double ConvertNBitsToDiff(uint32_t nBits) +uint64_t ConvertNBitsToDiff(uint32_t nBits) { int nShift = (nBits >> 24) & 0xff; @@ -981,5 +981,5 @@ double ConvertNBitsToDiff(uint32_t nBits) nShift--; } - return dDiff; + return (uint64_t)round(dDiff); } \ No newline at end of file diff --git a/src/util.h b/src/util.h index d85fcd698..f9036f702 100644 --- a/src/util.h +++ b/src/util.h @@ -349,6 +349,6 @@ std::unique_ptr MakeUnique(Args&&... args) return std::unique_ptr(new T(std::forward(args)...)); } -double ConvertNBitsToDiff(uint32_t nBits); +uint64_t ConvertNBitsToDiff(uint32_t nBits); #endif // BITCOIN_UTIL_H