summaryrefslogtreecommitdiff
path: root/src/util/amount.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-03 15:41:09 +0200
committerChristian Grothoff <christian@grothoff.org>2015-06-03 15:41:09 +0200
commitc3ab96b242ab18a7a856d59a3618f4bd13ac3384 (patch)
tree8fb70e805bc02ac8bf11b6a3ad85fd458636dacb /src/util/amount.c
parentd4f5af21513c229d336e6a9dd99dc98c8179d4ce (diff)
downloadexchange-c3ab96b242ab18a7a856d59a3618f4bd13ac3384.tar.gz
exchange-c3ab96b242ab18a7a856d59a3618f4bd13ac3384.tar.bz2
exchange-c3ab96b242ab18a7a856d59a3618f4bd13ac3384.zip
more documenting, checking for consistency between prepared statements and functional logic
Diffstat (limited to 'src/util/amount.c')
-rw-r--r--src/util/amount.c37
1 files changed, 37 insertions, 0 deletions
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
@@ -238,6 +238,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.
*
* @param a1 amount to test
@@ -261,6 +275,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().
* If unsure, check with #TALER_amount_cmp_currency() first to be sure that