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