diff --git a/wallet/wallet.c b/wallet/wallet.c index 144c6eb14..cd5659710 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2806,3 +2806,27 @@ void wallet_clean_utxos(struct wallet *w, struct bitcoind *bitcoind) } else tal_free(utxos); } + +struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx) +{ + sqlite3_stmt *stmt; + size_t count; + struct wallet_transaction *cur, *txs = tal_arr(ctx, struct wallet_transaction, 0); + + stmt = db_select_prepare(w->db, + "id, id, rawtx, blockheight, txindex, type, channel_id " + "FROM transactions"); + for (count = 0; db_select_step(w->db, stmt); count++) { + tal_resize(&txs, count + 1); + cur = &txs[count]; + sqlite3_column_sha256_double(stmt, 1, &cur->id.shad); + cur->rawtx = tal_dup_arr(txs, u8, sqlite3_column_blob(stmt, 2), + sqlite3_column_bytes(stmt, 2), 0); + cur->blockheight = sqlite3_column_int(stmt, 3); + cur->txindex = sqlite3_column_int(stmt, 4); + cur->type = sqlite3_column_int(stmt, 5); + cur->channel_id = sqlite3_column_int(stmt, 6); + } + + return txs; +} diff --git a/wallet/wallet.h b/wallet/wallet.h index 1f3b395c7..603559dce 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -289,6 +289,15 @@ struct channeltx { u32 depth; }; +struct wallet_transaction { + struct bitcoin_txid id; + u32 blockheight; + u32 txindex; + u8 *rawtx; + txtypes type; + u64 channel_id; +}; + /** * wallet_new - Constructor for a new sqlite3 based wallet * @@ -1131,4 +1140,14 @@ void add_unreleased_tx(struct wallet *w, struct unreleased_tx *utx); /* These will touch the db, so need to be explicitly freed. */ void free_unreleased_txs(struct wallet *w); + +/** + * Get a list of transactions that we track in the wallet. + * + * @param ctx: allocation context for the returned list + * @param wallet: Wallet to load from. + * @return A tal_arr of wallet transactions + */ +struct wallet_transaction *wallet_transactions_get(struct wallet *w, const tal_t *ctx); + #endif /* LIGHTNING_WALLET_WALLET_H */