From bf2ce9853e640384106f4dd7c242ea1e5e440871 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 1 Sep 2021 11:11:41 +0200 Subject: add long-time overdue convenience function --- src/include/taler_amount_lib.h | 11 +++++++++++ src/util/amount.c | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h index a1f6c7d35..c1f42e473 100644 --- a/src/include/taler_amount_lib.h +++ b/src/include/taler_amount_lib.h @@ -160,6 +160,17 @@ TALER_amount_set_zero (const char *cur, struct TALER_Amount *amount); +/** + * Test if the given @a amount is zero. + * + * @param amount amount to compare to zero + * @return true if the amount is zero, + * false if it is non-zero or invalid + */ +bool +TALER_amount_is_zero (const struct TALER_Amount *amount); + + /** * Test if the given amount is valid. * diff --git a/src/util/amount.c b/src/util/amount.c index 01f2a2313..ae9ae652e 100644 --- a/src/util/amount.c +++ b/src/util/amount.c @@ -241,6 +241,18 @@ TALER_amount_is_valid (const struct TALER_Amount *amount) } +bool +TALER_amount_is_zero (const struct TALER_Amount *amount) +{ + if (GNUNET_OK != + TALER_amount_is_valid (amount)) + return false; + return + (0 == amount->value) && + (0 == amount->fraction); +} + + /** * Test if @a a is valid, NBO variant. * -- cgit v1.2.3