From 64cba97d1ae12e0022a7575b9775446a0dc73f3b Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 28 May 2019 14:57:53 -0400 Subject: [PATCH] implemented sync(startHeight) --- src/wallet/MoneroWallet.cpp | 9 ++-- src/wallet/MoneroWallet.h | 90 ++++++++++++++++++++++++------------- todo.txt | 3 +- 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index e979af6..e2dc404 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -131,11 +131,6 @@ uint64_t MoneroWallet::getRestoreHeight() const { MoneroSyncResult MoneroWallet::sync() { cout << "sync()" << endl; throw runtime_error("Not implemented"); - // tools::wallet2* wallet = getHandle(env, instance, "walletHandle"); - // uint64_t blocksFetched; - // bool receivedMoney; - // wallet->refresh(wallet->is_trusted_daemon(), startHeight, blocksFetched, receivedMoney, true); - // cout << "Done refreshing. Blocks fetched: " << blocksFetched << ", received money: " << receivedMoney << endl; } MoneroSyncResult MoneroWallet::sync(MoneroSyncListener& listener) { @@ -145,7 +140,9 @@ MoneroSyncResult MoneroWallet::sync(MoneroSyncListener& listener) { MoneroSyncResult MoneroWallet::sync(uint64_t startHeight) { cout << "sync(startHeight)" << endl; - throw runtime_error("Not implemented"); + MoneroSyncResult result; + wallet2->refresh(wallet2->is_trusted_daemon(), startHeight, result.numBlocksFetched, result.receivedMoney, true); + return result; } MoneroSyncResult MoneroWallet::sync(uint64_t startHeight, MoneroSyncListener& listener) { diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index be6f47d..ecdf625 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -10,6 +10,8 @@ using namespace crypto; */ namespace monero { + // ----------------------------------- MODEL -------------------------------- + /** * Models a result of syncing a wallet. */ @@ -19,41 +21,56 @@ namespace monero { MoneroSyncResult() {} MoneroSyncResult(const uint64_t numBlocksFetched, const bool receivedMoney) : numBlocksFetched(numBlocksFetched), receivedMoney(receivedMoney) {} }; -// -// class i_wallet2_callback -// { -// public: -// // Full wallet callbacks -// virtual void on_new_block(uint64_t height, const cryptonote::block& block) {} -// virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {} -// virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {} -// virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {} -// virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {} -// virtual boost::optional on_get_password(const char *reason) { return boost::none; } -// // Light wallet callbacks -// virtual void on_lw_new_block(uint64_t height) {} -// virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} -// virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} -// virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) {} -// // Device callbacks -// virtual void on_device_button_request(uint64_t code) {} -// virtual void on_device_button_pressed() {} -// virtual boost::optional on_device_pin_request() { return boost::none; } -// virtual boost::optional on_device_passphrase_request(bool on_device) { return boost::none; } -// virtual void on_device_progress(const hw::device_progress& event) {}; -// // Common callbacks -// virtual void on_pool_tx_removed(const crypto::hash &txid) {} -// virtual ~i_wallet2_callback() {} -// }; + + /** + * Models a result of syncing a wallet. + */ + struct MoneroBlockHeader { + // TODO + }; + + /** + * Models a result of syncing a wallet. + */ + struct MoneroBlock : public MoneroBlockHeader { + // TODO + }; + + // --------------------------------- LISTENERS ------------------------------ + + // class i_wallet2_callback + // { + // public: + // // Full wallet callbacks + // virtual void on_new_block(uint64_t height, const cryptonote::block& block) {} + // virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {} + // virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {} + // virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {} + // virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {} + // virtual boost::optional on_get_password(const char *reason) { return boost::none; } + // // Light wallet callbacks + // virtual void on_lw_new_block(uint64_t height) {} + // virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} + // virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {} + // virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) {} + // // Device callbacks + // virtual void on_device_button_request(uint64_t code) {} + // virtual void on_device_button_pressed() {} + // virtual boost::optional on_device_pin_request() { return boost::none; } + // virtual boost::optional on_device_passphrase_request(bool on_device) { return boost::none; } + // virtual void on_device_progress(const hw::device_progress& event) {}; + // // Common callbacks + // virtual void on_pool_tx_removed(const crypto::hash &txid) {} + // virtual ~i_wallet2_callback() {} + // }; /** * Receives progress notifications as a wallet is synchronized. */ class MoneroSyncListener { - public: /** - * Invoked with info as sync progress is made. + * Invoked when sync progress is made. * * @param startHeight is the starting height of the sync request * @param numBlocksDone is the number of blocks synced @@ -64,13 +81,26 @@ namespace monero { virtual void onSyncProgress(uint64_t startHeight, uint64_t numBlocksDone, uint64_t numBlocksTotal, double percentDone, string message); }; + /** + * Receives notifications as a wallet is updated. + */ + class MoneroWalletListener : public MoneroSyncListener { + + /** + * Invoked when a new block is processed. + * + * @param block is the newly processed block + */ + virtual void onNewBlock(MoneroBlock& block); + }; + + // ---------------------------- WALLET INTERFACE ---------------------------- + /** * Monero wallet interface. */ class MoneroWallet { - // --------------------------------- PUBLIC -------------------------------- - public: /** diff --git a/todo.txt b/todo.txt index f75cf5a..acc70f8 100644 --- a/todo.txt +++ b/todo.txt @@ -1,2 +1,3 @@ DaemonConnection is its own object -rename external-libs/monero to monero-core for clarity \ No newline at end of file +rename external-libs/monero to monero-core for clarity +onSyncProgress(startHeight, currentHeight, endHeight, percentDone, message)? \ No newline at end of file