Skip to content

Commit

Permalink
common/amount: round tiny msat amount to 0sat
Browse files Browse the repository at this point in the history
This parses < 1000msat amounts as being 0sat instead of failing.

Otherwise bcli would fail on 0-value outputs (happens on testnet for
transaction eca4cefef2a98de5df67a6630c63af5a72ab57583e0f3bf066d976f28213f447) as
parse_amount_sat() expected the amount to end with 000msat.
  • Loading branch information
darosior committed Mar 28, 2020
1 parent 8c984fb commit e37fa3c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool parse_amount_msat(struct amount_msat *msat, const char *s, size_t slen)
/* Valid strings:
* [0-9]+ => satoshi.
* [0-9]+sat => satoshi.
* [0-9]+000msat => satoshi.
* [0-9]+msat => satoshi.
* [0-9]+.[0-9]{1,8}btc => satoshi.
*/
bool parse_amount_sat(struct amount_sat *sat, const char *s, size_t slen)
Expand All @@ -198,8 +198,10 @@ bool parse_amount_sat(struct amount_sat *sat, const char *s, size_t slen)
if (!post_decimal_ptr && memeqstr(suffix_ptr, suffix_len, "sat"))
return from_number(&sat->satoshis, s, whole_number_len, 0);
if (!post_decimal_ptr && memeqstr(suffix_ptr, suffix_len, "msat")) {
if (!memends(s, whole_number_len, "000", strlen("000")))
return false;
if (!memends(s, whole_number_len, "000", strlen("000"))) {
*sat = AMOUNT_SAT(0);
return true;
}
return from_number(&sat->satoshis, s, whole_number_len - 3, 0);
}
if (post_decimal_ptr && memeqstr(suffix_ptr, suffix_len, "btc"))
Expand Down

0 comments on commit e37fa3c

Please sign in to comment.