Find all the utxos that are p2sh in our wallet */
| 561 | |
| 562 | /* Find all the utxos that are p2sh in our wallet */ |
| 563 | static struct command_result *listfunds_done(struct command *cmd, |
| 564 | const char *method, |
| 565 | const char *buf, |
| 566 | const jsmntok_t *result, |
| 567 | struct listfunds_info *info) |
| 568 | { |
| 569 | struct bitcoin_outpoint *utxos; |
| 570 | const jsmntok_t *outputs_tok, *tok; |
| 571 | size_t i; |
| 572 | struct txprepare *txp = info->txp; |
| 573 | |
| 574 | /* Find all the utxos in our wallet that are p2sh! */ |
| 575 | outputs_tok = json_get_member(buf, result, "outputs"); |
| 576 | txp->output_total = AMOUNT_SAT(0); |
| 577 | if (!outputs_tok) |
| 578 | plugin_err(cmd->plugin, |
| 579 | "`listfunds` payload has no outputs token: %.*s", |
| 580 | json_tok_full_len(result), |
| 581 | json_tok_full(buf, result)); |
| 582 | |
| 583 | utxos = tal_arr(cmd, struct bitcoin_outpoint, 0); |
| 584 | json_for_each_arr(i, tok, outputs_tok) { |
| 585 | struct bitcoin_outpoint prev_out; |
| 586 | struct amount_sat val; |
| 587 | bool is_reserved; |
| 588 | char *status; |
| 589 | const char *err; |
| 590 | |
| 591 | err = json_scan(tmpctx, buf, tok, |
| 592 | "{amount_msat:%" |
| 593 | ",status:%" |
| 594 | ",reserved:%" |
| 595 | ",txid:%" |
| 596 | ",output:%}", |
| 597 | JSON_SCAN(json_to_sat, &val), |
| 598 | JSON_SCAN_TAL(cmd, json_strdup, &status), |
| 599 | JSON_SCAN(json_to_bool, &is_reserved), |
| 600 | JSON_SCAN(json_to_txid, &prev_out.txid), |
| 601 | JSON_SCAN(json_to_number, &prev_out.n)); |
| 602 | if (err) |
| 603 | plugin_err(cmd->plugin, |
| 604 | "`listfunds` payload did not scan. %s: %.*s", |
| 605 | err, json_tok_full_len(result), |
| 606 | json_tok_full(buf, result)); |
| 607 | |
| 608 | /* Skip non-p2sh outputs */ |
| 609 | if (!json_get_member(buf, tok, "redeemscript")) |
| 610 | continue; |
| 611 | |
| 612 | /* only include confirmed + unconfirmed outputs */ |
| 613 | if (!streq(status, "confirmed") |
| 614 | && !streq(status, "unconfirmed")) |
| 615 | continue; |
| 616 | |
| 617 | if (!info->reservedok && is_reserved) |
| 618 | continue; |
| 619 | |
| 620 | tal_arr_expand(&utxos, prev_out); |
nothing calls this directly
no test coverage detected