Skip to content

Commit

Permalink
callback functions interface
Browse files Browse the repository at this point in the history
  • Loading branch information
SNeedlewoods committed Nov 18, 2024
1 parent 8738c59 commit 85d3200
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,31 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
}
}

virtual void on_reorg(uint64_t height, uint64_t blocks_detached, size_t transfers_detached) { /* TODO */ }
virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; }
virtual void on_pool_tx_removed(const crypto::hash &txid) { /* TODO */ }
virtual void on_reorg(std::uint64_t height, std::uint64_t blocks_detached, std::size_t transfers_detached)
{
if (m_listener) {
m_listener->onReorg(height, blocks_detached, transfers_detached);
}
}

virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason)
{
if (m_listener) {
auto password = m_listener->onGetPassword(reason);
if (password) {
return boost::make_optional(epee::wipeable_string((*password).data(), (*password).size()));
}
}
return boost::none;
}

virtual void on_pool_tx_removed(const crypto::hash &txid)
{
std::string txid_hex = epee::string_tools::pod_to_hex(txid);
if (m_listener) {
m_listener->onPoolTxRemoved(txid_hex);
}
}

WalletListener * m_listener;
WalletImpl * m_wallet;
Expand Down
15 changes: 15 additions & 0 deletions src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,21 @@ struct WalletListener
* @brief If the listener is created before the wallet this enables to set created wallet object
*/
virtual void onSetWallet(Wallet * wallet) { (void)wallet; };

/**
* @brief called on blockchain reorg
*/
virtual void onReorg(std::uint64_t height, std::uint64_t blocks_detached, std::size_t transfers_detached) = 0;

/**
* @brief called by scan_output() to decrypt keys
*/
virtual optional<std::string> onGetPassword(const char *reason) = 0;

/**
* @brief called when obsolete pool transactions get removed
*/
virtual void onPoolTxRemoved(const std::string &txid) = 0;
};


Expand Down

0 comments on commit 85d3200

Please sign in to comment.