* json_fundchannel_start - Entrypoint for funding a channel */
| 1098 | * json_fundchannel_start - Entrypoint for funding a channel |
| 1099 | */ |
| 1100 | static struct command_result *json_fundchannel_start(struct command *cmd, |
| 1101 | const char *buffer, |
| 1102 | const jsmntok_t *obj UNNEEDED, |
| 1103 | const jsmntok_t *params) |
| 1104 | { |
| 1105 | struct funding_channel * fc = tal(cmd, struct funding_channel); |
| 1106 | struct node_id *id; |
| 1107 | struct peer *peer; |
| 1108 | bool *announce_channel; |
| 1109 | u32 *feerate_per_kw, *mindepth; |
| 1110 | int fds[2]; |
| 1111 | struct amount_sat *amount, *reserve; |
| 1112 | struct amount_msat *push_msat; |
| 1113 | u32 *upfront_shutdown_script_wallet_index; |
| 1114 | struct channel_id tmp_channel_id; |
| 1115 | |
| 1116 | fc->cmd = cmd; |
| 1117 | fc->cancels = tal_arr(fc, struct command *, 0); |
| 1118 | fc->uc = NULL; |
| 1119 | fc->inflight = false; |
| 1120 | fc->funding_scriptpubkey = NULL; |
| 1121 | |
| 1122 | if (!param(fc->cmd, buffer, params, |
| 1123 | p_req("id", param_node_id, &id), |
| 1124 | p_req("amount", param_sat, &amount), |
| 1125 | p_opt("feerate", param_feerate, &feerate_per_kw), |
| 1126 | p_opt_def("announce", param_bool, &announce_channel, true), |
| 1127 | p_opt("close_to", param_bitcoin_address, &fc->our_upfront_shutdown_script), |
| 1128 | p_opt("push_msat", param_msat, &push_msat), |
| 1129 | p_opt_def("mindepth", param_u32, &mindepth, cmd->ld->config.anchor_confirms), |
| 1130 | p_opt("reserve", param_sat, &reserve), |
| 1131 | NULL)) |
| 1132 | return command_param_failed(); |
| 1133 | |
| 1134 | if (push_msat && amount_msat_greater_sat(*push_msat, *amount)) |
| 1135 | return command_fail(cmd, FUND_CANNOT_AFFORD, |
| 1136 | "Requested to push_msat of %s is greater than " |
| 1137 | "available funding amount %s", |
| 1138 | type_to_string(tmpctx, struct amount_msat, push_msat), |
| 1139 | type_to_string(tmpctx, struct amount_sat, amount)); |
| 1140 | |
| 1141 | fc->funding_sats = *amount; |
| 1142 | if (!feerate_per_kw) { |
| 1143 | feerate_per_kw = tal(cmd, u32); |
| 1144 | *feerate_per_kw = opening_feerate(cmd->ld->topology); |
| 1145 | if (!*feerate_per_kw) { |
| 1146 | return command_fail(cmd, LIGHTNINGD, |
| 1147 | "Cannot estimate fees"); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | if (*feerate_per_kw < feerate_floor()) { |
| 1152 | return command_fail(cmd, LIGHTNINGD, |
| 1153 | "Feerate below feerate floor"); |
| 1154 | } |
| 1155 | |
| 1156 | if (!topology_synced(cmd->ld->topology)) { |
| 1157 | return command_fail(cmd, FUNDING_STILL_SYNCING_BITCOIN, |
nothing calls this directly
no test coverage detected