fundpsbt/utxopsbt gets a viable PSBT for us. */
| 276 | |
| 277 | /* fundpsbt/utxopsbt gets a viable PSBT for us. */ |
| 278 | static 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); |
nothing calls this directly
no test coverage detected