Browse Source

common/amount: accept 0msat in parse_amount_sat()

Changelog-fixed: bcli now handles 0msat outputs in gettxout.

Co-authored-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
darosior 5 years ago
committed by Rusty Russell
parent
commit
13fbce90ca
  1. 7
      common/amount.c
  2. 2
      common/test/run-amount.c

7
common/amount.c

@ -181,6 +181,7 @@ bool parse_amount_msat(struct amount_msat *msat, const char *s, size_t slen)
* [0-9]+ => satoshi.
* [0-9]+sat => satoshi.
* [0-9]+000msat => satoshi.
* 0msat => 0 satoshi
* [0-9]+.[0-9]{1,8}btc => satoshi.
*/
bool parse_amount_sat(struct amount_sat *sat, const char *s, size_t slen)
@ -198,8 +199,12 @@ 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")))
if (!memends(s, whole_number_len, "000", strlen("000"))) {
if (memeqstr(s, whole_number_len, "0"))
return from_number(&sat->satoshis, s,
whole_number_len, 0);
return false;
}
return from_number(&sat->satoshis, s, whole_number_len - 3, 0);
}
if (post_decimal_ptr && memeqstr(suffix_ptr, suffix_len, "btc"))

2
common/test/run-amount.c

@ -101,7 +101,7 @@ int main(void)
PASS_SAT(&sat, "1000msat", 1);
PASS_SAT(&sat, "1000000msat", 1000);
PASS_SAT(&sat, "2100000000000000000msat", 2100000000000000ULL);
FAIL_SAT(&sat, "0msat");
PASS_SAT(&sat, "0msat", 0);
FAIL_SAT(&sat, "100msat");
FAIL_SAT(&sat, "2000000000000000999msat");
FAIL_SAT(&sat, "-1000msat");

Loading…
Cancel
Save