Dump every active watch as a flat array; per-type fields go first * so the consumer can dispatch on shape. */
| 547 | /* Dump every active watch as a flat array; per-type fields go first |
| 548 | * so the consumer can dispatch on shape. */ |
| 549 | struct command_result *json_bwatch_list(struct command *cmd, |
| 550 | const char *buffer, |
| 551 | const jsmntok_t *params) |
| 552 | { |
| 553 | struct bwatch *bwatch = bwatch_of(cmd->plugin); |
| 554 | struct json_out *jout; |
| 555 | struct watch *w; |
| 556 | struct scriptpubkey_watches_iter sit; |
| 557 | struct outpoint_watches_iter oit; |
| 558 | struct scid_watches_iter scit; |
| 559 | struct blockdepth_watches_iter bdit; |
| 560 | |
| 561 | if (!param(cmd, buffer, params, NULL)) |
| 562 | return command_param_failed(); |
| 563 | |
| 564 | jout = json_out_new(cmd); |
| 565 | json_out_start(jout, NULL, '{'); |
| 566 | json_out_start(jout, "watches", '['); |
| 567 | |
| 568 | for (w = scriptpubkey_watches_first(bwatch->scriptpubkey_watches, &sit); |
| 569 | w; |
| 570 | w = scriptpubkey_watches_next(bwatch->scriptpubkey_watches, &sit)) { |
| 571 | json_out_start(jout, NULL, '{'); |
| 572 | json_out_addstr(jout, "scriptpubkey", |
| 573 | tal_hexstr(tmpctx, w->key.scriptpubkey.script, |
| 574 | w->key.scriptpubkey.len)); |
| 575 | json_out_watch_common(jout, w->type, w->start_block, w->owners); |
| 576 | json_out_end(jout, '}'); |
| 577 | } |
| 578 | |
| 579 | for (w = outpoint_watches_first(bwatch->outpoint_watches, &oit); |
| 580 | w; |
| 581 | w = outpoint_watches_next(bwatch->outpoint_watches, &oit)) { |
| 582 | json_out_start(jout, NULL, '{'); |
| 583 | json_out_addstr(jout, "outpoint", |
| 584 | fmt_bitcoin_outpoint(tmpctx, &w->key.outpoint)); |
| 585 | json_out_watch_common(jout, w->type, w->start_block, w->owners); |
| 586 | json_out_end(jout, '}'); |
| 587 | } |
| 588 | |
| 589 | for (w = scid_watches_first(bwatch->scid_watches, &scit); |
| 590 | w; |
| 591 | w = scid_watches_next(bwatch->scid_watches, &scit)) { |
| 592 | json_out_start(jout, NULL, '{'); |
| 593 | json_out_add(jout, "blockheight", false, "%u", |
| 594 | short_channel_id_blocknum(w->key.scid)); |
| 595 | json_out_add(jout, "txindex", false, "%u", |
| 596 | short_channel_id_txnum(w->key.scid)); |
| 597 | json_out_add(jout, "outnum", false, "%u", |
| 598 | short_channel_id_outnum(w->key.scid)); |
| 599 | json_out_watch_common(jout, w->type, w->start_block, w->owners); |
| 600 | json_out_end(jout, '}'); |
| 601 | } |
| 602 | |
| 603 | for (w = blockdepth_watches_first(bwatch->blockdepth_watches, &bdit); |
| 604 | w; |
| 605 | w = blockdepth_watches_next(bwatch->blockdepth_watches, &bdit)) { |
| 606 | json_out_start(jout, NULL, '{'); |
nothing calls this directly
no test coverage detected