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

Function compute_mfc_all

plugins/spender/multifundchannel.c:1271–1321  ·  view source on GitHub ↗

If one of the destinations specified "all", figure out how much that is. */

Source from the content-addressed store, hash-verified

1269
1270/* If one of the destinations specified "all", figure out how much that is. */
1271static struct command_result *
1272compute_mfc_all(struct multifundchannel_command *mfc)
1273{
1274 size_t all_index = SIZE_MAX;
1275 struct multifundchannel_destination *all_dest;
1276
1277 assert(has_all(mfc));
1278
1279 for (size_t i = 0; i < tal_count(mfc->destinations); ++i) {
1280 struct multifundchannel_destination *dest;
1281 dest = &mfc->destinations[i];
1282 if (dest->all) {
1283 assert(all_index == SIZE_MAX);
1284 all_index = i;
1285 continue;
1286 }
1287 /* Subtract the amount from the excess. */
1288 if (!amount_sat_sub(&mfc->excess_sat,
1289 mfc->excess_sat, dest->amount))
1290 /* Not enough funds! */
1291 return mfc_fail(mfc, FUND_CANNOT_AFFORD,
1292 "Insufficient funds.");
1293 }
1294 assert(all_index != SIZE_MAX);
1295 all_dest = &mfc->destinations[all_index];
1296
1297 /* Is the excess above the dust amount? */
1298 if (amount_sat_less(mfc->excess_sat, chainparams->dust_limit))
1299 return mfc_fail(mfc, FUND_OUTPUT_IS_DUST,
1300 "Output 'all' %s would be dust",
1301 type_to_string(tmpctx, struct amount_sat,
1302 &mfc->excess_sat));
1303
1304 /* Assign the remainder to the 'all' output. */
1305 all_dest->amount = mfc->excess_sat;
1306 if (!feature_negotiated(plugin_feature_set(mfc->cmd->plugin),
1307 all_dest->their_features,
1308 OPT_LARGE_CHANNELS)
1309 && amount_sat_greater(all_dest->amount,
1310 chainparams->max_funding))
1311 all_dest->amount = chainparams->max_funding;
1312 /* Remove it from the excess. */
1313 bool ok = amount_sat_sub(&mfc->excess_sat,
1314 mfc->excess_sat, all_dest->amount);
1315 assert(ok);
1316 /* Remove the 'all' flag. */
1317 all_dest->all = false;
1318
1319 /* Continue. */
1320 return handle_mfc_change(mfc);
1321}
1322
1323static struct command_result *
1324after_fundpsbt(struct command *cmd,

Callers 1

after_fundpsbtFunction · 0.85

Calls 9

has_allFunction · 0.85
mfc_failFunction · 0.85
amount_sat_lessFunction · 0.85
plugin_feature_setFunction · 0.85
amount_sat_greaterFunction · 0.85
handle_mfc_changeFunction · 0.85
amount_sat_subFunction · 0.50
type_to_stringClass · 0.50
feature_negotiatedFunction · 0.50

Tested by

no test coverage detected