Skip to content

Commit

Permalink
wallet - check for fee changes in keysets
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Dec 4, 2024
1 parent c9af011 commit 5be7fa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 17 additions & 1 deletion wallet/keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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)
Expand All @@ -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
}
1 change: 0 additions & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,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

Expand Down

0 comments on commit 5be7fa8

Please sign in to comment.