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

Function guess_type

plugins/offers.c:580–644  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578}
579
580static enum likely_type guess_type(const char *buffer, const jsmntok_t *tok)
581{
582 jsmntok_t tok_copy = *tok;
583
584 if (tok_pull(buffer, &tok_copy, "lno1"))
585 return LIKELY_BOLT12_OFFER;
586 if (tok_pull(buffer, &tok_copy, "lni1"))
587 return LIKELY_BOLT12_INV;
588 if (tok_pull(buffer, &tok_copy, "lnr1"))
589 return LIKELY_BOLT12_INVREQ;
590 if (tok_pull(buffer, &tok_copy, "lnp1"))
591 return LIKELY_BOLT12_PAYER_PROOF;
592 if (tok_pull(buffer, &tok_copy, "clnemerg1"))
593 return LIKELY_EMERGENCY_RECOVER;
594 /* BOLT #11:
595 *
596 * The human-readable part of a Lightning invoice consists of
597 * two sections:
598 *
599 * 1. `prefix`: `ln` + BIP-0173 currency prefix (e.g. `lnbc`
600 * for Bitcoin mainnet, `lntb` for Bitcoin testnet, `lntbs`
601 * for Bitcoin signet, and `lnbcrt` for Bitcoin regtest)
602 *
603 * 1. `amount`: optional number in that currency, followed by
604 * an optional `multiplier` letter. The unit encoded here
605 * is the 'social' convention of a payment unit -- in the
606 * case of Bitcoin the unit is 'bitcoin' NOT satoshis.
607 */
608 if (tok_pull(buffer, &tok_copy, "lnbcrt")
609 || tok_pull(buffer, &tok_copy, "lnbc")
610 || tok_pull(buffer, &tok_copy, "lntbs")
611 || tok_pull(buffer, &tok_copy, "lntb")) {
612 /* Now find last '1', which separates hrp from data */
613 const char *delim = memrchr(buffer + tok_copy.start, '1',
614 tok_copy.end - tok_copy.start);
615 if (!delim)
616 return LIKELY_OTHER;
617
618 /* BOLT #11:
619 * The following `multiplier` letters are defined:
620 *
621 * * `m` (milli): multiply by 0.001
622 * * `u` (micro): multiply by 0.000001
623 * * `n` (nano): multiply by 0.000000001
624 * * `p` (pico): multiply by 0.000000000001
625 */
626 delim--;
627 if (delim > buffer + tok_copy.start
628 && (tolower(*delim) == 'm'
629 || tolower(*delim) == 'u'
630 || tolower(*delim) == 'n'
631 || tolower(*delim) == 'p')) {
632 delim--;
633 }
634
635 while (delim >= buffer + tok_copy.start) {
636 if (!cisdigit(*delim))
637 return LIKELY_OTHER;

Callers 2

param_decodableFunction · 0.85
run_likely_testsFunction · 0.85

Calls 3

tok_pullFunction · 0.85
memrchrFunction · 0.85
cisdigitFunction · 0.85

Tested by 1

run_likely_testsFunction · 0.68