mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
accounts/abi/bind/v2: export DeploymentParams fields
The constructor function doesn't make sense. The struct has one required and two optional fields, and we may want to add more configuration later. With the constructor function, all parameters always need to be given, even the optional ones. And we can't extend the function without breaking the API. So it's better to use require users to write the literal.
This commit is contained in:
parent
8200bbf4a0
commit
d3dfbf9bfa
3 changed files with 29 additions and 24 deletions
|
|
@ -14,22 +14,15 @@ import (
|
|||
// set of contracts. It takes an optional override
|
||||
// list to specify contracts/libraries that have already been deployed on-chain.
|
||||
type DeploymentParams struct {
|
||||
contracts []*MetaData
|
||||
// map of solidity library pattern to constructor input.
|
||||
inputs map[string][]byte
|
||||
Contracts []*MetaData
|
||||
|
||||
// Map of solidity library pattern to constructor input.
|
||||
Inputs map[string][]byte
|
||||
|
||||
// Overrides is an optional map of pattern to deployment address.
|
||||
// Contracts/libraries that refer to dependencies in the override
|
||||
// set are linked to the provided address (an already-deployed contract).
|
||||
overrides map[string]common.Address
|
||||
}
|
||||
|
||||
// NewDeploymentParams instantiates a DeploymentParams instance.
|
||||
func NewDeploymentParams(contracts []*MetaData, inputs map[string][]byte, overrides map[string]common.Address) *DeploymentParams {
|
||||
return &DeploymentParams{
|
||||
contracts,
|
||||
inputs,
|
||||
overrides,
|
||||
}
|
||||
Overrides map[string]common.Address
|
||||
}
|
||||
|
||||
// DeploymentResult encapsulates information about the result of the deployment
|
||||
|
|
@ -38,6 +31,7 @@ func NewDeploymentParams(contracts []*MetaData, inputs map[string][]byte, overri
|
|||
type DeploymentResult struct {
|
||||
// map of contract library pattern -> deploy transaction
|
||||
Txs map[string]*types.Transaction
|
||||
|
||||
// map of contract library pattern -> deployed address
|
||||
Addrs map[string]common.Address
|
||||
}
|
||||
|
|
@ -56,11 +50,11 @@ type depTreeDeployer struct {
|
|||
}
|
||||
|
||||
func newDepTreeDeployer(deployParams *DeploymentParams, deployFn DeployFn) *depTreeDeployer {
|
||||
deployedAddrs := maps.Clone(deployParams.overrides)
|
||||
deployedAddrs := maps.Clone(deployParams.Overrides)
|
||||
if deployedAddrs == nil {
|
||||
deployedAddrs = make(map[string]common.Address)
|
||||
}
|
||||
inputs := deployParams.inputs
|
||||
inputs := deployParams.Inputs
|
||||
if inputs == nil {
|
||||
inputs = make(map[string][]byte)
|
||||
}
|
||||
|
|
@ -123,7 +117,7 @@ func (d *depTreeDeployer) result() *DeploymentResult {
|
|||
// deployed are returned in the result.
|
||||
func LinkAndDeploy(deployParams *DeploymentParams, deploy DeployFn) (res *DeploymentResult, err error) {
|
||||
deployer := newDepTreeDeployer(deployParams, deploy)
|
||||
for _, contract := range deployParams.contracts {
|
||||
for _, contract := range deployParams.Contracts {
|
||||
if _, err := deployer.linkAndDeploy(contract); err != nil {
|
||||
return deployer.result(), err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,10 @@ func testLinkCase(tcInput linkTestCaseInput) error {
|
|||
overrides[pattern] = override
|
||||
}
|
||||
|
||||
deployParams := NewDeploymentParams(contractsList, nil, overrides)
|
||||
deployParams := &DeploymentParams{
|
||||
Contracts: contractsList,
|
||||
Overrides: overrides,
|
||||
}
|
||||
res, err := LinkAndDeploy(deployParams, mockDeploy)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -108,8 +108,10 @@ func TestDeploymentLibraries(t *testing.T) {
|
|||
|
||||
c := nested_libraries.NewC1()
|
||||
constructorInput := c.PackConstructor(big.NewInt(42), big.NewInt(1))
|
||||
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, nil)
|
||||
|
||||
deploymentParams := &bind.DeploymentParams{
|
||||
Contracts: []*bind.MetaData{&nested_libraries.C1MetaData},
|
||||
Inputs: map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput},
|
||||
}
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %+v\n", err)
|
||||
|
|
@ -149,8 +151,9 @@ func TestDeploymentWithOverrides(t *testing.T) {
|
|||
defer bindBackend.Backend.Close()
|
||||
|
||||
// deploy all the library dependencies of our target contract, but not the target contract itself.
|
||||
deploymentParams := bind.NewDeploymentParams(nested_libraries.C1MetaData.Deps, nil, nil)
|
||||
|
||||
deploymentParams := &bind.DeploymentParams{
|
||||
Contracts: nested_libraries.C1MetaData.Deps,
|
||||
}
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %+v\n", err)
|
||||
|
|
@ -170,8 +173,13 @@ func TestDeploymentWithOverrides(t *testing.T) {
|
|||
c := nested_libraries.NewC1()
|
||||
constructorInput := c.PackConstructor(big.NewInt(42), big.NewInt(1))
|
||||
overrides := res.Addrs
|
||||
|
||||
// deploy the contract
|
||||
deploymentParams = bind.NewDeploymentParams([]*bind.MetaData{&nested_libraries.C1MetaData}, map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput}, overrides)
|
||||
deploymentParams = &bind.DeploymentParams{
|
||||
Contracts: []*bind.MetaData{&nested_libraries.C1MetaData},
|
||||
Inputs: map[string][]byte{nested_libraries.C1MetaData.Pattern: constructorInput},
|
||||
Overrides: overrides,
|
||||
}
|
||||
res, err = bind.LinkAndDeploy(deploymentParams, makeTestDeployer(opts, bindBackend))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %+v\n", err)
|
||||
|
|
@ -208,7 +216,7 @@ func TestEvents(t *testing.T) {
|
|||
t.Fatalf("error setting up testing env: %v", err)
|
||||
}
|
||||
|
||||
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&events.CMetaData}, nil, nil)
|
||||
deploymentParams := &bind.DeploymentParams{Contracts: []*bind.MetaData{&events.CMetaData}}
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
|
||||
if err != nil {
|
||||
t.Fatalf("error deploying contract for testing: %v", err)
|
||||
|
|
@ -307,7 +315,7 @@ func TestErrors(t *testing.T) {
|
|||
t.Fatalf("error setting up testing env: %v", err)
|
||||
}
|
||||
|
||||
deploymentParams := bind.NewDeploymentParams([]*bind.MetaData{&solc_errors.CMetaData}, nil, nil)
|
||||
deploymentParams := &bind.DeploymentParams{Contracts: []*bind.MetaData{&solc_errors.CMetaData}}
|
||||
res, err := bind.LinkAndDeploy(deploymentParams, makeTestDeployer(txAuth, backend))
|
||||
if err != nil {
|
||||
t.Fatalf("error deploying contract for testing: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue