Skip to content

Commit bc21cf1

Browse files
committed
Use EIP155 keyed transactor from go-ethereum
After bumping up go-ethereum dependency we can use keyed transactor with chain ID implementation provided by the library instead of implementing it on our own.
1 parent 6cea6fe commit bc21cf1

2 files changed

Lines changed: 12 additions & 42 deletions

File tree

tools/generators/ethlike/contract.go.tmpl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,12 @@ func New{{.Class}}(
5757
From: accountKey.Address,
5858
}
5959

60-
// FIXME Switch to bind.NewKeyedTransactorWithChainID when go-ethereum dep
61-
// FIXME bumps beyond 1.9.25.
62-
key := accountKey.PrivateKey
63-
keyAddress := crypto.PubkeyToAddress(key.PublicKey)
64-
if chainId == nil {
65-
return nil, fmt.Errorf("no chain id specified")
66-
}
67-
transactorOptions := &bind.TransactOpts{
68-
From: keyAddress,
69-
Signer: func(_ types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
70-
signer := types.NewEIP155Signer(chainId)
71-
72-
if address != keyAddress {
73-
return nil, fmt.Errorf("not authorized to sign this account")
74-
}
75-
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
76-
if err != nil {
77-
return nil, err
78-
}
79-
return tx.WithSignature(signer, signature)
80-
},
60+
transactorOptions, err := bind.NewKeyedTransactorWithChainID(
61+
accountKey.PrivateKey,
62+
chainId,
63+
)
64+
if err != nil {
65+
return nil, fmt.Errorf("failed to instantiate transactor: [%v]", err)
8166
}
8267

8368
contract, err := abi.New{{.AbiClass}}(

tools/generators/ethlike/contract_template_content.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,12 @@ func New{{.Class}}(
6060
From: accountKey.Address,
6161
}
6262
63-
// FIXME Switch to bind.NewKeyedTransactorWithChainID when go-ethereum dep
64-
// FIXME bumps beyond 1.9.25.
65-
key := accountKey.PrivateKey
66-
keyAddress := crypto.PubkeyToAddress(key.PublicKey)
67-
if chainId == nil {
68-
return nil, fmt.Errorf("no chain id specified")
69-
}
70-
transactorOptions := &bind.TransactOpts{
71-
From: keyAddress,
72-
Signer: func(_ types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
73-
signer := types.NewEIP155Signer(chainId)
74-
75-
if address != keyAddress {
76-
return nil, fmt.Errorf("not authorized to sign this account")
77-
}
78-
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
79-
if err != nil {
80-
return nil, err
81-
}
82-
return tx.WithSignature(signer, signature)
83-
},
63+
transactorOptions, err := bind.NewKeyedTransactorWithChainID(
64+
accountKey.PrivateKey,
65+
chainId,
66+
)
67+
if err != nil {
68+
return nil, fmt.Errorf("failed to instantiate transactor: [%v]", err)
8469
}
8570
8671
contract, err := abi.New{{.AbiClass}}(

0 commit comments

Comments
 (0)