From bc63fa606ea45c5ee3cff835a7a85c99ad35db23 Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 13 Aug 2021 09:24:33 +0200 Subject: [PATCH] delete imported key --- VERSION | 2 +- api/geth_backend.go | 24 ++++++++++++++++++++++++ mobile/status.go | 10 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 859193bd1..ea2ccc8ac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.83.11 +0.83.12 diff --git a/api/geth_backend.go b/api/geth_backend.go index abfd8ae80..9ae82c703 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -8,6 +8,7 @@ import ( "math/big" "os" "path/filepath" + "strings" "sync" "time" @@ -203,6 +204,29 @@ func (b *GethStatusBackend) DeleteMulticcount(keyUID string, keyStoreDir string) return os.RemoveAll(keyStoreDir) } +func (b *GethStatusBackend) DeleteImportedKey(address, password, keyStoreDir string) error { + b.mu.Lock() + defer b.mu.Unlock() + + err := filepath.Walk(keyStoreDir, func(path string, fileInfo os.FileInfo, err error) error { + if err != nil { + return err + } + if strings.Contains(fileInfo.Name(), address) { + _, err := b.accountManager.VerifyAccountPassword(keyStoreDir, "0x"+address, password) + if err != nil { + b.log.Error("failed to verify account", "account", address, "error", err) + return err + } + + return os.Remove(path) + } + return nil + }) + + return err +} + func (b *GethStatusBackend) ensureAppDBOpened(account multiaccounts.Account, password string) (err error) { b.mu.Lock() defer b.mu.Unlock() diff --git a/mobile/status.go b/mobile/status.go index 8d9c9daf5..5d2d05784 100644 --- a/mobile/status.go +++ b/mobile/status.go @@ -262,6 +262,16 @@ func DeleteMultiaccount(keyUID, keyStoreDir string) string { return makeJSONResponse(nil) } +// DeleteImportedKey +func DeleteImportedKey(address, password, keyStoreDir string) string { + err := statusBackend.DeleteImportedKey(address, password, keyStoreDir) + if err != nil { + return makeJSONResponse(err) + } + + return makeJSONResponse(nil) +} + // InitKeystore initialize keystore before doing any operations with keys. func InitKeystore(keydir string) string { err := statusBackend.AccountManager().InitKeystore(keydir)