diff --git a/src/cli/spvnode.c b/src/cli/spvnode.c index fa70e3d6c..57298020c 100644 --- a/src/cli/spvnode.c +++ b/src/cli/spvnode.c @@ -473,28 +473,37 @@ int main(int argc, char* argv[]) { #if WITH_WALLET dogecoin_ecc_start(); if (address != NULL) { - int res = dogecoin_register_watch_address_with_node(address); - printf("registered: %d %s\n", res, address); - uint64_t amount = dogecoin_get_balance(address); - if (amount > 0) { - char* amount_str = dogecoin_get_balance_str(address); - printf("amount: %s\n", amount_str); - unsigned int utxo_count = dogecoin_get_utxos_length(address); - if (utxo_count) { - printf("utxo count: %d\n", utxo_count); - unsigned int i = 1; - for (; i <= utxo_count; i++) { - printf("txid: %s\n", dogecoin_get_utxo_txid_str(address, i)); - printf("vout: %d\n", dogecoin_get_utxo_vout(address, i)); - char* utxo_amount_str = dogecoin_get_utxo_amount(address, i); - printf("amount: %s\n", utxo_amount_str); - dogecoin_free(utxo_amount_str); + char delim[] = " "; + // copy address into a new string, strtok modifies the string + char* address_copy = strdup(address); + char *ptr; + char* temp_address_copy = address_copy; + + while((ptr = strtok_r(temp_address_copy, delim, &temp_address_copy))) { + int res = dogecoin_register_watch_address_with_node(ptr); + printf("registered: %d %s\n", res, ptr); + uint64_t amount = dogecoin_get_balance(ptr); + if (amount > 0) { + char* amount_str = dogecoin_get_balance_str(ptr); + printf("amount: %s\n", amount_str); + unsigned int utxo_count = dogecoin_get_utxos_length(ptr); + if (utxo_count) { + printf("utxo count: %d\n", utxo_count); + unsigned int i = 1; + for (; i <= utxo_count; i++) { + printf("txid: %s\n", dogecoin_get_utxo_txid_str(ptr, i)); + printf("vout: %d\n", dogecoin_get_utxo_vout(ptr, i)); + char* utxo_amount_str = dogecoin_get_utxo_amount(ptr, i); + printf("amount: %s\n", utxo_amount_str); + dogecoin_free(utxo_amount_str); + } } + dogecoin_free(amount_str); } - dogecoin_free(amount_str); + res = dogecoin_unregister_watch_address_with_node(ptr); + printf("unregistered: %s\n", res ? "true" : "false"); } - res = dogecoin_unregister_watch_address_with_node(address); - printf("unregistered: %s\n", res ? "true" : "false"); + dogecoin_free(address_copy); } dogecoin_ecc_stop(); #endif diff --git a/src/wallet.c b/src/wallet.c index acfd82e35..43b81dba5 100644 --- a/src/wallet.c +++ b/src/wallet.c @@ -1582,6 +1582,7 @@ int dogecoin_unregister_watch_address_with_node(char* address) { dogecoin_p2pkh_addr_from_hash160(waddr->pubkeyhash, wallet->chain, p2pkh_check, P2PKHLEN); if (memcmp(record->str, buf, record->len)==0) { found = 1; + dogecoin_wallet_addr_free(waddr); } else { const char* addr_match = find_needle(ptr, strlen(ptr), p2pkh_check, P2PKHLEN); if (!addr_match) { @@ -1590,7 +1591,6 @@ int dogecoin_unregister_watch_address_with_node(char* address) { dogecoin_wallet_addr_free(waddr); } } - if (found) dogecoin_wallet_addr_free(waddr); free(buf); } else if (rectype == WALLET_DB_REC_TYPE_TX) { unsigned char* buf = dogecoin_uchar_vla(reclen); @@ -1613,6 +1613,7 @@ int dogecoin_unregister_watch_address_with_node(char* address) { goto copy; } } + dogecoin_free(buf); copy: dogecoin_wallet_scrape_utxos(wallet_new, wtx); dogecoin_wallet_add_wtx_move(wallet_new, wtx); // hands memory management over to the binary tree @@ -1621,6 +1622,10 @@ int dogecoin_unregister_watch_address_with_node(char* address) { } } + if (!wallet_new->waddr_vector->len) { + dogecoin_wallet_next_addr(wallet_new); + } + cstr_free(record, true); dogecoin_wallet_flush(wallet); dogecoin_wallet_flush(wallet_new);