fix issue 187 (#262)

fix_issue_266
LuttyYang 3 years ago committed by GitHub
parent 940cedd554
commit a2997242b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      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

Loading…
Cancel
Save