gitlab.com/yannislg/go-pulse@v0.0.0-20210722055913-a3e24e95638d/accounts/abi/bind/template.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package bind
    18  
    19  import "github.com/ethereum/go-ethereum/accounts/abi"
    20  
    21  // tmplData is the data structure required to fill the binding template.
    22  type tmplData struct {
    23  	Package   string                   // Name of the package to place the generated file in
    24  	Contracts map[string]*tmplContract // List of contracts to generate into this file
    25  	Libraries map[string]string        // Map the bytecode's link pattern to the library name
    26  	Structs   map[string]*tmplStruct   // Contract struct type definitions
    27  }
    28  
    29  // tmplContract contains the data needed to generate an individual contract binding.
    30  type tmplContract struct {
    31  	Type        string                 // Type name of the main contract binding
    32  	InputABI    string                 // JSON ABI used as the input to generate the binding from
    33  	InputBin    string                 // Optional EVM bytecode used to denetare deploy code from
    34  	FuncSigs    map[string]string      // Optional map: string signature -> 4-byte signature
    35  	Constructor abi.Method             // Contract constructor for deploy parametrization
    36  	Calls       map[string]*tmplMethod // Contract calls that only read state data
    37  	Transacts   map[string]*tmplMethod // Contract calls that write state data
    38  	Fallback    *tmplMethod            // Additional special fallback function
    39  	Receive     *tmplMethod            // Additional special receive function
    40  	Events      map[string]*tmplEvent  // Contract events accessors
    41  	Libraries   map[string]string      // Same as tmplData, but filtered to only keep what the contract needs
    42  	Library     bool                   // Indicator whether the contract is a library
    43  }
    44  
    45  // tmplMethod is a wrapper around an abi.Method that contains a few preprocessed
    46  // and cached data fields.
    47  type tmplMethod struct {
    48  	Original   abi.Method // Original method as parsed by the abi package
    49  	Normalized abi.Method // Normalized version of the parsed method (capitalized names, non-anonymous args/returns)
    50  	Structured bool       // Whether the returns should be accumulated into a struct
    51  }
    52  
    53  // tmplEvent is a wrapper around an a
    54  type tmplEvent struct {
    55  	Original   abi.Event // Original event as parsed by the abi package
    56  	Normalized abi.Event // Normalized version of the parsed fields
    57  }
    58  
    59  // tmplField is a wrapper around a struct field with binding language
    60  // struct type definition and relative filed name.
    61  type tmplField struct {
    62  	Type    string   // Field type representation depends on target binding language
    63  	Name    string   // Field name converted from the raw user-defined field name
    64  	SolKind abi.Type // Raw abi type information
    65  }
    66  
    67  // tmplStruct is a wrapper around an abi.tuple contains a auto-generated
    68  // struct name.
    69  type tmplStruct struct {
    70  	Name   string       // Auto-generated struct name(before solidity v0.5.11) or raw name.
    71  	Fields []*tmplField // Struct fields definition depends on the binding language.
    72  }
    73  
    74  // tmplSource is language to template mapping containing all the supported
    75  // programming languages the package can generate to.
    76  var tmplSource = map[Lang]string{
    77  	LangGo:   tmplSourceGo,
    78  	LangJava: tmplSourceJava,
    79  }
    80  
    81  // tmplSourceGo is the Go source template use to generate the contract binding
    82  // based on.
    83  const tmplSourceGo = `
    84  // Code generated - DO NOT EDIT.
    85  // This file is a generated binding and any manual changes will be lost.
    86  
    87  package {{.Package}}
    88  
    89  import (
    90  	"math/big"
    91  	"strings"
    92  
    93  	ethereum "github.com/ethereum/go-ethereum"
    94  	"github.com/ethereum/go-ethereum/accounts/abi"
    95  	"github.com/ethereum/go-ethereum/accounts/abi/bind"
    96  	"github.com/ethereum/go-ethereum/common"
    97  	"github.com/ethereum/go-ethereum/core/types"
    98  	"github.com/ethereum/go-ethereum/event"
    99  )
   100  
   101  // Reference imports to suppress errors if they are not otherwise used.
   102  var (
   103  	_ = big.NewInt
   104  	_ = strings.NewReader
   105  	_ = ethereum.NotFound
   106  	_ = abi.U256
   107  	_ = bind.Bind
   108  	_ = common.Big1
   109  	_ = types.BloomLookup
   110  	_ = event.NewSubscription
   111  )
   112  
   113  {{$structs := .Structs}}
   114  {{range $structs}}
   115  	// {{.Name}} is an auto generated low-level Go binding around an user-defined struct.
   116  	type {{.Name}} struct {
   117  	{{range $field := .Fields}}
   118  	{{$field.Name}} {{$field.Type}}{{end}}
   119  	}
   120  {{end}}
   121  
   122  {{range $contract := .Contracts}}
   123  	// {{.Type}}ABI is the input ABI used to generate the binding from.
   124  	const {{.Type}}ABI = "{{.InputABI}}"
   125  
   126  	{{if $contract.FuncSigs}}
   127  		// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
   128  		var {{.Type}}FuncSigs = map[string]string{
   129  			{{range $strsig, $binsig := .FuncSigs}}"{{$binsig}}": "{{$strsig}}",
   130  			{{end}}
   131  		}
   132  	{{end}}
   133  
   134  	{{if .InputBin}}
   135  		// {{.Type}}Bin is the compiled bytecode used for deploying new contracts.
   136  		var {{.Type}}Bin = "0x{{.InputBin}}"
   137  
   138  		// Deploy{{.Type}} deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
   139  		func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type $structs}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) {
   140  		  parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI))
   141  		  if err != nil {
   142  		    return common.Address{}, nil, nil, err
   143  		  }
   144  		  {{range $pattern, $name := .Libraries}}
   145  			{{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend)
   146  			{{$contract.Type}}Bin = strings.Replace({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:], -1)
   147  		  {{end}}
   148  		  address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
   149  		  if err != nil {
   150  		    return common.Address{}, nil, nil, err
   151  		  }
   152  		  return address, tx, &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil
   153  		}
   154  	{{end}}
   155  
   156  	// {{.Type}} is an auto generated Go binding around an Ethereum contract.
   157  	type {{.Type}} struct {
   158  	  {{.Type}}Caller     // Read-only binding to the contract
   159  	  {{.Type}}Transactor // Write-only binding to the contract
   160  	  {{.Type}}Filterer   // Log filterer for contract events
   161  	}
   162  
   163  	// {{.Type}}Caller is an auto generated read-only Go binding around an Ethereum contract.
   164  	type {{.Type}}Caller struct {
   165  	  contract *bind.BoundContract // Generic contract wrapper for the low level calls
   166  	}
   167  
   168  	// {{.Type}}Transactor is an auto generated write-only Go binding around an Ethereum contract.
   169  	type {{.Type}}Transactor struct {
   170  	  contract *bind.BoundContract // Generic contract wrapper for the low level calls
   171  	}
   172  
   173  	// {{.Type}}Filterer is an auto generated log filtering Go binding around an Ethereum contract events.
   174  	type {{.Type}}Filterer struct {
   175  	  contract *bind.BoundContract // Generic contract wrapper for the low level calls
   176  	}
   177  
   178  	// {{.Type}}Session is an auto generated Go binding around an Ethereum contract,
   179  	// with pre-set call and transact options.
   180  	type {{.Type}}Session struct {
   181  	  Contract     *{{.Type}}        // Generic contract binding to set the session for
   182  	  CallOpts     bind.CallOpts     // Call options to use throughout this session
   183  	  TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
   184  	}
   185  
   186  	// {{.Type}}CallerSession is an auto generated read-only Go binding around an Ethereum contract,
   187  	// with pre-set call options.
   188  	type {{.Type}}CallerSession struct {
   189  	  Contract *{{.Type}}Caller // Generic contract caller binding to set the session for
   190  	  CallOpts bind.CallOpts    // Call options to use throughout this session
   191  	}
   192  
   193  	// {{.Type}}TransactorSession is an auto generated write-only Go binding around an Ethereum contract,
   194  	// with pre-set transact options.
   195  	type {{.Type}}TransactorSession struct {
   196  	  Contract     *{{.Type}}Transactor // Generic contract transactor binding to set the session for
   197  	  TransactOpts bind.TransactOpts    // Transaction auth options to use throughout this session
   198  	}
   199  
   200  	// {{.Type}}Raw is an auto generated low-level Go binding around an Ethereum contract.
   201  	type {{.Type}}Raw struct {
   202  	  Contract *{{.Type}} // Generic contract binding to access the raw methods on
   203  	}
   204  
   205  	// {{.Type}}CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
   206  	type {{.Type}}CallerRaw struct {
   207  		Contract *{{.Type}}Caller // Generic read-only contract binding to access the raw methods on
   208  	}
   209  
   210  	// {{.Type}}TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
   211  	type {{.Type}}TransactorRaw struct {
   212  		Contract *{{.Type}}Transactor // Generic write-only contract binding to access the raw methods on
   213  	}
   214  
   215  	// New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract.
   216  	func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) {
   217  	  contract, err := bind{{.Type}}(address, backend, backend, backend)
   218  	  if err != nil {
   219  	    return nil, err
   220  	  }
   221  	  return &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil
   222  	}
   223  
   224  	// New{{.Type}}Caller creates a new read-only instance of {{.Type}}, bound to a specific deployed contract.
   225  	func New{{.Type}}Caller(address common.Address, caller bind.ContractCaller) (*{{.Type}}Caller, error) {
   226  	  contract, err := bind{{.Type}}(address, caller, nil, nil)
   227  	  if err != nil {
   228  	    return nil, err
   229  	  }
   230  	  return &{{.Type}}Caller{contract: contract}, nil
   231  	}
   232  
   233  	// New{{.Type}}Transactor creates a new write-only instance of {{.Type}}, bound to a specific deployed contract.
   234  	func New{{.Type}}Transactor(address common.Address, transactor bind.ContractTransactor) (*{{.Type}}Transactor, error) {
   235  	  contract, err := bind{{.Type}}(address, nil, transactor, nil)
   236  	  if err != nil {
   237  	    return nil, err
   238  	  }
   239  	  return &{{.Type}}Transactor{contract: contract}, nil
   240  	}
   241  
   242  	// New{{.Type}}Filterer creates a new log filterer instance of {{.Type}}, bound to a specific deployed contract.
   243   	func New{{.Type}}Filterer(address common.Address, filterer bind.ContractFilterer) (*{{.Type}}Filterer, error) {
   244   	  contract, err := bind{{.Type}}(address, nil, nil, filterer)
   245   	  if err != nil {
   246   	    return nil, err
   247   	  }
   248   	  return &{{.Type}}Filterer{contract: contract}, nil
   249   	}
   250  
   251  	// bind{{.Type}} binds a generic wrapper to an already deployed contract.
   252  	func bind{{.Type}}(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
   253  	  parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI))
   254  	  if err != nil {
   255  	    return nil, err
   256  	  }
   257  	  return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
   258  	}
   259  
   260  	// Call invokes the (constant) contract method with params as input values and
   261  	// sets the output to result. The result type might be a single field for simple
   262  	// returns, a slice of interfaces for anonymous returns and a struct for named
   263  	// returns.
   264  	func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
   265  		return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...)
   266  	}
   267  
   268  	// Transfer initiates a plain transaction to move funds to the contract, calling
   269  	// its default method if one is available.
   270  	func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
   271  		return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts)
   272  	}
   273  
   274  	// Transact invokes the (paid) contract method with params as input values.
   275  	func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
   276  		return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...)
   277  	}
   278  
   279  	// Call invokes the (constant) contract method with params as input values and
   280  	// sets the output to result. The result type might be a single field for simple
   281  	// returns, a slice of interfaces for anonymous returns and a struct for named
   282  	// returns.
   283  	func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
   284  		return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...)
   285  	}
   286  
   287  	// Transfer initiates a plain transaction to move funds to the contract, calling
   288  	// its default method if one is available.
   289  	func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
   290  		return _{{$contract.Type}}.Contract.contract.Transfer(opts)
   291  	}
   292  
   293  	// Transact invokes the (paid) contract method with params as input values.
   294  	func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
   295  		return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...)
   296  	}
   297  
   298  	{{range .Calls}}
   299  		// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   300  		//
   301  		// Solidity: {{formatmethod .Original $structs}}
   302  		func (_{{$contract.Type}} *{{$contract.Type}}Caller) {{.Normalized.Name}}(opts *bind.CallOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type $structs}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}};{{end}} },{{else}}{{range .Normalized.Outputs}}{{bindtype .Type $structs}},{{end}}{{end}} error) {
   303  			{{if .Structured}}ret := new(struct{
   304  				{{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}}
   305  				{{end}}
   306  			}){{else}}var (
   307  				{{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type $structs}})
   308  				{{end}}
   309  			){{end}}
   310  			out := {{if .Structured}}ret{{else}}{{if eq (len .Normalized.Outputs) 1}}ret0{{else}}&[]interface{}{
   311  				{{range $i, $_ := .Normalized.Outputs}}ret{{$i}},
   312  				{{end}}
   313  			}{{end}}{{end}}
   314  			err := _{{$contract.Type}}.contract.Call(opts, out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   315  			return {{if .Structured}}*ret,{{else}}{{range $i, $_ := .Normalized.Outputs}}*ret{{$i}},{{end}}{{end}} err
   316  		}
   317  
   318  		// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   319  		//
   320  		// Solidity: {{formatmethod .Original $structs}}
   321  		func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type $structs}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}};{{end}} }, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type $structs}},{{end}} {{end}} error) {
   322  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   323  		}
   324  
   325  		// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   326  		//
   327  		// Solidity: {{formatmethod .Original $structs}}
   328  		func (_{{$contract.Type}} *{{$contract.Type}}CallerSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type $structs}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type $structs}};{{end}} }, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type $structs}},{{end}} {{end}} error) {
   329  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   330  		}
   331  	{{end}}
   332  
   333  	{{range .Transacts}}
   334  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   335  		//
   336  		// Solidity: {{formatmethod .Original $structs}}
   337  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) {
   338  			return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   339  		}
   340  
   341  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   342  		//
   343  		// Solidity: {{formatmethod .Original $structs}}
   344  		func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) {
   345  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}})
   346  		}
   347  
   348  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   349  		//
   350  		// Solidity: {{formatmethod .Original $structs}}
   351  		func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) {
   352  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}})
   353  		}
   354  	{{end}}
   355  
   356  	{{if .Fallback}} 
   357  		// Fallback is a paid mutator transaction binding the contract fallback function.
   358  		//
   359  		// Solidity: {{formatmethod .Fallback.Original $structs}}
   360  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Fallback(opts *bind.TransactOpts, calldata []byte) (*types.Transaction, error) {
   361  			return _{{$contract.Type}}.contract.RawTransact(opts, calldata)
   362  		}
   363  
   364  		// Fallback is a paid mutator transaction binding the contract fallback function.
   365  		//
   366  		// Solidity: {{formatmethod .Fallback.Original $structs}}
   367  		func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) {
   368  		  return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
   369  		}
   370  	
   371  		// Fallback is a paid mutator transaction binding the contract fallback function.
   372  		// 
   373  		// Solidity: {{formatmethod .Fallback.Original $structs}}
   374  		func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) {
   375  		  return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
   376  		}
   377  	{{end}}
   378  
   379  	{{if .Receive}} 
   380  		// Receive is a paid mutator transaction binding the contract receive function.
   381  		//
   382  		// Solidity: {{formatmethod .Receive.Original $structs}}
   383  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Receive(opts *bind.TransactOpts) (*types.Transaction, error) {
   384  			return _{{$contract.Type}}.contract.RawTransact(opts, nil) // calldata is disallowed for receive function
   385  		}
   386  
   387  		// Receive is a paid mutator transaction binding the contract receive function.
   388  		//
   389  		// Solidity: {{formatmethod .Receive.Original $structs}}
   390  		func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) {
   391  		  return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
   392  		}
   393  	
   394  		// Receive is a paid mutator transaction binding the contract receive function.
   395  		// 
   396  		// Solidity: {{formatmethod .Receive.Original $structs}}
   397  		func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) {
   398  		  return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
   399  		}
   400  	{{end}}
   401  
   402  	{{range .Events}}
   403  		// {{$contract.Type}}{{.Normalized.Name}}Iterator is returned from Filter{{.Normalized.Name}} and is used to iterate over the raw logs and unpacked data for {{.Normalized.Name}} events raised by the {{$contract.Type}} contract.
   404  		type {{$contract.Type}}{{.Normalized.Name}}Iterator struct {
   405  			Event *{{$contract.Type}}{{.Normalized.Name}} // Event containing the contract specifics and raw log
   406  
   407  			contract *bind.BoundContract // Generic contract to use for unpacking event data
   408  			event    string              // Event name to use for unpacking event data
   409  
   410  			logs chan types.Log        // Log channel receiving the found contract events
   411  			sub  ethereum.Subscription // Subscription for errors, completion and termination
   412  			done bool                  // Whether the subscription completed delivering logs
   413  			fail error                 // Occurred error to stop iteration
   414  		}
   415  		// Next advances the iterator to the subsequent event, returning whether there
   416  		// are any more events found. In case of a retrieval or parsing error, false is
   417  		// returned and Error() can be queried for the exact failure.
   418  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Next() bool {
   419  			// If the iterator failed, stop iterating
   420  			if (it.fail != nil) {
   421  				return false
   422  			}
   423  			// If the iterator completed, deliver directly whatever's available
   424  			if (it.done) {
   425  				select {
   426  				case log := <-it.logs:
   427  					it.Event = new({{$contract.Type}}{{.Normalized.Name}})
   428  					if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
   429  						it.fail = err
   430  						return false
   431  					}
   432  					it.Event.Raw = log
   433  					return true
   434  
   435  				default:
   436  					return false
   437  				}
   438  			}
   439  			// Iterator still in progress, wait for either a data or an error event
   440  			select {
   441  			case log := <-it.logs:
   442  				it.Event = new({{$contract.Type}}{{.Normalized.Name}})
   443  				if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
   444  					it.fail = err
   445  					return false
   446  				}
   447  				it.Event.Raw = log
   448  				return true
   449  
   450  			case err := <-it.sub.Err():
   451  				it.done = true
   452  				it.fail = err
   453  				return it.Next()
   454  			}
   455  		}
   456  		// Error returns any retrieval or parsing error occurred during filtering.
   457  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Error() error {
   458  			return it.fail
   459  		}
   460  		// Close terminates the iteration process, releasing any pending underlying
   461  		// resources.
   462  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Close() error {
   463  			it.sub.Unsubscribe()
   464  			return nil
   465  		}
   466  
   467  		// {{$contract.Type}}{{.Normalized.Name}} represents a {{.Normalized.Name}} event raised by the {{$contract.Type}} contract.
   468  		type {{$contract.Type}}{{.Normalized.Name}} struct { {{range .Normalized.Inputs}}
   469  			{{capitalise .Name}} {{if .Indexed}}{{bindtopictype .Type $structs}}{{else}}{{bindtype .Type $structs}}{{end}}; {{end}}
   470  			Raw types.Log // Blockchain specific contextual infos
   471  		}
   472  
   473  		// Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   474  		//
   475  		// Solidity: {{formatevent .Original $structs}}
   476   		func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Filter{{.Normalized.Name}}(opts *bind.FilterOpts{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} []{{bindtype .Type $structs}}{{end}}{{end}}) (*{{$contract.Type}}{{.Normalized.Name}}Iterator, error) {
   477  			{{range .Normalized.Inputs}}
   478  			{{if .Indexed}}var {{.Name}}Rule []interface{}
   479  			for _, {{.Name}}Item := range {{.Name}} {
   480  				{{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item)
   481  			}{{end}}{{end}}
   482  
   483  			logs, sub, err := _{{$contract.Type}}.contract.FilterLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}})
   484  			if err != nil {
   485  				return nil, err
   486  			}
   487  			return &{{$contract.Type}}{{.Normalized.Name}}Iterator{contract: _{{$contract.Type}}.contract, event: "{{.Original.Name}}", logs: logs, sub: sub}, nil
   488   		}
   489  
   490  		// Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   491  		//
   492  		// Solidity: {{formatevent .Original $structs}}
   493  		func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Watch{{.Normalized.Name}}(opts *bind.WatchOpts, sink chan<- *{{$contract.Type}}{{.Normalized.Name}}{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} []{{bindtype .Type $structs}}{{end}}{{end}}) (event.Subscription, error) {
   494  			{{range .Normalized.Inputs}}
   495  			{{if .Indexed}}var {{.Name}}Rule []interface{}
   496  			for _, {{.Name}}Item := range {{.Name}} {
   497  				{{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item)
   498  			}{{end}}{{end}}
   499  
   500  			logs, sub, err := _{{$contract.Type}}.contract.WatchLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}})
   501  			if err != nil {
   502  				return nil, err
   503  			}
   504  			return event.NewSubscription(func(quit <-chan struct{}) error {
   505  				defer sub.Unsubscribe()
   506  				for {
   507  					select {
   508  					case log := <-logs:
   509  						// New log arrived, parse the event and forward to the user
   510  						event := new({{$contract.Type}}{{.Normalized.Name}})
   511  						if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil {
   512  							return err
   513  						}
   514  						event.Raw = log
   515  
   516  						select {
   517  						case sink <- event:
   518  						case err := <-sub.Err():
   519  							return err
   520  						case <-quit:
   521  							return nil
   522  						}
   523  					case err := <-sub.Err():
   524  						return err
   525  					case <-quit:
   526  						return nil
   527  					}
   528  				}
   529  			}), nil
   530  		}
   531  
   532  		// Parse{{.Normalized.Name}} is a log parse operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   533  		//
   534  		// Solidity: {{formatevent .Original $structs}}
   535  		func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Parse{{.Normalized.Name}}(log types.Log) (*{{$contract.Type}}{{.Normalized.Name}}, error) {
   536  			event := new({{$contract.Type}}{{.Normalized.Name}})
   537  			if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil {
   538  				return nil, err
   539  			}
   540  			return event, nil
   541  		}
   542  
   543   	{{end}}
   544  {{end}}
   545  `
   546  
   547  // tmplSourceJava is the Java source template use to generate the contract binding
   548  // based on.
   549  const tmplSourceJava = `
   550  // This file is an automatically generated Java binding. Do not modify as any
   551  // change will likely be lost upon the next re-generation!
   552  
   553  package {{.Package}};
   554  
   555  import org.ethereum.geth.*;
   556  import java.util.*;
   557  
   558  {{$structs := .Structs}}
   559  {{range $contract := .Contracts}}
   560  {{if not .Library}}public {{end}}class {{.Type}} {
   561  	// ABI is the input ABI used to generate the binding from.
   562  	public final static String ABI = "{{.InputABI}}";
   563  	{{if $contract.FuncSigs}}
   564  		// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
   565  		public final static Map<String, String> {{.Type}}FuncSigs;
   566  		static {
   567  			Hashtable<String, String> temp = new Hashtable<String, String>();
   568  			{{range $strsig, $binsig := .FuncSigs}}temp.put("{{$binsig}}", "{{$strsig}}");
   569  			{{end}}
   570  			{{.Type}}FuncSigs = Collections.unmodifiableMap(temp);
   571  		}
   572  	{{end}}
   573  	{{if .InputBin}}
   574  	// BYTECODE is the compiled bytecode used for deploying new contracts.
   575  	public final static String BYTECODE = "0x{{.InputBin}}";
   576  
   577  	// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
   578  	public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type $structs}} {{.Name}}{{end}}) throws Exception {
   579  		Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
   580  		String bytecode = BYTECODE;
   581  		{{if .Libraries}}
   582  
   583  		// "link" contract to dependent libraries by deploying them first.
   584  		{{range $pattern, $name := .Libraries}}
   585  		{{capitalise $name}} {{decapitalise $name}}Inst = {{capitalise $name}}.deploy(auth, client);
   586  		bytecode = bytecode.replace("__${{$pattern}}$__", {{decapitalise $name}}Inst.Address.getHex().substring(2));
   587  		{{end}}
   588  		{{end}}
   589  		{{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   590  		{{end}}
   591  		return new {{.Type}}(Geth.deployContract(auth, ABI, Geth.decodeFromHex(bytecode), client, args));
   592  	}
   593  
   594  	// Internal constructor used by contract deployment.
   595  	private {{.Type}}(BoundContract deployment) {
   596  		this.Address  = deployment.getAddress();
   597  		this.Deployer = deployment.getDeployer();
   598  		this.Contract = deployment;
   599  	}
   600  	{{end}}
   601  
   602  	// Ethereum address where this contract is located at.
   603  	public final Address Address;
   604  
   605  	// Ethereum transaction in which this contract was deployed (if known!).
   606  	public final Transaction Deployer;
   607  
   608  	// Contract instance bound to a blockchain address.
   609  	private final BoundContract Contract;
   610  
   611  	// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
   612  	public {{.Type}}(Address address, EthereumClient client) throws Exception {
   613  		this(Geth.bindContract(address, ABI, client));
   614  	}
   615  
   616  	{{range .Calls}}
   617  	{{if gt (len .Normalized.Outputs) 1}}
   618  	// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
   619  	public class {{capitalise .Normalized.Name}}Results {
   620  		{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type $structs}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
   621  		{{end}}
   622  	}
   623  	{{end}}
   624  
   625  	// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   626  	//
   627  	// Solidity: {{.Original.String}}
   628  	public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type $structs}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type $structs}} {{.Name}}{{end}}) throws Exception {
   629  		Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
   630  		{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   631  		{{end}}
   632  
   633  		Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
   634  		{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type $structs) .Type}}(); results.set({{$index}}, result{{$index}});
   635  		{{end}}
   636  
   637  		if (opts == null) {
   638  			opts = Geth.newCallOpts();
   639  		}
   640  		this.Contract.call(opts, results, "{{.Original.Name}}", args);
   641  		{{if gt (len .Normalized.Outputs) 1}}
   642  			{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
   643  			{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type $structs) .Type}}();
   644  			{{end}}
   645  			return result;
   646  		{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type $structs) .Type}}();{{end}}
   647  		{{end}}
   648  	}
   649  	{{end}}
   650  
   651  	{{range .Transacts}}
   652  	// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   653  	//
   654  	// Solidity: {{.Original.String}}
   655  	public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type $structs}} {{.Name}}{{end}}) throws Exception {
   656  		Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
   657  		{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   658  		{{end}}
   659  		return this.Contract.transact(opts, "{{.Original.Name}}"	, args);
   660  	}
   661  	{{end}}
   662  
   663      {{if .Fallback}}
   664  	// Fallback is a paid mutator transaction binding the contract fallback function.
   665  	//
   666  	// Solidity: {{formatmethod .Fallback.Original $structs}}
   667  	public Transaction Fallback(TransactOpts opts, byte[] calldata) throws Exception { 
   668  		return this.Contract.rawTransact(opts, calldata);
   669  	}
   670      {{end}}
   671  
   672      {{if .Receive}}
   673  	// Receive is a paid mutator transaction binding the contract receive function.
   674  	//
   675  	// Solidity: {{formatmethod .Receive.Original $structs}}
   676  	public Transaction Receive(TransactOpts opts) throws Exception { 
   677  		return this.Contract.rawTransact(opts, null);
   678  	}
   679      {{end}}
   680  }
   681  {{end}}
   682  `