daemon: new relay_tx command and RPC

This commit is contained in:
moneromooo-monero 2017-04-02 12:17:35 +01:00
parent c9063c0b8f
commit 548075b1f5
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
8 changed files with 122 additions and 1 deletions

View file

@ -563,4 +563,19 @@ bool t_command_parser_executor::update(const std::vector<std::string>& args)
return m_executor.update(args.front());
}
bool t_command_parser_executor::relay_tx(const std::vector<std::string>& args)
{
if (args.size() != 1) return false;
std::string txid;
crypto::hash hash;
if (!parse_hash256(args[0], hash))
{
std::cout << "failed to parse tx id" << std::endl;
return true;
}
txid = args[0];
return m_executor.relay_tx(txid);
}
} // namespace daemonize

View file

@ -132,6 +132,8 @@ public:
bool print_blockchain_dynamic_stats(const std::vector<std::string>& args);
bool update(const std::vector<std::string>& args);
bool relay_tx(const std::vector<std::string>& args);
};
} // namespace daemonize

View file

@ -248,6 +248,11 @@ t_command_server::t_command_server(
, std::bind(&t_command_parser_executor::update, &m_parser, p::_1)
, "subcommands: check (check if an update is available), download (download it is there is), update (not implemented)"
);
m_command_lookup.set_handler(
"relay_tx"
, std::bind(&t_command_parser_executor::relay_tx, &m_parser, p::_1)
, "Relay a given transaction by its txid"
);
}
bool t_command_server::process_command_str(const std::string& cmd)

View file

@ -1646,4 +1646,32 @@ bool t_rpc_command_executor::update(const std::string &command)
return true;
}
bool t_rpc_command_executor::relay_tx(const std::string &txid)
{
cryptonote::COMMAND_RPC_RELAY_TX::request req;
cryptonote::COMMAND_RPC_RELAY_TX::response res;
std::string fail_message = "Unsuccessful";
epee::json_rpc::error error_resp;
req.txids.push_back(txid);
if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "relay_tx", fail_message.c_str()))
{
return true;
}
}
else
{
if (!m_rpc_server->on_relay_tx(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
{
tools::fail_msg_writer() << make_error(fail_message, res.status);
return true;
}
}
return true;
}
}// namespace daemonize

View file

@ -153,6 +153,8 @@ public:
bool print_blockchain_dynamic_stats(uint64_t nblocks);
bool update(const std::string &command);
bool relay_tx(const std::string &txid);
};
} // namespace daemonize