From c3ab96b242ab18a7a856d59a3618f4bd13ac3384 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 3 Jun 2015 15:41:09 +0200 Subject: more documenting, checking for consistency between prepared statements and functional logic --- src/util/amount.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/util/amount.c') diff --git a/src/util/amount.c b/src/util/amount.c index 74ffcd36f..20b8618df 100644 --- a/src/util/amount.c +++ b/src/util/amount.c @@ -237,6 +237,20 @@ test_valid (const struct TALER_Amount *a) } +/** + * Test if @a a is valid, NBO variant. + * + * @param a amount to test + * @return #GNUNET_YES if valid, + * #GNUNET_NO if invalid + */ +static int +test_valid_nbo (const struct TALER_AmountNBO *a) +{ + return ('\0' != a->currency[0]); +} + + /** * Test if @a a1 and @a a2 are the same currency. * @@ -260,6 +274,29 @@ TALER_amount_cmp_currency (const struct TALER_Amount *a1, } +/** + * Test if @a a1 and @a a2 are the same currency, NBO variant. + * + * @param a1 amount to test + * @param a2 amount to test + * @return #GNUNET_YES if @a a1 and @a a2 are the same currency + * #GNUNET_NO if the currencies are different, + * #GNUNET_SYSERR if either amount is invalid + */ +int +TALER_amount_cmp_currency_nbo (const struct TALER_AmountNBO *a1, + const struct TALER_AmountNBO *a2) +{ + if ( (GNUNET_NO == test_valid_nbo (a1)) || + (GNUNET_NO == test_valid_nbo (a2)) ) + return GNUNET_SYSERR; + if (0 == strcasecmp (a1->currency, + a2->currency)) + return GNUNET_YES; + return GNUNET_NO; +} + + /** * Compare the value/fraction of two amounts. Does not compare the currency. * Comparing amounts of different currencies will cause the program to abort(). -- cgit v1.2.3