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