From a2997242b52f21a8598d9a1df9bb5e10b379dfb8 Mon Sep 17 00:00:00 2001 From: LuttyYang Date: Thu, 15 Jul 2021 15:23:48 +0800 Subject: [PATCH] fix issue 187 (#262) --- pkg/account/import.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/account/import.go b/pkg/account/import.go index edadf26..b683d74 100644 --- a/pkg/account/import.go +++ b/pkg/account/import.go @@ -3,6 +3,7 @@ package account import ( "encoding/hex" "fmt" + "github.com/ethereum/go-ethereum/crypto" "github.com/mitchellh/go-homedir" "io" "io/ioutil" @@ -42,6 +43,12 @@ func ImportFromPrivateKey(privateKey, name, passphrase string) (string, error) { // btcec.PrivKeyFromBytes only returns a secret key and public key sk, _ := btcec.PrivKeyFromBytes(btcec.S256(), privateKeyBytes) + oneAddress := address.ToBech32(crypto.PubkeyToAddress(sk.PublicKey)) + + if store.FromAddress(oneAddress) != nil { + return "", fmt.Errorf("address %s already exists", oneAddress) + } + ks := store.FromAccountName(name) _, err = ks.ImportECDSA(sk.ToECDSA(), passphrase) return name, err