mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
wallet2+API: use separate callbacks for lightwallets
This commit is contained in:
parent
d92618675b
commit
97c2e449ce
@ -155,6 +155,38 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
||||
// TODO;
|
||||
}
|
||||
|
||||
// Light wallet callbacks
|
||||
virtual void on_lw_new_block(uint64_t height)
|
||||
{
|
||||
if (m_listener) {
|
||||
m_listener->newBlock(height);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
|
||||
{
|
||||
if (m_listener) {
|
||||
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
||||
m_listener->moneyReceived(tx_hash, amount);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
|
||||
{
|
||||
if (m_listener) {
|
||||
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
||||
m_listener->unconfirmedMoneyReceived(tx_hash, amount);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount)
|
||||
{
|
||||
if (m_listener) {
|
||||
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
|
||||
m_listener->moneySpent(tx_hash, amount);
|
||||
}
|
||||
}
|
||||
|
||||
WalletListener * m_listener;
|
||||
WalletImpl * m_wallet;
|
||||
};
|
||||
|
@ -1857,8 +1857,7 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re
|
||||
if(m_light_wallet_blockchain_height != prev_height)
|
||||
{
|
||||
MDEBUG("new block since last time!");
|
||||
cryptonote::block dummy;
|
||||
m_callback->on_new_block(m_light_wallet_blockchain_height - 1, dummy);
|
||||
m_callback->on_lw_new_block(m_light_wallet_blockchain_height - 1);
|
||||
}
|
||||
m_light_wallet_connected = true;
|
||||
MDEBUG("lw scanned block height: " << m_light_wallet_scanned_block_height);
|
||||
@ -5119,16 +5118,14 @@ void wallet2::light_wallet_get_address_txs()
|
||||
pool_txs.push_back(tx_hash);
|
||||
m_unconfirmed_payments.emplace(tx_hash, payment);
|
||||
if (0 != m_callback) {
|
||||
cryptonote::transaction dummy_tx;
|
||||
m_callback->on_unconfirmed_money_received(t.height, payment.m_tx_hash, dummy_tx, payment.m_amount);
|
||||
m_callback->on_lw_unconfirmed_money_received(t.height, payment.m_tx_hash, payment.m_amount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (std::find(payments_txs.begin(), payments_txs.end(), tx_hash) == payments_txs.end()) {
|
||||
m_payments.emplace(tx_hash, payment);
|
||||
if (0 != m_callback) {
|
||||
cryptonote::transaction dummy_tx;
|
||||
m_callback->on_money_received(t.height, payment.m_tx_hash, dummy_tx, payment.m_amount);
|
||||
m_callback->on_lw_money_received(t.height, payment.m_tx_hash, payment.m_amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5178,7 +5175,7 @@ void wallet2::light_wallet_get_address_txs()
|
||||
}
|
||||
if (0 != m_callback)
|
||||
{
|
||||
m_callback->on_money_spent(t.height, tx_hash, dummy_tx, amount_sent, dummy_tx);
|
||||
m_callback->on_lw_money_spent(t.height, tx_hash, amount_sent);
|
||||
}
|
||||
}
|
||||
// If not new - check the amount and update if necessary.
|
||||
|
@ -71,11 +71,18 @@ namespace tools
|
||||
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) {}
|
||||
// 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) {}
|
||||
// Common callbacks
|
||||
virtual void on_pool_tx_removed(const crypto::hash &txid) {}
|
||||
virtual ~i_wallet2_callback() {}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user