MCPcopy Create free account
hub / github.com/ElementsProject/lightning / start_mw

Function start_mw

plugins/spender/multiwithdraw.c:331–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329 struct multiwithdraw_command *mw);
330
331static 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);

Callers 1

json_multiwithdrawFunction · 0.85

Calls 12

bitcoin_tx_core_weightFunction · 0.85
bitcoin_tx_output_weightFunction · 0.85
json_add_jsonstrFunction · 0.85
mw_failFunction · 0.85
plugin_logFunction · 0.50
json_add_boolFunction · 0.50
json_add_u32Function · 0.50
json_add_stringFunction · 0.50
amount_sat_addFunction · 0.50
type_to_stringClass · 0.50
json_add_u64Function · 0.50
send_outreqFunction · 0.50

Tested by

no test coverage detected