diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index a1bb3d5..56146bd 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -698,11 +698,6 @@ namespace monero { virtual void on_new_block(uint64_t height, const cryptonote::block& cnBlock) { - // // convert cryptonote block to library model - // shared_ptr block = MoneroUtils::cnBlockToBlock(cnBlock); - // block->height = height; - // listener->onNewBlock(*block); - // notify listener of block if (listener != boost::none) listener->onNewBlock(height); @@ -716,14 +711,45 @@ namespace monero { } } - 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, uint64_t unlock_time) { - //MTRACE("Wallet2Listener::on_money_received()"); - //throw runtime_error("Not implemented"); + virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cnTx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time) { + MTRACE("Wallet2Listener::on_money_received()"); + if (listener == boost::none) return; + + // create native library tx + shared_ptr block = make_shared(); + block->height = height; + shared_ptr tx = make_shared(); + block->txs.push_back(tx); + tx->block = block; + tx->id = epee::string_tools::pod_to_hex(txid); + shared_ptr transfer = make_shared(); + tx->incomingTransfers.push_back(transfer); + transfer->tx = tx; + transfer->amount = amount; + + // notify listener of transfer + listener->onIncomingTransfer(*transfer); } 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) { -// MTRACE("Wallet2Listener::on_money_spent()") -// // TODO; + MTRACE("Wallet2Listener::on_money_spent()"); + + // create native library tx + shared_ptr block = make_shared(); + block->height = height; + shared_ptr tx = make_shared(); + block->txs.push_back(tx); + tx->block = block; + tx->id = epee::string_tools::pod_to_hex(txid); + shared_ptr transfer = make_shared(); + tx->outgoingTransfer = transfer; + transfer->tx = tx; + transfer->amount = amount; + + // notify listener of transfer + listener->onOutgoingTransfer(*transfer); + + // TODO **: to notify or not to notify? // std::string tx_hash = epee::string_tools::pod_to_hex(txid); // LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height // << ", tx: " << tx_hash diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index aef88fa..26a8b5a 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -127,6 +127,20 @@ namespace monero { * @param block is the newly processed block */ virtual void onNewBlock(uint64_t height) {}; + + /** + * Invoked when the wallet receives an incoming transfer. + * + * @param transfer is the incoming transfer to the wallet + */ + virtual void onIncomingTransfer(const MoneroIncomingTransfer& transfer) {}; + + /** + * Invoked when the wallet sends an outgoing transfer. + * + * @param transfer is the outgoing transfer from the wallet + */ + virtual void onOutgoingTransfer(const MoneroOutgoingTransfer& transfer) {}; }; // forward declaration of internal wallet2 listener