mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
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>
This commit is contained in:
parent
b7db588a8a
commit
13fbce90ca
2 changed files with 7 additions and 2 deletions
|
@ -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"))
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue