Browse Source

WIP: fixed getblocktemplate.

cn_merge
Jianping Wu 6 years ago
parent
commit
5424d869fa
  1. 4
      src/rpc/mining.cpp
  2. 4
      src/util.cpp
  3. 2
      src/util.h

4
src/rpc/mining.cpp

@ -952,12 +952,12 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
std::string kevaBlockData = HexStr(stream.begin(), stream.end()); std::string kevaBlockData = HexStr(stream.begin(), stream.end());
cryptonote::tx_extra_keva_block extra_keva_block; cryptonote::tx_extra_keva_block extra_keva_block;
extra_keva_block.keva_block = kevaBlockData; 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"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal error: failed to add block");
} }
UniValue result(UniValue::VOBJ); 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("blocktemplate_blob", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("difficulty", (double)difficulty)); result.push_back(Pair("difficulty", (double)difficulty));
result.push_back(Pair("height", (uint64_t)height)); result.push_back(Pair("height", (uint64_t)height));

4
src/util.cpp

@ -962,7 +962,7 @@ int64_t GetStartupTime()
return nStartupTime; return nStartupTime;
} }
double ConvertNBitsToDiff(uint32_t nBits) uint64_t ConvertNBitsToDiff(uint32_t nBits)
{ {
int nShift = (nBits >> 24) & 0xff; int nShift = (nBits >> 24) & 0xff;
@ -981,5 +981,5 @@ double ConvertNBitsToDiff(uint32_t nBits)
nShift--; nShift--;
} }
return dDiff; return (uint64_t)round(dDiff);
} }

2
src/util.h

@ -349,6 +349,6 @@ std::unique_ptr<T> MakeUnique(Args&&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
double ConvertNBitsToDiff(uint32_t nBits); uint64_t ConvertNBitsToDiff(uint32_t nBits);
#endif // BITCOIN_UTIL_H #endif // BITCOIN_UTIL_H

Loading…
Cancel
Save