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

Function psbt_created

plugins/txprepare.c:278–346  ·  view source on GitHub ↗

fundpsbt/utxopsbt gets a viable PSBT for us. */

Source from the content-addressed store, hash-verified

276
277/* fundpsbt/utxopsbt gets a viable PSBT for us. */
278static struct command_result *psbt_created(struct command *cmd,
279 const char *buf,
280 const jsmntok_t *result,
281 struct txprepare *txp)
282{
283 const jsmntok_t *psbttok;
284 struct out_req *req;
285 struct amount_msat excess_msat;
286 struct amount_sat excess;
287 u32 weight;
288
289 psbttok = json_get_member(buf, result, "psbt");
290 txp->psbt = json_tok_psbt(txp, buf, psbttok);
291 if (!txp->psbt)
292 return command_fail(cmd, LIGHTNINGD,
293 "Unparsable psbt: '%.*s'",
294 psbttok->end - psbttok->start,
295 buf + psbttok->start);
296
297 if (!json_to_number(buf, json_get_member(buf, result, "feerate_per_kw"),
298 &txp->feerate))
299 return command_fail(cmd, LIGHTNINGD,
300 "Unparsable feerate_per_kw: '%.*s'",
301 result->end - result->start,
302 buf + result->start);
303
304 if (!json_to_msat(buf, json_get_member(buf, result, "excess_msat"),
305 &excess_msat)
306 || !amount_msat_to_sat(&excess, excess_msat))
307 return command_fail(cmd, LIGHTNINGD,
308 "Unparsable excess_msat: '%.*s'",
309 result->end - result->start,
310 buf + result->start);
311
312 if (!json_to_number(buf, json_get_member(buf, result,
313 "estimated_final_weight"),
314 &weight))
315 return command_fail(cmd, LIGHTNINGD,
316 "Unparsable estimated_final_weight: '%.*s'",
317 result->end - result->start,
318 buf + result->start);
319
320 /* If we have an "all" output, now we can derive its value: excess
321 * in this case will be total value after inputs paid for themselves. */
322 if (txp->all_output_idx != -1) {
323 if (!resolve_all_output_amount(txp, excess))
324 return command_fail(cmd, FUND_CANNOT_AFFORD,
325 "Insufficient funds to make"
326 " 'all' output");
327
328 /* Never produce change if they asked for all */
329 excess = AMOUNT_SAT(0);
330 }
331
332 /* So, do we need change? */
333 txp->change_amount = change_amount(excess, txp->feerate, weight);
334 if (amount_sat_eq(txp->change_amount, AMOUNT_SAT(0)))
335 return finish_txprepare(cmd, txp);

Callers

nothing calls this directly

Calls 11

json_tok_psbtFunction · 0.85
amount_msat_to_satFunction · 0.85
change_amountFunction · 0.85
finish_txprepareFunction · 0.85
command_failFunction · 0.70
send_outreqFunction · 0.70
json_get_memberFunction · 0.50
json_to_numberFunction · 0.50
json_to_msatFunction · 0.50
amount_sat_eqFunction · 0.50

Tested by

no test coverage detected