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

Function print_offer_amount

devtools/bolt12-cli.c:89–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89static bool print_offer_amount(const struct bitcoin_blkid *chains,
90 const char *iso4217, u64 amount)
91{
92 const char *currency;
93 unsigned int minor_unit;
94 bool ok = true;
95
96 /* BOLT #12:
97 * - if a specific minimum `offer_amount` is required for successful payment:
98 * - MUST set `offer_amount` to the amount expected (per item).
99 * - MUST set `offer_amount` greater than zero.
100 * - if the currency for `offer_amount` is that of all entries in `chains`:
101 * - MUST specify `offer_amount` in multiples of the minimum lightning-payable unit
102 * (e.g. milli-satoshis for bitcoin).
103 * - otherwise:
104 * - MUST specify `offer_currency` `iso4217` as an ISO 4217 three-letter code.
105 * - MUST specify `offer_amount` in the currency unit adjusted by the ISO 4217
106 * exponent (e.g. USD cents).
107 * - MUST set `offer_description` to a complete description of the purpose
108 * of the payment.
109 * - otherwise:
110 * - MUST NOT set `offer_amount`
111 * - MUST NOT set `offer_currency`
112 * - MAY set `offer_description`
113 */
114 if (!iso4217) {
115 if (tal_count(chains) == 0)
116 currency = "bc";
117 else {
118 const struct chainparams *ch;
119
120 ch = chainparams_by_chainhash(&chains[0]);
121 if (!ch) {
122 currency = tal_fmt(tmpctx, "UNKNOWN CHAINHASH %s",
123 fmt_bitcoin_blkid(tmpctx,
124 &chains[0]));
125 ok = false;
126 } else
127 currency = ch->lightning_hrp;
128 }
129 minor_unit = 11;
130 } else {
131 const struct iso4217_name_and_divisor *iso;
132 iso = find_iso4217(iso4217, tal_bytelen(iso4217));
133 if (iso) {
134 minor_unit = iso->minor_unit;
135 currency = iso->name;
136 } else {
137 minor_unit = 0;
138 currency = tal_fmt(tmpctx, "%.*s (UNKNOWN CURRENCY)",
139 (int)tal_bytelen(iso4217), iso4217);
140 ok = false;
141 }
142 }
143
144 if (!minor_unit)
145 printf("offer_amount: %"PRIu64"%s\n", amount, currency);
146 else {

Callers 1

mainFunction · 0.85

Calls 4

fmt_bitcoin_blkidFunction · 0.85
find_iso4217Function · 0.85
tal_bytelenFunction · 0.85
chainparams_by_chainhashFunction · 0.50

Tested by

no test coverage detected