From 2fae0ba2e281887193dc0aecfc852fe1f9e434dd Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:11:07 +0200 Subject: [PATCH] use integer division as per https://github.com/cashubtc/nuts/pull/126\#discussion_r1625244955 (#549) --- cashu/mint/verification.py | 3 +-- cashu/wallet/transactions.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cashu/mint/verification.py b/cashu/mint/verification.py index e97daf9..68bbbc4 100644 --- a/cashu/mint/verification.py +++ b/cashu/mint/verification.py @@ -1,4 +1,3 @@ -import math from typing import Dict, List, Literal, Optional, Tuple, Union from loguru import logger @@ -256,7 +255,7 @@ class LedgerVerification( def get_fees_for_proofs(self, proofs: List[Proof]) -> int: if not len(set([self.keysets[p.id].unit for p in proofs])) == 1: raise TransactionUnitError("inputs have different units.") - fee = math.ceil(sum([self.keysets[p.id].input_fee_ppk for p in proofs]) / 1000) + fee = (sum([self.keysets[p.id].input_fee_ppk for p in proofs]) + 999) // 1000 return fee def _verify_equation_balanced( diff --git a/cashu/wallet/transactions.py b/cashu/wallet/transactions.py index 7ac5ffa..94c47c5 100644 --- a/cashu/wallet/transactions.py +++ b/cashu/wallet/transactions.py @@ -1,4 +1,3 @@ -import math import uuid from typing import Dict, List, Tuple, Union @@ -24,13 +23,13 @@ class WalletTransactions(SupportsDb, SupportsKeysets): unit: Unit def get_fees_for_keyset(self, amounts: List[int], keyset: WalletKeyset) -> int: - fees = max(math.ceil(sum([keyset.input_fee_ppk for a in amounts]) / 1000), 0) + fees = max((sum([keyset.input_fee_ppk for a in amounts]) + 999) // 1000, 0) return fees def get_fees_for_proofs(self, proofs: List[Proof]) -> int: # for each proof, find the keyset with the same id and sum the fees fees = max( - math.ceil(sum([self.keysets[p.id].input_fee_ppk for p in proofs]) / 1000), 0 + (sum([self.keysets[p.id].input_fee_ppk for p in proofs]) + 999) // 1000, 0 ) return fees