github.com/snowblossomcoin/go-ethereum@v1.9.25/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  	{{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: {{.Original.String}}
   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  			var out []interface{}
   304  			err := _{{$contract.Type}}.contract.Call(opts, &out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   305  			{{if .Structured}}
   306  			outstruct := new(struct{ {{range .Normalized.Outputs}} {{.Name}} {{bindtype .Type $structs}}; {{end}} })
   307  			{{range $i, $t := .Normalized.Outputs}} 
   308  			outstruct.{{.Name}} = out[{{$i}}].({{bindtype .Type $structs}}){{end}}
   309  
   310  			return *outstruct, err
   311  			{{else}}
   312  			if err != nil {
   313  				return {{range $i, $_ := .Normalized.Outputs}}*new({{bindtype .Type $structs}}), {{end}} err
   314  			}
   315  			{{range $i, $t := .Normalized.Outputs}}
   316  			out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}}
   317  			
   318  			return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err
   319  			{{end}}
   320  		}
   321  
   322  		// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   323  		//
   324  		// Solidity: {{.Original.String}}
   325  		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) {
   326  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   327  		}
   328  
   329  		// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   330  		//
   331  		// Solidity: {{.Original.String}}
   332  		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) {
   333  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   334  		}
   335  	{{end}}
   336  
   337  	{{range .Transacts}}
   338  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   339  		//
   340  		// Solidity: {{.Original.String}}
   341  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) {
   342  			return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}})
   343  		}
   344  
   345  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   346  		//
   347  		// Solidity: {{.Original.String}}
   348  		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) {
   349  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}})
   350  		}
   351  
   352  		// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   353  		//
   354  		// Solidity: {{.Original.String}}
   355  		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) {
   356  		  return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}})
   357  		}
   358  	{{end}}
   359  
   360  	{{if .Fallback}} 
   361  		// Fallback is a paid mutator transaction binding the contract fallback function.
   362  		//
   363  		// Solidity: {{.Fallback.Original.String}}
   364  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Fallback(opts *bind.TransactOpts, calldata []byte) (*types.Transaction, error) {
   365  			return _{{$contract.Type}}.contract.RawTransact(opts, calldata)
   366  		}
   367  
   368  		// Fallback is a paid mutator transaction binding the contract fallback function.
   369  		//
   370  		// Solidity: {{.Fallback.Original.String}}
   371  		func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) {
   372  		  return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
   373  		}
   374  	
   375  		// Fallback is a paid mutator transaction binding the contract fallback function.
   376  		// 
   377  		// Solidity: {{.Fallback.Original.String}}
   378  		func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) {
   379  		  return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata)
   380  		}
   381  	{{end}}
   382  
   383  	{{if .Receive}} 
   384  		// Receive is a paid mutator transaction binding the contract receive function.
   385  		//
   386  		// Solidity: {{.Receive.Original.String}}
   387  		func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Receive(opts *bind.TransactOpts) (*types.Transaction, error) {
   388  			return _{{$contract.Type}}.contract.RawTransact(opts, nil) // calldata is disallowed for receive function
   389  		}
   390  
   391  		// Receive is a paid mutator transaction binding the contract receive function.
   392  		//
   393  		// Solidity: {{.Receive.Original.String}}
   394  		func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) {
   395  		  return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
   396  		}
   397  	
   398  		// Receive is a paid mutator transaction binding the contract receive function.
   399  		// 
   400  		// Solidity: {{.Receive.Original.String}}
   401  		func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) {
   402  		  return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts)
   403  		}
   404  	{{end}}
   405  
   406  	{{range .Events}}
   407  		// {{$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.
   408  		type {{$contract.Type}}{{.Normalized.Name}}Iterator struct {
   409  			Event *{{$contract.Type}}{{.Normalized.Name}} // Event containing the contract specifics and raw log
   410  
   411  			contract *bind.BoundContract // Generic contract to use for unpacking event data
   412  			event    string              // Event name to use for unpacking event data
   413  
   414  			logs chan types.Log        // Log channel receiving the found contract events
   415  			sub  ethereum.Subscription // Subscription for errors, completion and termination
   416  			done bool                  // Whether the subscription completed delivering logs
   417  			fail error                 // Occurred error to stop iteration
   418  		}
   419  		// Next advances the iterator to the subsequent event, returning whether there
   420  		// are any more events found. In case of a retrieval or parsing error, false is
   421  		// returned and Error() can be queried for the exact failure.
   422  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Next() bool {
   423  			// If the iterator failed, stop iterating
   424  			if (it.fail != nil) {
   425  				return false
   426  			}
   427  			// If the iterator completed, deliver directly whatever's available
   428  			if (it.done) {
   429  				select {
   430  				case log := <-it.logs:
   431  					it.Event = new({{$contract.Type}}{{.Normalized.Name}})
   432  					if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
   433  						it.fail = err
   434  						return false
   435  					}
   436  					it.Event.Raw = log
   437  					return true
   438  
   439  				default:
   440  					return false
   441  				}
   442  			}
   443  			// Iterator still in progress, wait for either a data or an error event
   444  			select {
   445  			case log := <-it.logs:
   446  				it.Event = new({{$contract.Type}}{{.Normalized.Name}})
   447  				if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
   448  					it.fail = err
   449  					return false
   450  				}
   451  				it.Event.Raw = log
   452  				return true
   453  
   454  			case err := <-it.sub.Err():
   455  				it.done = true
   456  				it.fail = err
   457  				return it.Next()
   458  			}
   459  		}
   460  		// Error returns any retrieval or parsing error occurred during filtering.
   461  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Error() error {
   462  			return it.fail
   463  		}
   464  		// Close terminates the iteration process, releasing any pending underlying
   465  		// resources.
   466  		func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Close() error {
   467  			it.sub.Unsubscribe()
   468  			return nil
   469  		}
   470  
   471  		// {{$contract.Type}}{{.Normalized.Name}} represents a {{.Normalized.Name}} event raised by the {{$contract.Type}} contract.
   472  		type {{$contract.Type}}{{.Normalized.Name}} struct { {{range .Normalized.Inputs}}
   473  			{{capitalise .Name}} {{if .Indexed}}{{bindtopictype .Type $structs}}{{else}}{{bindtype .Type $structs}}{{end}}; {{end}}
   474  			Raw types.Log // Blockchain specific contextual infos
   475  		}
   476  
   477  		// Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   478  		//
   479  		// Solidity: {{.Original.String}}
   480   		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) {
   481  			{{range .Normalized.Inputs}}
   482  			{{if .Indexed}}var {{.Name}}Rule []interface{}
   483  			for _, {{.Name}}Item := range {{.Name}} {
   484  				{{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item)
   485  			}{{end}}{{end}}
   486  
   487  			logs, sub, err := _{{$contract.Type}}.contract.FilterLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}})
   488  			if err != nil {
   489  				return nil, err
   490  			}
   491  			return &{{$contract.Type}}{{.Normalized.Name}}Iterator{contract: _{{$contract.Type}}.contract, event: "{{.Original.Name}}", logs: logs, sub: sub}, nil
   492   		}
   493  
   494  		// Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   495  		//
   496  		// Solidity: {{.Original.String}}
   497  		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) {
   498  			{{range .Normalized.Inputs}}
   499  			{{if .Indexed}}var {{.Name}}Rule []interface{}
   500  			for _, {{.Name}}Item := range {{.Name}} {
   501  				{{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item)
   502  			}{{end}}{{end}}
   503  
   504  			logs, sub, err := _{{$contract.Type}}.contract.WatchLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}})
   505  			if err != nil {
   506  				return nil, err
   507  			}
   508  			return event.NewSubscription(func(quit <-chan struct{}) error {
   509  				defer sub.Unsubscribe()
   510  				for {
   511  					select {
   512  					case log := <-logs:
   513  						// New log arrived, parse the event and forward to the user
   514  						event := new({{$contract.Type}}{{.Normalized.Name}})
   515  						if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil {
   516  							return err
   517  						}
   518  						event.Raw = log
   519  
   520  						select {
   521  						case sink <- event:
   522  						case err := <-sub.Err():
   523  							return err
   524  						case <-quit:
   525  							return nil
   526  						}
   527  					case err := <-sub.Err():
   528  						return err
   529  					case <-quit:
   530  						return nil
   531  					}
   532  				}
   533  			}), nil
   534  		}
   535  
   536  		// Parse{{.Normalized.Name}} is a log parse operation binding the contract event 0x{{printf "%x" .Original.ID}}.
   537  		//
   538  		// Solidity: {{.Original.String}}
   539  		func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Parse{{.Normalized.Name}}(log types.Log) (*{{$contract.Type}}{{.Normalized.Name}}, error) {
   540  			event := new({{$contract.Type}}{{.Normalized.Name}})
   541  			if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil {
   542  				return nil, err
   543  			}
   544  			return event, nil
   545  		}
   546  
   547   	{{end}}
   548  {{end}}
   549  `
   550  
   551  // tmplSourceJava is the Java source template that the generated Java contract binding
   552  // is based on.
   553  const tmplSourceJava = `
   554  // This file is an automatically generated Java binding. Do not modify as any
   555  // change will likely be lost upon the next re-generation!
   556  
   557  package {{.Package}};
   558  
   559  import org.ethereum.geth.*;
   560  import java.util.*;
   561  
   562  {{$structs := .Structs}}
   563  {{range $contract := .Contracts}}
   564  {{if not .Library}}public {{end}}class {{.Type}} {
   565  	// ABI is the input ABI used to generate the binding from.
   566  	public final static String ABI = "{{.InputABI}}";
   567  	{{if $contract.FuncSigs}}
   568  		// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
   569  		public final static Map<String, String> {{.Type}}FuncSigs;
   570  		static {
   571  			Hashtable<String, String> temp = new Hashtable<String, String>();
   572  			{{range $strsig, $binsig := .FuncSigs}}temp.put("{{$binsig}}", "{{$strsig}}");
   573  			{{end}}
   574  			{{.Type}}FuncSigs = Collections.unmodifiableMap(temp);
   575  		}
   576  	{{end}}
   577  	{{if .InputBin}}
   578  	// BYTECODE is the compiled bytecode used for deploying new contracts.
   579  	public final static String BYTECODE = "0x{{.InputBin}}";
   580  
   581  	// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
   582  	public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type $structs}} {{.Name}}{{end}}) throws Exception {
   583  		Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
   584  		String bytecode = BYTECODE;
   585  		{{if .Libraries}}
   586  
   587  		// "link" contract to dependent libraries by deploying them first.
   588  		{{range $pattern, $name := .Libraries}}
   589  		{{capitalise $name}} {{decapitalise $name}}Inst = {{capitalise $name}}.deploy(auth, client);
   590  		bytecode = bytecode.replace("__${{$pattern}}$__", {{decapitalise $name}}Inst.Address.getHex().substring(2));
   591  		{{end}}
   592  		{{end}}
   593  		{{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   594  		{{end}}
   595  		return new {{.Type}}(Geth.deployContract(auth, ABI, Geth.decodeFromHex(bytecode), client, args));
   596  	}
   597  
   598  	// Internal constructor used by contract deployment.
   599  	private {{.Type}}(BoundContract deployment) {
   600  		this.Address  = deployment.getAddress();
   601  		this.Deployer = deployment.getDeployer();
   602  		this.Contract = deployment;
   603  	}
   604  	{{end}}
   605  
   606  	// Ethereum address where this contract is located at.
   607  	public final Address Address;
   608  
   609  	// Ethereum transaction in which this contract was deployed (if known!).
   610  	public final Transaction Deployer;
   611  
   612  	// Contract instance bound to a blockchain address.
   613  	private final BoundContract Contract;
   614  
   615  	// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
   616  	public {{.Type}}(Address address, EthereumClient client) throws Exception {
   617  		this(Geth.bindContract(address, ABI, client));
   618  	}
   619  
   620  	{{range .Calls}}
   621  	{{if gt (len .Normalized.Outputs) 1}}
   622  	// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
   623  	public class {{capitalise .Normalized.Name}}Results {
   624  		{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type $structs}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
   625  		{{end}}
   626  	}
   627  	{{end}}
   628  
   629  	// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
   630  	//
   631  	// Solidity: {{.Original.String}}
   632  	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 {
   633  		Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
   634  		{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   635  		{{end}}
   636  
   637  		Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
   638  		{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type $structs) .Type}}(); results.set({{$index}}, result{{$index}});
   639  		{{end}}
   640  
   641  		if (opts == null) {
   642  			opts = Geth.newCallOpts();
   643  		}
   644  		this.Contract.call(opts, results, "{{.Original.Name}}", args);
   645  		{{if gt (len .Normalized.Outputs) 1}}
   646  			{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
   647  			{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type $structs) .Type}}();
   648  			{{end}}
   649  			return result;
   650  		{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type $structs) .Type}}();{{end}}
   651  		{{end}}
   652  	}
   653  	{{end}}
   654  
   655  	{{range .Transacts}}
   656  	// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
   657  	//
   658  	// Solidity: {{.Original.String}}
   659  	public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type $structs}} {{.Name}}{{end}}) throws Exception {
   660  		Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
   661  		{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
   662  		{{end}}
   663  		return this.Contract.transact(opts, "{{.Original.Name}}"	, args);
   664  	}
   665  	{{end}}
   666  
   667      {{if .Fallback}}
   668  	// Fallback is a paid mutator transaction binding the contract fallback function.
   669  	//
   670  	// Solidity: {{.Fallback.Original.String}}
   671  	public Transaction Fallback(TransactOpts opts, byte[] calldata) throws Exception { 
   672  		return this.Contract.rawTransact(opts, calldata);
   673  	}
   674      {{end}}
   675  
   676      {{if .Receive}}
   677  	// Receive is a paid mutator transaction binding the contract receive function.
   678  	//
   679  	// Solidity: {{.Receive.Original.String}}
   680  	public Transaction Receive(TransactOpts opts) throws Exception { 
   681  		return this.Contract.rawTransact(opts, null);
   682  	}
   683      {{end}}
   684  }
   685  {{end}}
   686  `