update sample code with outputs is_confirmed, is_locked

set m_is_confirmed, m_is_unlocked in output notifications
This commit is contained in:
woodser
2021-01-11 21:37:28 -05:00
parent e313fe52d9
commit f0d5bd5e4b
3 changed files with 23 additions and 1 deletions
+15
View File
@@ -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<monero_tx_wallet>(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) {
+5 -1
View File
@@ -774,6 +774,7 @@ namespace monero {
// create library tx
std::shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(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<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
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<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
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<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
tx->m_inputs.push_back(output);
output->m_tx = tx;
+3
View File
@@ -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<monero_tx_wallet>(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;