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