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

Function onchain_wallet_fund

plugins/spender/splice.c:723–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

721}
722
723static struct command_result *onchain_wallet_fund(struct command *cmd,
724 struct splice_cmd *splice_cmd,
725 size_t index,
726 struct amount_sat already_funded)
727{
728 struct splice_script_result *action = splice_cmd->actions[index];
729 struct splice_cmd_action_state *state = splice_cmd->states[index];
730 struct out_req *req;
731 struct splice_index_pkg *pkg;
732 struct amount_sat sats;
733 const char *command;
734 bool addinginputs = !amount_sat_is_zero(action->out_sat);
735
736 pkg = tal(cmd->plugin, struct splice_index_pkg);
737 pkg->splice_cmd = splice_cmd;
738 pkg->index = index;
739
740 command = "addpsbtoutput";
741 if (addinginputs) {
742 command = "addpsbtinput";
743 splice_cmd->wallet_inputs_to_signed++;
744 }
745
746 req = jsonrpc_request_start(cmd, command,
747 addpsbt_get_result,
748 splice_error_pkg, pkg);
749
750 if (addinginputs) {
751 sats = action->out_sat;
752 if (!amount_sat_sub(&sats, sats, already_funded))
753 return do_fail(cmd, splice_cmd, JSONRPC2_INVALID_PARAMS,
754 tal_fmt(tmpctx,
755 "Internal error; unable to sub"
756 " already_funded %s sats from out_stats"
757 " %s onchain_wallet_fund",
758 fmt_amount_sat(tmpctx, already_funded),
759 fmt_amount_sat(tmpctx, sats)));
760 json_add_sats(req->js, "satoshi", sats);
761 assert(splice_cmd->feerate_per_kw);
762 json_add_u32(req->js, "min_feerate", splice_cmd->feerate_per_kw);
763
764 plugin_log(cmd->plugin, LOG_DBG, "Adding input of at least %s",
765 fmt_amount_sat(tmpctx, sats));
766 }
767 else {
768 json_add_sats(req->js, "satoshi", action->in_sat);
769
770 plugin_log(cmd->plugin, LOG_DBG, "Adding output of %s",
771 fmt_amount_sat(tmpctx, action->in_sat));
772 }
773
774 json_add_psbt(req->js, "initialpsbt", splice_cmd->psbt);
775 json_add_bool(req->js, "add_initiator_serial_ids", true);
776 if (addinginputs)
777 json_add_bool(req->js, "mark_our_inputs", true);
778
779 if (state->state == SPLICE_CMD_PENDING) {
780 plugin_log(cmd->plugin, LOG_DBG, "Not marking index %d done"

Callers 2

handle_wallet_fundFunction · 0.85
continue_spliceFunction · 0.85

Calls 10

amount_sat_is_zeroFunction · 0.85
do_failFunction · 0.85
json_add_satsFunction · 0.85
json_add_u32Function · 0.85
json_add_psbtFunction · 0.85
json_add_boolFunction · 0.85
amount_sat_subFunction · 0.50
fmt_amount_satFunction · 0.50
plugin_logFunction · 0.50
send_outreqFunction · 0.50

Tested by

no test coverage detected