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

Function start_mw

plugins/spender/multiwithdraw.c:332–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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