MCPcopy Create free account
hub / github.com/ElementsProject/lightning / wallet_stmt2output

Function wallet_stmt2output

wallet/wallet.c:359–424  ·  view source on GitHub ↗

* wallet_stmt2output - Extract data from stmt and fill an UTXO */

Source from the content-addressed store, hash-verified

357 * wallet_stmt2output - Extract data from stmt and fill an UTXO
358 */
359static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt)
360{
361 struct utxo *utxo = tal(ctx, struct utxo);
362 u32 *blockheight, *spendheight;
363 db_col_txid(stmt, "prev_out_tx", &utxo->outpoint.txid);
364 utxo->outpoint.n = db_col_int(stmt, "prev_out_index");
365 utxo->amount = db_col_amount_sat(stmt, "value");
366 utxo->status = db_col_int(stmt, "status");
367 utxo->keyindex = db_col_int(stmt, "keyindex");
368
369 utxo->is_in_coinbase = db_col_int(stmt, "is_in_coinbase") == 1;
370
371 if (!db_col_is_null(stmt, "channel_id")) {
372 utxo->close_info = tal(utxo, struct unilateral_close_info);
373 utxo->close_info->channel_id = db_col_u64(stmt, "channel_id");
374 db_col_node_id(stmt, "peer_id", &utxo->close_info->peer_id);
375 utxo->close_info->commitment_point
376 = db_col_optional(utxo->close_info, stmt,
377 "commitment_point",
378 pubkey);
379 utxo->close_info->option_anchors
380 = db_col_int(stmt, "option_anchor_outputs");
381 utxo->close_info->csv = db_col_int(stmt, "csv_lock");
382 } else {
383 utxo->close_info = NULL;
384 db_col_ignore(stmt, "peer_id");
385 db_col_ignore(stmt, "commitment_point");
386 db_col_ignore(stmt, "option_anchor_outputs");
387 db_col_ignore(stmt, "csv_lock");
388 }
389
390 utxo->scriptPubkey = db_col_arr(utxo, stmt, "scriptpubkey", u8);
391 /* FIXME: add p2tr to type? */
392 if (wallet_output_type_in_db(db_col_int(stmt, "type")) == WALLET_OUTPUT_P2SH_WPKH)
393 utxo->utxotype = UTXO_P2SH_P2WPKH;
394 else if (is_p2wpkh(utxo->scriptPubkey, tal_bytelen(utxo->scriptPubkey), NULL))
395 utxo->utxotype = UTXO_P2WPKH;
396 else if (is_p2tr(utxo->scriptPubkey, tal_bytelen(utxo->scriptPubkey), NULL))
397 utxo->utxotype = UTXO_P2TR;
398 else if (is_p2wsh(utxo->scriptPubkey, tal_bytelen(utxo->scriptPubkey), NULL)) {
399 if (!utxo->close_info)
400 fatal("Unspendable scriptPubkey without close_info %s", tal_hex(tmpctx, utxo->scriptPubkey));
401 utxo->utxotype = UTXO_P2WSH_FROM_CLOSE;
402 } else
403 fatal("Unknown utxo type %s", tal_hex(tmpctx, utxo->scriptPubkey));
404
405 utxo->blockheight = NULL;
406 utxo->spendheight = NULL;
407
408 if (!db_col_is_null(stmt, "confirmation_height")) {
409 blockheight = tal(utxo, u32);
410 *blockheight = db_col_int(stmt, "confirmation_height");
411 utxo->blockheight = blockheight;
412 }
413
414 if (!db_col_is_null(stmt, "spend_height")) {
415 spendheight = tal(utxo, u32);
416 *spendheight = db_col_int(stmt, "spend_height");

Callers 4

gather_utxosFunction · 0.85
wallet_utxo_getFunction · 0.85
wallet_find_utxoFunction · 0.85
wallet_has_fundsFunction · 0.85

Calls 15

db_col_txidFunction · 0.85
db_col_intFunction · 0.85
db_col_amount_satFunction · 0.85
db_col_is_nullFunction · 0.85
db_col_u64Function · 0.85
db_col_node_idFunction · 0.85
db_col_ignoreFunction · 0.85
wallet_output_type_in_dbFunction · 0.85
is_p2wpkhFunction · 0.85
tal_bytelenFunction · 0.85
is_p2wshFunction · 0.85
tal_hexFunction · 0.85

Tested by

no test coverage detected