fix(keycard): convert regular to a keycard account process fixed

This commit is contained in:
Sale Djenic 2023-01-25 18:46:20 +01:00 committed by saledjenic
parent d8e2884d4e
commit 902d4b7501
5 changed files with 61 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"github.com/google/uuid"
@ -606,7 +607,7 @@ func (m *Manager) ReEncryptKeyStoreDir(keyDirPath, oldPass, newPass string) erro
return nil
}
func (m *Manager) DeleteAccount(keyDirPath string, address types.Address) error {
func (m *Manager) DeleteAccount(keyDirPath string, address types.Address, ignoreCase bool) error {
var err error
var foundKeyFile string
err = filepath.Walk(keyDirPath, func(path string, fileInfo os.FileInfo, err error) error {
@ -629,8 +630,14 @@ func (m *Manager) DeleteAccount(keyDirPath string, address types.Address) error
return fmt.Errorf("failed to read key file: %s", e)
}
if types.HexToAddress("0x"+accountKey.Address).Hex() == address.Hex() {
foundKeyFile = path
if ignoreCase {
if strings.EqualFold("0x"+accountKey.Address, address.String()) {
foundKeyFile = path
}
} else {
if types.HexToAddress("0x"+accountKey.Address).Hex() == address.Hex() {
foundKeyFile = path
}
}
return nil

View File

@ -604,6 +604,26 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(keyStoreDir string, account
return err
}
masterAddress, err := accountDB.GetMasterAddress()
if err != nil {
return err
}
dappsAddress, err := accountDB.GetDappsAddress()
if err != nil {
return err
}
eip1581Address, err := accountDB.GetEIP1581Address()
if err != nil {
return err
}
walletRootAddress, err := accountDB.GetWalletRootAddress()
if err != nil {
return err
}
err = b.closeAppDB()
if err != nil {
return err
@ -614,13 +634,18 @@ func (b *GethStatusBackend) ConvertToKeycardAccount(keyStoreDir string, account
return err
}
// 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 {
// This action deletes an account from the keystore, no need to check for error in this context here, cause if this
// action fails from whichever reason the account is still successfully migrated since keystore won't be used any more.
_ = b.accountManager.DeleteAccount(keyStoreDir, acc.Address)
_ = b.accountManager.DeleteAccount(keyStoreDir, acc.Address, true)
}
}
_ = b.accountManager.DeleteAccount(keyStoreDir, masterAddress, true)
_ = b.accountManager.DeleteAccount(keyStoreDir, dappsAddress, true)
_ = b.accountManager.DeleteAccount(keyStoreDir, eip1581Address, true)
_ = b.accountManager.DeleteAccount(keyStoreDir, walletRootAddress, true)
return nil
}

View File

@ -402,6 +402,11 @@ var (
dBColumnName: "wallet_root_address",
valueHandler: AddressHandler,
}
MasterAddress = SettingField{
reactFieldName: "address",
dBColumnName: "address",
valueHandler: AddressHandler,
}
SettingFieldRegister = []SettingField{
AnonMetricsShouldSend,

View File

@ -587,6 +587,22 @@ func (db *Database) GetWalletRootAddress() (rst types.Address, err error) {
return
}
func (db *Database) GetEIP1581Address() (rst types.Address, err error) {
err = db.makeSelectRow(EIP1581Address).Scan(&rst)
if err == sql.ErrNoRows {
return rst, nil
}
return
}
func (db *Database) GetMasterAddress() (rst types.Address, err error) {
err = db.makeSelectRow(MasterAddress).Scan(&rst)
if err == sql.ErrNoRows {
return rst, nil
}
return
}
func (db *Database) TestNetworksEnabled() (rst bool, err error) {
err = db.makeSelectRow(TestNetworksEnabled).Scan(&rst)
if err == sql.ErrNoRows {

View File

@ -78,7 +78,7 @@ func (api *API) DeleteAccount(ctx context.Context, address types.Address) error
return err
}
if acc.Type != accounts.AccountTypeWatch {
err = api.manager.DeleteAccount(api.config.KeyStoreDir, address)
err = api.manager.DeleteAccount(api.config.KeyStoreDir, address, true)
var e *account.ErrCannotLocateKeyFile
if err != nil && !errors.As(err, &e) {
return err
@ -444,7 +444,7 @@ func (api *API) AddMigratedKeyPair(ctx context.Context, kcUID string, kpName str
for _, addr := range addresses {
// This action deletes an account from the keystore, no need to check for error in this context here, cause if this
// action fails from whichever reason the account is still successfully migrated since keystore won't be used any more.
_ = api.manager.DeleteAccount(keyStoreDir, addr)
_ = api.manager.DeleteAccount(keyStoreDir, addr, true)
}
return nil
}