| 234 | AUTODATA(json_command, &listaddrs_command); |
| 235 | |
| 236 | static void json_add_utxo(struct json_stream *response, |
| 237 | const char *fieldname, |
| 238 | struct wallet *wallet, |
| 239 | const struct utxo *utxo) |
| 240 | { |
| 241 | const char *out; |
| 242 | bool reserved; |
| 243 | |
| 244 | json_object_start(response, fieldname); |
| 245 | json_add_txid(response, "txid", &utxo->outpoint.txid); |
| 246 | json_add_num(response, "output", utxo->outpoint.n); |
| 247 | json_add_amount_sat_compat(response, utxo->amount, |
| 248 | "value", "amount_msat"); |
| 249 | |
| 250 | if (utxo->is_p2sh) { |
| 251 | struct pubkey key; |
| 252 | bip32_pubkey(wallet->bip32_base, &key, utxo->keyindex); |
| 253 | |
| 254 | json_add_hex_talarr(response, "redeemscript", |
| 255 | bitcoin_redeem_p2sh_p2wpkh(tmpctx, &key)); |
| 256 | } |
| 257 | |
| 258 | json_add_hex_talarr(response, "scriptpubkey", utxo->scriptPubkey); |
| 259 | out = encode_scriptpubkey_to_addr(tmpctx, chainparams, |
| 260 | utxo->scriptPubkey); |
| 261 | if (!out) |
| 262 | log_broken(wallet->log, |
| 263 | "Could not encode utxo %s%s!", |
| 264 | type_to_string(tmpctx, |
| 265 | struct bitcoin_outpoint, |
| 266 | &utxo->outpoint), |
| 267 | utxo->close_info ? " (has close_info)" : ""); |
| 268 | else |
| 269 | json_add_string(response, "address", out); |
| 270 | |
| 271 | if (utxo->spendheight) |
| 272 | json_add_string(response, "status", "spent"); |
| 273 | else if (utxo->blockheight) { |
| 274 | json_add_string(response, "status", "confirmed"); |
| 275 | json_add_num(response, "blockheight", *utxo->blockheight); |
| 276 | } else |
| 277 | json_add_string(response, "status", "unconfirmed"); |
| 278 | |
| 279 | reserved = utxo_is_reserved(utxo, |
| 280 | get_block_height(wallet->ld->topology)); |
| 281 | json_add_bool(response, "reserved", reserved); |
| 282 | if (reserved) |
| 283 | json_add_num(response, "reserved_to_block", |
| 284 | utxo->reserved_til); |
| 285 | if (utxo->close_info && utxo->close_info->csv > 1) { |
| 286 | json_add_num(response, "csv_lock", utxo->close_info->csv); |
| 287 | |
| 288 | if (utxo->blockheight) |
| 289 | json_add_u32(response, "spendable_at", |
| 290 | *utxo->blockheight + utxo->close_info->csv); |
| 291 | } |
| 292 | |
| 293 | json_object_end(response); |
no test coverage detected