From 52bcbfb482a52520430e3d089afe9dd1a4b3f530 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 28 May 2019 16:42:59 -0400 Subject: [PATCH] implemented block notifications in wallet listener --- src/wallet/MoneroWallet.cpp | 45 ++++++++++++++++++++----------------- src/wallet/MoneroWallet.h | 7 +++--- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index ee258dd..9045fc0 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -7,6 +7,30 @@ using namespace cryptonote; +/** + * Adapts wallet2 notifications to a public listener. + */ +struct Wallet2ListenerAdapter : public tools::i_wallet2_callback { + + Wallet2ListenerAdapter(MoneroWalletListener* listener) { + this->listener = listener; + } + + ~Wallet2ListenerAdapter() { + + } + + virtual void on_new_block(uint64_t height, const cryptonote::block& cnBlock) { + MoneroBlock block; + block.height = height; + listener->onNewBlock(block); + } + + MoneroWalletListener* listener; +}; + +// ------------------------------- WALLET METHODS ----------------------------- + bool MoneroWallet::walletExists(const string& path) { cout << "walletExists(" << path << ")" << endl; bool keyFileExists; @@ -128,27 +152,6 @@ uint64_t MoneroWallet::getRestoreHeight() const { return wallet2->get_refresh_from_block_height(); } -/** - * Adapts wallet2 notifications to a public listener. - */ -struct Wallet2ListenerAdapter : public tools::i_wallet2_callback { - - Wallet2ListenerAdapter(MoneroWalletListener* listener) { - this->listener = listener; - } - - ~Wallet2ListenerAdapter() { - - } - - virtual void on_new_block(uint64_t height, const cryptonote::block& block) { - cout << "Wallet2ListenerAdapter.on_new_block()" << endl; - throw runtime_error("Not implemented"); - } - - MoneroWalletListener* listener; -}; - void MoneroWallet::setListener(MoneroWalletListener* listener) { cout << "setListener()" << endl; this->listener = listener; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 3579efc..118be35 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -23,15 +23,14 @@ namespace monero { }; /** - * Models a result of syncing a wallet. + * Models a Monero block header. */ struct MoneroBlockHeader { uint64_t height; - MoneroBlockHeader() {} }; /** - * Models a result of syncing a wallet. + * Models a Monero block. */ struct MoneroBlock : public MoneroBlockHeader { // TODO @@ -69,6 +68,7 @@ namespace monero { * Receives progress notifications as a wallet is synchronized. */ class MoneroSyncListener { + public: /** * Invoked when sync progress is made. @@ -86,6 +86,7 @@ namespace monero { * Receives notifications as a wallet is updated. */ class MoneroWalletListener : public MoneroSyncListener { + public: /** * Invoked when a new block is processed.