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

Function addpsbt_get_result

plugins/spender/splice.c:636–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634}
635
636static struct command_result *addpsbt_get_result(struct command *cmd,
637 const char *methodname,
638 const char *buf,
639 const jsmntok_t *result,
640 struct splice_index_pkg *pkg)
641{
642 struct splice_cmd *splice_cmd = pkg->splice_cmd;
643 size_t index = pkg->index;
644 struct splice_script_result *action = splice_cmd->actions[index];
645 const jsmntok_t *tok;
646 struct amount_sat excess_sat;
647 struct splice_script_result *out_wallet;
648
649 tal_free(pkg);
650 tok = json_get_member(buf, result, "psbt");
651
652 tal_free(splice_cmd->psbt);
653 splice_cmd->psbt = json_to_psbt(splice_cmd, buf, tok);
654 assert(splice_cmd->psbt);
655
656 tok = json_get_member(buf, result, "excess_msat");
657 if (tok) {
658 if (!json_to_msat_to_sat(buf, tok, &excess_sat))
659 return command_fail_badparam(cmd, "addpsbt", buf, tok,
660 "invalid excess_msat");
661
662 if (!amount_sat_is_zero(excess_sat)) {
663 if (!amount_sat_add(&action->out_sat, action->out_sat,
664 excess_sat))
665 return do_fail(cmd, splice_cmd,
666 JSONRPC2_INVALID_PARAMS,
667 "Unable to add excess sats");
668
669 plugin_log(cmd->plugin, LOG_DBG,
670 "Received input(s) with %s",
671 fmt_amount_sat(tmpctx, action->out_sat));
672
673 out_wallet = output_wallet(splice_cmd);
674 plugin_log(cmd->plugin, LOG_DBG,
675 "Adding excess sats back into out wallet %s"
676 " which already has %s",
677 fmt_amount_sat(tmpctx, excess_sat),
678 out_wallet
679 ? fmt_amount_sat(tmpctx,
680 out_wallet->in_sat)
681 : "(NO WALLET)");
682
683 if (!out_wallet) {
684 plugin_log(cmd->plugin, LOG_DBG, "Generating"
685 " output wallet.");
686 out_wallet = make_wallet(splice_cmd);
687 }
688
689 if (out_wallet) {
690 if (!amount_sat_add(&out_wallet->in_sat,
691 out_wallet->in_sat,
692 excess_sat))
693 return do_fail(cmd, splice_cmd,

Callers

nothing calls this directly

Calls 13

tal_freeFunction · 0.85
json_get_memberFunction · 0.85
json_to_psbtFunction · 0.85
amount_sat_is_zeroFunction · 0.85
do_failFunction · 0.85
output_walletFunction · 0.85
make_walletFunction · 0.85
continue_spliceFunction · 0.85
json_to_msat_to_satFunction · 0.70
command_fail_badparamFunction · 0.50
amount_sat_addFunction · 0.50
plugin_logFunction · 0.50

Tested by

no test coverage detected