aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaquee <jaquee.monero@gmail.com>2017-08-05 17:01:50 +0200
committerJaquee <jaquee.monero@gmail.com>2017-10-15 17:58:28 +0200
commit97c2e449ce97be1150f088fd0ec83213cf43a7f9 (patch)
tree146f7b78e3c78f687091f912581a8e29b0f7b249
parentwalletAPI: correct confirmations in txHistory for unsynced wallets (diff)
downloadmonero-97c2e449ce97be1150f088fd0ec83213cf43a7f9.tar.xz
wallet2+API: use separate callbacks for lightwallets
-rw-r--r--src/wallet/api/wallet.cpp32
-rw-r--r--src/wallet/wallet2.cpp11
-rw-r--r--src/wallet/wallet2.h7
3 files changed, 43 insertions, 7 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 1eba791cf..db7e60cd7 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -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;
};
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 4d3445e94..b0ce28b9b 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -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.
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index e8a30dba9..6cc8ec7c4 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -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() {}
};