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 b5aae4a commit 22f6d6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions multiwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 22f6d6f

Please sign in to comment.