diff --git a/README.md b/README.md index 825e59d..2ef5e2c 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,21 @@ string random_primary = wallet_random->get_primary_address(); uint64_t random_height = wallet_random->get_height(); bool random_is_synced = wallet_random->is_synced(); +// receive notifications when funds are received, confirmed, and unlocked +struct : monero_wallet_listener { + void on_output_received(const monero_output_wallet& output) { + cout << "Wallet received funds!" << endl; + uint64_t amount = output.m_amount.get(); + string tx_hash = output.m_tx->m_hash.get(); + bool is_confirmed = output.m_tx->m_is_confirmed.get(); + bool is_locked = dynamic_pointer_cast(output.m_tx)->m_is_locked.get(); + int account_index = output.m_account_index.get(); + int subaddress_index = output.m_subaddress_index.get(); + OUTPUT_RECEIVED = true; + } +} my_listener; +wallet_random->add_listener(my_listener); + // receive notifications when the wallet receives funds struct : monero_wallet_listener { void on_output_received(const monero_output_wallet& output) { diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index da453f2..0430bd1 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -774,6 +774,7 @@ namespace monero { // create library tx std::shared_ptr tx = std::static_pointer_cast(monero_utils::cn_tx_to_tx(cn_tx, true)); tx->m_hash = epee::string_tools::pod_to_hex(txid); + tx->m_is_confirmed = false; tx->m_is_locked = true; std::shared_ptr output = std::make_shared(); tx->m_outputs.push_back(output); @@ -810,8 +811,9 @@ namespace monero { block->m_txs.push_back(tx); tx->m_block = block; tx->m_hash = epee::string_tools::pod_to_hex(txid); - tx->m_unlock_height = unlock_height; + tx->m_is_confirmed = true;\ tx->m_is_locked = true; + tx->m_unlock_height = unlock_height; std::shared_ptr output = std::make_shared(); tx->m_outputs.push_back(output); output->m_tx = tx; @@ -849,6 +851,8 @@ namespace monero { block->m_txs.push_back(tx); tx->m_block = block; tx->m_hash = epee::string_tools::pod_to_hex(txid); + tx->m_is_confirmed = true; + tx->m_is_locked = true; std::shared_ptr output = std::make_shared(); tx->m_inputs.push_back(output); output->m_tx = tx; diff --git a/test/sample_code.cpp b/test/sample_code.cpp index 03fa8c0..6b4821d 100644 --- a/test/sample_code.cpp +++ b/test/sample_code.cpp @@ -97,7 +97,10 @@ int main(int argc, const char* argv[]) { struct : monero_wallet_listener { void on_output_received(const monero_output_wallet& output) { cout << "Wallet received funds!" << endl; + uint64_t amount = output.m_amount.get(); string tx_hash = output.m_tx->m_hash.get(); + bool is_confirmed = output.m_tx->m_is_confirmed.get(); + bool is_locked = static_pointer_cast(output.m_tx)->m_is_locked.get(); int account_index = output.m_account_index.get(); int subaddress_index = output.m_subaddress_index.get(); OUTPUT_RECEIVED = true;