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

Function json_listchainmoves

lightningd/coin_mvts.c:296–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296static struct command_result *json_listchainmoves(struct command *cmd,
297 const char *buffer,
298 const jsmntok_t *obj UNNEEDED,
299 const jsmntok_t *params)
300{
301 struct json_stream *response;
302 struct db_stmt *stmt;
303 enum wait_index *listindex;
304 u64 *liststart;
305 u32 *listlimit;
306
307 if (!param(cmd, buffer, params,
308 p_opt("index", param_index, &listindex),
309 p_opt_def("start", param_u64, &liststart, 0),
310 p_opt("limit", param_u32, &listlimit),
311 NULL))
312 return command_param_failed();
313
314 if (*liststart != 0 && !listindex) {
315 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
316 "Can only specify {start} with {index}");
317 }
318 if (listlimit && !listindex) {
319 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
320 "Can only specify {limit} with {index}");
321 }
322 if (listindex && *listindex != WAIT_INDEX_CREATED) {
323 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
324 "index must be 'created', since chainmoves are never updated");
325 }
326 response = json_stream_success(cmd);
327 json_array_start(response, "chainmoves");
328 for (stmt = wallet_chain_moves_first(cmd->ld->wallet, *liststart, listlimit);
329 stmt;
330 stmt = wallet_chain_moves_next(cmd->ld->wallet, stmt)) {
331 struct chain_coin_mvt *chain_mvt;
332 u64 id;
333 chain_mvt = wallet_chain_move_extract(cmd, stmt, cmd->ld, &id);
334 json_object_start(response, NULL);
335 json_add_chain_mvt_fields(response, false, false, false, chain_mvt, id);
336 json_object_end(response);
337 }
338 json_array_end(response);
339
340 return command_success(cmd, response);
341}
342static const struct json_command listchainmoves_command = {
343 "listchainmoves",
344 json_listchainmoves,

Callers

nothing calls this directly

Calls 13

json_array_startFunction · 0.85
wallet_chain_moves_firstFunction · 0.85
wallet_chain_moves_nextFunction · 0.85
json_object_startFunction · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70

Tested by

no test coverage detected