Skip to content

Commit f67db3c

Browse files
committed
wallet: new routine to simply get the funding spend tx, if known.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 5a84440 commit f67db3c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

wallet/wallet.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,36 @@ struct channeltx *wallet_channeltxs_get(const tal_t *ctx, struct wallet *w,
48014801
return res;
48024802
}
48034803

4804+
struct bitcoin_tx *wallet_get_funding_spend(const tal_t *ctx,
4805+
struct wallet *w,
4806+
u64 channel_id,
4807+
u32 *blockheight)
4808+
{
4809+
struct db_stmt *stmt;
4810+
struct bitcoin_tx *tx;
4811+
4812+
stmt = db_prepare_v2(w->db,
4813+
SQL("SELECT"
4814+
" t.blockheight"
4815+
", t.rawtx"
4816+
" FROM channeltxs c"
4817+
" JOIN transactions t ON t.id = c.transaction_id"
4818+
" WHERE c.channel_id = ? AND t.blockheight IS NOT NULL AND c.type = ?"
4819+
" ORDER BY c.id ASC;"));
4820+
db_bind_int(stmt, channel_id);
4821+
db_bind_int(stmt, WIRE_ONCHAIND_INIT);
4822+
db_query_prepared(stmt);
4823+
4824+
if (db_step(stmt)) {
4825+
tx = db_col_tx(ctx, stmt, "t.rawtx");
4826+
*blockheight = db_col_int(stmt, "t.blockheight");
4827+
} else
4828+
tx = NULL;
4829+
tal_free(stmt);
4830+
4831+
return tx;
4832+
}
4833+
48044834
static bool wallet_forwarded_payment_update(struct wallet *w,
48054835
const struct htlc_in *in,
48064836
const struct htlc_out *out,

wallet/wallet.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,14 @@ u32 *wallet_onchaind_channels(const tal_t *ctx, struct wallet *w);
12381238
struct channeltx *wallet_channeltxs_get(const tal_t *ctx, struct wallet *w,
12391239
u32 channel_id);
12401240

1241+
/**
1242+
* Get the transaction which spend funding for this channel, if any.
1243+
*/
1244+
struct bitcoin_tx *wallet_get_funding_spend(const tal_t *ctx,
1245+
struct wallet *w,
1246+
u64 channel_id,
1247+
u32 *blockheight);
1248+
12411249
/**
12421250
* Add of update a forwarded_payment
12431251
*/

0 commit comments

Comments
 (0)