diff options
author | Marius van der Wijden <m.vanderwijden@live.de> | 2019-06-08 21:19:26 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2019-06-08 21:19:26 +0800 |
commit | 6f80629383b2e725fb882c345ae4221574643a32 (patch) | |
tree | 5b2e5a06b8b121e17672267cc756a5e907f61070 | |
parent | afb9e6513f953a813d508633d6ff786fbd18b0b3 (diff) | |
download | go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar.gz go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar.bz2 go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar.lz go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar.xz go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.tar.zst go-tangerine-6f80629383b2e725fb882c345ae4221574643a32.zip |
accounts: added transactorFromKeyStore (#19685)
-rw-r--r-- | accounts/abi/bind/auth.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/accounts/abi/bind/auth.go b/accounts/abi/bind/auth.go index e6bb0c3b5..ad482abc0 100644 --- a/accounts/abi/bind/auth.go +++ b/accounts/abi/bind/auth.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -42,6 +43,24 @@ func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) { return NewKeyedTransactor(key.PrivateKey), nil } +// NewTransactor is a utility method to easily create a transaction signer from +// an decrypted key from a keystore +func NewTransactorFromKeyStore(keystore *keystore.KeyStore, account accounts.Account) (*TransactOpts, error) { + return &TransactOpts{ + From: account.Address, + Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) { + if address != account.Address { + return nil, errors.New("not authorized to sign this account") + } + signature, err := keystore.SignHash(account, signer.Hash(tx).Bytes()) + if err != nil { + return nil, err + } + return tx.WithSignature(signer, signature) + }, + }, nil +} + // NewKeyedTransactor is a utility method to easily create a transaction signer // from a single private key. func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts { |