mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 06:23:47 +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
|
package bind
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"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
|
// DefaultDeployer returns a DeployFn that signs and submits creation transactions
|
||||||
// using the given signer.
|
// using the given signer.
|
||||||
func DefaultDeployer(ctx context.Context, from common.Address, backend ContractBackend, signer SignerFn) DeployFn {
|
func DefaultDeployer(opts *TransactOpts, backend ContractBackend) DeployFn {
|
||||||
opts := &TransactOpts{
|
|
||||||
From: from,
|
|
||||||
Nonce: nil,
|
|
||||||
Signer: signer,
|
|
||||||
Context: ctx,
|
|
||||||
}
|
|
||||||
return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) {
|
return func(input []byte, deployer []byte) (common.Address, *types.Transaction, error) {
|
||||||
addr, tx, err := DeployContract(opts, deployer, backend, input)
|
addr, tx, err := DeployContract(opts, deployer, backend, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -60,20 +60,9 @@ func testSetup() (*backends.SimulatedBackend, error) {
|
||||||
return &bindBackend, nil
|
return &bindBackend, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestDeployer(backend bind.ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
|
func makeTestDeployer(backend simulated.Client) func(input, deployer []byte) (common.Address, *types.Transaction, error) {
|
||||||
signer := types.LatestSigner(params.AllDevChainProtocolChanges)
|
chainId, _ := backend.ChainID(context.Background())
|
||||||
sign := func(sender common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
return bind.DefaultDeployer(bind.NewKeyedTransactor(testKey, chainId), backend)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test that deploying a contract with library dependencies works,
|
// test that deploying a contract with library dependencies works,
|
||||||
|
|
@ -91,7 +80,7 @@ func TestDeploymentLibraries(t *testing.T) {
|
||||||
Contracts: []*bind.MetaData{&nested_libraries.C1MetaData},
|
Contracts: []*bind.MetaData{&nested_libraries.C1MetaData},
|
||||||
Inputs: map[string][]byte{nested_libraries.C1MetaData.ID: constructorInput},
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("err: %+v\n", err)
|
t.Fatalf("err: %+v\n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue