BOLT 11 human-readable formatting changes

This commit is contained in:
lisa neigut
2018-09-20 13:07:53 -07:00
committed by Rusty Russell
parent 2327f04b54
commit b287f2f007
2 changed files with 24 additions and 14 deletions

View File

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

View File

@@ -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,
@@ -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 {
@@ -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,
@@ -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;
}
@@ -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;