aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorHoria Mihai David <david.horiamihai@gmail.com>2021-01-11 22:20:12 +0100
committerhMihaiDavid <24855110+hMihaiDavid@users.noreply.github.com>2021-02-17 20:25:55 +0100
commit186271e5d1633964a37220e3b6c1aebb4f691fd9 (patch)
treedab728ded4b39ee6f85909c2ba7d21b75525eb63 /src/wallet
parentMerge pull request #7285 (diff)
downloadmonero-186271e5d1633964a37220e3b6c1aebb4f691fd9.tar.xz
monero-wallet-cli: Added command scan_tx
To implement this feature, the wallet2::scan_tx API was implemented.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet2.cpp42
-rw-r--r--src/wallet/wallet2.h2
2 files changed, 44 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index d80335db8..d2bcc04d6 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -30,6 +30,7 @@
#include <numeric>
#include <tuple>
+#include <queue>
#include <boost/format.hpp>
#include <boost/optional/optional.hpp>
#include <boost/algorithm/string/classification.hpp>
@@ -1602,6 +1603,47 @@ std::string wallet2::get_subaddress_label(const cryptonote::subaddress_index& in
return m_subaddress_labels[index.major][index.minor];
}
//----------------------------------------------------------------------------------------------------
+void wallet2::scan_tx(const std::vector<crypto::hash> &txids)
+{
+ // Get the transactions from daemon in batches and add them to a priority queue ordered in chronological order
+ auto cmp_tx_entry = [](const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry& l, const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry& r)
+ { return l.block_height > r.block_height; };
+
+ std::priority_queue<cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry, std::vector<COMMAND_RPC_GET_TRANSACTIONS::entry>, decltype(cmp_tx_entry)> txq(cmp_tx_entry);
+ const size_t SLICE_SIZE = 100; // RESTRICTED_TRANSACTIONS_COUNT as defined in rpc/core_rpc_server.cpp, hardcoded in daemon code
+ for(size_t slice = 0; slice < txids.size(); slice += SLICE_SIZE) {
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
+ req.decode_as_json = false;
+ req.prune = true;
+
+ size_t ntxes = slice + SLICE_SIZE > txids.size() ? txids.size() - slice : SLICE_SIZE;
+ for (size_t i = slice; i < slice + ntxes; ++i)
+ req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txids[i]));
+
+ {
+ const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
+ req.client = get_client_signature();
+ bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, *m_http_client, rpc_timeout);
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to get transaction from daemon");
+ THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error, "Failed to get transaction from daemon");
+ }
+
+ for (auto& tx_info : res.txs)
+ txq.push(tx_info);
+ }
+
+ // Process the transactions in chronologically ascending order
+ while(!txq.empty()) {
+ auto& tx_info = txq.top();
+ cryptonote::transaction tx;
+ crypto::hash tx_hash;
+ THROW_WALLET_EXCEPTION_IF(!get_pruned_tx(tx_info, tx, tx_hash), error::wallet_internal_error, "Failed to get transaction from daemon (2)");
+ process_new_transaction(tx_hash, tx, tx_info.output_indices, tx_info.block_height, 0, tx_info.block_timestamp, false, tx_info.in_pool, tx_info.double_spend_seen, {}, {});
+ txq.pop();
+ }
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::set_subaddress_label(const cryptonote::subaddress_index& index, const std::string &label)
{
THROW_WALLET_EXCEPTION_IF(index.major >= m_subaddress_labels.size(), error::account_index_outofbound);
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 68f03db72..1488c6976 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1264,6 +1264,8 @@ private:
std::string get_spend_proof(const crypto::hash &txid, const std::string &message);
bool check_spend_proof(const crypto::hash &txid, const std::string &message, const std::string &sig_str);
+ void scan_tx(const std::vector<crypto::hash> &txids);
+
/*!
* \brief Generates a proof that proves the reserve of unspent funds
* \param account_minreserve When specified, collect outputs only belonging to the given account and prove the smallest reserve above the given amount