wallet2: add on_reorg callback

This commit is contained in:
Crypto City 2019-11-17 21:12:46 +00:00 committed by wowario
parent 1a86d67ef4
commit bb88fdfcdd
No known key found for this signature in database
GPG Key ID: 793504B449C69220
2 changed files with 5 additions and 1 deletions

View File

@ -3851,7 +3851,7 @@ void wallet2::detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, ui
transfers_detached = std::distance(it, m_transfers.end()); transfers_detached = std::distance(it, m_transfers.end());
m_transfers.erase(it, m_transfers.end()); m_transfers.erase(it, m_transfers.end());
size_t blocks_detached = m_blockchain.size() - height; const uint64_t blocks_detached = m_blockchain.size() - height;
m_blockchain.crop(height); m_blockchain.crop(height);
for (auto it = m_payments.begin(); it != m_payments.end(); ) for (auto it = m_payments.begin(); it != m_payments.end(); )
@ -3870,6 +3870,9 @@ void wallet2::detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, ui
++it; ++it;
} }
if (m_callback)
m_callback->on_reorg(height, blocks_detached, transfers_detached);
LOG_PRINT_L0("Detached blockchain on height " << height << ", transfers detached " << transfers_detached << ", blocks detached " << blocks_detached); LOG_PRINT_L0("Detached blockchain on height " << height << ", transfers detached " << transfers_detached << ", blocks detached " << blocks_detached);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------

View File

@ -138,6 +138,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, 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_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) {}