Skip to content

Commit

Permalink
wallet_api: add scanTransactions function
Browse files Browse the repository at this point in the history
  • Loading branch information
selsta committed May 26, 2022
1 parent 97271b7 commit de2f0d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,42 @@ bool WalletImpl::importOutputs(const string &filename)
return true;
}

bool WalletImpl::scanTransactions(const std::vector<std::string> &txids)
{
if (txids.empty())
{
setStatusError(string(tr("Failed to scan transactions: no transaction ids provided.")));
return false;
}

// Parse and dedup args
std::unordered_set<crypto::hash> txids_u;
for (const auto &s : txids)
{
crypto::hash txid;
if (!epee::string_tools::hex_to_pod(s, txid))
{
setStatusError(string(tr("Invalid txid specified: ")) + s);
return false;
}
txids_u.insert(txid);
}
std::vector<crypto::hash> txids_v(txids_u.begin(), txids_u.end());

try
{
m_wallet->scan_tx(txids_v);
}
catch (const std::exception &e)
{
LOG_ERROR("Failed to scan transaction: " << e.what());
setStatusError(string(tr("Failed to scan transaction: ")) + e.what());
return false;
}

return true;
}

void WalletImpl::addSubaddressAccount(const std::string& label)
{
m_wallet->add_subaddress_account(label);
Expand Down
1 change: 1 addition & 0 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class WalletImpl : public Wallet
bool importKeyImages(const std::string &filename) override;
bool exportOutputs(const std::string &filename, bool all = false) override;
bool importOutputs(const std::string &filename) override;
bool scanTransactions(const std::vector<std::string> &txids) override;

virtual void disposeTransaction(PendingTransaction * t) override;
virtual uint64_t estimateTransactionFee(const std::vector<std::pair<std::string, uint64_t>> &destinations,
Expand Down
7 changes: 7 additions & 0 deletions src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,13 @@ struct Wallet
*/
virtual bool importOutputs(const std::string &filename) = 0;

/*!
* \brief scanTransactions - scan a list of transaction ids, this operation may reveal the txids to the remote node and affect your privacy
* \param txids - list of transaction ids
* \return - true on success
*/
virtual bool scanTransactions(const std::vector<std::string> &txids) = 0;

virtual TransactionHistory * history() = 0;
virtual AddressBook * addressBook() = 0;
virtual Subaddress * subaddress() = 0;
Expand Down

0 comments on commit de2f0d0

Please sign in to comment.