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

Function init

plugins/chanbackup.c:1115–1169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1113}
1114
1115static const char *init(struct command *init_cmd,
1116 const char *buf UNUSED,
1117 const jsmntok_t *config UNUSED)
1118{
1119 struct chanbackup *cb = tal(init_cmd->plugin, struct chanbackup);
1120 struct modern_scb_chan **scb_chan;
1121 const char *info = "scb secret";
1122 u8 *info_hex = tal_dup_arr(tmpctx, u8, (u8*)info, strlen(info), 0);
1123 u8 *features;
1124 u8 *latestscb;
1125
1126 /* Figure out if they specified --experimental-peer-storage */
1127 rpc_scan(init_cmd, "getinfo",
1128 take(json_out_obj(NULL, NULL, NULL)),
1129 "{our_features:{init:%}}",
1130 JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &features));
1131
1132 /* If we unset this feature, we don't even *send* peer backups */
1133 cb->handle_their_peer_backup
1134 = cb->send_our_peer_backup
1135 = feature_offered(features, OPT_PROVIDE_STORAGE);
1136
1137 rpc_scan(init_cmd, "staticbackup",
1138 take(json_out_obj(NULL, NULL, NULL)),
1139 "{scb:%}", JSON_SCAN(json_to_scb_chan, &scb_chan));
1140
1141 rpc_scan(init_cmd, "makesecret",
1142 take(json_out_obj(NULL, "hex",
1143 tal_hexstr(tmpctx,
1144 info_hex,
1145 tal_bytelen(info_hex)))),
1146 "{secret:%}", JSON_SCAN(json_to_secret, &cb->secret));
1147
1148 /* Caching timestamp of latestscb that we have stored. This
1149 * would be useful for upgrading `chanbackup/latestscb`. */
1150 cb->latest_timestamp = 0;
1151 if (rpc_scan_datastore_hex(tmpctx, init_cmd,
1152 mkdatastorekey(tmpctx, "chanbackup", "latestscb"),
1153 JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &latestscb)) == NULL) {
1154 u64 version;
1155 struct modern_scb_chan **scb_tlvs;
1156 bool is_converted;
1157 read_static_chan_backup(init_cmd, latestscb, &version, &cb->latest_timestamp, &scb_tlvs, &is_converted);
1158 }
1159
1160 setup_backup_map(init_cmd, cb);
1161 plugin_set_data(init_cmd->plugin, cb);
1162 plugin_log(init_cmd->plugin, LOG_DBG, "Chanbackup Initialised!");
1163
1164 /* flush the tmp file, if exists */
1165 unlink_noerr("scb.tmp");
1166
1167 maybe_create_new_scb(init_cmd->plugin, scb_chan);
1168 return NULL;
1169}
1170
1171static const struct plugin_notification notifs[] = {
1172 {

Callers

nothing calls this directly

Calls 12

feature_offeredFunction · 0.85
tal_hexstrFunction · 0.85
tal_bytelenFunction · 0.85
read_static_chan_backupFunction · 0.85
setup_backup_mapFunction · 0.85
plugin_set_dataFunction · 0.85
unlink_noerrFunction · 0.85
maybe_create_new_scbFunction · 0.85
rpc_scanFunction · 0.70
json_out_objFunction · 0.70
rpc_scan_datastore_hexFunction · 0.70
plugin_logFunction · 0.70

Tested by

no test coverage detected