mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-24 03:54:21 +01:00
fix: increment fees for correct keysets (#825)
* fix: increment fees for correct keysets * pythonic short --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
@@ -224,8 +224,11 @@ class Ledger(
|
||||
proofs (List[Proof]): Proofs to add to known secret table.
|
||||
conn: (Optional[Connection], optional): Database connection to reuse. Will create a new one if not given. Defaults to None.
|
||||
"""
|
||||
# sum_proofs = sum([p.amount for p in proofs])
|
||||
fees_proofs = self.get_fees_for_proofs(proofs)
|
||||
# Group proofs by keyset_id to calculate fees per keyset
|
||||
proofs_by_keyset: Dict[str, List[Proof]] = {}
|
||||
for p in proofs:
|
||||
proofs_by_keyset.setdefault(p.id, []).append(p)
|
||||
|
||||
async with self.db.get_connection(conn) as conn:
|
||||
# store in db
|
||||
for p in proofs:
|
||||
@@ -241,9 +244,18 @@ class Ledger(
|
||||
Y=p.Y, state=ProofSpentState.spent, witness=p.witness or None
|
||||
)
|
||||
)
|
||||
await self.crud.bump_keyset_fees_paid(
|
||||
keyset=self.keyset, amount=fees_proofs, db=self.db, conn=conn
|
||||
)
|
||||
|
||||
# Calculate and increment fees for each keyset separately
|
||||
for keyset_id, keyset_proofs in proofs_by_keyset.items():
|
||||
keyset_fees = self.get_fees_for_proofs(keyset_proofs)
|
||||
if keyset_fees > 0:
|
||||
logger.trace(f"Adding fees {keyset_fees} to keyset {keyset_id}")
|
||||
await self.crud.bump_keyset_fees_paid(
|
||||
keyset=self.keysets[keyset_id],
|
||||
amount=keyset_fees,
|
||||
db=self.db,
|
||||
conn=conn,
|
||||
)
|
||||
|
||||
async def _generate_change_promises(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user