github.com/klaytn/klaytn@v1.12.1/accounts/abi/bind/template.go (about)

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