* wallet_stmt2output - Extract data from stmt and fill an UTXO */
| 357 | * wallet_stmt2output - Extract data from stmt and fill an UTXO |
| 358 | */ |
| 359 | static 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"); |
no test coverage detected