fix abigen v2

This commit is contained in:
maskpp 2025-04-22 17:08:31 +08:00
parent 0d9c49c753
commit 2958387a84
6 changed files with 50 additions and 134 deletions

View file

@ -93,12 +93,8 @@ var (
// the contract method with ID 0x{{printf "%x" .Original.ID}}. // the contract method with ID 0x{{printf "%x" .Original.ID}}.
// //
// Solidity: {{.Original.String}} // Solidity: {{.Original.String}}
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Pack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) []byte { func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Pack{{.Normalized.Name}}({{range .Normalized.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) ([]byte, error) {
enc, err := {{ decapitalise $contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) return {{ decapitalise $contract.Type}}.abi.Pack("{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
if err != nil {
panic(err)
}
return enc
} }
{{/* Unpack method is needed only when there are return args */}} {{/* Unpack method is needed only when there are return args */}}
@ -117,14 +113,14 @@ var (
// //
// Solidity: {{.Original.String}} // Solidity: {{.Original.String}}
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}(data []byte) ( func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) Unpack{{.Normalized.Name}}(data []byte) (
{{- if .Structured}} {{.Normalized.Name}}Output,{{else}} {{- if .Structured}} *{{.Normalized.Name}}Output,{{else}}
{{- range .Normalized.Outputs}} {{bindtype .Type $structs}},{{- end }} {{- range .Normalized.Outputs}} {{bindtype .Type $structs}},{{- end }}
{{- end }} error) { {{- end }} error) {
out, err := {{ decapitalise $contract.Type}}.abi.Unpack("{{.Original.Name}}", data) out, err := {{ decapitalise $contract.Type}}.abi.Unpack("{{.Original.Name}}", data)
{{- if .Structured}} {{- if .Structured}}
outstruct := new({{.Normalized.Name}}Output) outstruct := new({{.Normalized.Name}}Output)
if err != nil { if err != nil {
return *outstruct, err return outstruct, nil
} }
{{- range $i, $t := .Normalized.Outputs}} {{- range $i, $t := .Normalized.Outputs}}
{{- if ispointertype .Type}} {{- if ispointertype .Type}}
@ -133,8 +129,7 @@ var (
outstruct.{{capitalise .Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}) outstruct.{{capitalise .Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
{{- end }} {{- end }}
{{- end }} {{- end }}
return *outstruct, err return outstruct, nil{{else}}
{{else}}
if err != nil { if err != nil {
return {{range $i, $_ := .Normalized.Outputs}}{{if ispointertype .Type}}new({{underlyingbindtype .Type }}), {{else}}*new({{bindtype .Type $structs}}), {{end}}{{end}} err return {{range $i, $_ := .Normalized.Outputs}}{{if ispointertype .Type}}new({{underlyingbindtype .Type }}), {{else}}*new({{bindtype .Type $structs}}), {{end}}{{end}} err
} }
@ -145,8 +140,7 @@ var (
out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}) out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
{{- end }} {{- end }}
{{- end}} {{- end}}
return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} nil return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} nil{{- end}}
{{- end}}
} }
{{end}} {{end}}
{{end}} {{end}}

View file

@ -62,12 +62,8 @@ func (c *DB) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0x9507d39a. // the contract method with ID 0x9507d39a.
// //
// Solidity: function get(uint256 k) returns(uint256) // Solidity: function get(uint256 k) returns(uint256)
func (dB *DB) PackGet(k *big.Int) []byte { func (dB *DB) PackGet(k *big.Int) ([]byte, error) {
enc, err := dB.abi.Pack("get", k) return dB.abi.Pack("get", k)
if err != nil {
panic(err)
}
return enc
} }
// UnpackGet is the Go binding that unpacks the parameters returned // UnpackGet is the Go binding that unpacks the parameters returned
@ -87,12 +83,8 @@ func (dB *DB) UnpackGet(data []byte) (*big.Int, error) {
// the contract method with ID 0xe369ba3b. // the contract method with ID 0xe369ba3b.
// //
// Solidity: function getNamedStatParams() view returns(uint256 gets, uint256 inserts, uint256 mods) // Solidity: function getNamedStatParams() view returns(uint256 gets, uint256 inserts, uint256 mods)
func (dB *DB) PackGetNamedStatParams() []byte { func (dB *DB) PackGetNamedStatParams() ([]byte, error) {
enc, err := dB.abi.Pack("getNamedStatParams") return dB.abi.Pack("getNamedStatParams")
if err != nil {
panic(err)
}
return enc
} }
// GetNamedStatParamsOutput serves as a container for the return parameters of contract // GetNamedStatParamsOutput serves as a container for the return parameters of contract
@ -107,29 +99,24 @@ type GetNamedStatParamsOutput struct {
// from invoking the contract method with ID 0xe369ba3b. // from invoking the contract method with ID 0xe369ba3b.
// //
// Solidity: function getNamedStatParams() view returns(uint256 gets, uint256 inserts, uint256 mods) // Solidity: function getNamedStatParams() view returns(uint256 gets, uint256 inserts, uint256 mods)
func (dB *DB) UnpackGetNamedStatParams(data []byte) (GetNamedStatParamsOutput, error) { func (dB *DB) UnpackGetNamedStatParams(data []byte) (*GetNamedStatParamsOutput, error) {
out, err := dB.abi.Unpack("getNamedStatParams", data) out, err := dB.abi.Unpack("getNamedStatParams", data)
outstruct := new(GetNamedStatParamsOutput) outstruct := new(GetNamedStatParamsOutput)
if err != nil { if err != nil {
return *outstruct, err return outstruct, nil
} }
outstruct.Gets = abi.ConvertType(out[0], new(big.Int)).(*big.Int) outstruct.Gets = abi.ConvertType(out[0], new(big.Int)).(*big.Int)
outstruct.Inserts = abi.ConvertType(out[1], new(big.Int)).(*big.Int) outstruct.Inserts = abi.ConvertType(out[1], new(big.Int)).(*big.Int)
outstruct.Mods = abi.ConvertType(out[2], new(big.Int)).(*big.Int) outstruct.Mods = abi.ConvertType(out[2], new(big.Int)).(*big.Int)
return *outstruct, err return outstruct, nil
} }
// PackGetStatParams is the Go binding used to pack the parameters required for calling // PackGetStatParams is the Go binding used to pack the parameters required for calling
// the contract method with ID 0x6fcb9c70. // the contract method with ID 0x6fcb9c70.
// //
// Solidity: function getStatParams() view returns(uint256, uint256, uint256) // Solidity: function getStatParams() view returns(uint256, uint256, uint256)
func (dB *DB) PackGetStatParams() []byte { func (dB *DB) PackGetStatParams() ([]byte, error) {
enc, err := dB.abi.Pack("getStatParams") return dB.abi.Pack("getStatParams")
if err != nil {
panic(err)
}
return enc
} }
// GetStatParamsOutput serves as a container for the return parameters of contract // GetStatParamsOutput serves as a container for the return parameters of contract
@ -144,29 +131,24 @@ type GetStatParamsOutput struct {
// from invoking the contract method with ID 0x6fcb9c70. // from invoking the contract method with ID 0x6fcb9c70.
// //
// Solidity: function getStatParams() view returns(uint256, uint256, uint256) // Solidity: function getStatParams() view returns(uint256, uint256, uint256)
func (dB *DB) UnpackGetStatParams(data []byte) (GetStatParamsOutput, error) { func (dB *DB) UnpackGetStatParams(data []byte) (*GetStatParamsOutput, error) {
out, err := dB.abi.Unpack("getStatParams", data) out, err := dB.abi.Unpack("getStatParams", data)
outstruct := new(GetStatParamsOutput) outstruct := new(GetStatParamsOutput)
if err != nil { if err != nil {
return *outstruct, err return outstruct, nil
} }
outstruct.Arg0 = abi.ConvertType(out[0], new(big.Int)).(*big.Int) outstruct.Arg0 = abi.ConvertType(out[0], new(big.Int)).(*big.Int)
outstruct.Arg1 = abi.ConvertType(out[1], new(big.Int)).(*big.Int) outstruct.Arg1 = abi.ConvertType(out[1], new(big.Int)).(*big.Int)
outstruct.Arg2 = abi.ConvertType(out[2], new(big.Int)).(*big.Int) outstruct.Arg2 = abi.ConvertType(out[2], new(big.Int)).(*big.Int)
return *outstruct, err return outstruct, nil
} }
// PackGetStatsStruct is the Go binding used to pack the parameters required for calling // PackGetStatsStruct is the Go binding used to pack the parameters required for calling
// the contract method with ID 0xee8161e0. // the contract method with ID 0xee8161e0.
// //
// Solidity: function getStatsStruct() view returns((uint256,uint256,uint256)) // Solidity: function getStatsStruct() view returns((uint256,uint256,uint256))
func (dB *DB) PackGetStatsStruct() []byte { func (dB *DB) PackGetStatsStruct() ([]byte, error) {
enc, err := dB.abi.Pack("getStatsStruct") return dB.abi.Pack("getStatsStruct")
if err != nil {
panic(err)
}
return enc
} }
// UnpackGetStatsStruct is the Go binding that unpacks the parameters returned // UnpackGetStatsStruct is the Go binding that unpacks the parameters returned
@ -186,12 +168,8 @@ func (dB *DB) UnpackGetStatsStruct(data []byte) (DBStats, error) {
// the contract method with ID 0x1d834a1b. // the contract method with ID 0x1d834a1b.
// //
// Solidity: function insert(uint256 k, uint256 v) returns(uint256) // Solidity: function insert(uint256 k, uint256 v) returns(uint256)
func (dB *DB) PackInsert(k *big.Int, v *big.Int) []byte { func (dB *DB) PackInsert(k *big.Int, v *big.Int) ([]byte, error) {
enc, err := dB.abi.Pack("insert", k, v) return dB.abi.Pack("insert", k, v)
if err != nil {
panic(err)
}
return enc
} }
// UnpackInsert is the Go binding that unpacks the parameters returned // UnpackInsert is the Go binding that unpacks the parameters returned

View file

@ -55,24 +55,16 @@ func (c *C) Instance(backend bind.ContractBackend, addr common.Address) *bind.Bo
// the contract method with ID 0xcb493749. // the contract method with ID 0xcb493749.
// //
// Solidity: function EmitMulti() returns() // Solidity: function EmitMulti() returns()
func (c *C) PackEmitMulti() []byte { func (c *C) PackEmitMulti() ([]byte, error) {
enc, err := c.abi.Pack("EmitMulti") return c.abi.Pack("EmitMulti")
if err != nil {
panic(err)
}
return enc
} }
// PackEmitOne is the Go binding used to pack the parameters required for calling // PackEmitOne is the Go binding used to pack the parameters required for calling
// the contract method with ID 0xe8e49a71. // the contract method with ID 0xe8e49a71.
// //
// Solidity: function EmitOne() returns() // Solidity: function EmitOne() returns()
func (c *C) PackEmitOne() []byte { func (c *C) PackEmitOne() ([]byte, error) {
enc, err := c.abi.Pack("EmitOne") return c.abi.Pack("EmitOne")
if err != nil {
panic(err)
}
return enc
} }
// CBasic1 represents a basic1 event raised by the C contract. // CBasic1 represents a basic1 event raised by the C contract.

View file

@ -71,12 +71,8 @@ func (c1 *C1) PackConstructor(v1 *big.Int, v2 *big.Int) []byte {
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256 res) // Solidity: function Do(uint256 val) pure returns(uint256 res)
func (c1 *C1) PackDo(val *big.Int) []byte { func (c1 *C1) PackDo(val *big.Int) ([]byte, error) {
enc, err := c1.abi.Pack("Do", val) return c1.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -139,12 +135,8 @@ func (c2 *C2) PackConstructor(v1 *big.Int, v2 *big.Int) []byte {
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256 res) // Solidity: function Do(uint256 val) pure returns(uint256 res)
func (c2 *C2) PackDo(val *big.Int) []byte { func (c2 *C2) PackDo(val *big.Int) ([]byte, error) {
enc, err := c2.abi.Pack("Do", val) return c2.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -191,12 +183,8 @@ func (c *L1) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l1 *L1) PackDo(val *big.Int) []byte { func (l1 *L1) PackDo(val *big.Int) ([]byte, error) {
enc, err := l1.abi.Pack("Do", val) return l1.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -246,12 +234,8 @@ func (c *L2) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l2 *L2) PackDo(val *big.Int) []byte { func (l2 *L2) PackDo(val *big.Int) ([]byte, error) {
enc, err := l2.abi.Pack("Do", val) return l2.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -301,12 +285,8 @@ func (c *L2b) Instance(backend bind.ContractBackend, addr common.Address) *bind.
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l2b *L2b) PackDo(val *big.Int) []byte { func (l2b *L2b) PackDo(val *big.Int) ([]byte, error) {
enc, err := l2b.abi.Pack("Do", val) return l2b.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -353,12 +333,8 @@ func (c *L3) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l3 *L3) PackDo(val *big.Int) []byte { func (l3 *L3) PackDo(val *big.Int) ([]byte, error) {
enc, err := l3.abi.Pack("Do", val) return l3.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -409,12 +385,8 @@ func (c *L4) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l4 *L4) PackDo(val *big.Int) []byte { func (l4 *L4) PackDo(val *big.Int) ([]byte, error) {
enc, err := l4.abi.Pack("Do", val) return l4.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned
@ -464,12 +436,8 @@ func (c *L4b) Instance(backend bind.ContractBackend, addr common.Address) *bind.
// the contract method with ID 0x2ad11272. // the contract method with ID 0x2ad11272.
// //
// Solidity: function Do(uint256 val) pure returns(uint256) // Solidity: function Do(uint256 val) pure returns(uint256)
func (l4b *L4b) PackDo(val *big.Int) []byte { func (l4b *L4b) PackDo(val *big.Int) ([]byte, error) {
enc, err := l4b.abi.Pack("Do", val) return l4b.abi.Pack("Do", val)
if err != nil {
panic(err)
}
return enc
} }
// UnpackDo is the Go binding that unpacks the parameters returned // UnpackDo is the Go binding that unpacks the parameters returned

View file

@ -55,24 +55,16 @@ func (c *C) Instance(backend bind.ContractBackend, addr common.Address) *bind.Bo
// the contract method with ID 0xb0a378b0. // the contract method with ID 0xb0a378b0.
// //
// Solidity: function Bar() pure returns() // Solidity: function Bar() pure returns()
func (c *C) PackBar() []byte { func (c *C) PackBar() ([]byte, error) {
enc, err := c.abi.Pack("Bar") return c.abi.Pack("Bar")
if err != nil {
panic(err)
}
return enc
} }
// PackFoo is the Go binding used to pack the parameters required for calling // PackFoo is the Go binding used to pack the parameters required for calling
// the contract method with ID 0xbfb4ebcf. // the contract method with ID 0xbfb4ebcf.
// //
// Solidity: function Foo() pure returns() // Solidity: function Foo() pure returns()
func (c *C) PackFoo() []byte { func (c *C) PackFoo() ([]byte, error) {
enc, err := c.abi.Pack("Foo") return c.abi.Pack("Foo")
if err != nil {
panic(err)
}
return enc
} }
// UnpackError attempts to decode the provided error data using user-defined // UnpackError attempts to decode the provided error data using user-defined
@ -172,12 +164,8 @@ func (c *C2) Instance(backend bind.ContractBackend, addr common.Address) *bind.B
// the contract method with ID 0xbfb4ebcf. // the contract method with ID 0xbfb4ebcf.
// //
// Solidity: function Foo() pure returns() // Solidity: function Foo() pure returns()
func (c2 *C2) PackFoo() []byte { func (c2 *C2) PackFoo() ([]byte, error) {
enc, err := c2.abi.Pack("Foo") return c2.abi.Pack("Foo")
if err != nil {
panic(err)
}
return enc
} }
// UnpackError attempts to decode the provided error data using user-defined // UnpackError attempts to decode the provided error data using user-defined

View file

@ -55,12 +55,8 @@ func (c *MyContract) Instance(backend bind.ContractBackend, addr common.Address)
// the contract method with ID 0xbd6d1007. // the contract method with ID 0xbd6d1007.
// //
// Solidity: function GetNums() pure returns(uint256[5]) // Solidity: function GetNums() pure returns(uint256[5])
func (myContract *MyContract) PackGetNums() []byte { func (myContract *MyContract) PackGetNums() ([]byte, error) {
enc, err := myContract.abi.Pack("GetNums") return myContract.abi.Pack("GetNums")
if err != nil {
panic(err)
}
return enc
} }
// UnpackGetNums is the Go binding that unpacks the parameters returned // UnpackGetNums is the Go binding that unpacks the parameters returned