* Compute the total sum of balances. Limits the maximum size we can * pay as a preflight test. Returns `false` on errors, otherwise * `sum` contains the sum of all channel balances.*/
| 936 | * pay as a preflight test. Returns `false` on errors, otherwise |
| 937 | * `sum` contains the sum of all channel balances.*/ |
| 938 | static bool payment_listpeerchannels_balance_sum(struct payment *p, |
| 939 | const char *buf, |
| 940 | const jsmntok_t *toks, |
| 941 | struct amount_msat *sum) |
| 942 | { |
| 943 | *sum = AMOUNT_MSAT(0); |
| 944 | const jsmntok_t *channels, *channel; |
| 945 | struct amount_msat spendable; |
| 946 | bool connected; |
| 947 | size_t i; |
| 948 | const char *err; |
| 949 | |
| 950 | channels = json_get_member(buf, toks, "channels"); |
| 951 | |
| 952 | json_for_each_arr(i, channel, channels) |
| 953 | { |
| 954 | err = json_scan(tmpctx, buf, channel, |
| 955 | "{spendable_msat?:%,peer_connected:%}", |
| 956 | JSON_SCAN(json_to_msat, &spendable), |
| 957 | JSON_SCAN(json_to_bool, &connected)); |
| 958 | if (err) { |
| 959 | paymod_log(p, LOG_UNUSUAL, |
| 960 | "Bad listpeerchannels.channels %zu: %s", i, |
| 961 | err); |
| 962 | return false; |
| 963 | } |
| 964 | |
| 965 | if (!amount_msat_accumulate(sum, spendable)) { |
| 966 | paymod_log( |
| 967 | p, LOG_BROKEN, |
| 968 | "Integer sum overflow summing spendable amounts."); |
| 969 | return false; |
| 970 | } |
| 971 | } |
| 972 | return true; |
| 973 | } |
| 974 | |
| 975 | static struct command_result * |
| 976 | payment_listpeerchannels_success(struct command *cmd, |
no test coverage detected