Merge pull request #797

d662ab5 rpc: print human readable time since received when printing pool (moneromooo-monero)
5c9dd23 rpc: add a do_not_relay boolean to tx submission (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2016-04-14 16:20:41 +09:00
commit c2e9866fc6
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
4 changed files with 37 additions and 12 deletions

View file

@ -70,6 +70,23 @@ namespace {
<< "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl << "difficulty: " << boost::lexical_cast<std::string>(header.difficulty) << std::endl
<< "reward: " << boost::lexical_cast<std::string>(header.reward); << "reward: " << boost::lexical_cast<std::string>(header.reward);
} }
std::string get_human_time_ago(time_t t, time_t now)
{
if (t == now)
return "now";
time_t dt = t > now ? t - now : now - t;
std::string s;
if (dt < 90)
s = boost::lexical_cast<std::string>(dt) + " seconds";
else if (dt < 90 * 60)
s = boost::lexical_cast<std::string>(dt/60) + " minutes";
else if (dt < 36 * 3600)
s = boost::lexical_cast<std::string>(dt/3600) + " hours";
else
s = boost::lexical_cast<std::string>(dt/(3600*24)) + " days";
return s + " " + (t > now ? "in the future" : "ago");
}
} }
t_rpc_command_executor::t_rpc_command_executor( t_rpc_command_executor::t_rpc_command_executor(
@ -679,6 +696,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() {
} }
if (! res.transactions.empty()) if (! res.transactions.empty())
{ {
const time_t now = time(NULL);
tools::msg_writer() << "Transactions: "; tools::msg_writer() << "Transactions: ";
for (auto & tx_info : res.transactions) for (auto & tx_info : res.transactions)
{ {
@ -686,7 +704,7 @@ bool t_rpc_command_executor::print_transaction_pool_long() {
<< tx_info.tx_json << std::endl << tx_info.tx_json << std::endl
<< "blob_size: " << tx_info.blob_size << std::endl << "blob_size: " << tx_info.blob_size << std::endl
<< "fee: " << cryptonote::print_money(tx_info.fee) << std::endl << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
<< "receive_time: " << tx_info.receive_time << std::endl << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
<< "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
@ -757,17 +775,21 @@ bool t_rpc_command_executor::print_transaction_pool_short() {
{ {
tools::msg_writer() << "Pool is empty" << std::endl; tools::msg_writer() << "Pool is empty" << std::endl;
} }
for (auto & tx_info : res.transactions) else
{ {
tools::msg_writer() << "id: " << tx_info.id_hash << std::endl const time_t now = time(NULL);
<< "blob_size: " << tx_info.blob_size << std::endl for (auto & tx_info : res.transactions)
<< "fee: " << cryptonote::print_money(tx_info.fee) << std::endl {
<< "receive_time: " << tx_info.receive_time << std::endl tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
<< "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl << "blob_size: " << tx_info.blob_size << std::endl
<< "max_used_block_height: " << tx_info.max_used_block_height << std::endl << "fee: " << cryptonote::print_money(tx_info.fee) << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
<< "last_failed_height: " << tx_info.last_failed_height << std::endl << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
<< "last_failed_id: " << tx_info.last_failed_id_hash << std::endl; << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
<< "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
<< "last_failed_height: " << tx_info.last_failed_height << std::endl
<< "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
}
} }
return true; return true;

View file

@ -407,7 +407,7 @@ namespace cryptonote
return true; return true;
} }
if(!tvc.m_should_be_relayed) if(!tvc.m_should_be_relayed || req.do_not_relay)
{ {
LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed"); LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
res.reason = "Not relayed"; res.reason = "Not relayed";

View file

@ -244,12 +244,14 @@ namespace cryptonote
struct request struct request
{ {
std::string tx_as_hex; std::string tx_as_hex;
bool do_not_relay;
request() {} request() {}
explicit request(const transaction &); explicit request(const transaction &);
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_as_hex) KV_SERIALIZE(tx_as_hex)
KV_SERIALIZE(do_not_relay)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View file

@ -1974,6 +1974,7 @@ void wallet2::commit_tx(pending_tx& ptx)
COMMAND_RPC_SEND_RAW_TX::request req; COMMAND_RPC_SEND_RAW_TX::request req;
req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(ptx.tx)); req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(ptx.tx));
req.do_not_relay = false;
COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp; COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000);