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

Function start_mw

plugins/spender/multiwithdraw.c:330–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

json_multiwithdrawFunction · 0.85

Calls 12

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

Tested by

no test coverage detected