aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-10-11 10:30:52 +0200
committerRiccardo Spagni <ric@spagni.net>2016-10-11 10:30:53 +0200
commit3db0ebafe54044fea13d8d5f09948210855fbae6 (patch)
treebb4a186e6ef10ec4aa836887d4187f4f4f510572
parentMerge pull request #1205 (diff)
parentprint_coinbase_tx_sum now breaks output into fee and emission components (diff)
downloadmonero-3db0ebafe54044fea13d8d5f09948210855fbae6.tar.xz
Merge pull request #1204
7db29d6 print_coinbase_tx_sum now breaks output into fee and emission components (Dion Ahmetaj) dd6c443 changed params from start/end index to height/count (Dion Ahmetaj) e95d3f3 attempted to remove whitespace spam (Dion Ahmetaj) 412da63 added print_coinbase_tx_sum option (Dion Ahmetaj)
-rw-r--r--.gitignore1
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp28
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
-rw-r--r--src/daemon/command_parser_executor.cpp22
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp5
-rw-r--r--src/daemon/rpc_command_executor.cpp35
-rw-r--r--src/daemon/rpc_command_executor.h2
-rw-r--r--src/rpc/core_rpc_server.cpp8
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h28
11 files changed, 139 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 622bbdb3a..a27982af1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -103,3 +103,4 @@ local.properties
.texlipse
.idea/
+/testnet \ No newline at end of file
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 149fb09df..9a44d9d3f 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -616,6 +616,34 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
+ std::pair<uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count)
+ {
+ std::list<block> blocks;
+ std::list<transaction> txs;
+ std::list<crypto::hash> 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_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 std::pair<uint64_t, uint64_t>(emission_amount, total_fee_amount);
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
{
std::unordered_set<crypto::key_image> ki;
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 6727d6b04..407e89197 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -600,6 +600,13 @@ namespace cryptonote
*/
size_t get_block_sync_size() const { return block_sync_size; }
+ /**
+ * @brief get the sum of coinbase tx amounts between blocks
+ *
+ * @return the number of blocks to sync in one go
+ */
+ std::pair<uint64_t, uint64_t> get_coinbase_tx_sum(const uint64_t start_offset, const uint64_t count);
+
private:
/**
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 6ea862b56..5d7ed6cc0 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -452,5 +452,27 @@ bool t_command_parser_executor::output_histogram(const std::vector<std::string>&
return m_executor.output_histogram(min_count, max_count);
}
+bool t_command_parser_executor::print_coinbase_tx_sum(const std::vector<std::string>& args)
+{
+ if(!args.size())
+ {
+ std::cout << "need block height parameter" << std::endl;
+ return false;
+ }
+ uint64_t height = 0;
+ uint64_t count = 0;
+ if(!epee::string_tools::get_xtype_from_string(height, args[0]))
+ {
+ std::cout << "wrong starter block height parameter" << std::endl;
+ return false;
+ }
+ if(args.size() >1 && !epee::string_tools::get_xtype_from_string(count, args[1]))
+ {
+ std::cout << "wrong count parameter" << std::endl;
+ return false;
+ }
+
+ return m_executor.print_coinbase_tx_sum(height, count);
+}
} // namespace daemonize
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index 7819bd261..6a984aa71 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -115,6 +115,8 @@ public:
bool flush_txpool(const std::vector<std::string>& args);
bool output_histogram(const std::vector<std::string>& args);
+
+ bool print_coinbase_tx_sum(const std::vector<std::string>& args);
};
} // namespace daemonize
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index cb54d1966..1418b920f 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -215,6 +215,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::output_histogram, &m_parser, p::_1)
, "Print output histogram (amount, instances)"
);
+ m_command_lookup.set_handler(
+ "print_coinbase_tx_sum"
+ , std::bind(&t_command_parser_executor::print_coinbase_tx_sum, &m_parser, p::_1)
+ , "Print sum of coinbase transactions (start height, block count)"
+ );
}
bool t_command_server::process_command_str(const std::string& cmd)
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index e7229f7f9..db0d0a6e4 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1270,5 +1270,40 @@ bool t_rpc_command_executor::output_histogram(uint64_t min_count, uint64_t max_c
return true;
}
+bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t count)
+{
+ cryptonote::COMMAND_RPC_GET_COINBASE_TX_SUM::request req;
+ cryptonote::COMMAND_RPC_GET_COINBASE_TX_SUM::response res;
+ epee::json_rpc::error error_resp;
+
+ req.height = height;
+ req.count = count;
+
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "get_coinbase_tx_sum", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_coinbase_tx_sum(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ tools::msg_writer() << "Sum of coinbase transactions between block heights ["
+ << height << ", " << (height + count) << ") is "
+ << 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;
+}
+
}// namespace daemonize
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 5eed44353..c097453e7 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -133,6 +133,8 @@ public:
bool flush_txpool(const std::string &txid);
bool output_histogram(uint64_t min_count, uint64_t max_count);
+
+ bool print_coinbase_tx_sum(uint64_t height, uint64_t count);
};
} // namespace daemonize
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 700019250..e8b2d5cb1 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1266,6 +1266,14 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ 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)
+ {
+ std::pair<uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
+ res.emission_amount = amounts.first;
+ res.fee_amount = amounts.second;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res)
{
// TODO
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 68da59f6b..147f019d6 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -115,6 +115,7 @@ namespace cryptonote
MAP_JON_RPC_WE_IF("flush_txpool", on_flush_txpool, COMMAND_RPC_FLUSH_TRANSACTION_POOL, !m_restricted)
MAP_JON_RPC_WE("get_output_histogram", on_get_output_histogram, COMMAND_RPC_GET_OUTPUT_HISTOGRAM)
MAP_JON_RPC_WE("get_version", on_get_version, COMMAND_RPC_GET_VERSION)
+ MAP_JON_RPC_WE("get_coinbase_tx_sum", on_get_coinbase_tx_sum, COMMAND_RPC_GET_COINBASE_TX_SUM)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -160,6 +161,7 @@ namespace cryptonote
bool on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request& req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response& res, epee::json_rpc::error& error_resp);
bool on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request& req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response& res, epee::json_rpc::error& error_resp);
bool on_get_version(const COMMAND_RPC_GET_VERSION::request& req, COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& error_resp);
+ bool 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);
//-----------------------
private:
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index dd2116e51..61c302e45 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -1226,5 +1226,31 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};
-}
+ struct COMMAND_RPC_GET_COINBASE_TX_SUM
+ {
+ struct request
+ {
+ uint64_t height;
+ uint64_t count;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(height);
+ KV_SERIALIZE(count);
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+ uint64_t emission_amount;
+ uint64_t fee_amount;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(emission_amount)
+ KV_SERIALIZE(fee_amount)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+}