From ef6cefe9aa4e86ceae3623dcf166d67b410d1fcf Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 27 Apr 2023 01:36:57 +0000 Subject: [PATCH] Fix protocoin current balance floating point precision bug --- apiserver/apiserver/api/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index d6c2ddc..2519339 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -1190,7 +1190,7 @@ class ProtocoinViewSet(Base): source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 source_user_balance = float(source_user_balance) - if source_user_balance != balance: + if abs(source_user_balance - balance) > 0.01: # stupid https://docs.djangoproject.com/en/4.2/ref/databases/#decimal-handling raise exceptions.ValidationError(dict(balance='Incorrect current balance.')) if source_user_balance < amount: @@ -1324,7 +1324,7 @@ class ProtocoinViewSet(Base): source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 source_user_balance = float(source_user_balance) - if source_user_balance != balance: + if abs(source_user_balance - balance) > 0.01: # stupid https://docs.djangoproject.com/en/4.2/ref/databases/#decimal-handling raise exceptions.ValidationError(dict(balance='Incorrect current balance.')) if source_user_balance < amount: