Skip to content

Commit

Permalink
BOLT 11 human-readable formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
niftynei authored and rustyrussell committed Sep 21, 2018
1 parent 2327f04 commit b287f2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/
BOLTVERSION := fd9da9b95eb5d585252d7e749212151502e0cc17
BOLTVERSION := 21e3688e843f82267b3970cda69fa93158dc9517

-include config.vars

Expand Down
36 changes: 23 additions & 13 deletions common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,

/* 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"))
return decode_fail(b11, fail,
Expand All @@ -510,14 +511,13 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,

/* BOLT #11:
*
* A reader SHOULD fail if `amount` contains a non-digit or
* is followed by anything except a `multiplier` in the table
* above. */
* - If the `amount` is empty:
* */
amountstr = tal_strdup(tmpctx, hrp + strlen(prefix));
if (streq(amountstr, "")) {
/* BOLT #11:
*
* A reader SHOULD indicate if amount is unspecified
* - SHOULD indicate if amount is unspecified
*/
b11->msatoshi = NULL;
} else {
Expand All @@ -537,10 +537,9 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,

/* BOLT #11:
*
* A reader SHOULD fail if `amount` contains a non-digit or
* is followed by anything except a `multiplier` in the table
* above.
*/
* MUST fail if `amount` contains a non-digit or is followed by
* anything except a `multiplier` in the table above
**/
amount = strtoull(amountstr, &end, 10);
if (amount == ULLONG_MAX && errno == ERANGE)
return decode_fail(b11, fail,
Expand All @@ -549,7 +548,12 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
return decode_fail(b11, fail,
"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 = amount * m10 / 10;
}
Expand Down Expand Up @@ -873,9 +877,15 @@ char *bolt11_encode_(const tal_t *ctx,

/* BOLT #11:
*
* A writer MUST encode `amount` as a positive decimal integer
* with no leading zeroes and SHOULD use the shortest representation
* possible.
* A writer:
* - MUST encode `prefix` using the currency it requires
* 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) {
char postfix;
Expand Down

0 comments on commit b287f2f

Please sign in to comment.