add bool last param to newBlock callback
Some checks failed
ci/gh-actions/cli / build-macos (push) Has been cancelled
ci/gh-actions/cli / build-windows (push) Has been cancelled
ci/gh-actions/cli / build-ubuntu (ubuntu-20.04) (push) Has been cancelled
ci/gh-actions/cli / build-ubuntu (ubuntu-22.04) (push) Has been cancelled
ci/gh-actions/cli / libwallet-ubuntu (push) Has been cancelled
ci/gh-actions/cli / source-archive (push) Has been cancelled
ci/gh-actions/depends / Cross-Mac aarch64 (push) Has been cancelled
ci/gh-actions/depends / ARM v8 (push) Has been cancelled
ci/gh-actions/depends / ARM v7 (push) Has been cancelled
ci/gh-actions/depends / i686 Linux (push) Has been cancelled
ci/gh-actions/depends / i686 Win (push) Has been cancelled
ci/gh-actions/depends / RISCV 64bit (push) Has been cancelled
ci/gh-actions/depends / Cross-Mac x86_64 (push) Has been cancelled
ci/gh-actions/depends / x86_64 Freebsd (push) Has been cancelled
ci/gh-actions/depends / x86_64 Linux (push) Has been cancelled
ci/gh-actions/depends / Win64 (push) Has been cancelled
ci/gh-actions/cli / test-ubuntu (push) Has been cancelled

This commit is contained in:
- 2024-12-28 14:14:54 +01:00
parent 64b54a40b9
commit 6e83819921
7 changed files with 21 additions and 17 deletions

View file

@ -5719,7 +5719,7 @@ bool simple_wallet::save_bc(const std::vector<std::string>& args)
return true; 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) if (m_locked)
return; return;

View file

@ -343,7 +343,7 @@ namespace cryptonote
bool check_daemon_rpc_prices(const std::string &daemon_url, uint32_t &actual_cph, uint32_t &claimed_cph); bool check_daemon_rpc_prices(const std::string &daemon_url, uint32_t &actual_cph, uint32_t &claimed_cph);
//----------------- i_wallet2_callback --------------------- //----------------- 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_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_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_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);

View file

@ -142,7 +142,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
return m_listener; 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 // 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 // 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) { if(height >= m_wallet->m_wallet->get_refresh_from_block_height() || height % 1000 == 0) {
// LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height); // LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
if (m_listener) { 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 // 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) { if (m_listener) {
m_listener->newBlock(height); m_listener->newBlock(height, last);
} }
} }

View file

@ -400,8 +400,9 @@ struct WalletListener
/** /**
* @brief newBlock - called when new block received * @brief newBlock - called when new block received
* @param height - block height * @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; * @brief updated - generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet;

View file

@ -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); 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> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, 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> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache)
{ {
THROW_WALLET_EXCEPTION_IF(bche.txs.size() + 1 != parsed_block.o_indices.indices.size(), error::wallet_internal_error, 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()) + "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); m_blockchain.push_back(bl_id);
if (0 != m_callback) 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<crypto::hash>& ids, uint64_t granularity) const void wallet2::get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity) const
@ -3335,9 +3335,11 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
const crypto::hash &bl_id = parsed_blocks[i].hash; const crypto::hash &bl_id = parsed_blocks[i].hash;
const cryptonote::block &bl = parsed_blocks[i].block; const cryptonote::block &bl = parsed_blocks[i].block;
bool last = i == blocks.size() - 1;
if(current_index >= m_blockchain.size()) if(current_index >= 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; ++blocks_added;
} }
else if(bl_id != m_blockchain[current_index]) else if(bl_id != m_blockchain[current_index])
@ -3354,7 +3356,7 @@ void wallet2::process_parsed_blocks(uint64_t start_height, const std::vector<cry
std::to_string(reorg_depth)); std::to_string(reorg_depth));
handle_reorg(current_index, output_tracker_cache); handle_reorg(current_index, output_tracker_cache);
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);
} }
else else
{ {
@ -3901,7 +3903,7 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
if (0 != m_callback) if (0 != m_callback)
{ // FIXME: this isn't right, but simplewallet just logs that we got a block. { // FIXME: this isn't right, but simplewallet just logs that we got a block.
cryptonote::block dummy; cryptonote::block dummy;
m_callback->on_new_block(current_index, dummy); m_callback->on_new_block(current_index, false, dummy);
} }
} }
else if(bl_id != m_blockchain[current_index]) 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) if(m_light_wallet_blockchain_height != prev_height)
{ {
MDEBUG("new block since last time!"); 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; m_light_wallet_connected = true;
MDEBUG("lw scanned block height: " << m_light_wallet_scanned_block_height); MDEBUG("lw scanned block height: " << m_light_wallet_scanned_block_height);

View file

@ -139,7 +139,7 @@ private:
{ {
public: public:
// Full wallet callbacks // 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_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_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_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 void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; } virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; }
// Light wallet callbacks // 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_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_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) {} 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<crypto::chacha_key>& keys_to_encrypt); bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password, boost::optional<crypto::chacha_key>& keys_to_encrypt);
void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &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<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL, bool ignore_callbacks = false); void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &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<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL, bool ignore_callbacks = false);
bool should_skip_block(const cryptonote::block &b, uint64_t height) const; 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> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, 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> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
detached_blockchain_data detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL); detached_blockchain_data detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
void handle_reorg(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL); void handle_reorg(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const; void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const;

View file

@ -847,7 +847,7 @@ struct MyWalletListener : public Monero::WalletListener
// cv_receive.notify_one(); // cv_receive.notify_one();
} }
virtual void newBlock(uint64_t height) virtual void newBlock(uint64_t height, bool last)
{ {
// std::cout << "wallet: " << wallet->mainAddress() // std::cout << "wallet: " << wallet->mainAddress()
// <<", new block received, blockHeight: " << height << std::endl; // <<", new block received, blockHeight: " << height << std::endl;