rpc: send confirmations in get_transactions result

if the wallet does it, it would get a wrong result (possibly even
negative) if its local chain is not synced up to the daemon's yet
This commit is contained in:
moneromooo-monero 2021-04-15 15:29:13 +00:00
parent f6279a633d
commit 4da1112967
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
3 changed files with 19 additions and 5 deletions

View file

@ -1043,6 +1043,7 @@ namespace cryptonote
if (e.in_pool) if (e.in_pool)
{ {
e.block_height = e.block_timestamp = std::numeric_limits<uint64_t>::max(); e.block_height = e.block_timestamp = std::numeric_limits<uint64_t>::max();
e.confirmations = 0;
auto it = per_tx_pool_tx_info.find(tx_hash); auto it = per_tx_pool_tx_info.find(tx_hash);
if (it != per_tx_pool_tx_info.end()) if (it != per_tx_pool_tx_info.end())
{ {
@ -1061,6 +1062,7 @@ namespace cryptonote
else else
{ {
e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash); e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
e.confirmations = m_core.get_current_blockchain_height() - e.block_height;
e.block_timestamp = m_core.get_blockchain_storage().get_db().get_block_timestamp(e.block_height); e.block_timestamp = m_core.get_blockchain_storage().get_db().get_block_timestamp(e.block_height);
e.received_timestamp = 0; e.received_timestamp = 0;
e.double_spend_seen = false; e.double_spend_seen = false;

View file

@ -88,7 +88,7 @@ namespace cryptonote
// advance which version they will stop working with // advance which version they will stop working with
// Don't go over 32767 for any of these // Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 3 #define CORE_RPC_VERSION_MAJOR 3
#define CORE_RPC_VERSION_MINOR 6 #define CORE_RPC_VERSION_MINOR 7
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR) #define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@ -350,6 +350,7 @@ namespace cryptonote
bool in_pool; bool in_pool;
bool double_spend_seen; bool double_spend_seen;
uint64_t block_height; uint64_t block_height;
uint64_t confirmations;
uint64_t block_timestamp; uint64_t block_timestamp;
uint64_t received_timestamp; uint64_t received_timestamp;
std::vector<uint64_t> output_indices; std::vector<uint64_t> output_indices;
@ -367,6 +368,7 @@ namespace cryptonote
if (!this_ref.in_pool) if (!this_ref.in_pool)
{ {
KV_SERIALIZE(block_height) KV_SERIALIZE(block_height)
KV_SERIALIZE(confirmations)
KV_SERIALIZE(block_timestamp) KV_SERIALIZE(block_timestamp)
KV_SERIALIZE(output_indices) KV_SERIALIZE(output_indices)
} }

View file

@ -11515,6 +11515,9 @@ void wallet2::check_tx_key_helper(const cryptonote::transaction &tx, const crypt
void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations) void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations)
{ {
uint32_t rpc_version;
THROW_WALLET_EXCEPTION_IF(!check_connection(&rpc_version), error::wallet_internal_error, "Failed to connect to daemon: " + get_daemon_address());
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));
@ -11559,12 +11562,19 @@ void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_de
in_pool = res.txs.front().in_pool; in_pool = res.txs.front().in_pool;
confirmations = 0; confirmations = 0;
if (!in_pool) if (!in_pool)
{
if (rpc_version < MAKE_CORE_RPC_VERSION(3, 7))
{ {
std::string err; std::string err;
uint64_t bc_height = get_daemon_blockchain_height(err); uint64_t bc_height = get_daemon_blockchain_height(err);
if (err.empty()) if (err.empty() && bc_height > res.txs.front().block_height)
confirmations = bc_height - res.txs.front().block_height; confirmations = bc_height - res.txs.front().block_height;
} }
else
{
confirmations = res.txs.front().confirmations;
}
}
} }
std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message) std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message)