diff --git a/api/geth_backend.go b/api/geth_backend.go index 32671ab8e..32c3c0fb0 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -647,11 +647,6 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun return err } - masterAddress, err := accountDB.GetMasterAddress() - if err != nil { - return err - } - dappsAddress, err := accountDB.GetDappsAddress() if err != nil { return err @@ -678,8 +673,6 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun } // We need to delete all accounts for the keypair which is being migrated - // no need to check for the error below cause if this action fails from - // whichever reason the account is still successfully migrated for _, acc := range knownAccounts { if account.KeyUID == acc.KeyUID { err = b.tryToDeleteAccount(acc.Address, password, newPassword) @@ -689,11 +682,6 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(account multiaccounts.Accoun } } - err = b.tryToDeleteAccount(masterAddress, password, newPassword) - if err != nil { - return err - } - err = b.tryToDeleteAccount(dappsAddress, password, newPassword) if err != nil { return err diff --git a/services/accounts/accounts.go b/services/accounts/accounts.go index f3e3b928a..b8a08f886 100644 --- a/services/accounts/accounts.go +++ b/services/accounts/accounts.go @@ -243,6 +243,19 @@ func (api *API) VerifyPassword(password string) bool { } func (api *API) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Context, kcUID string, kpName string, keyUID string, accountAddresses []string, password string) error { + if len(accountAddresses) == 0 { + return errors.New("cannot migrate a keypair without any address") + } + + acc, err := api.db.GetAccountByAddress(types.Address(common.HexToAddress(accountAddresses[0]))) + if err != nil { + return err + } + + if len(acc.DerivedFrom) == 0 { + return errors.New("an account being migrated doesn't contain `derived_from` field set") + } + kp := keypairs.KeyPair{ KeycardUID: kcUID, KeycardName: kpName, @@ -267,7 +280,13 @@ func (api *API) AddMigratedKeyPairOrAddAccountsIfKeyPairIsAdded(ctx context.Cont return err } } + + err = api.manager.DeleteAccount(types.Address(common.HexToAddress(acc.DerivedFrom)), password) + if err != nil { + return err + } } + return nil }