1919package geth
2020
2121import (
22- "errors"
2322 "math/big"
2423 "strings"
2524
@@ -28,7 +27,6 @@ import (
2827 "github.com/ethereum/go-ethereum/accounts/keystore"
2928 "github.com/ethereum/go-ethereum/common"
3029 "github.com/ethereum/go-ethereum/core/types"
31- "github.com/ethereum/go-ethereum/crypto"
3230)
3331
3432// Signer is an interface defining the callback when a contract requires a
@@ -82,28 +80,14 @@ func NewTransactOpts() *TransactOpts {
8280 return new (TransactOpts )
8381}
8482
85- // NewKeyedTransactor is a utility method to easily create a transaction signer
83+ // NewKeyedTransactOpts is a utility method to easily create a transaction signer
8684// from a single private key.
8785func NewKeyedTransactOpts (keyJson []byte , passphrase string ) (* TransactOpts , error ) {
8886 key , err := keystore .DecryptKey (keyJson , passphrase )
8987 if err != nil {
9088 return nil , err
9189 }
92- keyAddr := crypto .PubkeyToAddress (key .PrivateKey .PublicKey )
93- opts := bind.TransactOpts {
94- From : keyAddr ,
95- Signer : func (signer types.Signer , address common.Address , tx * types.Transaction ) (* types.Transaction , error ) {
96- if address != keyAddr {
97- return nil , errors .New ("not authorized to sign this account" )
98- }
99- signature , err := crypto .Sign (signer .Hash (tx ).Bytes (), key .PrivateKey )
100- if err != nil {
101- return nil , err
102- }
103- return tx .WithSignature (signer , signature )
104- },
105- }
106- return & TransactOpts {opts }, nil
90+ return & TransactOpts {* bind .NewKeyedTransactor (key .PrivateKey )}, nil
10791}
10892
10993func (opts * TransactOpts ) GetFrom () * Address { return & Address {opts .opts .From } }
0 commit comments