github.com/amazechain/amc@v0.1.3/accounts/abi/bind/template.go (about)

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