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

Function json_balance_snapshot

plugins/bkpr/bookkeeper.c:959–1143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

957}
958
959static struct command_result *json_balance_snapshot(struct command *cmd,
960 const char *buf,
961 const jsmntok_t *params)
962{
963 const char *err;
964 size_t i;
965 u32 blockheight;
966 u64 timestamp;
967 struct new_account_info **new_accts;
968 const jsmntok_t *accounts_tok, *acct_tok,
969 *snap_tok = json_get_member(buf, params, "balance_snapshot");
970
971 if (snap_tok == NULL || snap_tok->type != JSMN_OBJECT)
972 plugin_err(cmd->plugin,
973 "`balance_snapshot` payload did not scan %s: %.*s",
974 "no 'balance_snapshot'", json_tok_full_len(params),
975 json_tok_full(buf, params));
976
977 err = json_scan(cmd, buf, snap_tok,
978 "{blockheight:%"
979 ",timestamp:%}",
980 JSON_SCAN(json_to_number, &blockheight),
981 JSON_SCAN(json_to_u64, &timestamp));
982
983 if (err)
984 plugin_err(cmd->plugin,
985 "`balance_snapshot` payload did not scan %s: %.*s",
986 err, json_tok_full_len(params),
987 json_tok_full(buf, params));
988
989 accounts_tok = json_get_member(buf, snap_tok, "accounts");
990 if (accounts_tok == NULL || accounts_tok->type != JSMN_ARRAY)
991 plugin_err(cmd->plugin,
992 "`balance_snapshot` payload did not scan %s: %.*s",
993 "no 'balance_snapshot.accounts'",
994 json_tok_full_len(params),
995 json_tok_full(buf, params));
996
997 new_accts = tal_arr(cmd, struct new_account_info *, 0);
998
999 db_begin_transaction(db);
1000 json_for_each_arr(i, acct_tok, accounts_tok) {
1001 struct acct_balance **balances, *bal;
1002 struct amount_msat snap_balance, credit_diff, debit_diff;
1003 char *acct_name, *currency;
1004 bool exists;
1005
1006 err = json_scan(cmd, buf, acct_tok,
1007 "{account_id:%"
1008 ",balance_msat:%"
1009 ",coin_type:%}",
1010 JSON_SCAN_TAL(tmpctx, json_strdup, &acct_name),
1011 JSON_SCAN(json_to_msat, &snap_balance),
1012 JSON_SCAN_TAL(tmpctx, json_strdup,
1013 &currency));
1014 if (err)
1015 plugin_err(cmd->plugin,
1016 "`balance_snapshot` payload did not"

Callers

nothing calls this directly

Calls 15

account_get_balanceFunction · 0.85
msat_find_diffFunction · 0.85
amount_msat_zeroFunction · 0.85
time_nowFunction · 0.85
find_accountFunction · 0.85
new_accountFunction · 0.85
account_addFunction · 0.85
is_channel_accountFunction · 0.85
log_channel_eventFunction · 0.85
notification_handledFunction · 0.85
new_channel_eventFunction · 0.70
account_entry_tag_strFunction · 0.70

Tested by

no test coverage detected