Skip to content

Commit c5fa9c4

Browse files
committed
accounts/abi: don't capitalise argument names in pack functions. normalizeArgs returns args with names that start lowercase.
1 parent 8b506f5 commit c5fa9c4

File tree

19 files changed

+116
-107
lines changed

19 files changed

+116
-107
lines changed

accounts/abi/abigen/bindv2.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,15 @@ func normalizeArgs(args abi.Arguments) abi.Arguments {
195195

196196
for i, input := range args {
197197
if isKeyWord(input.Name) {
198-
args[i].Name = fmt.Sprintf("Arg%d", i)
198+
args[i].Name = fmt.Sprintf("arg%d", i)
199199
}
200200
args[i].Name = abi.ToCamelCase(args[i].Name)
201201
if args[i].Name == "" {
202-
args[i].Name = fmt.Sprintf("Arg%d", i)
202+
args[i].Name = fmt.Sprintf("arg%d", i)
203+
} else {
204+
args[i].Name = strings.ToLower(args[i].Name[:1]) + args[i].Name[1:]
203205
}
206+
204207
for index := 0; ; index++ {
205208
if !used[args[i].Name] {
206209
used[args[i].Name] = true

accounts/abi/abigen/bindv2_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ func TestNormalizeArgs(t *testing.T) {
303303
expected []string
304304
}
305305
for i, tc := range []normalizeArgsTc{
306-
{[]string{"arg1", "Arg1"}, []string{"Arg1", "Arg10"}},
307-
{[]string{"", ""}, []string{"Arg0", "Arg1"}},
308-
{[]string{"var", "const"}, []string{"Arg0", "Arg1"}},
309-
{[]string{"_res", "Res"}, []string{"Res", "Res0"}},
310-
{[]string{"_", "__"}, []string{"Arg0", "Arg1"}}} {
306+
{[]string{"arg1", "arg1"}, []string{"arg1", "arg10"}},
307+
{[]string{"", ""}, []string{"arg0", "arg1"}},
308+
{[]string{"var", "const"}, []string{"arg0", "arg1"}},
309+
{[]string{"_res", "Res"}, []string{"res", "res0"}},
310+
{[]string{"_", "__"}, []string{"arg0", "arg1"}}} {
311311
var inpArgs abi.Arguments
312312
for _, inpArgName := range tc.inp {
313313
inpArgs = append(inpArgs, abi.Argument{

accounts/abi/abigen/source2.go.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
// {{.Name}} is an auto generated low-level Go binding around an user-defined struct.
3030
type {{.Name}} struct {
3131
{{range $field := .Fields}}
32-
{{$field.Name}} {{$field.Type}}{{end}}
32+
{{capitalise $field.Name}} {{$field.Type}}{{end}}
3333
}
3434
{{end}}
3535

@@ -108,7 +108,7 @@ var (
108108
// method {{ .Normalized.Name }}.
109109
type {{.Normalized.Name}}Output struct {
110110
{{range .Normalized.Outputs}}
111-
{{.Name}} {{bindtype .Type $structs}}{{end}}
111+
{{capitalise .Name}} {{bindtype .Type $structs}}{{end}}
112112
}
113113
{{ end }}
114114

@@ -128,9 +128,9 @@ var (
128128
}
129129
{{- range $i, $t := .Normalized.Outputs}}
130130
{{- if ispointertype .Type}}
131-
outstruct.{{.Name}} = abi.ConvertType(out[{{$i}}], new({{underlyingbindtype .Type }})).({{bindtype .Type $structs}})
131+
outstruct.{{capitalise .Name}} = abi.ConvertType(out[{{$i}}], new({{underlyingbindtype .Type }})).({{bindtype .Type $structs}})
132132
{{- else }}
133-
outstruct.{{.Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
133+
outstruct.{{capitalise .Name}} = *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}})
134134
{{- end }}
135135
{{- end }}
136136
return *outstruct, err

accounts/abi/abigen/testdata/v2/callbackparam.go.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func (c *CallbackParam) Instance(backend bind.ContractBackend, addr common.Addre
5555
// the contract method with ID 0xd7a5aba2.
5656
//
5757
// Solidity: function test(function callback) returns()
58-
func (callbackParam *CallbackParam) PackTest(Callback [24]byte) []byte {
59-
enc, err := callbackParam.abi.Pack("test", Callback)
58+
func (callbackParam *CallbackParam) PackTest(callback [24]byte) []byte {
59+
enc, err := callbackParam.abi.Pack("test", callback)
6060
if err != nil {
6161
panic(err)
6262
}

accounts/abi/abigen/testdata/v2/crowdsale.go.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func (crowdsale *Crowdsale) UnpackDeadline(data []byte) (*big.Int, error) {
154154
// the contract method with ID 0xdc0d3dff.
155155
//
156156
// Solidity: function funders(uint256 ) returns(address addr, uint256 amount)
157-
func (crowdsale *Crowdsale) PackFunders(Arg0 *big.Int) []byte {
158-
enc, err := crowdsale.abi.Pack("funders", Arg0)
157+
func (crowdsale *Crowdsale) PackFunders(arg0 *big.Int) []byte {
158+
enc, err := crowdsale.abi.Pack("funders", arg0)
159159
if err != nil {
160160
panic(err)
161161
}

accounts/abi/abigen/testdata/v2/dao.go.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (dAO *DAO) PackConstructor(minimumQuorumForProposals *big.Int, minutesForDe
6767
// the contract method with ID 0x9644fcbd.
6868
//
6969
// Solidity: function changeMembership(address targetMember, bool canVote, string memberName) returns()
70-
func (dAO *DAO) PackChangeMembership(TargetMember common.Address, CanVote bool, MemberName string) []byte {
71-
enc, err := dAO.abi.Pack("changeMembership", TargetMember, CanVote, MemberName)
70+
func (dAO *DAO) PackChangeMembership(targetMember common.Address, canVote bool, memberName string) []byte {
71+
enc, err := dAO.abi.Pack("changeMembership", targetMember, canVote, memberName)
7272
if err != nil {
7373
panic(err)
7474
}
@@ -79,8 +79,8 @@ func (dAO *DAO) PackChangeMembership(TargetMember common.Address, CanVote bool,
7979
// the contract method with ID 0xbcca1fd3.
8080
//
8181
// Solidity: function changeVotingRules(uint256 minimumQuorumForProposals, uint256 minutesForDebate, int256 marginOfVotesForMajority) returns()
82-
func (dAO *DAO) PackChangeVotingRules(MinimumQuorumForProposals *big.Int, MinutesForDebate *big.Int, MarginOfVotesForMajority *big.Int) []byte {
83-
enc, err := dAO.abi.Pack("changeVotingRules", MinimumQuorumForProposals, MinutesForDebate, MarginOfVotesForMajority)
82+
func (dAO *DAO) PackChangeVotingRules(minimumQuorumForProposals *big.Int, minutesForDebate *big.Int, marginOfVotesForMajority *big.Int) []byte {
83+
enc, err := dAO.abi.Pack("changeVotingRules", minimumQuorumForProposals, minutesForDebate, marginOfVotesForMajority)
8484
if err != nil {
8585
panic(err)
8686
}
@@ -91,8 +91,8 @@ func (dAO *DAO) PackChangeVotingRules(MinimumQuorumForProposals *big.Int, Minute
9191
// the contract method with ID 0xeceb2945.
9292
//
9393
// Solidity: function checkProposalCode(uint256 proposalNumber, address beneficiary, uint256 etherAmount, bytes transactionBytecode) returns(bool codeChecksOut)
94-
func (dAO *DAO) PackCheckProposalCode(ProposalNumber *big.Int, Beneficiary common.Address, EtherAmount *big.Int, TransactionBytecode []byte) []byte {
95-
enc, err := dAO.abi.Pack("checkProposalCode", ProposalNumber, Beneficiary, EtherAmount, TransactionBytecode)
94+
func (dAO *DAO) PackCheckProposalCode(proposalNumber *big.Int, beneficiary common.Address, etherAmount *big.Int, transactionBytecode []byte) []byte {
95+
enc, err := dAO.abi.Pack("checkProposalCode", proposalNumber, beneficiary, etherAmount, transactionBytecode)
9696
if err != nil {
9797
panic(err)
9898
}
@@ -141,8 +141,8 @@ func (dAO *DAO) UnpackDebatingPeriodInMinutes(data []byte) (*big.Int, error) {
141141
// the contract method with ID 0x237e9492.
142142
//
143143
// Solidity: function executeProposal(uint256 proposalNumber, bytes transactionBytecode) returns(int256 result)
144-
func (dAO *DAO) PackExecuteProposal(ProposalNumber *big.Int, TransactionBytecode []byte) []byte {
145-
enc, err := dAO.abi.Pack("executeProposal", ProposalNumber, TransactionBytecode)
144+
func (dAO *DAO) PackExecuteProposal(proposalNumber *big.Int, transactionBytecode []byte) []byte {
145+
enc, err := dAO.abi.Pack("executeProposal", proposalNumber, transactionBytecode)
146146
if err != nil {
147147
panic(err)
148148
}
@@ -191,8 +191,8 @@ func (dAO *DAO) UnpackMajorityMargin(data []byte) (*big.Int, error) {
191191
// the contract method with ID 0x39106821.
192192
//
193193
// Solidity: function memberId(address ) returns(uint256)
194-
func (dAO *DAO) PackMemberId(Arg0 common.Address) []byte {
195-
enc, err := dAO.abi.Pack("memberId", Arg0)
194+
func (dAO *DAO) PackMemberId(arg0 common.Address) []byte {
195+
enc, err := dAO.abi.Pack("memberId", arg0)
196196
if err != nil {
197197
panic(err)
198198
}
@@ -216,8 +216,8 @@ func (dAO *DAO) UnpackMemberId(data []byte) (*big.Int, error) {
216216
// the contract method with ID 0x5daf08ca.
217217
//
218218
// Solidity: function members(uint256 ) returns(address member, bool canVote, string name, uint256 memberSince)
219-
func (dAO *DAO) PackMembers(Arg0 *big.Int) []byte {
220-
enc, err := dAO.abi.Pack("members", Arg0)
219+
func (dAO *DAO) PackMembers(arg0 *big.Int) []byte {
220+
enc, err := dAO.abi.Pack("members", arg0)
221221
if err != nil {
222222
panic(err)
223223
}
@@ -280,8 +280,8 @@ func (dAO *DAO) UnpackMinimumQuorum(data []byte) (*big.Int, error) {
280280
// the contract method with ID 0xb1050da5.
281281
//
282282
// Solidity: function newProposal(address beneficiary, uint256 etherAmount, string JobDescription, bytes transactionBytecode) returns(uint256 proposalID)
283-
func (dAO *DAO) PackNewProposal(Beneficiary common.Address, EtherAmount *big.Int, JobDescription string, TransactionBytecode []byte) []byte {
284-
enc, err := dAO.abi.Pack("newProposal", Beneficiary, EtherAmount, JobDescription, TransactionBytecode)
283+
func (dAO *DAO) PackNewProposal(beneficiary common.Address, etherAmount *big.Int, jobDescription string, transactionBytecode []byte) []byte {
284+
enc, err := dAO.abi.Pack("newProposal", beneficiary, etherAmount, jobDescription, transactionBytecode)
285285
if err != nil {
286286
panic(err)
287287
}
@@ -355,8 +355,8 @@ func (dAO *DAO) UnpackOwner(data []byte) (common.Address, error) {
355355
// the contract method with ID 0x013cf08b.
356356
//
357357
// Solidity: function proposals(uint256 ) returns(address recipient, uint256 amount, string description, uint256 votingDeadline, bool executed, bool proposalPassed, uint256 numberOfVotes, int256 currentResult, bytes32 proposalHash)
358-
func (dAO *DAO) PackProposals(Arg0 *big.Int) []byte {
359-
enc, err := dAO.abi.Pack("proposals", Arg0)
358+
func (dAO *DAO) PackProposals(arg0 *big.Int) []byte {
359+
enc, err := dAO.abi.Pack("proposals", arg0)
360360
if err != nil {
361361
panic(err)
362362
}
@@ -404,8 +404,8 @@ func (dAO *DAO) UnpackProposals(data []byte) (ProposalsOutput, error) {
404404
// the contract method with ID 0xf2fde38b.
405405
//
406406
// Solidity: function transferOwnership(address newOwner) returns()
407-
func (dAO *DAO) PackTransferOwnership(NewOwner common.Address) []byte {
408-
enc, err := dAO.abi.Pack("transferOwnership", NewOwner)
407+
func (dAO *DAO) PackTransferOwnership(newOwner common.Address) []byte {
408+
enc, err := dAO.abi.Pack("transferOwnership", newOwner)
409409
if err != nil {
410410
panic(err)
411411
}
@@ -416,8 +416,8 @@ func (dAO *DAO) PackTransferOwnership(NewOwner common.Address) []byte {
416416
// the contract method with ID 0xd3c0715b.
417417
//
418418
// Solidity: function vote(uint256 proposalNumber, bool supportsProposal, string justificationText) returns(uint256 voteID)
419-
func (dAO *DAO) PackVote(ProposalNumber *big.Int, SupportsProposal bool, JustificationText string) []byte {
420-
enc, err := dAO.abi.Pack("vote", ProposalNumber, SupportsProposal, JustificationText)
419+
func (dAO *DAO) PackVote(proposalNumber *big.Int, supportsProposal bool, justificationText string) []byte {
420+
enc, err := dAO.abi.Pack("vote", proposalNumber, supportsProposal, justificationText)
421421
if err != nil {
422422
panic(err)
423423
}

accounts/abi/abigen/testdata/v2/deeplynestedarray.go.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func (c *DeeplyNestedArray) Instance(backend bind.ContractBackend, addr common.A
5555
// the contract method with ID 0x98ed1856.
5656
//
5757
// Solidity: function deepUint64Array(uint256 , uint256 , uint256 ) view returns(uint64)
58-
func (deeplyNestedArray *DeeplyNestedArray) PackDeepUint64Array(Arg0 *big.Int, Arg1 *big.Int, Arg2 *big.Int) []byte {
59-
enc, err := deeplyNestedArray.abi.Pack("deepUint64Array", Arg0, Arg1, Arg2)
58+
func (deeplyNestedArray *DeeplyNestedArray) PackDeepUint64Array(arg0 *big.Int, arg1 *big.Int, arg2 *big.Int) []byte {
59+
enc, err := deeplyNestedArray.abi.Pack("deepUint64Array", arg0, arg1, arg2)
6060
if err != nil {
6161
panic(err)
6262
}
@@ -105,8 +105,8 @@ func (deeplyNestedArray *DeeplyNestedArray) UnpackRetrieveDeepArray(data []byte)
105105
// the contract method with ID 0x34424855.
106106
//
107107
// Solidity: function storeDeepUintArray(uint64[3][4][5] arr) returns()
108-
func (deeplyNestedArray *DeeplyNestedArray) PackStoreDeepUintArray(Arr [5][4][3]uint64) []byte {
109-
enc, err := deeplyNestedArray.abi.Pack("storeDeepUintArray", Arr)
108+
func (deeplyNestedArray *DeeplyNestedArray) PackStoreDeepUintArray(arr [5][4][3]uint64) []byte {
109+
enc, err := deeplyNestedArray.abi.Pack("storeDeepUintArray", arr)
110110
if err != nil {
111111
panic(err)
112112
}

accounts/abi/abigen/testdata/v2/inputchecker.go.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func (c *InputChecker) Instance(backend bind.ContractBackend, addr common.Addres
5454
// the contract method with ID 0x3e708e82.
5555
//
5656
// Solidity: function anonInput(string ) returns()
57-
func (inputChecker *InputChecker) PackAnonInput(Arg0 string) []byte {
58-
enc, err := inputChecker.abi.Pack("anonInput", Arg0)
57+
func (inputChecker *InputChecker) PackAnonInput(arg0 string) []byte {
58+
enc, err := inputChecker.abi.Pack("anonInput", arg0)
5959
if err != nil {
6060
panic(err)
6161
}
@@ -66,8 +66,8 @@ func (inputChecker *InputChecker) PackAnonInput(Arg0 string) []byte {
6666
// the contract method with ID 0x28160527.
6767
//
6868
// Solidity: function anonInputs(string , string ) returns()
69-
func (inputChecker *InputChecker) PackAnonInputs(Arg0 string, Arg1 string) []byte {
70-
enc, err := inputChecker.abi.Pack("anonInputs", Arg0, Arg1)
69+
func (inputChecker *InputChecker) PackAnonInputs(arg0 string, arg1 string) []byte {
70+
enc, err := inputChecker.abi.Pack("anonInputs", arg0, arg1)
7171
if err != nil {
7272
panic(err)
7373
}
@@ -78,8 +78,8 @@ func (inputChecker *InputChecker) PackAnonInputs(Arg0 string, Arg1 string) []byt
7878
// the contract method with ID 0xc689ebdc.
7979
//
8080
// Solidity: function mixedInputs(string , string str) returns()
81-
func (inputChecker *InputChecker) PackMixedInputs(Arg0 string, Str string) []byte {
82-
enc, err := inputChecker.abi.Pack("mixedInputs", Arg0, Str)
81+
func (inputChecker *InputChecker) PackMixedInputs(arg0 string, str string) []byte {
82+
enc, err := inputChecker.abi.Pack("mixedInputs", arg0, str)
8383
if err != nil {
8484
panic(err)
8585
}
@@ -90,8 +90,8 @@ func (inputChecker *InputChecker) PackMixedInputs(Arg0 string, Str string) []byt
9090
// the contract method with ID 0x0d402005.
9191
//
9292
// Solidity: function namedInput(string str) returns()
93-
func (inputChecker *InputChecker) PackNamedInput(Str string) []byte {
94-
enc, err := inputChecker.abi.Pack("namedInput", Str)
93+
func (inputChecker *InputChecker) PackNamedInput(str string) []byte {
94+
enc, err := inputChecker.abi.Pack("namedInput", str)
9595
if err != nil {
9696
panic(err)
9797
}
@@ -102,8 +102,8 @@ func (inputChecker *InputChecker) PackNamedInput(Str string) []byte {
102102
// the contract method with ID 0x63c796ed.
103103
//
104104
// Solidity: function namedInputs(string str1, string str2) returns()
105-
func (inputChecker *InputChecker) PackNamedInputs(Str1 string, Str2 string) []byte {
106-
enc, err := inputChecker.abi.Pack("namedInputs", Str1, Str2)
105+
func (inputChecker *InputChecker) PackNamedInputs(str1 string, str2 string) []byte {
106+
enc, err := inputChecker.abi.Pack("namedInputs", str1, str2)
107107
if err != nil {
108108
panic(err)
109109
}

accounts/abi/abigen/testdata/v2/interactor.go.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func (interactor *Interactor) UnpackDeployString(data []byte) (string, error) {
9292
// the contract method with ID 0xd736c513.
9393
//
9494
// Solidity: function transact(string str) returns()
95-
func (interactor *Interactor) PackTransact(Str string) []byte {
96-
enc, err := interactor.abi.Pack("transact", Str)
95+
func (interactor *Interactor) PackTransact(str string) []byte {
96+
enc, err := interactor.abi.Pack("transact", str)
9797
if err != nil {
9898
panic(err)
9999
}

accounts/abi/abigen/testdata/v2/nameconflict.go.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func (c *NameConflict) Instance(backend bind.ContractBackend, addr common.Addres
6161
// the contract method with ID 0xcce7b048.
6262
//
6363
// Solidity: function addRequest((bytes,bytes) req) pure returns()
64-
func (nameConflict *NameConflict) PackAddRequest(Req Oraclerequest) []byte {
65-
enc, err := nameConflict.abi.Pack("addRequest", Req)
64+
func (nameConflict *NameConflict) PackAddRequest(req Oraclerequest) []byte {
65+
enc, err := nameConflict.abi.Pack("addRequest", req)
6666
if err != nil {
6767
panic(err)
6868
}

0 commit comments

Comments
 (0)