From 22f6d6fc8e7df135ddc757c7b3b318952a8acac4 Mon Sep 17 00:00:00 2001 From: codemaestro64 Date: Sun, 24 May 2020 12:20:28 +0100 Subject: [PATCH] prevent more than one wallet from using the same seed --- errors.go | 1 + multiwallet.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/errors.go b/errors.go index 0f98a4dc..c723995e 100644 --- a/errors.go +++ b/errors.go @@ -33,6 +33,7 @@ const ( ErrAddressDiscoveryNotDone = "address_discovery_not_done" ErrChangingPassphrase = "err_changing_passphrase" ErrSavingWallet = "err_saving_wallet" + ErrSeedExists = "wallet_seed_exists" ) // todo, should update this method to translate more error kinds. diff --git a/multiwallet.go b/multiwallet.go index cc641265..c5575bb3 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -405,10 +405,19 @@ 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) + } + } + if mw.IsConnectedToDecredNetwork() { mw.CancelSync() defer mw.SpvSync() } + // Perform database save operations in batch transaction // for automatic rollback if error occurs at any point. err = mw.batchDbTransaction(func(db storm.Node) error {