gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: dedicated class for cur


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: dedicated class for currency mismatch errors
Date: Wed, 10 May 2017 11:25:36 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 8e7202e  dedicated class for currency mismatch errors
8e7202e is described below

commit 8e7202eb62683b734255cbf62ffc314f92f0d3d2
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed May 10 11:25:36 2017 +0200

    dedicated class for currency mismatch errors
---
 talerbank/app/amounts.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/talerbank/app/amounts.py b/talerbank/app/amounts.py
index 8f713c4..4e55abe 100644
--- a/talerbank/app/amounts.py
+++ b/talerbank/app/amounts.py
@@ -25,17 +25,25 @@ logger = logging.getLogger(__name__)
 
 FRACTION = 100000000
 
+class CurrencyMismatchException(Exception):
+    pass
+
+def check_currency(a1, a2):
+    if a1["currency"] != a2["currency"]:
+        logger.error("Different currencies given: %s vs %s" % (a1["currency"], 
a2["currency"]))
+        raise CurrencyMismatchException
+
 def get_zero():
     return dict(value=0, fraction=0, currency=settings.TALER_CURRENCY)
 
 def amount_add(a1, a2):
-    assert(a1["currency"] == a2["currency"])
+    check_currency(a1, a2)
     a1_float = floatify(a1)
     a2_float = floatify(a2)
     return parse_amount("%s %s" % (str(a1_float + a2_float), a2["currency"]))
 
 def amount_sub(a1, a2):
-    assert(a1["currency"] == a2["currency"])
+    check_currency(a1, a2)
     a1_float = floatify(a1)
     a2_float = floatify(a2)
     sub = a1_float - a2_float
@@ -44,7 +52,7 @@ def amount_sub(a1, a2):
 
 # Return -1 if a1 < a2, 0 if a1 == a2, 1 if a1 > a2
 def amount_cmp(a1, a2):
-    assert(a1["currency"] == a2["currency"])
+    check_currency(a1, a2)
     a1_float = floatify(a1)
     a2_float = floatify(a2)
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]