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

Function payment_listpeerchannels_balance_sum

plugins/libplugin-pay.c:938–973  ·  view source on GitHub ↗

* 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.*/

Source from the content-addressed store, hash-verified

936 * pay as a preflight test. Returns `false` on errors, otherwise
937 * `sum` contains the sum of all channel balances.*/
938static 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
975static struct command_result *
976payment_listpeerchannels_success(struct command *cmd,

Callers 1

Calls 4

json_get_memberFunction · 0.85
paymod_logFunction · 0.85
amount_msat_accumulateFunction · 0.85
json_scanFunction · 0.50

Tested by

no test coverage detected