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

Function listfunds_success

plugins/funder.c:389–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387}
388
389static struct command_result *
390listfunds_success(struct command *cmd,
391 const char *buf,
392 const jsmntok_t *result,
393 struct open_info *info)
394{
395 struct amount_sat available_funds, est_fee;
396 const jsmntok_t *outputs_tok, *tok;
397 struct out_req *req;
398 size_t i;
399 const char *funding_err;
400
401 outputs_tok = json_get_member(buf, result, "outputs");
402 if (!outputs_tok)
403 plugin_err(cmd->plugin,
404 "`listfunds` payload has no outputs token: %*.s",
405 json_tok_full_len(result),
406 json_tok_full(buf, result));
407
408 available_funds = AMOUNT_SAT(0);
409 json_for_each_arr(i, tok, outputs_tok) {
410 struct amount_sat val;
411 bool is_reserved, is_p2sh;
412 char *status;
413 const char *err;
414
415 err = json_scan(tmpctx, buf, tok,
416 "{amount_msat:%"
417 ",status:%"
418 ",reserved:%}",
419 JSON_SCAN(json_to_msat_as_sats, &val),
420 JSON_SCAN_TAL(cmd, json_strdup, &status),
421 JSON_SCAN(json_to_bool, &is_reserved));
422 if (err)
423 plugin_err(cmd->plugin,
424 "`listfunds` payload did not scan. %s: %*.s",
425 err, json_tok_full_len(result),
426 json_tok_full(buf, result));
427
428 /* is it a p2sh output? */
429 if (json_get_member(buf, tok, "redeemscript"))
430 is_p2sh = true;
431 else
432 is_p2sh = false;
433
434 /* The estimated fee per utxo. */
435 est_fee = amount_tx_fee(info->funding_feerate_perkw,
436 bitcoin_tx_input_weight(is_p2sh, 110));
437
438 /* we skip reserved funds */
439 if (is_reserved)
440 continue;
441
442 /* we skip unconfirmed+spent funds */
443 if (!streq(status, "confirmed"))
444 continue;
445
446 /* Don't include outputs that can't cover their weight;

Callers

nothing calls this directly

Calls 15

bitcoin_tx_input_weightFunction · 0.85
calculate_our_fundingFunction · 0.85
funder_policy_descFunction · 0.85
amount_sat_zeroFunction · 0.85
command_hook_successFunction · 0.85
feerate_style_nameFunction · 0.85
plugin_errFunction · 0.70
plugin_logFunction · 0.70
send_outreqFunction · 0.70
json_get_memberFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected