| 497 | } |
| 498 | |
| 499 | static struct command_result *json_withdraw(struct command *cmd, |
| 500 | const char *buffer, |
| 501 | const jsmntok_t *params) |
| 502 | { |
| 503 | struct txprepare *txp = tal(cmd, struct txprepare); |
| 504 | struct amount_sat *amount; |
| 505 | const u8 *scriptpubkey; |
| 506 | const char *feerate; |
| 507 | struct bitcoin_outpoint *utxos; |
| 508 | unsigned int *minconf; |
| 509 | |
| 510 | if (!param(cmd, buffer, params, |
| 511 | p_req("destination", param_bitcoin_address, |
| 512 | &scriptpubkey), |
| 513 | p_req("satoshi", param_sat_or_all, &amount), |
| 514 | p_opt("feerate", param_string, &feerate), |
| 515 | p_opt_def("minconf", param_number, &minconf, 1), |
| 516 | p_opt("utxos", param_outpoint_arr, &utxos), |
| 517 | NULL)) |
| 518 | return command_param_failed(); |
| 519 | |
| 520 | /* Convert destination/satoshi into array as txprepare expects */ |
| 521 | txp->outputs = tal_arr(txp, struct tx_output, 1); |
| 522 | |
| 523 | if (amount_sat_eq(*amount, AMOUNT_SAT(-1ULL))) { |
| 524 | txp->all_output_idx = 0; |
| 525 | txp->output_total = AMOUNT_SAT(0); |
| 526 | } else { |
| 527 | txp->all_output_idx = -1; |
| 528 | txp->output_total = *amount; |
| 529 | } |
| 530 | txp->outputs[0].amount = *amount; |
| 531 | txp->outputs[0].script = scriptpubkey; |
| 532 | txp->outputs[0].is_to_external = true; |
| 533 | txp->weight = bitcoin_tx_core_weight(1, tal_count(txp->outputs)) |
| 534 | + bitcoin_tx_output_weight(tal_bytelen(scriptpubkey)); |
| 535 | |
| 536 | return txprepare_continue(cmd, txp, feerate, minconf, utxos, true); |
| 537 | } |
| 538 | |
| 539 | static const struct plugin_command commands[] = { |
| 540 | { |
nothing calls this directly
no test coverage detected