Skip to content

Commit

Permalink
wallet - fix wrong keyset id being used
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Jun 28, 2024
1 parent dcfd2a1 commit 31f5235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,20 @@ func (w *Wallet) Receive(token cashu.Token, swap bool) (uint64, error) {

tokenMintURL := token.Token[0].Mint
// only add mint if not previously trusted
_, ok := w.mints[tokenMintURL]
walletMint, ok := w.mints[tokenMintURL]
if !ok {
_, err := w.addMint(tokenMintURL)
mint, err := w.addMint(tokenMintURL)
if err != nil {
return 0, err
}
walletMint = *mint
}

activeSatKeyset := w.GetActiveSatKeyset()
var activeSatKeyset crypto.WalletKeyset
for _, k := range walletMint.activeKeysets {
activeSatKeyset = k
break
}
counter := w.counterForKeyset(activeSatKeyset.Id)

// create blinded messages
Expand Down Expand Up @@ -634,7 +639,12 @@ func (w *Wallet) getProofsForAmount(amount uint64, mintURL string) (cashu.Proofs
return selectedProofs, nil
}

activeSatKeyset := w.GetActiveSatKeyset()
var activeSatKeyset crypto.WalletKeyset
for _, k := range selectedMint.activeKeysets {
activeSatKeyset = k
break
}

counter := w.counterForKeyset(activeSatKeyset.Id)

// blinded messages for send amount
Expand Down Expand Up @@ -836,6 +846,7 @@ func (w *Wallet) counterForKeyset(keysetId string) uint32 {
return w.db.GetKeysetCounter(keysetId)
}

// get active sat keyset for current mint
func (w *Wallet) GetActiveSatKeyset() crypto.WalletKeyset {
var activeKeyset crypto.WalletKeyset
for _, keyset := range w.currentMint.activeKeysets {
Expand Down
4 changes: 2 additions & 2 deletions wallet/wallet_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func testMain(m *testing.M) int {
}

testMintPath := filepath.Join(".", "testmint1")
testMint, err := testutils.CreateTestMintServer(lnd1, "mykey", "3338", testMintPath)
testMint, err := testutils.CreateTestMintServer(lnd1, "secretkey1", "3338", testMintPath)
if err != nil {
log.Println(err)
return 1
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestReceive(t *testing.T) {
}

testMintPath := filepath.Join(".", "testmint2")
testMint, err := testutils.CreateTestMintServer(lnd2, "mykey", "3339", testMintPath)
testMint, err := testutils.CreateTestMintServer(lnd2, "secretkey2", "3339", testMintPath)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 31f5235

Please sign in to comment.