Exemplo n.º 1
0
// NewTransactor is a utility method to easily create a transaction signer from
// an encrypted json key stream and the associated passphrase.
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
	json, err := ioutil.ReadAll(keyin)
	if err != nil {
		return nil, err
	}
	key, err := crypto.DecryptKey(json, passphrase)
	if err != nil {
		return nil, err
	}
	return NewKeyedTransactor(key), nil
}
Exemplo n.º 2
0
// ImportAccount inserts an encrypted external account into the local keystore
// by first decrypting it, and then inserting using the local master password.
func (eapis *EtherAPIs) ImportAccount(keyjson []byte, password string) (common.Address, error) {
	key, err := crypto.DecryptKey(keyjson, password)
	if err != nil {
		return common.Address{}, err
	}
	if eapis.ethereum.AccountManager().HasAccount(key.Address) {
		return common.Address{}, errors.New("account already exists")
	}
	if err := eapis.client.Keystore().StoreKey(key, eapis.password); err != nil {
		return common.Address{}, err
	}
	if err := eapis.ethereum.AccountManager().Unlock(key.Address, eapis.password); err != nil {
		panic(fmt.Sprintf("Newly imported account failed to unlock: %v", err))
	}
	go eapis.eventmux.Post(NewAccountEvent{key.Address})

	return key.Address, nil
}