mirror of
https://github.com/status-im/status-go.git
synced 2025-02-18 01:37:22 +00:00
fix: prevent to import same account twice (#2633)
This commit is contained in:
parent
631907839a
commit
f1cd9120c9
@ -2,6 +2,7 @@ package accounts
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -85,6 +86,14 @@ func (api *API) AddAccountWithMnemonic(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addressExists, err := api.db.AddressExists(types.Address(common.HexToAddress(accountInfos[pathWalletRoot].Address)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if addressExists {
|
||||||
|
return errors.New("account already exists")
|
||||||
|
}
|
||||||
|
|
||||||
account := accounts.Account{
|
account := accounts.Account{
|
||||||
Address: types.Address(common.HexToAddress(accountInfos[pathWalletRoot].Address)),
|
Address: types.Address(common.HexToAddress(accountInfos[pathWalletRoot].Address)),
|
||||||
PublicKey: types.HexBytes(accountInfos[pathWalletRoot].PublicKey),
|
PublicKey: types.HexBytes(accountInfos[pathWalletRoot].PublicKey),
|
||||||
@ -115,6 +124,14 @@ func (api *API) AddAccountWithPrivateKey(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addressExists, err := api.db.AddressExists(types.Address(common.HexToAddress(info.Address)))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if addressExists {
|
||||||
|
return errors.New("account already exists")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = api.manager.AccountsGenerator().StoreAccount(info.ID, password)
|
_, err = api.manager.AccountsGenerator().StoreAccount(info.ID, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user