Find all the events for this account, ordered by timestamp */
| 354 | |
| 355 | /* Find all the events for this account, ordered by timestamp */ |
| 356 | static struct command_result *json_list_account_events(struct command *cmd, |
| 357 | const char *buf, |
| 358 | const jsmntok_t *params) |
| 359 | { |
| 360 | struct json_stream *res; |
| 361 | struct account *acct; |
| 362 | const char *acct_name; |
| 363 | struct channel_event **channel_events; |
| 364 | struct chain_event **chain_events; |
| 365 | struct onchain_fee **onchain_fees; |
| 366 | |
| 367 | if (!param(cmd, buf, params, |
| 368 | p_opt("account", param_string, &acct_name), |
| 369 | NULL)) |
| 370 | return command_param_failed(); |
| 371 | |
| 372 | if (acct_name) { |
| 373 | db_begin_transaction(db); |
| 374 | acct = find_account(cmd, db, acct_name); |
| 375 | db_commit_transaction(db); |
| 376 | |
| 377 | if (!acct) |
| 378 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 379 | "Account '%s' not found", |
| 380 | acct_name); |
| 381 | } else |
| 382 | acct = NULL; |
| 383 | |
| 384 | db_begin_transaction(db); |
| 385 | if (acct) { |
| 386 | channel_events = account_get_channel_events(cmd, db, acct); |
| 387 | chain_events = account_get_chain_events(cmd, db, acct); |
| 388 | onchain_fees = account_get_chain_fees(cmd, db, acct); |
| 389 | } else { |
| 390 | channel_events = list_channel_events(cmd, db); |
| 391 | chain_events = list_chain_events(cmd, db); |
| 392 | onchain_fees = list_chain_fees(cmd, db); |
| 393 | } |
| 394 | db_commit_transaction(db); |
| 395 | |
| 396 | res = jsonrpc_stream_success(cmd); |
| 397 | json_array_start(res, "events"); |
| 398 | for (size_t i = 0, j = 0, k = 0; |
| 399 | i < tal_count(chain_events) |
| 400 | || j < tal_count(channel_events) |
| 401 | || k < tal_count(onchain_fees); |
| 402 | /* Incrementing happens inside loop */) { |
| 403 | struct channel_event *chan; |
| 404 | struct chain_event *chain; |
| 405 | struct onchain_fee *fee; |
| 406 | u64 lowest = 0; |
| 407 | |
| 408 | if (i < tal_count(chain_events)) |
| 409 | chain = chain_events[i]; |
| 410 | else |
| 411 | chain = NULL; |
| 412 | if (j < tal_count(channel_events)) |
| 413 | chan = channel_events[j]; |
nothing calls this directly
no test coverage detected