| 957 | } |
| 958 | |
| 959 | static 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, ×tamp)); |
| 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 | ¤cy)); |
| 1014 | if (err) |
| 1015 | plugin_err(cmd->plugin, |
| 1016 | "`balance_snapshot` payload did not" |
nothing calls this directly
no test coverage detected