Browse Source

BOLT 11 human-readable formatting changes

json-streaming
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
b287f2f007
  1. 2
      Makefile
  2. 36
      common/bolt11.c

2
Makefile

@ -9,7 +9,7 @@ CCANDIR := ccan
# Where we keep the BOLT RFCs # Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/ BOLTDIR := ../lightning-rfc/
BOLTVERSION := fd9da9b95eb5d585252d7e749212151502e0cc17 BOLTVERSION := 21e3688e843f82267b3970cda69fa93158dc9517
-include config.vars -include config.vars

36
common/bolt11.c

@ -498,7 +498,8 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
/* BOLT #11: /* BOLT #11:
* *
* A reader MUST fail if it does not understand the `prefix`. * A reader:
* - MUST fail if it does not understand the `prefix`
*/ */
if (!strstarts(prefix, "ln")) if (!strstarts(prefix, "ln"))
return decode_fail(b11, fail, return decode_fail(b11, fail,
@ -510,14 +511,13 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
/* BOLT #11: /* BOLT #11:
* *
* A reader SHOULD fail if `amount` contains a non-digit or * - If the `amount` is empty:
* is followed by anything except a `multiplier` in the table * */
* above. */
amountstr = tal_strdup(tmpctx, hrp + strlen(prefix)); amountstr = tal_strdup(tmpctx, hrp + strlen(prefix));
if (streq(amountstr, "")) { if (streq(amountstr, "")) {
/* BOLT #11: /* BOLT #11:
* *
* A reader SHOULD indicate if amount is unspecified * - SHOULD indicate if amount is unspecified
*/ */
b11->msatoshi = NULL; b11->msatoshi = NULL;
} else { } else {
@ -537,10 +537,9 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
/* BOLT #11: /* BOLT #11:
* *
* A reader SHOULD fail if `amount` contains a non-digit or * MUST fail if `amount` contains a non-digit or is followed by
* is followed by anything except a `multiplier` in the table * anything except a `multiplier` in the table above
* above. **/
*/
amount = strtoull(amountstr, &end, 10); amount = strtoull(amountstr, &end, 10);
if (amount == ULLONG_MAX && errno == ERANGE) if (amount == ULLONG_MAX && errno == ERANGE)
return decode_fail(b11, fail, return decode_fail(b11, fail,
@ -549,7 +548,12 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
return decode_fail(b11, fail, return decode_fail(b11, fail,
"Invalid amount postfix '%s'", end); "Invalid amount postfix '%s'", end);
/* Convert to millisatoshis. */ /* BOLT #11:
*
* - If the `multiplier` is present:
* - MUST multiply `amount` by the `multiplier`
* value to derive the amount required for payment
**/
b11->msatoshi = tal(b11, u64); b11->msatoshi = tal(b11, u64);
*b11->msatoshi = amount * m10 / 10; *b11->msatoshi = amount * m10 / 10;
} }
@ -873,9 +877,15 @@ char *bolt11_encode_(const tal_t *ctx,
/* BOLT #11: /* BOLT #11:
* *
* A writer MUST encode `amount` as a positive decimal integer * A writer:
* with no leading zeroes and SHOULD use the shortest representation * - MUST encode `prefix` using the currency it requires
* possible. * for successful payment
* - If it requires a specific minimum amount for successful payment:
* - MUST include that `amount`
* - MUST encode `amount` as a positive decimal integer
* with no leading zeroes
* - SHOULD use the shortest representation possible by
* using the largest multiplier or omitting the multiplier
*/ */
if (b11->msatoshi) { if (b11->msatoshi) {
char postfix; char postfix;

Loading…
Cancel
Save