Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bcli: don't get upset at 0-value outputs #3605

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion common/test/run-amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down