rpc: allow getting pruned blocks from gettransactions

and get them pruned in find_and_save_rings, since it does not need
the pruned data in the first place.

Also set decode_to_json to false where missing, we don't need this
either.
This commit is contained in:
moneromooo-monero 2018-04-04 10:03:16 +01:00
parent 8361d60aef
commit 25fe67e4cf
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 27 additions and 8 deletions

View file

@ -209,6 +209,15 @@ namespace cryptonote
return true; return true;
} }
//------------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------------
static cryptonote::blobdata get_pruned_tx_blob(cryptonote::transaction &tx)
{
std::stringstream ss;
binary_archive<true> ba(ss);
bool r = tx.serialize_base(ba);
CHECK_AND_ASSERT_MES(r, cryptonote::blobdata(), "Failed to serialize rct signatures base");
return ss.str();
}
//------------------------------------------------------------------------------------------------------------------------------
static cryptonote::blobdata get_pruned_tx_blob(const cryptonote::blobdata &blobdata) static cryptonote::blobdata get_pruned_tx_blob(const cryptonote::blobdata &blobdata)
{ {
cryptonote::transaction tx; cryptonote::transaction tx;
@ -216,14 +225,9 @@ namespace cryptonote
if (!cryptonote::parse_and_validate_tx_from_blob(blobdata, tx)) if (!cryptonote::parse_and_validate_tx_from_blob(blobdata, tx))
{ {
MERROR("Failed to parse and validate tx from blob"); MERROR("Failed to parse and validate tx from blob");
return blobdata; return cryptonote::blobdata();
} }
return get_pruned_tx_blob(tx);
std::stringstream ss;
binary_archive<true> ba(ss);
bool r = tx.serialize_base(ba);
CHECK_AND_ASSERT_MES(r, blobdata, "Failed to serialize rct signatures base");
return ss.str();
} }
//------------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res) bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res)
@ -633,7 +637,7 @@ namespace cryptonote
crypto::hash tx_hash = *vhi++; crypto::hash tx_hash = *vhi++;
e.tx_hash = *txhi++; e.tx_hash = *txhi++;
blobdata blob = t_serializable_object_to_blob(tx); blobdata blob = req.prune ? get_pruned_tx_blob(tx) : t_serializable_object_to_blob(tx);
e.as_hex = string_tools::buff_to_hex_nodelimer(blob); e.as_hex = string_tools::buff_to_hex_nodelimer(blob);
if (req.decode_as_json) if (req.decode_as_json)
e.as_json = obj_to_json_str(tx); e.as_json = obj_to_json_str(tx);

View file

@ -563,10 +563,12 @@ namespace cryptonote
{ {
std::list<std::string> txs_hashes; std::list<std::string> txs_hashes;
bool decode_as_json; bool decode_as_json;
bool prune;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(txs_hashes) KV_SERIALIZE(txs_hashes)
KV_SERIALIZE(decode_as_json) KV_SERIALIZE(decode_as_json)
KV_SERIALIZE_OPT(prune, false)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View file

@ -2010,6 +2010,7 @@ void wallet2::update_pool_state(bool refreshed)
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(p.first)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(p.first));
MDEBUG("asking for " << txids.size() << " transactions"); MDEBUG("asking for " << txids.size() << " transactions");
req.decode_as_json = false; req.decode_as_json = false;
req.prune = false;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client, rpc_timeout); bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client, rpc_timeout);
m_daemon_rpc_mutex.unlock(); m_daemon_rpc_mutex.unlock();
@ -5575,6 +5576,7 @@ bool wallet2::find_and_save_rings(bool force)
// get those transactions from the daemon // get those transactions from the daemon
req.decode_as_json = false; req.decode_as_json = false;
req.prune = true;
bool r; bool r;
{ {
const boost::lock_guard<boost::mutex> lock{m_daemon_rpc_mutex}; const boost::lock_guard<boost::mutex> lock{m_daemon_rpc_mutex};
@ -8155,6 +8157,7 @@ std::string wallet2::get_spend_proof(const crypto::hash &txid, const std::string
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req); COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
req.decode_as_json = false; req.decode_as_json = false;
req.prune = false;
COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res); COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
bool r; bool r;
{ {
@ -8274,6 +8277,7 @@ bool wallet2::check_spend_proof(const crypto::hash &txid, const std::string &mes
COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req); COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
req.decode_as_json = false; req.decode_as_json = false;
req.prune = false;
COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res); COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
bool r; bool r;
{ {
@ -8396,6 +8400,8 @@ void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_de
COMMAND_RPC_GET_TRANSACTIONS::request req; COMMAND_RPC_GET_TRANSACTIONS::request req;
COMMAND_RPC_GET_TRANSACTIONS::response res; COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
req.decode_as_json = false;
req.prune = false;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool ok = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client); bool ok = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client);
m_daemon_rpc_mutex.unlock(); m_daemon_rpc_mutex.unlock();
@ -8532,6 +8538,8 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
COMMAND_RPC_GET_TRANSACTIONS::request req; COMMAND_RPC_GET_TRANSACTIONS::request req;
COMMAND_RPC_GET_TRANSACTIONS::response res; COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
req.decode_as_json = false;
req.prune = false;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool ok = net_utils::invoke_http_json("/gettransactions", req, res, m_http_client); bool ok = net_utils::invoke_http_json("/gettransactions", req, res, m_http_client);
m_daemon_rpc_mutex.unlock(); m_daemon_rpc_mutex.unlock();
@ -8642,6 +8650,8 @@ bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account
COMMAND_RPC_GET_TRANSACTIONS::request req; COMMAND_RPC_GET_TRANSACTIONS::request req;
COMMAND_RPC_GET_TRANSACTIONS::response res; COMMAND_RPC_GET_TRANSACTIONS::response res;
req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid)); req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
req.decode_as_json = false;
req.prune = false;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool ok = net_utils::invoke_http_json("/gettransactions", req, res, m_http_client); bool ok = net_utils::invoke_http_json("/gettransactions", req, res, m_http_client);
m_daemon_rpc_mutex.unlock(); m_daemon_rpc_mutex.unlock();
@ -8875,6 +8885,8 @@ bool wallet2::check_reserve_proof(const cryptonote::account_public_address &addr
COMMAND_RPC_GET_TRANSACTIONS::response gettx_res; COMMAND_RPC_GET_TRANSACTIONS::response gettx_res;
for (size_t i = 0; i < proofs.size(); ++i) for (size_t i = 0; i < proofs.size(); ++i)
gettx_req.txs_hashes.push_back(epee::string_tools::pod_to_hex(proofs[i].txid)); gettx_req.txs_hashes.push_back(epee::string_tools::pod_to_hex(proofs[i].txid));
gettx_req.decode_as_json = false;
gettx_req.prune = false;
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();
bool ok = net_utils::invoke_http_json("/gettransactions", gettx_req, gettx_res, m_http_client); bool ok = net_utils::invoke_http_json("/gettransactions", gettx_req, gettx_res, m_http_client);
m_daemon_rpc_mutex.unlock(); m_daemon_rpc_mutex.unlock();
@ -9449,6 +9461,7 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag
COMMAND_RPC_GET_TRANSACTIONS::request gettxs_req; COMMAND_RPC_GET_TRANSACTIONS::request gettxs_req;
COMMAND_RPC_GET_TRANSACTIONS::response gettxs_res; COMMAND_RPC_GET_TRANSACTIONS::response gettxs_res;
gettxs_req.decode_as_json = false; gettxs_req.decode_as_json = false;
gettxs_req.prune = false;
for (const crypto::hash& spent_txid : spent_txids) for (const crypto::hash& spent_txid : spent_txids)
gettxs_req.txs_hashes.push_back(epee::string_tools::pod_to_hex(spent_txid)); gettxs_req.txs_hashes.push_back(epee::string_tools::pod_to_hex(spent_txid));
m_daemon_rpc_mutex.lock(); m_daemon_rpc_mutex.lock();