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

Function execute_splice

plugins/spender/splice.c:1773–1924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1771}
1772
1773static struct command_result *execute_splice(struct command *cmd,
1774 struct splice_cmd *splice_cmd)
1775{
1776 struct splice_script_result *action;
1777 struct splice_cmd_action_state *state;
1778 struct wally_psbt_output *output;
1779 u64 serial_id;
1780 int pays_fee;
1781 u8 *scriptpubkey;
1782
1783 /* Basic validation */
1784 pays_fee = 0;
1785 for (size_t i = 0; i < tal_count(splice_cmd->actions); i++) {
1786 int dest_count = 0;
1787 action = splice_cmd->actions[i];
1788 state = splice_cmd->states[i];
1789
1790 if (action->out_ppm && !action->onchain_wallet)
1791 return do_fail(cmd, splice_cmd, JSONRPC2_INVALID_PARAMS,
1792 "Should be no out_ppm on final"
1793 " except for the wallet");
1794 if (splice_cmd->actions[i]->pays_fee) {
1795 if (pays_fee)
1796 return do_fail(cmd, splice_cmd,
1797 JSONRPC2_INVALID_PARAMS,
1798 "Only one item may pay fee");
1799 pays_fee++;
1800 }
1801 if (splice_cmd->actions[i]->channel_id)
1802 dest_count++;
1803 if (splice_cmd->actions[i]->bitcoin_address)
1804 dest_count++;
1805 if (splice_cmd->actions[i]->onchain_wallet)
1806 dest_count++;
1807 if (dest_count < 1)
1808 return do_fail(cmd, splice_cmd, JSONRPC2_INVALID_PARAMS,
1809 "Must specify 1 destination per");
1810 if (dest_count > 1)
1811 return do_fail(cmd, splice_cmd, JSONRPC2_INVALID_PARAMS,
1812 "Too many destinations per");
1813
1814 /* If user specifies both sats in and out, we just use the
1815 * larger of the two and subtract the smaller. */
1816 if (amount_sat_greater(action->in_sat, action->out_sat)) {
1817 if (!amount_sat_sub(&action->in_sat, action->in_sat,
1818 action->out_sat))
1819 return do_fail(cmd, splice_cmd,
1820 JSONRPC2_INVALID_PARAMS,
1821 "Unable to sub out_sat from"
1822 " in_sat");
1823 action->out_sat = amount_sat(0);
1824 } else {
1825 if (!amount_sat_sub(&action->out_sat, action->out_sat,
1826 action->in_sat))
1827 return do_fail(cmd, splice_cmd,
1828 JSONRPC2_INVALID_PARAMS,
1829 "Unable to sub in_sat from"
1830 " out_sat");

Callers 1

stfu_channels_get_resultFunction · 0.85

Calls 15

do_failFunction · 0.85
amount_sat_greaterFunction · 0.85
add_to_debug_logFunction · 0.85
amount_sat_is_zeroFunction · 0.85
tal_bytelenFunction · 0.85
psbt_append_outputFunction · 0.85
psbt_new_output_serialFunction · 0.85
continue_spliceFunction · 0.85
amount_satClass · 0.70

Tested by

no test coverage detected