Browse Source

Fixed CN APIs.

cn_mining
Jianping Wu 6 years ago
parent
commit
350f6fa953
  1. 18
      src/cn_utils/cryptonote_config.h
  2. 81
      src/rpc/blockchain.cpp
  3. 7
      src/rpc/mining.cpp

18
src/cn_utils/cryptonote_config.h

@ -1,21 +1,21 @@ @@ -1,21 +1,21 @@
// Copyright (c) 2014-2018, The Monero Project
//
//
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once
@ -63,7 +63,9 @@ @@ -63,7 +63,9 @@
#define CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE 600
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 12
// COIN - number of smallest units in one coin
#define COIN ((uint64_t)1000000000000) // pow(10, 12)
// KEVACOIN: this definition conflicts with Bitcoin's definition
// and must be commented out!
//#define COIN ((uint64_t)1000000000000) // pow(10, 12)
#define FEE_PER_KB_OLD ((uint64_t)10000000000) // pow(10, 10)
#define FEE_PER_KB ((uint64_t)2000000000) // 2 * pow(10, 9)

81
src/rpc/blockchain.cpp

@ -707,7 +707,7 @@ UniValue getblockheader(const JSONRPCRequest& request) @@ -707,7 +707,7 @@ UniValue getblockheader(const JSONRPCRequest& request)
// Cryptonote RPC API: getlastblockheader
UniValue getlastblockheader(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
if (request.fHelp)
throw std::runtime_error(
"getlastblockheader\n"
"\nResult (for verbose = true):\n"
@ -747,29 +747,32 @@ UniValue getlastblockheader(const JSONRPCRequest& request) @@ -747,29 +747,32 @@ UniValue getlastblockheader(const JSONRPCRequest& request)
//TODO: easier way to do this?
CAmount coinbaseValue = coinbaseTx->GetValueOut();
UniValue result(UniValue::VOBJ);
UniValue blockHeader(UniValue::VOBJ);
// TODO: read major/minor versions from cn header.
result.push_back(Pair("major_version", (uint64_t)0));
result.push_back(Pair("minor_version", (uint64_t)0));
blockHeader.push_back(Pair("major_version", (uint64_t)block.cnHeader.major_version));
blockHeader.push_back(Pair("minor_version", (uint64_t)block.cnHeader.minor_version));
result.push_back(Pair("timestamp", (uint64_t)pblockindex->nTime));
result.push_back(Pair("prev_hash", pblockindex->pprev->GetBlockHash().GetHex()));
result.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce));
result.push_back(Pair("orphan_status", false));
result.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
blockHeader.push_back(Pair("timestamp", (uint64_t)pblockindex->nTime));
blockHeader.push_back(Pair("prev_hash", pblockindex->pprev->GetBlockHash().GetHex()));
blockHeader.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce));
blockHeader.push_back(Pair("orphan_status", false));
blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
const uint64_t depth = chainActive.Height() - pblockindex->nHeight + 1; // Same as confirmations.
result.push_back(Pair("depth", (uint64_t)depth));
result.push_back(Pair("hash", pblockindex->GetBlockHash().GetHex()));
result.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
blockHeader.push_back(Pair("depth", (uint64_t)depth));
blockHeader.push_back(Pair("hash", pblockindex->GetBlockHash().GetHex()));
blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
// TODO: implement cumulative_difficulty
result.push_back(Pair("cumulative_difficulty", 0));
result.push_back(Pair("reward", (uint64_t)coinbaseValue));
result.push_back(Pair("block_size", (int)::GetBlockWeight(block)));
result.push_back(Pair("num_txes", (uint64_t)pblockindex->nTx));
result.push_back(Pair("pow_hash", pblockindex->GetBlockPoWHash().GetHex()));
result.push_back(Pair("long_term_weight", 0.0)); // Not implemented
blockHeader.push_back(Pair("cumulative_difficulty", 0));
blockHeader.push_back(Pair("reward", (uint64_t)coinbaseValue));
blockHeader.push_back(Pair("block_size", (int)::GetBlockWeight(block)));
blockHeader.push_back(Pair("num_txes", (uint64_t)pblockindex->nTx));
blockHeader.push_back(Pair("pow_hash", block.GetPoWHash().GetHex()));
blockHeader.push_back(Pair("long_term_weight", 0.0)); // Not implemented
UniValue result(UniValue::VOBJ);
result.push_back(Pair("block_header", blockHeader));
result.push_back(Pair("status", "OK"));
return result;
}
@ -823,29 +826,33 @@ UniValue getblockheaderbyheight(const JSONRPCRequest& request) @@ -823,29 +826,33 @@ UniValue getblockheaderbyheight(const JSONRPCRequest& request)
//TODO: easier way to do this?
CAmount coinbaseValue = coinbaseTx->GetValueOut();
UniValue result(UniValue::VOBJ);
UniValue blockHeader(UniValue::VOBJ);
// TODO: read major/minor versions from cn header.
result.push_back(Pair("major_version", (uint64_t)0));
result.push_back(Pair("minor_version", (uint64_t)0));
blockHeader.push_back(Pair("major_version", (uint64_t)block.cnHeader.major_version));
blockHeader.push_back(Pair("minor_version", (uint64_t)block.cnHeader.minor_version));
result.push_back(Pair("timestamp", (uint64_t)pblockindex->nTime));
result.push_back(Pair("prev_hash", pblockindex->pprev->GetBlockHash().GetHex()));
result.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce));
result.push_back(Pair("orphan_status", false));
result.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
blockHeader.push_back(Pair("timestamp", (uint64_t)pblockindex->nTime));
blockHeader.push_back(Pair("prev_hash", pblockindex->pprev->GetBlockHash().GetHex()));
blockHeader.push_back(Pair("nonce", (uint64_t)pblockindex->nNonce));
blockHeader.push_back(Pair("orphan_status", false));
blockHeader.push_back(Pair("height", (uint64_t)pblockindex->nHeight));
const uint64_t depth = chainActive.Height() - nHeight + 1; // Same as confirmations.
result.push_back(Pair("depth", (uint64_t)depth));
result.push_back(Pair("hash", pblockindex->GetBlockHash().GetHex()));
result.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
blockHeader.push_back(Pair("depth", (uint64_t)depth));
blockHeader.push_back(Pair("hash", pblockindex->GetBlockHash().GetHex()));
blockHeader.push_back(Pair("difficulty", GetDifficulty(pblockindex)));
// TODO: implement cumulative_difficulty
result.push_back(Pair("cumulative_difficulty", 0));
result.push_back(Pair("reward", (uint64_t)coinbaseValue));
result.push_back(Pair("block_size", (int)::GetBlockWeight(block)));
result.push_back(Pair("num_txes", (uint64_t)pblockindex->nTx));
result.push_back(Pair("pow_hash", pblockindex->GetBlockPoWHash().GetHex()));
result.push_back(Pair("long_term_weight", 0.0)); // Not implemented
blockHeader.push_back(Pair("cumulative_difficulty", 0));
blockHeader.push_back(Pair("reward", (uint64_t)coinbaseValue));
blockHeader.push_back(Pair("block_size", (int)::GetBlockWeight(block)));
blockHeader.push_back(Pair("num_txes", (uint64_t)pblockindex->nTx));
blockHeader.push_back(Pair("pow_hash", block.GetPoWHash().GetHex()));
blockHeader.push_back(Pair("long_term_weight", 0.0)); // Not implemented
UniValue result(UniValue::VOBJ);
result.push_back(Pair("status", "OK"));
result.push_back(Pair("block_header", blockHeader));
return result;
}

7
src/rpc/mining.cpp

@ -300,8 +300,11 @@ UniValue CN_JSONRPCError(int code, const std::string& message) @@ -300,8 +300,11 @@ UniValue CN_JSONRPCError(int code, const std::string& message)
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
static UniValue BIP22ValidationResult(const CValidationState& state)
{
if (state.IsValid())
return NullUniValue;
if (state.IsValid()) {
UniValue result(UniValue::VOBJ);
result.push_back(Pair("status", "OK"));
return result;
}
std::string strRejectReason = state.GetRejectReason();
if (state.IsError())

Loading…
Cancel
Save