From 0364ba8a9a9a27a353a7f3a4ca244793dad7dd61 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 | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/errors.go b/errors.go index 476e42e1..5636aacd 100644 --- a/errors.go +++ b/errors.go @@ -30,6 +30,7 @@ const ( ErrLoggerAlreadyRegistered = "logger_already_registered" ErrLogRotatorAlreadyInitialized = "log_rotator_already_initialized" ErrAddressDiscoveryNotDone = "address_discovery_not_done" + ErrSeedExists = "wallet_seed_exists" ) // todo, should update this method to translate more error kinds. diff --git a/multiwallet.go b/multiwallet.go index a8041fa5..59ff1843 100644 --- a/multiwallet.go +++ b/multiwallet.go @@ -388,6 +388,14 @@ 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) + } + } + // Perform database save operations in batch transaction // for automatic rollback if error occurs at any point. err = mw.batchDbTransaction(func(db storm.Node) error {