fundpsbt/utxopsbt gets a viable PSBT for us. */
| 286 | |
| 287 | /* fundpsbt/utxopsbt gets a viable PSBT for us. */ |
| 288 | static struct command_result *psbt_created(struct command *cmd, |
| 289 | const char *method, |
| 290 | const char *buf, |
| 291 | const jsmntok_t *result, |
| 292 | struct txprepare *txp) |
| 293 | { |
| 294 | const jsmntok_t *psbttok; |
| 295 | struct amount_msat excess_msat; |
| 296 | struct amount_sat excess; |
| 297 | u32 weight; |
| 298 | |
| 299 | psbttok = json_get_member(buf, result, "psbt"); |
| 300 | txp->psbt = json_tok_psbt(txp, buf, psbttok); |
| 301 | if (!txp->psbt) |
| 302 | return command_fail(cmd, LIGHTNINGD, |
| 303 | "Unparsable psbt: '%.*s'", |
| 304 | psbttok->end - psbttok->start, |
| 305 | buf + psbttok->start); |
| 306 | |
| 307 | if (!psbt_set_version(txp->psbt, 2)) { |
| 308 | return command_fail(cmd, LIGHTNINGD, |
| 309 | "Unable to convert PSBT to version 2."); |
| 310 | } |
| 311 | |
| 312 | if (!json_to_number(buf, json_get_member(buf, result, "feerate_per_kw"), |
| 313 | &txp->feerate)) |
| 314 | return command_fail(cmd, LIGHTNINGD, |
| 315 | "Unparsable feerate_per_kw: '%.*s'", |
| 316 | result->end - result->start, |
| 317 | buf + result->start); |
| 318 | |
| 319 | if (!json_to_msat(buf, json_get_member(buf, result, "excess_msat"), |
| 320 | &excess_msat) |
| 321 | || !amount_msat_to_sat(&excess, excess_msat)) |
| 322 | return command_fail(cmd, LIGHTNINGD, |
| 323 | "Unparsable excess_msat: '%.*s'", |
| 324 | result->end - result->start, |
| 325 | buf + result->start); |
| 326 | |
| 327 | if (!json_to_number(buf, json_get_member(buf, result, |
| 328 | "estimated_final_weight"), |
| 329 | &weight)) |
| 330 | return command_fail(cmd, LIGHTNINGD, |
| 331 | "Unparsable estimated_final_weight: '%.*s'", |
| 332 | result->end - result->start, |
| 333 | buf + result->start); |
| 334 | |
| 335 | /* If we have an "all" output, we now know its value ("excess_msat") */ |
| 336 | if (txp->all_output_idx != -1) { |
| 337 | /* Subtract any other outputs they specified! */ |
| 338 | for (size_t i = 0; i < tal_count(txp->outputs); i++) { |
| 339 | if (i == txp->all_output_idx) |
| 340 | continue; |
| 341 | if (!amount_sat_sub(&excess, excess, txp->outputs[i].amount)) { |
| 342 | return command_fail(cmd, FUND_CANNOT_AFFORD, |
| 343 | "Could not afford output %zu", i); |
| 344 | } |
| 345 | } |
nothing calls this directly
no test coverage detected