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

Function json_openchannel_bump

lightningd/dual_open_control.c:2255–2392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2253}
2254
2255static struct command_result *
2256json_openchannel_bump(struct command *cmd,
2257 const char *buffer,
2258 const jsmntok_t *obj UNNEEDED,
2259 const jsmntok_t *params)
2260{
2261 struct channel_id *cid;
2262 struct channel *channel;
2263 struct amount_sat *amount, psbt_val;
2264 struct wally_psbt *psbt;
2265 u32 last_feerate_perkw, next_feerate_min, *feerate_per_kw_funding;
2266 struct open_attempt *oa;
2267
2268 if (!param(cmd, buffer, params,
2269 p_req("channel_id", param_channel_id, &cid),
2270 p_req("amount", param_sat, &amount),
2271 p_req("initialpsbt", param_psbt, &psbt),
2272 p_opt("funding_feerate", param_feerate,
2273 &feerate_per_kw_funding),
2274 NULL))
2275 return command_param_failed();
2276
2277 psbt_val = AMOUNT_SAT(0);
2278 for (size_t i = 0; i < psbt->num_inputs; i++) {
2279 struct amount_sat in_amt = psbt_input_get_amount(psbt, i);
2280 if (!amount_sat_add(&psbt_val, psbt_val, in_amt))
2281 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2282 "Overflow in adding PSBT input"
2283 " values. %s",
2284 type_to_string(tmpctx,
2285 struct wally_psbt,
2286 psbt));
2287 }
2288
2289 /* If they don't pass in at least enough in the PSBT to cover
2290 * their amount, nope */
2291 if (!amount_sat_greater(psbt_val, *amount))
2292 return command_fail(cmd, FUND_CANNOT_AFFORD,
2293 "Provided PSBT cannot afford funding of "
2294 "amount %s. %s",
2295 type_to_string(tmpctx,
2296 struct amount_sat,
2297 amount),
2298 type_to_string(tmpctx,
2299 struct wally_psbt,
2300 psbt));
2301
2302 if (!topology_synced(cmd->ld->topology)) {
2303 return command_fail(cmd, FUNDING_STILL_SYNCING_BITCOIN,
2304 "Still syncing with bitcoin network");
2305 }
2306
2307 /* Are we in a state where we can attempt an RBF? */
2308 channel = channel_by_cid(cmd->ld, cid);
2309 if (!channel)
2310 return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
2311 "Unknown channel %s",
2312 type_to_string(tmpctx, struct channel_id,

Callers

nothing calls this directly

Calls 15

amount_sat_greaterFunction · 0.85
topology_syncedFunction · 0.85
channel_by_cidFunction · 0.85
new_channel_open_attemptFunction · 0.85
psbt_add_serialsFunction · 0.85
psbt_has_required_fieldsFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
channel_state_nameFunction · 0.70
channel_state_strFunction · 0.70
subd_send_msgFunction · 0.70

Tested by

no test coverage detected