| 355 | AUTODATA(json_command, &listaddrs_command); |
| 356 | |
| 357 | static void json_add_utxo(struct json_stream *response, |
| 358 | const char *fieldname, |
| 359 | struct wallet *wallet, |
| 360 | const struct utxo *utxo) |
| 361 | { |
| 362 | const char *out; |
| 363 | bool reserved; |
| 364 | u32 current_height = get_block_height(wallet->ld->topology); |
| 365 | |
| 366 | json_object_start(response, fieldname); |
| 367 | json_add_txid(response, "txid", &utxo->outpoint.txid); |
| 368 | json_add_num(response, "output", utxo->outpoint.n); |
| 369 | json_add_amount_sat_msat(response, "amount_msat", utxo->amount); |
| 370 | |
| 371 | if (utxo->utxotype == UTXO_P2SH_P2WPKH) { |
| 372 | struct pubkey key; |
| 373 | bip32_pubkey(wallet->ld, &key, utxo->keyindex); |
| 374 | |
| 375 | json_add_hex_talarr(response, "redeemscript", |
| 376 | bitcoin_redeem_p2sh_p2wpkh(tmpctx, &key)); |
| 377 | } |
| 378 | |
| 379 | json_add_hex_talarr(response, "scriptpubkey", utxo->scriptPubkey); |
| 380 | out = encode_scriptpubkey_to_addr(tmpctx, chainparams, |
| 381 | utxo->scriptPubkey, |
| 382 | tal_bytelen(utxo->scriptPubkey)); |
| 383 | if (!out) |
| 384 | log_broken(wallet->log, |
| 385 | "Could not encode utxo %s%s!", |
| 386 | fmt_bitcoin_outpoint(tmpctx, |
| 387 | &utxo->outpoint), |
| 388 | utxo->close_info ? " (has close_info)" : ""); |
| 389 | else |
| 390 | json_add_string(response, "address", out); |
| 391 | |
| 392 | if (utxo->spendheight) |
| 393 | json_add_string(response, "status", "spent"); |
| 394 | else if (utxo->blockheight) { |
| 395 | json_add_string(response, "status", |
| 396 | utxo_is_immature(utxo, current_height) |
| 397 | ? "immature" |
| 398 | : "confirmed"); |
| 399 | |
| 400 | json_add_num(response, "blockheight", *utxo->blockheight); |
| 401 | } else |
| 402 | json_add_string(response, "status", "unconfirmed"); |
| 403 | |
| 404 | reserved = utxo_is_reserved(utxo, current_height); |
| 405 | json_add_bool(response, "reserved", reserved); |
| 406 | if (reserved) |
| 407 | json_add_num(response, "reserved_to_block", |
| 408 | utxo->reserved_til); |
| 409 | if (utxo->close_info && utxo->close_info->csv > 1) { |
| 410 | json_add_num(response, "csv_lock", utxo->close_info->csv); |
| 411 | |
| 412 | if (utxo->blockheight) |
| 413 | json_add_u32(response, "spendable_at", |
| 414 | *utxo->blockheight + utxo->close_info->csv); |
no test coverage detected