| 329 | struct multiwithdraw_command *mw); |
| 330 | |
| 331 | static struct command_result *start_mw(struct multiwithdraw_command *mw) |
| 332 | { |
| 333 | size_t startweight; |
| 334 | struct out_req *req; |
| 335 | |
| 336 | plugin_log(mw->cmd->plugin, LOG_DBG, |
| 337 | "multiwithdraw %"PRIu64": start.", |
| 338 | mw->id); |
| 339 | |
| 340 | startweight = bitcoin_tx_core_weight(1, tal_count(mw->outputs)); |
| 341 | for (size_t i = 0; i < tal_count(mw->outputs); ++i) { |
| 342 | struct multiwithdraw_destination *dest; |
| 343 | dest = &mw->outputs[i]; |
| 344 | startweight += bitcoin_tx_output_weight( |
| 345 | tal_count(dest->script)); |
| 346 | } |
| 347 | |
| 348 | if (mw->utxos) { |
| 349 | plugin_log(mw->cmd->plugin, LOG_DBG, |
| 350 | "multiwithdraw %"PRIu64": utxopsbt.", |
| 351 | mw->id); |
| 352 | req = jsonrpc_request_start(mw->cmd->plugin, |
| 353 | mw->cmd, |
| 354 | "utxopsbt", |
| 355 | &mw_after_fundpsbt, |
| 356 | &mw_forward_error, |
| 357 | mw); |
| 358 | json_add_bool(req->js, "reservedok", false); |
| 359 | json_add_jsonstr(req->js, "utxos", mw->utxos, strlen(mw->utxos)); |
| 360 | } else { |
| 361 | plugin_log(mw->cmd->plugin, LOG_DBG, |
| 362 | "multiwithdraw %"PRIu64": fundpsbt.", |
| 363 | mw->id); |
| 364 | req = jsonrpc_request_start(mw->cmd->plugin, |
| 365 | mw->cmd, |
| 366 | "fundpsbt", |
| 367 | &mw_after_fundpsbt, |
| 368 | &mw_forward_error, |
| 369 | mw); |
| 370 | json_add_u32(req->js, "minconf", *mw->minconf); |
| 371 | } |
| 372 | if (mw->has_all) |
| 373 | json_add_string(req->js, "satoshi", "all"); |
| 374 | else { |
| 375 | struct amount_sat sum = AMOUNT_SAT(0); |
| 376 | for (size_t i = 0; i < tal_count(mw->outputs); ++i) |
| 377 | if (!amount_sat_add(&sum, sum, mw->outputs[i].amount)) |
| 378 | return mw_fail(mw, |
| 379 | FUND_CANNOT_AFFORD, |
| 380 | "Overflow in amount sum."); |
| 381 | json_add_string(req->js, "satoshi", |
| 382 | type_to_string(tmpctx, struct amount_sat, |
| 383 | &sum)); |
| 384 | } |
| 385 | json_add_string(req->js, "feerate", mw->feerate); |
| 386 | json_add_u64(req->js, "startweight", startweight); |
| 387 | |
| 388 | return send_outreq(mw->cmd->plugin, req); |
no test coverage detected