| 686 | } |
| 687 | |
| 688 | static struct command_result *json_state_changed(struct command *cmd, |
| 689 | const char *buf, |
| 690 | const jsmntok_t *params) |
| 691 | { |
| 692 | struct chanbackup *cb = chanbackup(cmd->plugin); |
| 693 | const jsmntok_t *notiftok = json_get_member(buf, |
| 694 | params, |
| 695 | "channel_state_changed"), |
| 696 | *statetok = json_get_member(buf, notiftok, "new_state"); |
| 697 | |
| 698 | if (json_tok_streq(buf, statetok, "CLOSED") || |
| 699 | json_tok_streq(buf, statetok, "CHANNELD_AWAITING_LOCKIN") || |
| 700 | json_tok_streq(buf, statetok, "DUALOPEND_AWAITING_LOCKIN")) { |
| 701 | struct out_req *req; |
| 702 | req = jsonrpc_request_start(cmd, |
| 703 | "staticbackup", |
| 704 | after_staticbackup, |
| 705 | log_broken_and_complete, |
| 706 | NULL); |
| 707 | |
| 708 | return send_outreq(req); |
| 709 | } |
| 710 | |
| 711 | /* Once it has a normal channel, we will start storing its |
| 712 | * backups: put an empty record in place. */ |
| 713 | if (json_tok_streq(buf, statetok, "CHANNELD_NORMAL")) { |
| 714 | const jsmntok_t *nodeid_tok; |
| 715 | struct node_id node_id; |
| 716 | |
| 717 | nodeid_tok = json_get_member(buf, notiftok, "peer_id"); |
| 718 | if (!json_to_node_id(buf, nodeid_tok, &node_id)) |
| 719 | plugin_err(cmd->plugin, "Invalid peer_id in %.*s", |
| 720 | json_tok_full_len(notiftok), |
| 721 | json_tok_full(buf, notiftok)); |
| 722 | |
| 723 | /* Create a placeholder if necessary */ |
| 724 | if (!backup_map_get(cb->backups, &node_id)) { |
| 725 | struct peer_backup *pb |
| 726 | = add_to_backup_map(cb, &node_id, |
| 727 | take(tal_arr(NULL, u8, 0))); |
| 728 | return commit_peer_backup(cmd, pb); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | return notification_or_hook_done(cmd); |
| 733 | } |
| 734 | |
| 735 | |
| 736 | /* We use the hook here, since we want to send data to peer before any |
nothing calls this directly
no test coverage detected