diff --git a/wallet/wallet.c b/wallet/wallet.c index 423440938..21ee7e09c 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -6377,3 +6377,25 @@ struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx, return anchors; } + +struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet, + u64 liststart, const u32 *listlimit) +{ + struct db_stmt *stmt; + struct issued_address_type *addresseslist = tal_arr(ctx, struct issued_address_type, 0); + stmt = db_prepare_v2(wallet->db, SQL("SELECT keyidx, addrtype FROM addresses WHERE keyidx >= ? ORDER BY keyidx LIMIT ?;")); + db_bind_u64(stmt, liststart); + if (listlimit) + db_bind_int(stmt, *listlimit); + else + db_bind_int(stmt, INT_MAX); + db_query_prepared(stmt); + while(db_step(stmt)) { + struct issued_address_type a; + a.keyidx = db_col_u64(stmt, "keyidx"); + a.addrtype = wallet_addrtype_in_db(db_col_int(stmt, "addrtype")); + tal_arr_expand(&addresseslist, a); + } + tal_free(stmt); + return addresseslist; +} diff --git a/wallet/wallet.h b/wallet/wallet.h index 1c0062fee..c6f1bbe98 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -1798,4 +1798,23 @@ void wallet_remove_local_anchors(struct wallet *w, struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx, struct wallet *w, u64 channel_id); + +/* Get the addresses addrtype */ +struct issued_address_type { + u64 keyidx; + enum addrtype addrtype; +}; + +/** + * wallet_list_addresses: get the list of addresses with addrtype + * + * @ctx: tal context for returned array + * @wallet: the wallet + * @liststart: first index to return (0 == all). + * @listlimit: limit on number of entries to return (NULL == no limit). + * + * Returns NULL if none, otherwise list of addresses with addrtype. + */ +struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet, + u64 liststart, const u32 *listlimit); #endif /* LIGHTNING_WALLET_WALLET_H */