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

Function calculate_amounts

common/splice_script.c:2274–2448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2272}
2273
2274static struct splice_script_error *calculate_amounts(const tal_t *ctx,
2275 struct token ***tokens_inout)
2276{
2277 struct token **input = *tokens_inout;
2278 struct token **tokens;
2279 size_t n, left_wild_index, left_wilds, right_wilds;
2280 u32 left_used_ppm;
2281 bool right_used_ppm;
2282 struct amount_sat left_total, right_total;
2283 struct token *left_wildcard_token, *left_percent_token, *wallet_token;
2284
2285 left_wilds = 0;
2286 right_wilds = 0;
2287 left_used_ppm = 0;
2288 right_used_ppm = false;
2289 left_total = AMOUNT_SAT(0);
2290 right_total = AMOUNT_SAT(0);
2291 left_wildcard_token = NULL;
2292 left_percent_token = NULL;
2293 for (size_t i = 0; i < tal_count(input); i++) {
2294 switch(input[i]->type) {
2295 case TOK_CHAR:
2296 case TOK_ATSYM:
2297 case TOK_PLUS:
2298 case TOK_MINUS:
2299 case TOK_COLON:
2300 case TOK_LEASERATE:
2301 case TOK_ARROW:
2302 case TOK_PIPE:
2303 case TOK_STR:
2304 case TOK_SATS:
2305 case TOK_PERCENT:
2306 case TOK_QUESTION:
2307 case TOK_WILDCARD:
2308 case TOK_FEE:
2309 case TOK_CHANID:
2310 case TOK_WALLET:
2311 case TOK_FEERATE:
2312 case TOK_NODEID:
2313 case TOK_BTCADDR:
2314 case TOK_CHANQUERY:
2315 case TOK_MULTI_CHANID:
2316 case TOK_LEASEREQ:
2317 case TOK_DELIMITER:
2318 return new_error(ctx, INVALID_TOKEN, input[i],
2319 "calculate_amounts");
2320 case TOK_SEGMENT:
2321 if (input[i]->left->type == TOK_WILDCARD) {
2322 left_wildcard_token = input[i]->left;
2323 left_wilds++;
2324 }
2325 if (input[i]->right->type == TOK_WILDCARD)
2326 right_wilds++;
2327 if (input[i]->left->type == TOK_SATS)
2328 if (!amount_sat_add(&left_total, left_total,
2329 input[i]->left->amount_sat))
2330 return new_error(ctx, INTERNAL_ERROR,
2331 input[i]->left,

Callers 1

parse_splice_scriptFunction · 0.85

Calls 9

new_errorFunction · 0.85
amount_sat_greaterFunction · 0.85
new_error_msgFunction · 0.85
tal_freeFunction · 0.85
amount_sat_is_zeroFunction · 0.85
new_tokenFunction · 0.85
amount_sat_addFunction · 0.70
fmt_amount_satFunction · 0.70
amount_sat_eqFunction · 0.70

Tested by

no test coverage detected