| 1633 | } |
| 1634 | |
| 1635 | static struct command_result *continue_splice(struct command *cmd, |
| 1636 | struct splice_cmd *splice_cmd) |
| 1637 | { |
| 1638 | struct splice_script_result *action; |
| 1639 | struct splice_cmd_action_state *state; |
| 1640 | struct command_result *result; |
| 1641 | size_t index; |
| 1642 | bool multiple_require_sigs; |
| 1643 | struct splice_script_result *funding_wallet_action = NULL; |
| 1644 | size_t funding_wallet_index; |
| 1645 | |
| 1646 | add_to_debug_log(splice_cmd, "continue_splice"); |
| 1647 | |
| 1648 | if (!splice_cmd->feerate_per_kw) |
| 1649 | return load_feerate(cmd, splice_cmd); |
| 1650 | |
| 1651 | funding_wallet_action = input_wallet(splice_cmd, &funding_wallet_index); |
| 1652 | |
| 1653 | /* On first pass we add wallet actions that contribute funds but only |
| 1654 | * if it is a static amount */ |
| 1655 | if (funding_wallet_action |
| 1656 | && splice_cmd->states[funding_wallet_index]->state == SPLICE_CMD_NONE |
| 1657 | && !funding_wallet_action->out_ppm && !funding_wallet_action->pays_fee) { |
| 1658 | |
| 1659 | funding_wallet_action->out_sat = splice_cmd->needed_funds; |
| 1660 | plugin_log(cmd->plugin, LOG_INFORM, "funding static" |
| 1661 | " wallet inputs for %s", |
| 1662 | fmt_amount_sat(tmpctx, funding_wallet_action->out_sat)); |
| 1663 | return onchain_wallet_fund(cmd, splice_cmd, |
| 1664 | funding_wallet_index, AMOUNT_SAT(0)); |
| 1665 | } |
| 1666 | |
| 1667 | if (!splice_cmd->fee_calculated) { |
| 1668 | |
| 1669 | result = handle_fee_and_ppm(cmd, splice_cmd); |
| 1670 | if (result) |
| 1671 | return result; |
| 1672 | |
| 1673 | splice_cmd->fee_calculated = true; |
| 1674 | } |
| 1675 | |
| 1676 | /* Only after fee calcualtion can we add wallet actions taking funds */ |
| 1677 | for (size_t i = 0; i < tal_count(splice_cmd->actions); i++) { |
| 1678 | action = splice_cmd->actions[i]; |
| 1679 | state = splice_cmd->states[i]; |
| 1680 | if (state->state != SPLICE_CMD_NONE) |
| 1681 | continue; |
| 1682 | if (!action->onchain_wallet) |
| 1683 | continue; |
| 1684 | /* Add output for wallet funds */ |
| 1685 | if (amount_sat_less(action->in_sat, chainparams->dust_limit)) { |
| 1686 | plugin_log(cmd->plugin, LOG_INFORM, "Adding a" |
| 1687 | " wallet output of %s is below" |
| 1688 | " dust_limit of %s. Leaving dust as" |
| 1689 | " contribution to fee", |
| 1690 | fmt_amount_sat(tmpctx, action->in_sat), |
| 1691 | fmt_amount_sat(tmpctx, chainparams->dust_limit)); |
| 1692 | } else { |
no test coverage detected