Skip to content

Commit af2f960

Browse files
ShahanaFarooquirustyrussell
authored andcommitted
wallet: list addresses query
1 parent bb25298 commit af2f960

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

wallet/wallet.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6377,3 +6377,25 @@ struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx,
63776377

63786378
return anchors;
63796379
}
6380+
6381+
struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet,
6382+
u64 liststart, const u32 *listlimit)
6383+
{
6384+
struct db_stmt *stmt;
6385+
struct issued_address_type *addresseslist = tal_arr(ctx, struct issued_address_type, 0);
6386+
stmt = db_prepare_v2(wallet->db, SQL("SELECT keyidx, addrtype FROM addresses WHERE keyidx >= ? ORDER BY keyidx LIMIT ?;"));
6387+
db_bind_u64(stmt, liststart);
6388+
if (listlimit)
6389+
db_bind_int(stmt, *listlimit);
6390+
else
6391+
db_bind_int(stmt, INT_MAX);
6392+
db_query_prepared(stmt);
6393+
while(db_step(stmt)) {
6394+
struct issued_address_type a;
6395+
a.keyidx = db_col_u64(stmt, "keyidx");
6396+
a.addrtype = wallet_addrtype_in_db(db_col_int(stmt, "addrtype"));
6397+
tal_arr_expand(&addresseslist, a);
6398+
}
6399+
tal_free(stmt);
6400+
return addresseslist;
6401+
}

wallet/wallet.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,4 +1798,23 @@ void wallet_remove_local_anchors(struct wallet *w,
17981798
struct local_anchor_info *wallet_get_local_anchors(const tal_t *ctx,
17991799
struct wallet *w,
18001800
u64 channel_id);
1801+
1802+
/* Get the addresses addrtype */
1803+
struct issued_address_type {
1804+
u64 keyidx;
1805+
enum addrtype addrtype;
1806+
};
1807+
1808+
/**
1809+
* wallet_list_addresses: get the list of addresses with addrtype
1810+
*
1811+
* @ctx: tal context for returned array
1812+
* @wallet: the wallet
1813+
* @liststart: first index to return (0 == all).
1814+
* @listlimit: limit on number of entries to return (NULL == no limit).
1815+
*
1816+
* Returns NULL if none, otherwise list of addresses with addrtype.
1817+
*/
1818+
struct issued_address_type *wallet_list_addresses(const tal_t *ctx, struct wallet *wallet,
1819+
u64 liststart, const u32 *listlimit);
18011820
#endif /* LIGHTNING_WALLET_WALLET_H */

0 commit comments

Comments
 (0)