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

Function init_rebalances

plugins/bkpr/rebalances.c:106–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106struct rebalances *init_rebalances(const tal_t *ctx,
107 struct command *init_cmd)
108{
109 struct json_out *params = json_out_new(tmpctx);
110 const jsmntok_t *result;
111 const char *buf;
112 const jsmntok_t *datastore, *t;
113 size_t i;
114
115 struct rebalances *r = tal(ctx, struct rebalances);
116 r->pairs = tal(r, struct rebalance_htable);
117 rebalance_htable_init(r->pairs);
118 memleak_add_helper(r->pairs, memleak_scan_rebalance_htable);
119
120 /* Query all keys under bookkeeper/rebalances */
121 json_out_start(params, NULL, '{');
122 json_out_start(params, "key", '[');
123 json_out_addstr(params, NULL, "bookkeeper");
124 json_out_addstr(params, NULL, "rebalances");
125 json_out_end(params, ']');
126 json_out_end(params, '}');
127
128 result = jsonrpc_request_sync(tmpctx, init_cmd,
129 "listdatastore", params, &buf);
130
131 datastore = json_get_member(buf, result, "datastore");
132 json_for_each_arr(i, t, datastore) {
133 const jsmntok_t *keytok = json_get_member(buf, t, "key");
134 jsmntok_t lessertok, greatertok;
135 u64 lesser, greater;
136
137 if (keytok->size != 3)
138 goto weird;
139
140 /* key = ["bookkeeper", "rebalances", "<lesser>-<greater>"] */
141 if (!split_tok(buf, keytok + 3, '-', &lessertok, &greatertok))
142 goto weird;
143
144 if (!json_to_u64(buf, &lessertok, &lesser)
145 || !json_to_u64(buf, &greatertok, &greater))
146 goto weird;
147
148 new_rebalance_pair(r, lesser, greater);
149 continue;
150
151 weird:
152 plugin_log(init_cmd->plugin, LOG_BROKEN, "Unparsable datastore %.*s",
153 json_tok_full_len(keytok),
154 json_tok_full(buf, keytok));
155 }
156
157 return r;
158}

Callers 1

initFunction · 0.70

Calls 12

json_out_newFunction · 0.85
json_out_startFunction · 0.85
json_out_addstrFunction · 0.85
json_out_endFunction · 0.85
json_get_memberFunction · 0.85
split_tokFunction · 0.85
new_rebalance_pairFunction · 0.85
jsonrpc_request_syncFunction · 0.50
json_to_u64Function · 0.50
plugin_logFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected