From b896ed29664251807c7c2d90033396e7fcf258a4 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 6 Jan 2025 20:23:37 +0700 Subject: [PATCH] accounts/abi/bind, accounts/abi/bind/v2: move DeployContractRaw into v2 package --- accounts/abi/bind/base.go | 14 -------------- accounts/abi/bind/v2/lib.go | 15 +++++++++++++++ accounts/abi/bind/v2/lib_test.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 54f4b7989e..0825ec1aad 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -153,20 +153,6 @@ func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend Co return c.address, tx, c, nil } -// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the -// deployment address with a Go wrapper. It expects its parameters to be abi-encoded -// bytes. -func DeployContractRaw(opts *TransactOpts, bytecode []byte, backend ContractBackend, packedParams []byte) (common.Address, *types.Transaction, *BoundContract, error) { - c := NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend) - - tx, err := c.transact(opts, nil, append(bytecode, packedParams...)) - if err != nil { - return common.Address{}, nil, nil, err - } - c.address = crypto.CreateAddress(opts.From, tx.Nonce()) - return c.address, tx, c, nil -} - // Call invokes the (constant) contract method with params as input values and // sets the output to result. The result type might be a single field for simple // returns, a slice of interfaces for anonymous returns and a struct for named diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index 9d7c5e9739..6aff6514e9 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/event" ) @@ -175,3 +176,17 @@ func Call[T any](instance *ContractInstance, opts *bind.CallOpts, packedInput [] } return unpack(packedOutput) } + +// DeployContractRaw deploys a contract onto the Ethereum blockchain and binds the +// deployment address with a Go wrapper. It expects its parameters to be abi-encoded +// bytes. +func DeployContractRaw(opts *bind.TransactOpts, bytecode []byte, backend bind.ContractBackend, packedParams []byte) (common.Address, *types.Transaction, *bind.BoundContract, error) { + c := bind.NewBoundContract(common.Address{}, abi.ABI{}, backend, backend, backend) + + tx, err := c.RawTransact(opts, append(bytecode, packedParams...)) + if err != nil { + return common.Address{}, nil, nil, err + } + address := crypto.CreateAddress(opts.From, tx.Nonce()) + return address, tx, c, nil +} diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index a2c792aa8f..c9e5760626 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -98,7 +98,7 @@ func testSetup() (*bind.TransactOpts, *backends.SimulatedBackend, error) { func makeTestDeployer(auth *bind.TransactOpts, backend bind.ContractBackend) func(input, deployer []byte) (common.Address, *types.Transaction, error) { return func(input, deployer []byte) (common.Address, *types.Transaction, error) { - addr, tx, _, err := bind.DeployContractRaw(auth, deployer, backend, input) + addr, tx, _, err := DeployContractRaw(auth, deployer, backend, input) return addr, tx, err } }