added print_coinbase_tx_sum option
This commit is contained in:
parent
9798bde11e
commit
412da63622
|
@ -616,6 +616,20 @@ namespace cryptonote
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
|
uint64_t core::get_coinbase_tx_sum(const uint64_t start_height, const uint64_t end_height)
|
||||||
|
{
|
||||||
|
std::list<block> blocks;
|
||||||
|
uint64_t coinbase_tx_sum = 0;
|
||||||
|
uint64_t current_index = start_height;
|
||||||
|
this->get_blocks(start_height, end_height - start_height, blocks);
|
||||||
|
BOOST_FOREACH(auto& b, blocks)
|
||||||
|
{
|
||||||
|
coinbase_tx_sum += get_outs_money_amount(b.miner_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return coinbase_tx_sum;
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------
|
||||||
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
|
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
|
||||||
{
|
{
|
||||||
std::unordered_set<crypto::key_image> ki;
|
std::unordered_set<crypto::key_image> ki;
|
||||||
|
|
|
@ -600,6 +600,13 @@ namespace cryptonote
|
||||||
*/
|
*/
|
||||||
size_t get_block_sync_size() const { return block_sync_size; }
|
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
|
||||||
|
*/
|
||||||
|
uint64_t get_coinbase_tx_sum(const uint64_t start_height, const uint64_t end_height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
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 index parameter" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint64_t start_index = 0;
|
||||||
|
uint64_t end_index = 0;
|
||||||
|
if(!epee::string_tools::get_xtype_from_string(start_index, args[0]))
|
||||||
|
{
|
||||||
|
std::cout << "wrong starter block index parameter" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(args.size() >1 && !epee::string_tools::get_xtype_from_string(end_index, args[1]))
|
||||||
|
{
|
||||||
|
std::cout << "wrong end block index parameter" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_executor.print_coinbase_tx_sum(start_index, end_index);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace daemonize
|
} // namespace daemonize
|
||||||
|
|
|
@ -115,6 +115,8 @@ public:
|
||||||
bool flush_txpool(const std::vector<std::string>& args);
|
bool flush_txpool(const std::vector<std::string>& args);
|
||||||
|
|
||||||
bool output_histogram(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
|
} // namespace daemonize
|
||||||
|
|
|
@ -215,6 +215,11 @@ t_command_server::t_command_server(
|
||||||
, std::bind(&t_command_parser_executor::output_histogram, &m_parser, p::_1)
|
, std::bind(&t_command_parser_executor::output_histogram, &m_parser, p::_1)
|
||||||
, "Print output histogram (amount, instances)"
|
, "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 index, end index)"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool t_command_server::process_command_str(const std::string& cmd)
|
bool t_command_server::process_command_str(const std::string& cmd)
|
||||||
|
|
|
@ -1270,5 +1270,38 @@ bool t_rpc_command_executor::output_histogram(uint64_t min_count, uint64_t max_c
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t start_block_index, uint64_t end_block_index)
|
||||||
|
{
|
||||||
|
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.start_height = start_block_index;
|
||||||
|
req.end_height = end_block_index;
|
||||||
|
|
||||||
|
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 indexes "
|
||||||
|
<< start_block_index << " and " << end_block_index << " (inclusive) is "
|
||||||
|
<< cryptonote::print_money(res.amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}// namespace daemonize
|
}// namespace daemonize
|
||||||
|
|
|
@ -133,6 +133,8 @@ public:
|
||||||
bool flush_txpool(const std::string &txid);
|
bool flush_txpool(const std::string &txid);
|
||||||
|
|
||||||
bool output_histogram(uint64_t min_count, uint64_t max_count);
|
bool output_histogram(uint64_t min_count, uint64_t max_count);
|
||||||
|
|
||||||
|
bool print_coinbase_tx_sum(uint64_t start_block_index, uint64_t end_block_index);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace daemonize
|
} // namespace daemonize
|
||||||
|
|
|
@ -1266,6 +1266,12 @@ namespace cryptonote
|
||||||
return true;
|
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)
|
||||||
|
{
|
||||||
|
res.amount = m_core.get_coinbase_tx_sum(req.start_height, req.end_height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//------------------------------------------------------------------------------------------------------------------------------
|
||||||
bool core_rpc_server::on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res)
|
bool core_rpc_server::on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
@ -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_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_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_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_JSON_RPC_MAP()
|
||||||
END_URI_MAP2()
|
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_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_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_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:
|
private:
|
||||||
|
|
|
@ -1226,5 +1226,29 @@ namespace cryptonote
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
struct COMMAND_RPC_GET_COINBASE_TX_SUM
|
||||||
|
{
|
||||||
|
struct request
|
||||||
|
{
|
||||||
|
uint64_t start_height;
|
||||||
|
uint64_t end_height;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(start_height);
|
||||||
|
KV_SERIALIZE(end_height);
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
|
struct response
|
||||||
|
{
|
||||||
|
std::string status;
|
||||||
|
uint64_t amount;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(status)
|
||||||
|
KV_SERIALIZE(amount)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue