From 7db29d6903fe24eabaaf3b3afc364b6924d5b463 Mon Sep 17 00:00:00 2001 From: Dion Ahmetaj Date: Mon, 10 Oct 2016 19:55:18 -0400 Subject: [PATCH] print_coinbase_tx_sum now breaks output into fee and emission components --- src/cryptonote_core/cryptonote_core.cpp | 24 +++++++++++++++++++----- src/cryptonote_core/cryptonote_core.h | 2 +- src/daemon/rpc_command_executor.cpp | 4 +++- src/rpc/core_rpc_server.cpp | 4 +++- src/rpc/core_rpc_server_commands_defs.h | 6 ++++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index ecbc1067c..9a44d9d3f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -616,18 +616,32 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- - uint64_t core::get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count) + std::pair core::get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count) { std::list blocks; - uint64_t coinbase_tx_sum = 0; - uint64_t current_index = start_offset; + std::list txs; + std::list missed_txs; + uint64_t coinbase_amount = 0; + uint64_t emission_amount = 0; + uint64_t total_fee_amount = 0; + uint64_t tx_fee_amount = 0; this->get_blocks(start_offset, count, blocks); BOOST_FOREACH(auto& b, blocks) { - coinbase_tx_sum += get_outs_money_amount(b.miner_tx); + coinbase_amount = get_outs_money_amount(b.miner_tx); + this->get_transactions(b.tx_hashes, txs, missed_txs); + BOOST_FOREACH(const auto& tx, txs) + { + tx_fee_amount += get_tx_fee(tx); + } + + emission_amount += coinbase_amount - tx_fee_amount; + total_fee_amount += tx_fee_amount; + coinbase_amount = 0; + tx_fee_amount = 0; } - return coinbase_tx_sum; + return std::pair(emission_amount, total_fee_amount); } //----------------------------------------------------------------------------------------------- bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index c152e6a3f..407e89197 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -605,7 +605,7 @@ namespace cryptonote * * @return the number of blocks to sync in one go */ - uint64_t get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count); + std::pair get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count); private: diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index bf154597c..db0d0a6e4 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -1299,7 +1299,9 @@ bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t cou tools::msg_writer() << "Sum of coinbase transactions between block heights [" << height << ", " << (height + count) << ") is " - << cryptonote::print_money(res.amount); + << cryptonote::print_money(res.emission_amount + res.fee_amount) << " " + << "consisting of " << cryptonote::print_money(res.emission_amount) + << " in emissions, and " << cryptonote::print_money(res.fee_amount) << " in fees"; return true; } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index af36961f2..e8b2d5cb1 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1268,7 +1268,9 @@ namespace cryptonote //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_coinbase_tx_sum(const COMMAND_RPC_GET_COINBASE_TX_SUM::request& req, COMMAND_RPC_GET_COINBASE_TX_SUM::response& res, epee::json_rpc::error& error_resp) { - res.amount = m_core.get_coinbase_tx_sum(req.height, req.count); + std::pair amounts = m_core.get_coinbase_tx_sum(req.height, req.count); + res.emission_amount = amounts.first; + res.fee_amount = amounts.second; return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 47ce37f2f..61c302e45 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1243,11 +1243,13 @@ namespace cryptonote struct response { std::string status; - uint64_t amount; + uint64_t emission_amount; + uint64_t fee_amount; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) - KV_SERIALIZE(amount) + KV_SERIALIZE(emission_amount) + KV_SERIALIZE(fee_amount) END_KV_SERIALIZE_MAP() }; };