Skip to content

Commit

Permalink
prevent more than one wallet from using the same seed
Browse files Browse the repository at this point in the history
  • Loading branch information
codemaestro64 committed May 24, 2020
1 parent d115352 commit 0364ba8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions multiwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0364ba8

Please sign in to comment.