mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-14 07:03:29 +01:00
Merge pull request #791
f17b2f4
rpc: add pool/blockchain and block height results to gettransactions (moneromooo-monero)
This commit is contained in:
commit
8f63e89c7f
@ -575,16 +575,26 @@ bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 == res.txs_as_hex.size())
|
if (1 == res.txs.size() || 1 == res.txs_as_hex.size())
|
||||||
{
|
{
|
||||||
|
if (1 == res.txs.size())
|
||||||
|
{
|
||||||
|
// only available for new style answers
|
||||||
|
if (res.txs.front().in_pool)
|
||||||
|
tools::success_msg_writer() << "Found in pool";
|
||||||
|
else
|
||||||
|
tools::success_msg_writer() << "Found in blockchain at height " << res.txs.front().block_height;
|
||||||
|
}
|
||||||
|
|
||||||
// first as hex
|
// first as hex
|
||||||
tools::success_msg_writer() << res.txs_as_hex.front();
|
const std::string &as_hex = (1 == res.txs.size()) ? res.txs.front().as_hex : res.txs_as_hex.front();
|
||||||
|
tools::success_msg_writer() << as_hex;
|
||||||
|
|
||||||
// then as json
|
// then as json
|
||||||
crypto::hash tx_hash, tx_prefix_hash;
|
crypto::hash tx_hash, tx_prefix_hash;
|
||||||
cryptonote::transaction tx;
|
cryptonote::transaction tx;
|
||||||
cryptonote::blobdata blob;
|
cryptonote::blobdata blob;
|
||||||
if (!string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), blob))
|
if (!string_tools::parse_hexstr_to_binbuff(as_hex, blob))
|
||||||
{
|
{
|
||||||
tools::fail_msg_writer() << "Failed to parse tx";
|
tools::fail_msg_writer() << "Failed to parse tx";
|
||||||
}
|
}
|
||||||
|
@ -240,6 +240,7 @@ namespace cryptonote
|
|||||||
|
|
||||||
// try the pool for any missing txes
|
// try the pool for any missing txes
|
||||||
size_t found_in_pool = 0;
|
size_t found_in_pool = 0;
|
||||||
|
std::unordered_set<crypto::hash> pool_tx_hashes;
|
||||||
if (!missed_txs.empty())
|
if (!missed_txs.empty())
|
||||||
{
|
{
|
||||||
std::list<transaction> pool_txs;
|
std::list<transaction> pool_txs;
|
||||||
@ -248,9 +249,11 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
for (std::list<transaction>::const_iterator i = pool_txs.begin(); i != pool_txs.end(); ++i)
|
for (std::list<transaction>::const_iterator i = pool_txs.begin(); i != pool_txs.end(); ++i)
|
||||||
{
|
{
|
||||||
std::list<crypto::hash>::iterator mi = std::find(missed_txs.begin(), missed_txs.end(), get_transaction_hash(*i));
|
crypto::hash tx_hash = get_transaction_hash(*i);
|
||||||
|
std::list<crypto::hash>::iterator mi = std::find(missed_txs.begin(), missed_txs.end(), tx_hash);
|
||||||
if (mi != missed_txs.end())
|
if (mi != missed_txs.end())
|
||||||
{
|
{
|
||||||
|
pool_tx_hashes.insert(tx_hash);
|
||||||
missed_txs.erase(mi);
|
missed_txs.erase(mi);
|
||||||
txs.push_back(*i);
|
txs.push_back(*i);
|
||||||
++found_in_pool;
|
++found_in_pool;
|
||||||
@ -260,12 +263,33 @@ namespace cryptonote
|
|||||||
LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
|
LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<std::string>::const_iterator txhi = req.txs_hashes.begin();
|
||||||
|
std::vector<crypto::hash>::const_iterator vhi = vh.begin();
|
||||||
BOOST_FOREACH(auto& tx, txs)
|
BOOST_FOREACH(auto& tx, txs)
|
||||||
{
|
{
|
||||||
|
res.txs.push_back(COMMAND_RPC_GET_TRANSACTIONS::entry());
|
||||||
|
COMMAND_RPC_GET_TRANSACTIONS::entry &e = res.txs.back();
|
||||||
|
|
||||||
|
crypto::hash tx_hash = *vhi++;
|
||||||
|
e.tx_hash = *txhi++;
|
||||||
blobdata blob = t_serializable_object_to_blob(tx);
|
blobdata blob = t_serializable_object_to_blob(tx);
|
||||||
res.txs_as_hex.push_back(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)
|
||||||
res.txs_as_json.push_back(obj_to_json_str(tx));
|
e.as_json = obj_to_json_str(tx);
|
||||||
|
e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
|
||||||
|
if (e.in_pool)
|
||||||
|
{
|
||||||
|
e.block_height = std::numeric_limits<uint64_t>::max();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill up old style responses too, in case an old wallet asks
|
||||||
|
res.txs_as_hex.push_back(e.as_hex);
|
||||||
|
if (req.decode_as_json)
|
||||||
|
res.txs_as_json.push_back(e.as_json);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const auto& miss_tx, missed_txs)
|
BOOST_FOREACH(const auto& miss_tx, missed_txs)
|
||||||
@ -273,7 +297,7 @@ namespace cryptonote
|
|||||||
res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
|
res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_PRINT_L2(res.txs_as_hex.size() << " transactions found, " << res.missed_tx.size() << " not found");
|
LOG_PRINT_L2(res.txs.size() << " transactions found, " << res.missed_tx.size() << " not found");
|
||||||
res.status = CORE_RPC_STATUS_OK;
|
res.status = CORE_RPC_STATUS_OK;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -103,18 +103,41 @@ namespace cryptonote
|
|||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct entry
|
||||||
|
{
|
||||||
|
std::string tx_hash;
|
||||||
|
std::string as_hex;
|
||||||
|
std::string as_json;
|
||||||
|
bool in_pool;
|
||||||
|
uint64_t block_height;
|
||||||
|
|
||||||
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
|
KV_SERIALIZE(tx_hash)
|
||||||
|
KV_SERIALIZE(as_hex)
|
||||||
|
KV_SERIALIZE(as_json)
|
||||||
|
KV_SERIALIZE(in_pool)
|
||||||
|
KV_SERIALIZE(block_height)
|
||||||
|
END_KV_SERIALIZE_MAP()
|
||||||
|
};
|
||||||
|
|
||||||
struct response
|
struct response
|
||||||
{
|
{
|
||||||
std::list<std::string> txs_as_hex; //transactions blobs as hex
|
// older compatibility stuff
|
||||||
|
std::list<std::string> txs_as_hex; //transactions blobs as hex (old compat)
|
||||||
|
std::list<std::string> txs_as_json; //transactions decoded as json (old compat)
|
||||||
|
|
||||||
|
// in both old and new
|
||||||
std::list<std::string> missed_tx; //not found transactions
|
std::list<std::string> missed_tx; //not found transactions
|
||||||
std::list<std::string> txs_as_json; //transactions decoded as json
|
|
||||||
|
// new style
|
||||||
|
std::vector<entry> txs;
|
||||||
std::string status;
|
std::string status;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(txs_as_hex)
|
KV_SERIALIZE(txs_as_hex)
|
||||||
KV_SERIALIZE(missed_tx)
|
|
||||||
KV_SERIALIZE(txs_as_json)
|
KV_SERIALIZE(txs_as_json)
|
||||||
|
KV_SERIALIZE(txs)
|
||||||
|
KV_SERIALIZE(missed_tx)
|
||||||
KV_SERIALIZE(status)
|
KV_SERIALIZE(status)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
|
@ -2497,13 +2497,18 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
|
|||||||
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));
|
||||||
if (!net_utils::invoke_http_json_remote_command2(m_daemon_address + "/gettransactions", req, res, m_http_client) ||
|
if (!net_utils::invoke_http_json_remote_command2(m_daemon_address + "/gettransactions", req, res, m_http_client) ||
|
||||||
res.txs_as_hex.empty())
|
(res.txs.empty() && res.txs_as_hex.empty()))
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to get transaction from daemon");
|
fail_msg_writer() << tr("failed to get transaction from daemon");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cryptonote::blobdata tx_data;
|
cryptonote::blobdata tx_data;
|
||||||
if (!string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data))
|
bool ok;
|
||||||
|
if (!res.txs.empty())
|
||||||
|
ok = string_tools::parse_hexstr_to_binbuff(res.txs.front().as_hex, tx_data);
|
||||||
|
else
|
||||||
|
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
|
||||||
|
if (!ok)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to parse transaction from daemon");
|
fail_msg_writer() << tr("failed to parse transaction from daemon");
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user