diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 40be0230c..769debb87 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -5719,7 +5719,7 @@ bool simple_wallet::save_bc(const std::vector& args) return true; } //---------------------------------------------------------------------------------------------------- -void simple_wallet::on_new_block(uint64_t height, const cryptonote::block& block) +void simple_wallet::on_new_block(uint64_t height, bool last, const cryptonote::block& block) { if (m_locked) return; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 652708f5a..69add638e 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -343,7 +343,7 @@ namespace cryptonote bool check_daemon_rpc_prices(const std::string &daemon_url, uint32_t &actual_cph, uint32_t &claimed_cph); //----------------- i_wallet2_callback --------------------- - virtual void on_new_block(uint64_t height, const cryptonote::block& block); + virtual void on_new_block(uint64_t height, bool last, const cryptonote::block& block); virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, uint64_t burnt, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time); 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); diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 5ffc6b378..01c4e36d8 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -142,7 +142,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback return m_listener; } - virtual void on_new_block(uint64_t height, const cryptonote::block& block) + virtual void on_new_block(uint64_t height, bool last, const cryptonote::block& block) { // Don't flood the GUI with signals. On fast refresh - send signal every 1000th block // get_refresh_from_block_height() returns the blockheight from when the wallet was @@ -150,7 +150,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback if(height >= m_wallet->m_wallet->get_refresh_from_block_height() || height % 1000 == 0) { // LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); if (m_listener) { - m_listener->newBlock(height); + m_listener->newBlock(height, last); } } } @@ -211,10 +211,10 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback } // Light wallet callbacks - virtual void on_lw_new_block(uint64_t height) + virtual void on_lw_new_block(uint64_t height, bool last) { if (m_listener) { - m_listener->newBlock(height); + m_listener->newBlock(height, last); } } diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 225c79fa5..cb63bdf50 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -400,8 +400,9 @@ struct WalletListener /** * @brief newBlock - called when new block received * @param height - block height + * @param last - true if the block is the last block in the batch */ - virtual void newBlock(uint64_t height) = 0; + virtual void newBlock(uint64_t height, bool last) = 0; /** * @brief updated - generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c313b2c13..710435380 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2941,7 +2941,7 @@ bool wallet2::should_skip_block(const cryptonote::block &b, uint64_t height) con return !(b.timestamp + 60*60*24 > m_account.get_createtime() && height >= m_refresh_from_block_height && height >= m_skip_to_height); } //---------------------------------------------------------------------------------------------------- -void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, const std::vector &tx_cache_data, size_t tx_cache_data_offset, std::map, size_t> *output_tracker_cache) +void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, bool last, const std::vector &tx_cache_data, size_t tx_cache_data_offset, std::map, size_t> *output_tracker_cache) { THROW_WALLET_EXCEPTION_IF(bche.txs.size() + 1 != parsed_block.o_indices.indices.size(), error::wallet_internal_error, "block transactions=" + std::to_string(bche.txs.size()) + @@ -2976,7 +2976,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry m_blockchain.push_back(bl_id); if (0 != m_callback) - m_callback->on_new_block(height, b); + m_callback->on_new_block(height, last, b); } //---------------------------------------------------------------------------------------------------- void wallet2::get_short_chain_history(std::list& ids, uint64_t granularity) const @@ -3335,9 +3335,11 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector= m_blockchain.size()) { - process_new_blockchain_entry(bl, blocks[i], parsed_blocks[i], bl_id, current_index, tx_cache_data, tx_cache_data_offset, output_tracker_cache); + process_new_blockchain_entry(bl, blocks[i], parsed_blocks[i], bl_id, current_index, last, tx_cache_data, tx_cache_data_offset, output_tracker_cache); ++blocks_added; } else if(bl_id != m_blockchain[current_index]) @@ -3354,7 +3356,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vectoron_new_block(current_index, dummy); + m_callback->on_new_block(current_index, false, dummy); } } else if(bl_id != m_blockchain[current_index]) @@ -3996,7 +3998,8 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo if(m_light_wallet_blockchain_height != prev_height) { MDEBUG("new block since last time!"); - m_callback->on_lw_new_block(m_light_wallet_blockchain_height - 1); + // this fork does not support light wallets, so `last` param is just set to false + m_callback->on_lw_new_block(m_light_wallet_blockchain_height - 1, false); } m_light_wallet_connected = true; MDEBUG("lw scanned block height: " << m_light_wallet_scanned_block_height); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ee5f7bfd9..9460950c5 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -139,7 +139,7 @@ private: { public: // Full wallet callbacks - virtual void on_new_block(uint64_t height, const cryptonote::block& block) {} + virtual void on_new_block(uint64_t height, bool last, const cryptonote::block& block) {} virtual void on_reorg(uint64_t height, uint64_t blocks_detached, size_t transfers_detached) {} virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, uint64_t burnt, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) {} 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) {} @@ -147,7 +147,7 @@ private: 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_new_block(uint64_t height, bool last) {} 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) {} @@ -1769,7 +1769,7 @@ private: bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password, boost::optional& keys_to_encrypt); void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector &o_indices, uint64_t height, uint8_t block_version, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data, std::map, size_t> *output_tracker_cache = NULL, bool ignore_callbacks = false); bool should_skip_block(const cryptonote::block &b, uint64_t height) const; - void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, const std::vector &tx_cache_data, size_t tx_cache_data_offset, std::map, size_t> *output_tracker_cache = NULL); + void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, bool last, const std::vector &tx_cache_data, size_t tx_cache_data_offset, std::map, size_t> *output_tracker_cache = NULL); detached_blockchain_data detach_blockchain(uint64_t height, std::map, size_t> *output_tracker_cache = NULL); void handle_reorg(uint64_t height, std::map, size_t> *output_tracker_cache = NULL); void get_short_chain_history(std::list& ids, uint64_t granularity = 1) const; diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index 806f8afc2..7a16c661f 100644 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -847,7 +847,7 @@ struct MyWalletListener : public Monero::WalletListener // cv_receive.notify_one(); } - virtual void newBlock(uint64_t height) + virtual void newBlock(uint64_t height, bool last) { // std::cout << "wallet: " << wallet->mainAddress() // <<", new block received, blockHeight: " << height << std::endl;