Skip to content

Commit

Permalink
use integer division as per https://github.com/cashubtc/nuts/pull/126…
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jun 16, 2024
1 parent d30b1a2 commit aeb0e59
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cashu/mint/verification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from typing import Dict, List, Literal, Optional, Tuple, Union

from loguru import logger
Expand Down Expand Up @@ -256,7 +255,7 @@ def _verify_units_match(
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(
Expand Down
5 changes: 2 additions & 3 deletions cashu/wallet/transactions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
import uuid
from typing import Dict, List, Tuple, Union

Expand All @@ -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

Expand Down

0 comments on commit aeb0e59

Please sign in to comment.