From 2140b278a01ac32f46c120237512f55242a406db Mon Sep 17 00:00:00 2001 From: elnosh Date: Wed, 4 Dec 2024 12:13:16 -0500 Subject: [PATCH] wallet - check for fee changes in keysets --- wallet/keyset.go | 18 +++++++++++++++++- wallet/wallet.go | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/wallet/keyset.go b/wallet/keyset.go index 7e48805..16c9e62 100644 --- a/wallet/keyset.go +++ b/wallet/keyset.go @@ -105,11 +105,13 @@ func (w *Wallet) getActiveKeyset(mintURL string) (*crypto.WalletKeyset, error) { } activeKeyset := mint.activeKeyset + var activeInputFeePpk uint // check if there is new active keyset activeChanged := true for _, keyset := range allKeysets.Keysets { if keyset.Active && keyset.Id == activeKeyset.Id { activeChanged = false + activeInputFeePpk = keyset.InputFeePpk break } } @@ -129,10 +131,12 @@ func (w *Wallet) getActiveKeyset(mintURL string) (*crypto.WalletKeyset, error) { storedKeyset := w.db.GetKeyset(keyset.Id) if storedKeyset != nil { storedKeyset.Active = true + storedKeyset.InputFeePpk = keyset.InputFeePpk if err := w.db.SaveKeyset(storedKeyset); err != nil { return nil, err } - mint.activeKeyset = *storedKeyset + activeKeyset = *storedKeyset + mint.activeKeyset = activeKeyset delete(mint.inactiveKeysets, storedKeyset.Id) } else { keys, err := GetKeysetKeys(mintURL, keyset.Id) @@ -158,5 +162,17 @@ func (w *Wallet) getActiveKeyset(mintURL string) (*crypto.WalletKeyset, error) { } } + // check if input_fee_ppk changed for current active + if !activeChanged { + if activeInputFeePpk != activeKeyset.InputFeePpk { + activeKeyset.InputFeePpk = activeInputFeePpk + if err := w.db.SaveKeyset(&activeKeyset); err != nil { + return nil, err + } + mint.activeKeyset = activeKeyset + w.mints[mintURL] = mint + } + } + return &activeKeyset, nil } diff --git a/wallet/wallet.go b/wallet/wallet.go index cf7b2af..2a3f51a 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -1044,7 +1044,6 @@ func (w *Wallet) selectProofsForAmount( mint *walletMint, includeFees bool, ) (cashu.Proofs, error) { - // TODO: need to check first if 'input_fee_ppk' for keyset has changed var selectedProofs cashu.Proofs var fees uint64 = 0