@@ -43,17 +43,14 @@ import (
4343 "github.com/ethereum/go-ethereum/log"
4444)
4545
46- // BindHook is a callback function that can be used to customize the binding.
47- type BindHook func (lang Lang , pkg string , types []string , contracts map [string ]* TmplContract , structs map [string ]* TmplStruct ) (data interface {}, templateSource string , err error )
48-
4946// Lang is a target programming language selector to generate bindings for.
5047type Lang int
5148
5249const (
5350 LangGo Lang = iota
5451)
5552
56- func IsKeyWord (arg string ) bool {
53+ func isKeyWord (arg string ) bool {
5754 switch arg {
5855 case "break" :
5956 case "case" :
@@ -101,10 +98,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
10198func BindHelper (types []string , abis []string , bytecodes []string , fsigs []map [string ]string , pkg string , lang Lang , libs map [string ]string , aliases map [string ]string , bindHook BindHook ) (string , error ) {
10299 var (
103100 // contracts is the map of each individual contract requested binding
104- contracts = make (map [string ]* TmplContract )
101+ contracts = make (map [string ]* tmplContract )
105102
106103 // structs is the map of all redeclared structs shared by passed contracts.
107- structs = make (map [string ]* TmplStruct )
104+ structs = make (map [string ]* tmplStruct )
108105
109106 // isLib is the map used to flag each encountered library as such
110107 isLib = make (map [string ]struct {})
@@ -125,11 +122,11 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
125122
126123 // Extract the call and transact methods; events, struct definitions; and sort them alphabetically
127124 var (
128- calls = make (map [string ]* TmplMethod )
129- transacts = make (map [string ]* TmplMethod )
125+ calls = make (map [string ]* tmplMethod )
126+ transacts = make (map [string ]* tmplMethod )
130127 events = make (map [string ]* tmplEvent )
131- fallback * TmplMethod
132- receive * TmplMethod
128+ fallback * tmplMethod
129+ receive * tmplMethod
133130
134131 // identifiers are used to detect duplicated identifiers of functions
135132 // and events. For all calls, transacts and events, abigen will generate
@@ -172,7 +169,7 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
172169 normalized .Inputs = make ([]abi.Argument , len (original .Inputs ))
173170 copy (normalized .Inputs , original .Inputs )
174171 for j , input := range normalized .Inputs {
175- if input .Name == "" || IsKeyWord (input .Name ) {
172+ if input .Name == "" || isKeyWord (input .Name ) {
176173 normalized .Inputs [j ].Name = fmt .Sprintf ("arg%d" , j )
177174 }
178175 if hasStruct (input .Type ) {
@@ -191,9 +188,9 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
191188 }
192189 // Append the methods to the call or transact lists
193190 if original .IsConstant () {
194- calls [original .Name ] = & TmplMethod {Original : original , Normalized : normalized , Structured : structured (original .Outputs )}
191+ calls [original .Name ] = & tmplMethod {Original : original , Normalized : normalized , Structured : structured (original .Outputs )}
195192 } else {
196- transacts [original .Name ] = & TmplMethod {Original : original , Normalized : normalized , Structured : structured (original .Outputs )}
193+ transacts [original .Name ] = & tmplMethod {Original : original , Normalized : normalized , Structured : structured (original .Outputs )}
197194 }
198195 }
199196 for _ , original := range evmABI .Events {
@@ -224,7 +221,7 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
224221 normalized .Inputs = make ([]abi.Argument , len (original .Inputs ))
225222 copy (normalized .Inputs , original .Inputs )
226223 for j , input := range normalized .Inputs {
227- if input .Name == "" || IsKeyWord (input .Name ) {
224+ if input .Name == "" || isKeyWord (input .Name ) {
228225 normalized .Inputs [j ].Name = fmt .Sprintf ("arg%d" , j )
229226 }
230227 // Event is a bit special, we need to define event struct in binding,
@@ -245,12 +242,12 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
245242 }
246243 // Add two special fallback functions if they exist
247244 if evmABI .HasFallback () {
248- fallback = & TmplMethod {Original : evmABI .Fallback }
245+ fallback = & tmplMethod {Original : evmABI .Fallback }
249246 }
250247 if evmABI .HasReceive () {
251- receive = & TmplMethod {Original : evmABI .Receive }
248+ receive = & tmplMethod {Original : evmABI .Receive }
252249 }
253- contracts [types [i ]] = & TmplContract {
250+ contracts [types [i ]] = & tmplContract {
254251 Type : capitalise (types [i ]),
255252 InputABI : strings .ReplaceAll (strippedABI , "\" " , "\\ \" " ),
256253 InputBin : strings .TrimPrefix (strings .TrimSpace (bytecodes [i ]), "0x" ),
@@ -341,14 +338,10 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
341338
342339// bindType is a set of type binders that convert Solidity types to some supported
343340// programming language types.
344- var bindType = map [Lang ]func (kind abi.Type , structs map [string ]* TmplStruct ) string {
341+ var bindType = map [Lang ]func (kind abi.Type , structs map [string ]* tmplStruct ) string {
345342 LangGo : bindTypeGo ,
346343}
347344
348- var bindTypeNew = map [Lang ]func (kind abi.Type , structs map [string ]* TmplStruct ) string {
349- LangGo : bindTypeNewGo ,
350- }
351-
352345// bindBasicTypeGo converts basic solidity types(except array, slice and tuple) to Go ones.
353346func bindBasicTypeGo (kind abi.Type ) string {
354347 switch kind .T {
@@ -373,43 +366,10 @@ func bindBasicTypeGo(kind abi.Type) string {
373366 }
374367}
375368
376- // bindTypeNewGo converts new types to Go ones.
377- func bindTypeNewGo (kind abi.Type , structs map [string ]* TmplStruct ) string {
378- switch kind .T {
379- case abi .TupleTy :
380- return structs [kind .TupleRawName + kind .String ()].Name + "{}"
381- case abi .ArrayTy :
382- return fmt .Sprintf ("[%d]" , kind .Size ) + bindTypeGo (* kind .Elem , structs ) + "{}"
383- case abi .SliceTy :
384- return "nil"
385- case abi .AddressTy :
386- return "common.Address{}"
387- case abi .IntTy , abi .UintTy :
388- parts := regexp .MustCompile (`(u)?int([0-9]*)` ).FindStringSubmatch (kind .String ())
389- switch parts [2 ] {
390- case "8" , "16" , "32" , "64" :
391- return "0"
392- }
393- return "new(big.Int)"
394- case abi .FixedBytesTy :
395- return fmt .Sprintf ("[%d]byte" , kind .Size ) + "{}"
396- case abi .BytesTy :
397- return "[]byte{}"
398- case abi .FunctionTy :
399- return "[24]byte{}"
400- case abi .BoolTy :
401- return "false"
402- case abi .StringTy :
403- return `""`
404- default :
405- return "nil"
406- }
407- }
408-
409369// bindTypeGo converts solidity types to Go ones. Since there is no clear mapping
410370// from all Solidity types to Go ones (e.g. uint17), those that cannot be exactly
411371// mapped will use an upscaled type (e.g. BigDecimal).
412- func bindTypeGo (kind abi.Type , structs map [string ]* TmplStruct ) string {
372+ func bindTypeGo (kind abi.Type , structs map [string ]* tmplStruct ) string {
413373 switch kind .T {
414374 case abi .TupleTy :
415375 return structs [kind .TupleRawName + kind .String ()].Name
@@ -424,13 +384,13 @@ func bindTypeGo(kind abi.Type, structs map[string]*TmplStruct) string {
424384
425385// bindTopicType is a set of type binders that convert Solidity types to some
426386// supported programming language topic types.
427- var bindTopicType = map [Lang ]func (kind abi.Type , structs map [string ]* TmplStruct ) string {
387+ var bindTopicType = map [Lang ]func (kind abi.Type , structs map [string ]* tmplStruct ) string {
428388 LangGo : bindTopicTypeGo ,
429389}
430390
431391// bindTopicTypeGo converts a Solidity topic type to a Go one. It is almost the same
432392// functionality as for simple types, but dynamic types get converted to hashes.
433- func bindTopicTypeGo (kind abi.Type , structs map [string ]* TmplStruct ) string {
393+ func bindTopicTypeGo (kind abi.Type , structs map [string ]* tmplStruct ) string {
434394 bound := bindTypeGo (kind , structs )
435395
436396 // todo(rjl493456442) according solidity documentation, indexed event
@@ -447,14 +407,14 @@ func bindTopicTypeGo(kind abi.Type, structs map[string]*TmplStruct) string {
447407
448408// bindStructType is a set of type binders that convert Solidity tuple types to some supported
449409// programming language struct definition.
450- var bindStructType = map [Lang ]func (kind abi.Type , structs map [string ]* TmplStruct ) string {
410+ var bindStructType = map [Lang ]func (kind abi.Type , structs map [string ]* tmplStruct ) string {
451411 LangGo : bindStructTypeGo ,
452412}
453413
454414// bindStructTypeGo converts a Solidity tuple type to a Go one and records the mapping
455415// in the given map.
456416// Notably, this function will resolve and record nested struct recursively.
457- func bindStructTypeGo (kind abi.Type , structs map [string ]* TmplStruct ) string {
417+ func bindStructTypeGo (kind abi.Type , structs map [string ]* tmplStruct ) string {
458418 switch kind .T {
459419 case abi .TupleTy :
460420 // We compose a raw struct name and a canonical parameter expression
@@ -483,7 +443,7 @@ func bindStructTypeGo(kind abi.Type, structs map[string]*TmplStruct) string {
483443 }
484444 name = capitalise (name )
485445
486- structs [id ] = & TmplStruct {
446+ structs [id ] = & tmplStruct {
487447 Name : name ,
488448 Fields : fields ,
489449 }
@@ -568,11 +528,3 @@ func hasStruct(t abi.Type) bool {
568528 return false
569529 }
570530}
571-
572- func mkList (args ... interface {}) []interface {} {
573- return args
574- }
575-
576- func add (a , b int ) int {
577- return a + b
578- }
0 commit comments