Browse Source

wallet: add accessor getting close-info-needed unconfirmed UTXOs.

These are not confirmed by the normal methods (wallet_can_spend is false!),
so we'll deal with them manually.

We use UTXO_FIELDS in wallet_add_utxo, too, for consistency.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
27835df8fd
  1. 42
      wallet/wallet.c
  2. 10
      wallet/wallet.h

42
wallet/wallet.c

@ -61,6 +61,11 @@ struct wallet *wallet_new(struct lightningd *ld,
return wallet;
}
#define UTXO_FIELDS \
"prev_out_tx, prev_out_index, value, type, status, keyindex, " \
"channel_id, peer_id, commitment_point, confirmation_height, " \
"spend_height"
/* We actually use the db constraints to uniquify, so OK if this fails. */
bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
enum wallet_output_type type)
@ -68,17 +73,8 @@ bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
sqlite3_stmt *stmt;
stmt = db_prepare(w->db, "INSERT INTO outputs ("
"prev_out_tx, "
"prev_out_index, "
"value, "
"type, "
"status, "
"keyindex, "
"channel_id, "
"peer_id, "
"commitment_point, "
"confirmation_height, "
"spend_height) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
UTXO_FIELDS
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
sqlite3_bind_blob(stmt, 1, &utxo->txid, sizeof(utxo->txid), SQLITE_TRANSIENT);
sqlite3_bind_int(stmt, 2, utxo->outnum);
sqlite3_bind_int64(stmt, 3, utxo->amount);
@ -175,10 +171,6 @@ bool wallet_update_output_status(struct wallet *w,
return sqlite3_changes(w->db->sql) > 0;
}
#define UTXO_FIELDS \
"prev_out_tx, prev_out_index, value, type, status, keyindex, " \
"channel_id, peer_id, commitment_point, confirmation_height, " \
"spend_height"
struct utxo **wallet_get_utxos(const tal_t *ctx, struct wallet *w, const enum output_status state)
{
struct utxo **results;
@ -205,6 +197,26 @@ struct utxo **wallet_get_utxos(const tal_t *ctx, struct wallet *w, const enum ou
return results;
}
struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx, struct wallet *w)
{
struct utxo **results;
int i;
sqlite3_stmt *stmt = db_prepare(
w->db, "SELECT " UTXO_FIELDS
" FROM outputs WHERE channel_id IS NOT NULL and confirmation_height IS NULL");
results = tal_arr(ctx, struct utxo*, 0);
for (i=0; sqlite3_step(stmt) == SQLITE_ROW; i++) {
tal_resize(&results, i+1);
results[i] = tal(results, struct utxo);
wallet_stmt2output(stmt, results[i]);
}
db_stmt_done(stmt);
return results;
}
/**
* unreserve_utxo - Mark a reserved UTXO as available again
*/

10
wallet/wallet.h

@ -249,6 +249,16 @@ bool wallet_update_output_status(struct wallet *w,
struct utxo **wallet_get_utxos(const tal_t *ctx, struct wallet *w,
const enum output_status state);
/**
* wallet_get_unconfirmed_closeinfo_utxos - Retrieve any unconfirmed utxos w/ closeinfo
*
* Returns a `tal_arr` of `utxo` structs. Double indirection in order
* to be able to steal individual elements onto something else.
*/
struct utxo **wallet_get_unconfirmed_closeinfo_utxos(const tal_t *ctx,
struct wallet *w);
const struct utxo **wallet_select_coins(const tal_t *ctx, struct wallet *w,
const u64 value,
const u32 feerate_per_kw,

Loading…
Cancel
Save