mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 23:56:43 +00:00
accounts/abi/bind/v2: simplify DefaultDeployer func signature
This commit is contained in:
parent
8a4a5a60fb
commit
0df5b17df3
2 changed files with 5 additions and 23 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue