| 498 | } |
| 499 | #endif |
| 500 | static void json_transaction_details(struct json_stream *response, |
| 501 | const struct wallet_transaction *tx) |
| 502 | { |
| 503 | struct wally_tx *wtx = tx->tx->wtx; |
| 504 | |
| 505 | json_object_start(response, NULL); |
| 506 | json_add_txid(response, "hash", &tx->id); |
| 507 | json_add_hex_talarr(response, "rawtx", tx->rawtx); |
| 508 | json_add_num(response, "blockheight", tx->blockheight); |
| 509 | json_add_num(response, "txindex", tx->txindex); |
| 510 | #if EXPERIMENTAL_FEATURES |
| 511 | if (tx->annotation.type != 0) |
| 512 | json_add_txtypes(response, "type", tx->annotation.type); |
| 513 | |
| 514 | if (tx->annotation.channel.u64 != 0) |
| 515 | json_add_short_channel_id(response, "channel", &tx->annotation.channel); |
| 516 | #endif |
| 517 | json_add_u32(response, "locktime", wtx->locktime); |
| 518 | json_add_u32(response, "version", wtx->version); |
| 519 | |
| 520 | json_array_start(response, "inputs"); |
| 521 | for (size_t i = 0; i < wtx->num_inputs; i++) { |
| 522 | struct bitcoin_txid prevtxid; |
| 523 | struct wally_tx_input *in = &wtx->inputs[i]; |
| 524 | bitcoin_tx_input_get_txid(tx->tx, i, &prevtxid); |
| 525 | |
| 526 | json_object_start(response, NULL); |
| 527 | json_add_txid(response, "txid", &prevtxid); |
| 528 | json_add_u32(response, "index", in->index); |
| 529 | json_add_u32(response, "sequence", in->sequence); |
| 530 | #if EXPERIMENTAL_FEATURES |
| 531 | struct tx_annotation *ann = &tx->input_annotations[i]; |
| 532 | const char *txtype = txtype_to_string(ann->type); |
| 533 | if (txtype != NULL) |
| 534 | json_add_string(response, "type", txtype); |
| 535 | if (ann->channel.u64 != 0) |
| 536 | json_add_short_channel_id(response, "channel", &ann->channel); |
| 537 | #endif |
| 538 | |
| 539 | json_object_end(response); |
| 540 | } |
| 541 | json_array_end(response); |
| 542 | |
| 543 | json_array_start(response, "outputs"); |
| 544 | for (size_t i = 0; i < wtx->num_outputs; i++) { |
| 545 | struct wally_tx_output *out = &wtx->outputs[i]; |
| 546 | struct amount_asset amt = bitcoin_tx_output_get_amount(tx->tx, i); |
| 547 | struct amount_sat sat; |
| 548 | |
| 549 | /* TODO We should eventually handle non-bitcoin assets as well. */ |
| 550 | if (amount_asset_is_main(&amt)) |
| 551 | sat = amount_asset_to_sat(&amt); |
| 552 | else |
| 553 | sat = AMOUNT_SAT(0); |
| 554 | |
| 555 | json_object_start(response, NULL); |
| 556 | |
| 557 | json_add_u32(response, "index", i); |
no test coverage detected