| 575 | } |
| 576 | |
| 577 | static struct command_result * |
| 578 | listfunds_success(struct command *cmd, |
| 579 | const char *method, |
| 580 | const char *buf, |
| 581 | const jsmntok_t *result, |
| 582 | struct open_info *info) |
| 583 | { |
| 584 | struct amount_sat available_funds, committed_funds, total_fee; |
| 585 | const jsmntok_t *outputs_tok, *tok; |
| 586 | struct out_req *req; |
| 587 | struct bitcoin_outpoint **avail_prev_outs; |
| 588 | size_t i; |
| 589 | const char *funding_err; |
| 590 | |
| 591 | /* We only use this for RBFs, when there's a prev_outs list */ |
| 592 | struct funder_utxo **avail_utxos = tal_arr(cmd, struct funder_utxo *, 0); |
| 593 | |
| 594 | outputs_tok = json_get_member(buf, result, "outputs"); |
| 595 | if (!outputs_tok) |
| 596 | plugin_err(cmd->plugin, |
| 597 | "`listfunds` payload has no outputs token: %.*s", |
| 598 | json_tok_full_len(result), |
| 599 | json_tok_full(buf, result)); |
| 600 | |
| 601 | available_funds = AMOUNT_SAT(0); |
| 602 | committed_funds = AMOUNT_SAT(0); |
| 603 | total_fee = AMOUNT_SAT(0); |
| 604 | avail_prev_outs = tal_arr(info, struct bitcoin_outpoint *, 0); |
| 605 | json_for_each_arr(i, tok, outputs_tok) { |
| 606 | struct funder_utxo *utxo; |
| 607 | struct amount_sat est_fee; |
| 608 | bool is_reserved; |
| 609 | struct bitcoin_outpoint *prev_out; |
| 610 | char *status; |
| 611 | const char *err; |
| 612 | |
| 613 | utxo = tal(cmd, struct funder_utxo); |
| 614 | err = json_scan(tmpctx, buf, tok, |
| 615 | "{amount_msat:%" |
| 616 | ",status:%" |
| 617 | ",reserved:%" |
| 618 | ",txid:%" |
| 619 | ",output:%}", |
| 620 | JSON_SCAN(json_to_msat_as_sats, &utxo->val), |
| 621 | JSON_SCAN_TAL(cmd, json_strdup, &status), |
| 622 | JSON_SCAN(json_to_bool, &is_reserved), |
| 623 | JSON_SCAN(json_to_txid, &utxo->out.txid), |
| 624 | JSON_SCAN(json_to_number, &utxo->out.n)); |
| 625 | if (err) |
| 626 | plugin_err(cmd->plugin, |
| 627 | "`listfunds` payload did not scan. %s: %.*s", |
| 628 | err, json_tok_full_len(result), |
| 629 | json_tok_full(buf, result)); |
| 630 | |
| 631 | /* v2 opens don't support p2sh-wrapped inputs */ |
| 632 | if (json_get_member(buf, tok, "redeemscript")) |
| 633 | continue; |
| 634 |
nothing calls this directly
no test coverage detected