don't emit constructor input packing method if the contract constructor has no inputs

This commit is contained in:
Jared Wasinger 2025-01-08 19:28:45 +08:00 committed by Felix Lange
parent c92220f20e
commit 1b7aecef93
25 changed files with 79 additions and 126 deletions

View file

@ -63,10 +63,12 @@ var (
return &{{.Type}}{abi: *parsed}, nil
}
{{ if .Constructor.Inputs }}
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) PackConstructor({{range .Constructor.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) []byte {
res, _ := {{ decapitalise $contract.Type}}.abi.Pack("" {{range .Constructor.Inputs}}, {{.Name}}{{end}})
return res
}
{{ end -}}
{{range .Calls}}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.

View file

@ -51,11 +51,6 @@ func NewDB() (*DB, error) {
return &DB{abi: *parsed}, nil
}
func (dB *DB) PackConstructor() []byte {
res, _ := dB.abi.Pack("")
return res
}
// Get is a free data retrieval call binding the contract method 0x9507d39a.
//
// Solidity: function get(uint256 k) returns(uint256)

View file

@ -50,11 +50,6 @@ func NewC() (*C, error) {
return &C{abi: *parsed}, nil
}
func (c *C) PackConstructor() []byte {
res, _ := c.abi.Pack("")
return res
}
// DoSomethingWithManyArgs is a free data retrieval call binding the contract method 0x6fd8b968.
//
// Solidity: function DoSomethingWithManyArgs() pure returns(uint256, uint256, uint256, bool)

View file

@ -144,11 +144,6 @@ func NewL1() (*L1, error) {
return &L1{abi: *parsed}, nil
}
func (l1 *L1) PackConstructor() []byte {
res, _ := l1.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
@ -193,11 +188,6 @@ func NewL2() (*L2, error) {
return &L2{abi: *parsed}, nil
}
func (l2 *L2) PackConstructor() []byte {
res, _ := l2.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
@ -242,11 +232,6 @@ func NewL2b() (*L2b, error) {
return &L2b{abi: *parsed}, nil
}
func (l2b *L2b) PackConstructor() []byte {
res, _ := l2b.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
@ -288,11 +273,6 @@ func NewL3() (*L3, error) {
return &L3{abi: *parsed}, nil
}
func (l3 *L3) PackConstructor() []byte {
res, _ := l3.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
@ -338,11 +318,6 @@ func NewL4() (*L4, error) {
return &L4{abi: *parsed}, nil
}
func (l4 *L4) PackConstructor() []byte {
res, _ := l4.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)
@ -387,11 +362,6 @@ func NewL4b() (*L4b, error) {
return &L4b{abi: *parsed}, nil
}
func (l4b *L4b) PackConstructor() []byte {
res, _ := l4b.abi.Pack("")
return res
}
// Do is a free data retrieval call binding the contract method 0x2ad11272.
//
// Solidity: function Do(uint256 val) pure returns(uint256)

View file

@ -24,7 +24,7 @@ contract C {
}
// purpose of this is to test that generation of metadata for contract that emits one error produces valid Go code
contract 2C2 {
contract C2 {
function Foo() public pure {
revert BadThing({
arg1: uint256(0),

View file

@ -0,0 +1,65 @@
// Code generated via abigen V2 - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package uint256arrayreturn
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = abi.ConvertType
)
// MyContractMetaData contains all meta data concerning the MyContract contract.
var MyContractMetaData = bind.MetaData{
ABI: "[{\"inputs\":[],\"name\":\"GetNums\",\"outputs\":[{\"internalType\":\"uint256[5]\",\"name\":\"\",\"type\":\"uint256[5]\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}]",
Pattern: "e48e83c9c45b19a47bd451eedc725a6bff",
Bin: "0x6080604052348015600e575f80fd5b506101a78061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063bd6d10071461002d575b5f80fd5b61003561004b565b6040516100429190610158565b60405180910390f35b610053610088565b5f6040518060a001604052805f8152602001600181526020016002815260200160038152602001600481525090508091505090565b6040518060a00160405280600590602082028036833780820191505090505090565b5f60059050919050565b5f81905092915050565b5f819050919050565b5f819050919050565b6100d9816100c7565b82525050565b5f6100ea83836100d0565b60208301905092915050565b5f602082019050919050565b61010b816100aa565b61011581846100b4565b9250610120826100be565b805f5b8381101561015057815161013787826100df565b9650610142836100f6565b925050600181019050610123565b505050505050565b5f60a08201905061016b5f830184610102565b9291505056fea26469706673582212203fa25125c2101a81e9f20c6226dc2ebcf2845d4c211c842bf95771005a51acc964736f6c634300081a0033",
}
// MyContract is an auto generated Go binding around an Ethereum contract.
type MyContract struct {
abi abi.ABI
}
// NewMyContract creates a new instance of MyContract.
func NewMyContract() (*MyContract, error) {
parsed, err := MyContractMetaData.GetAbi()
if err != nil {
return nil, err
}
return &MyContract{abi: *parsed}, nil
}
// GetNums is a free data retrieval call binding the contract method 0xbd6d1007.
//
// Solidity: function GetNums() pure returns(uint256[5])
func (myContract *MyContract) PackGetNums() ([]byte, error) {
return myContract.abi.Pack("GetNums")
}
func (myContract *MyContract) UnpackGetNums(data []byte) ([5]*big.Int, error) {
out, err := myContract.abi.Unpack("GetNums", data)
if err != nil {
return *new([5]*big.Int), err
}
out0 := *abi.ConvertType(out[0], new([5]*big.Int)).(*[5]*big.Int)
return out0, err
}

View file

@ -0,0 +1 @@
{"contracts":{"contract.sol:MyContract":{"abi":[{"inputs":[],"name":"GetNums","outputs":[{"internalType":"uint256[5]","name":"","type":"uint256[5]"}],"stateMutability":"pure","type":"function"}],"bin":"6080604052348015600e575f80fd5b506101a78061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063bd6d10071461002d575b5f80fd5b61003561004b565b6040516100429190610158565b60405180910390f35b610053610088565b5f6040518060a001604052805f8152602001600181526020016002815260200160038152602001600481525090508091505090565b6040518060a00160405280600590602082028036833780820191505090505090565b5f60059050919050565b5f81905092915050565b5f819050919050565b5f819050919050565b6100d9816100c7565b82525050565b5f6100ea83836100d0565b60208301905092915050565b5f602082019050919050565b61010b816100aa565b61011581846100b4565b9250610120826100be565b805f5b8381101561015057815161013787826100df565b9650610142836100f6565b925050600181019050610123565b505050505050565b5f60a08201905061016b5f830184610102565b9291505056fea26469706673582212203fa25125c2101a81e9f20c6226dc2ebcf2845d4c211c842bf95771005a51acc964736f6c634300081a0033"}},"version":"0.8.26+commit.8a97fa7a.Darwin.appleclang"}

View file

@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract MyContract {
// emit multiple events, different types
function GetNums() public pure returns (uint256[5] memory) {
uint256[5] memory myNums = [uint256(0), uint256(1), uint256(2), uint256(3), uint256(4)];
return myNums;
}
}

View file

@ -44,11 +44,6 @@ func NewCallbackParam() (*CallbackParam, error) {
return &CallbackParam{abi: *parsed}, nil
}
func (callbackParam *CallbackParam) PackConstructor() []byte {
res, _ := callbackParam.abi.Pack("")
return res
}
// Test is a free data retrieval call binding the contract method 0xd7a5aba2.
//
// Solidity: function test(function callback) returns()

View file

@ -44,11 +44,6 @@ func NewDeeplyNestedArray() (*DeeplyNestedArray, error) {
return &DeeplyNestedArray{abi: *parsed}, nil
}
func (deeplyNestedArray *DeeplyNestedArray) PackConstructor() []byte {
res, _ := deeplyNestedArray.abi.Pack("")
return res
}
// DeepUint64Array is a free data retrieval call binding the contract method 0x98ed1856.
//
// Solidity: function deepUint64Array(uint256 , uint256 , uint256 ) view returns(uint64)

View file

@ -43,8 +43,3 @@ func NewEmpty() (*Empty, error) {
}
return &Empty{abi: *parsed}, nil
}
func (empty *Empty) PackConstructor() []byte {
res, _ := empty.abi.Pack("")
return res
}

View file

@ -43,11 +43,6 @@ func NewEventChecker() (*EventChecker, error) {
return &EventChecker{abi: *parsed}, nil
}
func (eventChecker *EventChecker) PackConstructor() []byte {
res, _ := eventChecker.abi.Pack("")
return res
}
// EventCheckerDynamic represents a Dynamic event raised by the EventChecker contract.
type EventCheckerDynamic struct {
IdxStr common.Hash

View file

@ -44,11 +44,6 @@ func NewGetter() (*Getter, error) {
return &Getter{abi: *parsed}, nil
}
func (getter *Getter) PackConstructor() []byte {
res, _ := getter.abi.Pack("")
return res
}
// Getter is a free data retrieval call binding the contract method 0x993a04b7.
//
// Solidity: function getter() returns(string, int256, bytes32)

View file

@ -44,11 +44,6 @@ func NewIdentifierCollision() (*IdentifierCollision, error) {
return &IdentifierCollision{abi: *parsed}, nil
}
func (identifierCollision *IdentifierCollision) PackConstructor() []byte {
res, _ := identifierCollision.abi.Pack("")
return res
}
// MyVar is a free data retrieval call binding the contract method 0x4ef1f0ad.
//
// Solidity: function MyVar() view returns(uint256)

View file

@ -43,11 +43,6 @@ func NewInputChecker() (*InputChecker, error) {
return &InputChecker{abi: *parsed}, nil
}
func (inputChecker *InputChecker) PackConstructor() []byte {
res, _ := inputChecker.abi.Pack("")
return res
}
// AnonInput is a free data retrieval call binding the contract method 0x3e708e82.
//
// Solidity: function anonInput(string ) returns()

View file

@ -50,11 +50,6 @@ func NewNameConflict() (*NameConflict, error) {
return &NameConflict{abi: *parsed}, nil
}
func (nameConflict *NameConflict) PackConstructor() []byte {
res, _ := nameConflict.abi.Pack("")
return res
}
// AddRequest is a free data retrieval call binding the contract method 0xcce7b048.
//
// Solidity: function addRequest((bytes,bytes) req) pure returns()

View file

@ -44,11 +44,6 @@ func NewNumericMethodName() (*NumericMethodName, error) {
return &NumericMethodName{abi: *parsed}, nil
}
func (numericMethodName *NumericMethodName) PackConstructor() []byte {
res, _ := numericMethodName.abi.Pack("")
return res
}
// E1test is a free data retrieval call binding the contract method 0xffa02795.
//
// Solidity: function _1test() pure returns()

View file

@ -43,11 +43,6 @@ func NewOutputChecker() (*OutputChecker, error) {
return &OutputChecker{abi: *parsed}, nil
}
func (outputChecker *OutputChecker) PackConstructor() []byte {
res, _ := outputChecker.abi.Pack("")
return res
}
// AnonOutput is a free data retrieval call binding the contract method 0x008bda05.
//
// Solidity: function anonOutput() returns(string)

View file

@ -44,11 +44,6 @@ func NewOverload() (*Overload, error) {
return &Overload{abi: *parsed}, nil
}
func (overload *Overload) PackConstructor() []byte {
res, _ := overload.abi.Pack("")
return res
}
// Foo is a free data retrieval call binding the contract method 0x04bc52f8.
//
// Solidity: function foo(uint256 i, uint256 j) returns()

View file

@ -44,11 +44,6 @@ func NewRangeKeyword() (*RangeKeyword, error) {
return &RangeKeyword{abi: *parsed}, nil
}
func (rangeKeyword *RangeKeyword) PackConstructor() []byte {
res, _ := rangeKeyword.abi.Pack("")
return res
}
// FunctionWithKeywordParameter is a free data retrieval call binding the contract method 0x527a119f.
//
// Solidity: function functionWithKeywordParameter(uint256 range) pure returns()

View file

@ -44,11 +44,6 @@ func NewSlicer() (*Slicer, error) {
return &Slicer{abi: *parsed}, nil
}
func (slicer *Slicer) PackConstructor() []byte {
res, _ := slicer.abi.Pack("")
return res
}
// EchoAddresses is a free data retrieval call binding the contract method 0xbe1127a3.
//
// Solidity: function echoAddresses(address[] input) returns(address[] output)

View file

@ -49,11 +49,6 @@ func NewStructs() (*Structs, error) {
return &Structs{abi: *parsed}, nil
}
func (structs *Structs) PackConstructor() []byte {
res, _ := structs.abi.Pack("")
return res
}
// F is a free data retrieval call binding the contract method 0x28811f59.
//
// Solidity: function F() view returns((bytes32)[] a, uint256[] c, bool[] d)

View file

@ -69,11 +69,6 @@ func NewTuple() (*Tuple, error) {
return &Tuple{abi: *parsed}, nil
}
func (tuple *Tuple) PackConstructor() []byte {
res, _ := tuple.abi.Pack("")
return res
}
// Func1 is a free data retrieval call binding the contract method 0x443c79b4.
//
// Solidity: function func1((uint256,uint256[],(uint256,uint256)[]) a, (uint256,uint256)[2][] b, (uint256,uint256)[][2] c, (uint256,uint256[],(uint256,uint256)[])[] d, uint256[] e) pure returns((uint256,uint256[],(uint256,uint256)[]), (uint256,uint256)[2][], (uint256,uint256)[][2], (uint256,uint256[],(uint256,uint256)[])[], uint256[])

View file

@ -44,11 +44,6 @@ func NewTupler() (*Tupler, error) {
return &Tupler{abi: *parsed}, nil
}
func (tupler *Tupler) PackConstructor() []byte {
res, _ := tupler.abi.Pack("")
return res
}
// Tuple is a free data retrieval call binding the contract method 0x3175aae2.
//
// Solidity: function tuple() returns(string a, int256 b, bytes32 c)

View file

@ -44,11 +44,6 @@ func NewUnderscorer() (*Underscorer, error) {
return &Underscorer{abi: *parsed}, nil
}
func (underscorer *Underscorer) PackConstructor() []byte {
res, _ := underscorer.abi.Pack("")
return res
}
// AllPurelyUnderscoredOutput is a free data retrieval call binding the contract method 0xb564b34d.
//
// Solidity: function AllPurelyUnderscoredOutput() view returns(int256 _, int256 __)