delete imported key

This commit is contained in:
andrey 2021-08-13 09:24:33 +02:00 committed by flexsurfer
parent f6dc6f752a
commit bc63fa606e
3 changed files with 35 additions and 1 deletions

View File

@ -1 +1 @@
0.83.11
0.83.12

View File

@ -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()

View File

@ -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)