accounts/abi/bind/v2: simplify DefaultDeployer func signature

This commit is contained in:
Jared Wasinger 2025-02-05 20:36:27 -08:00
parent 8a4a5a60fb
commit 0df5b17df3
2 changed files with 5 additions and 23 deletions

View file

@ -17,7 +17,6 @@
package bind
import (
"context"
"errors"
"github.com/ethereum/go-ethereum"
@ -196,13 +195,7 @@ func DeployContract(opts *TransactOpts, bytecode []byte, backend ContractBackend
// DefaultDeployer returns a DeployFn that signs and submits creation transactions
// using the given signer.
func DefaultDeployer(ctx context.Context, from common.Address, backend ContractBackend, signer SignerFn) DeployFn {
opts := &TransactOpts{
From: from,
Nonce: nil,
Signer: signer,
Context: ctx,
}
func DefaultDeployer(opts *TransactOpts, backend ContractBackend) DeployFn {
return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) {
addr, tx, err := DeployContract(opts, deployer, backend, input)
if err != nil {

View file

@ -60,20 +60,9 @@ func testSetup() (*backends.SimulatedBackend, error) {
return &bindBackend, nil
}
func makeTestDeployer(backend bind.ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
signer := types.LatestSigner(params.AllDevChainProtocolChanges)
sign := func(sender common.Address, tx *types.Transaction) (*types.Transaction, error) {
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), testKey)
if err != nil {
return nil, err
}
signedTx, err := tx.WithSignature(signer, signature)
if err != nil {
return nil, err
}
return signedTx, nil
}
return bind.DefaultDeployer(context.Background(), testAddr, backend, sign)
func makeTestDeployer(backend simulated.Client) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
chainId, _ := backend.ChainID(context.Background())
return bind.DefaultDeployer(bind.NewKeyedTransactor(testKey, chainId), backend)
}
// test that deploying a contract with library dependencies works,
@ -91,7 +80,7 @@ func TestDeploymentLibraries(t *testing.T) {
Contracts: []*bind.MetaData{&nested_libraries.C1MetaData},
Inputs: map[string][]byte{nested_libraries.C1MetaData.ID: constructorInput},
}
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(bindBackend))
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(bindBackend.Client))
if err != nil {
t.Fatalf("err: %+v\n", err)
}