diff --git a/CMakeLists.txt b/CMakeLists.txt index d6b9e272..d07b6e7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.6) +cmake_minimum_required(VERSION 3.0) include(CheckCXXCompilerFlag) set(VERSION "6.4.9") @@ -12,7 +12,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_CONFIGURATION_TYPES Debug RelWithDebInfo Release CACHE STRING INTERNAL) -set(CMAKE_SKIP_INSTALL_RULES ON) set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY ON) set(CMAKE_SUPPRESS_REGENERATION ON) diff --git a/src/CryptoNoteConfig.h b/src/CryptoNoteConfig.h index 44f43864..e4ef7f18 100644 --- a/src/CryptoNoteConfig.h +++ b/src/CryptoNoteConfig.h @@ -283,4 +283,3 @@ namespace CryptoNote } // namespace CryptoNote -#define ALLOW_DEBUG_COMMANDS diff --git a/src/CryptoNoteCore/TransactionExtra.h b/src/CryptoNoteCore/TransactionExtra.h index 7b47c36e..563068b6 100644 --- a/src/CryptoNoteCore/TransactionExtra.h +++ b/src/CryptoNoteCore/TransactionExtra.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include diff --git a/src/NodeRpcProxy/NodeRpcProxy.cpp b/src/NodeRpcProxy/NodeRpcProxy.cpp index 667ae4a7..be2e212d 100644 --- a/src/NodeRpcProxy/NodeRpcProxy.cpp +++ b/src/NodeRpcProxy/NodeRpcProxy.cpp @@ -500,25 +500,6 @@ std::error_code NodeRpcProxy::doGetNewBlocks(std::vector& knownBlo return ec; } -std::error_code NodeRpcProxy::doGetBlock(const uint32_t blockHeight, f_block_details_response& block) -{ - COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::request req = AUTO_VAL_INIT(req); - COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::response resp = AUTO_VAL_INIT(resp); - - req.blockHeight = blockHeight; - - std::error_code ec = jsonCommand("get_block_details_by_height", req, resp); - - if (ec) - { - return ec; - } - - block = std::move(resp.block); - - return ec; -} - std::error_code NodeRpcProxy::doGetTransactionOutsGlobalIndices(const Crypto::Hash& transactionHash, std::vector& outsGlobalIndices) { CryptoNote::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request req = AUTO_VAL_INIT(req); diff --git a/src/NodeRpcProxy/NodeRpcProxy.h b/src/NodeRpcProxy/NodeRpcProxy.h index 41b8b6a7..7002f5a5 100644 --- a/src/NodeRpcProxy/NodeRpcProxy.h +++ b/src/NodeRpcProxy/NodeRpcProxy.h @@ -88,7 +88,6 @@ class NodeRpcProxy : public CryptoNote::INode { std::error_code doRelayTransaction(const CryptoNote::Transaction& transaction); std::error_code doGetRandomOutsByAmounts(std::vector& amounts, uint64_t outsCount, std::vector& result); - std::error_code doGetBlock(const uint32_t blockHeight, f_block_details_response& block); std::error_code doGetNewBlocks(std::vector& knownBlockIds, std::vector& newBlocks, uint32_t& startHeight); diff --git a/src/P2p/NetNode.cpp b/src/P2p/NetNode.cpp index c8b26a75..928d4207 100644 --- a/src/P2p/NetNode.cpp +++ b/src/P2p/NetNode.cpp @@ -520,7 +520,9 @@ namespace CryptoNote //only in case if we really sure that we have external visible ip m_have_address = true; m_ip_address = 0; +#ifdef ALLOW_DEBUG_COMMANDS m_last_stat_request_time = 0; +#endif //configure self // m_net_server.get_config_object().m_pcommands_handler = this; diff --git a/src/P2p/NetNode.h b/src/P2p/NetNode.h index 0c9ef539..a92b54e5 100644 --- a/src/P2p/NetNode.h +++ b/src/P2p/NetNode.h @@ -153,15 +153,15 @@ namespace CryptoNote int handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, P2pConnectionContext& context); #ifdef ALLOW_DEBUG_COMMANDS - int handle_get_stat_info(int command, COMMAND_REQUEST_STAT_INFO::request& arg, COMMAND_REQUEST_STAT_INFO::response& rsp, P2pConnectionContext& context); - int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, P2pConnectionContext& context); - int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, P2pConnectionContext& context); + int handle_get_stat_info(int command, COMMAND_REQUEST_STAT_INFO::request &arg, COMMAND_REQUEST_STAT_INFO::response &rsp, P2pConnectionContext &context); + int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request &arg, COMMAND_REQUEST_NETWORK_STATE::response &rsp, P2pConnectionContext &context); + int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request &arg, COMMAND_REQUEST_PEER_ID::response &rsp, P2pConnectionContext &context); + bool check_trust(const proof_of_trust &tr); #endif bool init_config(); bool make_default_config(); bool store_config(); - bool check_trust(const proof_of_trust& tr); void initUpnp(); bool handshake(CryptoNote::LevinProtocol& proto, P2pConnectionContext& context, bool just_take_peerlist = false); diff --git a/src/Rpc/CoreRpcServerCommandsDefinitions.h b/src/Rpc/CoreRpcServerCommandsDefinitions.h index 4a3cde0f..7b440d6c 100644 --- a/src/Rpc/CoreRpcServerCommandsDefinitions.h +++ b/src/Rpc/CoreRpcServerCommandsDefinitions.h @@ -872,7 +872,7 @@ struct COMMAND_RPC_GET_BLOCK_TIMESTAMP_BY_HEIGHT { struct request { - uint32_t height; + uint64_t height; void serialize(ISerializer &s) { @@ -897,11 +897,11 @@ struct COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT { struct request { - uint32_t blockHeight; + uint64_t height; void serialize(ISerializer &s) { - KV_MEMBER(blockHeight) + KV_MEMBER(height) } }; diff --git a/src/Rpc/RpcServer.cpp b/src/Rpc/RpcServer.cpp index a8276512..e9b61808 100644 --- a/src/Rpc/RpcServer.cpp +++ b/src/Rpc/RpcServer.cpp @@ -259,167 +259,168 @@ bool RpcServer::on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request &req, CO return true; } -bool RpcServer::on_get_block_details_by_height(const COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::response &res) +bool RpcServer::fill_f_block_details_response(const Crypto::Hash &hash, f_block_details_response &block) { - try + Block blk; + if (!m_core.getBlockByHash(hash, blk)) { - logger(INFO) << "1 start"; - f_block_details_response blockDetails; - if (m_core.get_current_blockchain_height() <= req.blockHeight) - { - throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT, - std::string("Too big height: ") + std::to_string(req.blockHeight) + ", current blockchain height = " + std::to_string(m_core.get_current_blockchain_height() - 1)}; - } - Crypto::Hash hash = m_core.getBlockIdByHeight(req.blockHeight); + throw JsonRpc::JsonRpcError{ + CORE_RPC_ERROR_CODE_INTERNAL_ERROR, + "Internal error: can't get block by hash."}; + } - Block blk; - if (!m_core.getBlockByHash(hash, blk)) - { - throw JsonRpc::JsonRpcError{ - CORE_RPC_ERROR_CODE_INTERNAL_ERROR, - "Internal error: can't get block by height. Height = " + req.blockHeight + '.'}; - } + if (blk.baseTransaction.inputs.front().type() != typeid(BaseInput)) + { + throw JsonRpc::JsonRpcError{ + CORE_RPC_ERROR_CODE_INTERNAL_ERROR, + "Internal error: coinbase transaction in the block has the wrong type"}; + } - if (blk.baseTransaction.inputs.front().type() != typeid(BaseInput)) - { - throw JsonRpc::JsonRpcError{ - CORE_RPC_ERROR_CODE_INTERNAL_ERROR, - "Internal error: coinbase transaction in the block has the wrong type"}; - } + block_header_response block_header; - block_header_response block_header; + uint32_t block_height = boost::get(blk.baseTransaction.inputs.front()).blockIndex; + block.height = block_height; + Crypto::Hash tmp_hash = m_core.getBlockIdByHeight(block_height); + bool is_orphaned = hash != tmp_hash; - uint32_t block_height = boost::get(blk.baseTransaction.inputs.front()).blockIndex; - res.block.height = block_height; - Crypto::Hash tmp_hash = m_core.getBlockIdByHeight(block_height); - bool is_orphaned = hash != tmp_hash; + fill_block_header_response(blk, is_orphaned, block_height, hash, block_header); - fill_block_header_response(blk, is_orphaned, block_height, hash, block_header); + block.major_version = block_header.major_version; + block.minor_version = block_header.minor_version; + block.timestamp = block_header.timestamp; + block.prev_hash = block_header.prev_hash; + block.nonce = block_header.nonce; + block.hash = Common::podToHex(hash); + block.orphan_status = is_orphaned; + block.depth = m_core.get_current_blockchain_height() - block.height - 1; + m_core.getBlockDifficulty(static_cast(block.height), block.difficulty); - res.block.major_version = block_header.major_version; - res.block.minor_version = block_header.minor_version; - res.block.timestamp = block_header.timestamp; - res.block.prev_hash = block_header.prev_hash; - res.block.nonce = block_header.nonce; - res.block.hash = Common::podToHex(hash); - res.block.orphan_status = is_orphaned; - res.block.depth = m_core.get_current_blockchain_height() - res.block.height - 1; - m_core.getBlockDifficulty(static_cast(res.block.height), res.block.difficulty); + block.reward = block_header.reward; - res.block.reward = block_header.reward; + std::vector blocksSizes; + if (!m_core.getBackwardBlocksSizes(block.height, blocksSizes, parameters::CRYPTONOTE_REWARD_BLOCKS_WINDOW)) + { + return false; + } + block.sizeMedian = Common::medianValue(blocksSizes); - std::vector blocksSizes; - if (!m_core.getBackwardBlocksSizes(res.block.height, blocksSizes, parameters::CRYPTONOTE_REWARD_BLOCKS_WINDOW)) - { - return false; - } - res.block.sizeMedian = Common::medianValue(blocksSizes); + size_t blockSize = 0; + if (!m_core.getBlockSize(hash, blockSize)) + { + return false; + } + block.transactionsCumulativeSize = blockSize; - size_t blockSize = 0; - if (!m_core.getBlockSize(hash, blockSize)) - { - return false; - } - res.block.transactionsCumulativeSize = blockSize; + size_t blokBlobSize = getObjectBinarySize(blk); + size_t minerTxBlobSize = getObjectBinarySize(blk.baseTransaction); + block.blockSize = blokBlobSize + block.transactionsCumulativeSize - minerTxBlobSize; - size_t blokBlobSize = getObjectBinarySize(blk); - size_t minerTxBlobSize = getObjectBinarySize(blk.baseTransaction); - res.block.blockSize = blokBlobSize + res.block.transactionsCumulativeSize - minerTxBlobSize; + uint64_t alreadyGeneratedCoins; + if (!m_core.getAlreadyGeneratedCoins(hash, alreadyGeneratedCoins)) + { + return false; + } + block.alreadyGeneratedCoins = std::to_string(alreadyGeneratedCoins); - uint64_t alreadyGeneratedCoins; - if (!m_core.getAlreadyGeneratedCoins(hash, alreadyGeneratedCoins)) - { - return false; - } - res.block.alreadyGeneratedCoins = std::to_string(alreadyGeneratedCoins); + if (!m_core.getGeneratedTransactionsNumber(block.height, block.alreadyGeneratedTransactions)) + { + return false; + } - if (!m_core.getGeneratedTransactionsNumber(res.block.height, res.block.alreadyGeneratedTransactions)) + uint64_t prevBlockGeneratedCoins = 0; + if (block.height > 0) + { + if (!m_core.getAlreadyGeneratedCoins(blk.previousBlockHash, prevBlockGeneratedCoins)) { return false; } + } + uint64_t maxReward = 0; + uint64_t currentReward = 0; + int64_t emissionChange = 0; + if (blk.majorVersion < 2) + { + block.effectiveSizeMedian = block.sizeMedian; + } + else + { + block.effectiveSizeMedian = 0; + } + if (!m_core.getBlockReward(block.sizeMedian, 0, prevBlockGeneratedCoins, 0, block.height, maxReward, emissionChange)) + { + return false; + } + if (!m_core.getBlockReward(block.sizeMedian, block.transactionsCumulativeSize, prevBlockGeneratedCoins, 0, block.height, currentReward, emissionChange)) + { + return false; + } - uint64_t prevBlockGeneratedCoins = 0; - if (res.block.height > 0) - { - if (!m_core.getAlreadyGeneratedCoins(blk.previousBlockHash, prevBlockGeneratedCoins)) - { - return false; - } - } - uint64_t maxReward = 0; - uint64_t currentReward = 0; - int64_t emissionChange = 0; - bool penalizeFee = blk.majorVersion >= 2; - size_t blockGrantedFullRewardZone = penalizeFee ? m_core.currency().blockGrantedFullRewardZone() : res.block.effectiveSizeMedian = std::max(res.block.sizeMedian, blockGrantedFullRewardZone); - - if (!m_core.getBlockReward(res.block.sizeMedian, 0, prevBlockGeneratedCoins, 0, res.block.height, maxReward, emissionChange)) - { - return false; - } - if (!m_core.getBlockReward(res.block.sizeMedian, res.block.transactionsCumulativeSize, prevBlockGeneratedCoins, 0, res.block.height, currentReward, emissionChange)) + block.baseReward = maxReward; + if (maxReward == 0 && currentReward == 0) + { + block.penalty = static_cast(0); + } + else + { + if (maxReward < currentReward) { return false; } + block.penalty = static_cast(maxReward - currentReward) / static_cast(maxReward); + } - res.block.baseReward = maxReward; - if (maxReward == 0 && currentReward == 0) - { - res.block.penalty = static_cast(0); - } - else - { - if (maxReward < currentReward) - { - return false; - } - res.block.penalty = static_cast(maxReward - currentReward) / static_cast(maxReward); - } + // Base transaction adding + f_transaction_short_response base_transaction; + base_transaction.hash = Common::podToHex(getObjectHash(blk.baseTransaction)); + base_transaction.fee = 0; + base_transaction.amount_out = get_outs_money_amount(blk.baseTransaction); + base_transaction.size = getObjectBinarySize(blk.baseTransaction); + block.transactions.push_back(base_transaction); - // Base transaction adding - f_transaction_short_response transaction_short; - transaction_short.hash = Common::podToHex(getObjectHash(blk.baseTransaction)); - transaction_short.fee = 0; - transaction_short.amount_out = get_outs_money_amount(blk.baseTransaction); - transaction_short.size = getObjectBinarySize(blk.baseTransaction); - res.block.transactions.push_back(transaction_short); + std::list missed_txs; + std::list txs; + m_core.getTransactions(blk.transactionHashes, txs, missed_txs); - std::list missed_txs; - std::list txs; - m_core.getTransactions(blk.transactionHashes, txs, missed_txs); + block.totalFeeAmount = 0; - res.block.totalFeeAmount = 0; + for (const Transaction &tx : txs) + { + f_transaction_short_response transaction_short; + uint64_t amount_in = 0; + get_inputs_money_amount(tx, amount_in); + uint64_t amount_out = get_outs_money_amount(tx); - for (const Transaction &tx : txs) - { - f_transaction_short_response transaction_short; - uint64_t amount_in = 0; - get_inputs_money_amount(tx, amount_in); - uint64_t amount_out = get_outs_money_amount(tx); - - transaction_short.hash = Common::podToHex(getObjectHash(tx)); - transaction_short.fee = - amount_in < amount_out + parameters::MINIMUM_FEE //account for interest in output, it always has minimum fee - ? parameters::MINIMUM_FEE - : amount_in - amount_out; - transaction_short.amount_out = amount_out; - transaction_short.size = getObjectBinarySize(tx); - res.block.transactions.push_back(transaction_short); - - res.block.totalFeeAmount += transaction_short.fee; - } + transaction_short.hash = Common::podToHex(getObjectHash(tx)); + transaction_short.fee = + amount_in < amount_out + parameters::MINIMUM_FEE //account for interest in output, it always has minimum fee + ? parameters::MINIMUM_FEE + : amount_in - amount_out; + transaction_short.amount_out = amount_out; + transaction_short.size = getObjectBinarySize(tx); + block.transactions.push_back(transaction_short); - res.block = blockDetails; + block.totalFeeAmount += transaction_short.fee; } - catch (std::system_error &e) + return true; +} + +bool RpcServer::on_get_block_details_by_height(const COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_DETAILS_BY_HEIGHT::response &res) +{ + f_block_details_response blockDetails; + if (m_core.get_current_blockchain_height() <= req.height) { - throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_INTERNAL_ERROR, e.what()}; - return false; + throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT, + std::string("Too big height: ") + std::to_string(req.height) + ", current blockchain height = " + std::to_string(m_core.get_current_blockchain_height() - 1)}; } - catch (std::exception &e) + Crypto::Hash hash = m_core.getBlockIdByHeight(req.height); + + if (!fill_f_block_details_response(hash, blockDetails)) { - throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_INTERNAL_ERROR, "Error: " + std::string(e.what())}; - return false; + throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_INTERNAL_ERROR, + std::string("Unable to fill block details.")}; } + + res.block = blockDetails; res.status = CORE_RPC_STATUS_OK; return true; } @@ -1050,149 +1051,24 @@ bool RpcServer::f_on_blocks_list_json(const F_COMMAND_RPC_GET_BLOCKS_LIST::reque return true; } -bool RpcServer::f_on_block_json(const F_COMMAND_RPC_GET_BLOCK_DETAILS::request& req, F_COMMAND_RPC_GET_BLOCK_DETAILS::response& res) { +bool RpcServer::f_on_block_json(const F_COMMAND_RPC_GET_BLOCK_DETAILS::request &req, F_COMMAND_RPC_GET_BLOCK_DETAILS::response &res) +{ Hash hash; - - if (!parse_hash256(req.hash, hash)) { - throw JsonRpc::JsonRpcError{ - CORE_RPC_ERROR_CODE_WRONG_PARAM, - "Failed to parse hex representation of block hash. Hex = " + req.hash + '.' }; - } - - Block blk; - if (!m_core.getBlockByHash(hash, blk)) { - throw JsonRpc::JsonRpcError{ - CORE_RPC_ERROR_CODE_INTERNAL_ERROR, - "Internal error: can't get block by hash. Hash = " + req.hash + '.' }; - } - - if (blk.baseTransaction.inputs.front().type() != typeid(BaseInput)) { + f_block_details_response blockDetails; + if (!parse_hash256(req.hash, hash)) + { throw JsonRpc::JsonRpcError{ - CORE_RPC_ERROR_CODE_INTERNAL_ERROR, - "Internal error: coinbase transaction in the block has the wrong type" }; - } - - block_header_response block_header; - - uint32_t block_height = boost::get(blk.baseTransaction.inputs.front()).blockIndex; - res.block.height = block_height; - Crypto::Hash tmp_hash = m_core.getBlockIdByHeight(block_height); - bool is_orphaned = hash != tmp_hash; - - fill_block_header_response(blk, is_orphaned, block_height, hash, block_header); - - res.block.major_version = block_header.major_version; - res.block.minor_version = block_header.minor_version; - res.block.timestamp = block_header.timestamp; - res.block.prev_hash = block_header.prev_hash; - res.block.nonce = block_header.nonce; - res.block.hash = Common::podToHex(hash); - res.block.orphan_status = is_orphaned; - res.block.depth = m_core.get_current_blockchain_height() - res.block.height - 1; - m_core.getBlockDifficulty(static_cast(res.block.height), res.block.difficulty); - - res.block.reward = block_header.reward; - - std::vector blocksSizes; - if (!m_core.getBackwardBlocksSizes(res.block.height, blocksSizes, parameters::CRYPTONOTE_REWARD_BLOCKS_WINDOW)) { - return false; - } - res.block.sizeMedian = Common::medianValue(blocksSizes); - - size_t blockSize = 0; - if (!m_core.getBlockSize(hash, blockSize)) { - return false; + CORE_RPC_ERROR_CODE_WRONG_PARAM, + "Failed to parse hex representation of block hash. Hex = " + req.hash + '.'}; } - res.block.transactionsCumulativeSize = blockSize; - - size_t blokBlobSize = getObjectBinarySize(blk); - size_t minerTxBlobSize = getObjectBinarySize(blk.baseTransaction); - res.block.blockSize = blokBlobSize + res.block.transactionsCumulativeSize - minerTxBlobSize; - uint64_t alreadyGeneratedCoins; - if (!m_core.getAlreadyGeneratedCoins(hash, alreadyGeneratedCoins)) { - return false; - } - res.block.alreadyGeneratedCoins = std::to_string(alreadyGeneratedCoins); - - if (!m_core.getGeneratedTransactionsNumber(res.block.height, res.block.alreadyGeneratedTransactions)) { - return false; - } - - uint64_t prevBlockGeneratedCoins = 0; - if (res.block.height > 0) { - if (!m_core.getAlreadyGeneratedCoins(blk.previousBlockHash, prevBlockGeneratedCoins)) { - return false; - } - } - uint64_t maxReward = 0; - uint64_t currentReward = 0; - int64_t emissionChange = 0; - bool penalizeFee = blk.majorVersion >= 2; - size_t blockGrantedFullRewardZone = penalizeFee ? - m_core.currency().blockGrantedFullRewardZone() : - //m_core.currency().blockGrantedFullRewardZoneV1(); - res.block.effectiveSizeMedian = std::max(res.block.sizeMedian, blockGrantedFullRewardZone); - - // virtual bool getBlockReward(size_t medianSize, size_t currentBlockSize, uint64_t alreadyGeneratedCoins, uint64_t fee, uint32_t height, - // uint64_t& reward, int64_t& emissionChange) = 0; - - if (!m_core.getBlockReward(res.block.sizeMedian, 0, prevBlockGeneratedCoins, 0, res.block.height, maxReward, emissionChange)) { - return false; - } - if (!m_core.getBlockReward(res.block.sizeMedian, res.block.transactionsCumulativeSize, prevBlockGeneratedCoins, 0, res.block.height, currentReward, emissionChange)) { - return false; - } - - // if (!m_core.getBlockReward(res.block.sizeMedian, 0, prevBlockGeneratedCoins, 0, penalizeFee, maxReward, emissionChange)) { - // return false; - // } - // if (!m_core.getBlockReward(res.block.sizeMedian, res.block.transactionsCumulativeSize, prevBlockGeneratedCoins, 0, penalizeFee, currentReward, emissionChange)) { - // return false; - // } - - res.block.baseReward = maxReward; - if (maxReward == 0 && currentReward == 0) { - res.block.penalty = static_cast(0); - } else { - if (maxReward < currentReward) { - return false; - } - res.block.penalty = static_cast(maxReward - currentReward) / static_cast(maxReward); + if (!fill_f_block_details_response(hash, blockDetails)) + { + throw JsonRpc::JsonRpcError{CORE_RPC_ERROR_CODE_INTERNAL_ERROR, + std::string("Unable to fill block details.")}; } - // Base transaction adding - f_transaction_short_response transaction_short; - transaction_short.hash = Common::podToHex(getObjectHash(blk.baseTransaction)); - transaction_short.fee = 0; - transaction_short.amount_out = get_outs_money_amount(blk.baseTransaction); - transaction_short.size = getObjectBinarySize(blk.baseTransaction); - res.block.transactions.push_back(transaction_short); - - - std::list missed_txs; - std::list txs; - m_core.getTransactions(blk.transactionHashes, txs, missed_txs); - - res.block.totalFeeAmount = 0; - - for (const Transaction& tx : txs) { - f_transaction_short_response transaction_short; - uint64_t amount_in = 0; - get_inputs_money_amount(tx, amount_in); - uint64_t amount_out = get_outs_money_amount(tx); - - transaction_short.hash = Common::podToHex(getObjectHash(tx)); - transaction_short.fee = - amount_in < amount_out + parameters::MINIMUM_FEE //account for interest in output, it always has minimum fee - ? parameters::MINIMUM_FEE - : amount_in - amount_out; - transaction_short.amount_out = amount_out; - transaction_short.size = getObjectBinarySize(tx); - res.block.transactions.push_back(transaction_short); - - res.block.totalFeeAmount += transaction_short.fee; - } + res.block = blockDetails; res.status = CORE_RPC_STATUS_OK; return true; diff --git a/src/Rpc/RpcServer.h b/src/Rpc/RpcServer.h index 1b6b6a23..9ae9d46a 100644 --- a/src/Rpc/RpcServer.h +++ b/src/Rpc/RpcServer.h @@ -87,6 +87,8 @@ class RpcServer : public HttpServer { bool f_on_transactions_pool_json(const F_COMMAND_RPC_GET_POOL::request& req, F_COMMAND_RPC_GET_POOL::response& res); bool f_getMixin(const Transaction& transaction, uint64_t& mixin); + bool fill_f_block_details_response(const Crypto::Hash& hash, f_block_details_response& block); + Logging::LoggerRef logger; core& m_core; NodeServer& m_p2p; diff --git a/src/Transfers/BlockchainSynchronizer.cpp b/src/Transfers/BlockchainSynchronizer.cpp index d71d8020..0e61629b 100644 --- a/src/Transfers/BlockchainSynchronizer.cpp +++ b/src/Transfers/BlockchainSynchronizer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "CryptoNoteCore/TransactionApi.h" diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index bd06bd9b..1830fbda 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -112,11 +112,11 @@ namespace Crypto { return (std::numeric_limits::max)(); } #else - static T(min)() { + constexpr static T(min)() { return (std::numeric_limits::min)(); } - static T(max)() { + constexpr static T(max)() { return (std::numeric_limits::max)(); } #endif