MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_state_changed

Function json_state_changed

plugins/chanbackup.c:688–733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

686}
687
688static 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

Callers

nothing calls this directly

Calls 11

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
add_to_backup_mapFunction · 0.85
commit_peer_backupFunction · 0.85
chanbackupFunction · 0.70
send_outreqFunction · 0.70
plugin_errFunction · 0.70
json_to_node_idFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected