From 9a30eda32a00bc401b369c8a2a09f7aacecc9da0 Mon Sep 17 00:00:00 2001 From: codemaestro64 Date: Sun, 24 May 2020 12:57:17 +0100 Subject: [PATCH] rebase master. fix merge conflicts --- multiwallet.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/multiwallet.go b/multiwallet.go index c5575bb3..cd6743a3 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -1,6 +1,7 @@ package dcrlibwallet import ( + "bytes" "context" "encoding/json" "os" @@ -282,6 +283,7 @@ func (mw *MultiWallet) CreateNewWallet(walletName, privatePassphrase string, pri if err != nil { return nil, err } + wallet := &Wallet{ Name: walletName, CreatedAt: time.Now(), @@ -405,12 +407,10 @@ func (mw *MultiWallet) saveNewWallet(wallet *Wallet, setupWallet func() error) ( return nil, errors.New(ErrExist) } - // Check if any of the other wallets has the same seed with this wallet - // If so, return an error - for _, wal := range mw.wallets { - if wal.Seed == wallet.Seed { - return nil, errors.New(ErrSeedExists) - } + // check if wallet with same seed already exists + err = mw.checkForSeedClash(wallet.EncryptedSeed) + if err != nil { + return nil, err } if mw.IsConnectedToDecredNetwork() { @@ -661,3 +661,14 @@ func (mw *MultiWallet) ChangePrivatePassphraseForWallet(walletID int, oldPrivate return nil } + +// checkForSeedClash checks to see if any wallet in the multi wallet has the same seed as the passed seed +// returns an error if there is any +func (mw *MultiWallet) checkForSeedClash(encryptedSeed []byte) error { + for _, wal := range mw.wallets { + if bytes.Equal(wal.EncryptedSeed, encryptedSeed) { + return errors.New(ErrSeedExists) + } + } + return nil +}