github.com/core-coin/go-core/v2@v2.1.9/accounts/abi/bind/template.go (about) 1 // Copyright 2016 by the Authors 2 // This file is part of the go-core library. 3 // 4 // The go-core 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-core 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-core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package bind 18 19 import "github.com/core-coin/go-core/v2/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 CVM 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 ylem v0.5.11) or raw name. 72 Fields []*tmplField // Struct fields definition depends on the binding language. 73 } 74 75 // tmplSourceGo is the Go source template that the generated Go contract binding 76 // is based on. 77 const tmplSource = ` 78 // Code generated - DO NOT EDIT. 79 // This file is a generated binding and any manual changes will be lost. 80 81 package {{.Package}} 82 83 import ( 84 "math/big" 85 "strings" 86 87 core "github.com/core-coin/go-core/v2" 88 "github.com/core-coin/go-core/v2/accounts/abi" 89 "github.com/core-coin/go-core/v2/accounts/abi/bind" 90 "github.com/core-coin/go-core/v2/common" 91 "github.com/core-coin/go-core/v2/core/types" 92 "github.com/core-coin/go-core/v2/event" 93 ) 94 95 // Reference imports to suppress errors if they are not otherwise used. 96 var ( 97 _ = big.NewInt 98 _ = strings.NewReader 99 _ = core.NotFound 100 _ = bind.Bind 101 _ = common.Big1 102 _ = types.BloomLookup 103 _ = event.NewSubscription 104 ) 105 106 {{$structs := .Structs}} 107 {{range $structs}} 108 // {{.Name}} is an auto generated low-level Go binding around an user-defined struct. 109 type {{.Name}} struct { 110 {{range $field := .Fields}} 111 {{$field.Name}} {{$field.Type}}{{end}} 112 } 113 {{end}} 114 115 {{range $contract := .Contracts}} 116 // {{.Type}}ABI is the input ABI used to generate the binding from. 117 const {{.Type}}ABI = "{{.InputABI}}" 118 119 {{if $contract.FuncSigs}} 120 // {{.Type}}FuncSigs maps the 4-byte function signature to its string representation. 121 var {{.Type}}FuncSigs = map[string]string{ 122 {{range $strsig, $binsig := .FuncSigs}}"{{$binsig}}": "{{$strsig}}", 123 {{end}} 124 } 125 {{end}} 126 127 {{if .InputBin}} 128 // {{.Type}}Bin is the compiled bytecode used for deploying new contracts. 129 var {{.Type}}Bin = "0x{{.InputBin}}" 130 131 // Deploy{{.Type}} deploys a new Core contract, binding an instance of {{.Type}} to it. 132 func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type $structs}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) { 133 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 134 if err != nil { 135 return common.Address{}, nil, nil, err 136 } 137 {{range $pattern, $name := .Libraries}} 138 {{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend) 139 {{$contract.Type}}Bin = strings.Replace({{$contract.Type}}Bin, "____${{$pattern}}$____", {{decapitalise $name}}Addr.String(), -1) 140 {{end}} 141 address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) 142 if err != nil { 143 return common.Address{}, nil, nil, err 144 } 145 return address, tx, &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 146 } 147 {{end}} 148 149 // {{.Type}} is an auto generated Go binding around an Core contract. 150 type {{.Type}} struct { 151 {{.Type}}Caller // Read-only binding to the contract 152 {{.Type}}Transactor // Write-only binding to the contract 153 {{.Type}}Filterer // Log filterer for contract events 154 } 155 156 // {{.Type}}Caller is an auto generated read-only Go binding around an Core contract. 157 type {{.Type}}Caller struct { 158 contract *bind.BoundContract // Generic contract wrapper for the low level calls 159 } 160 161 // {{.Type}}Transactor is an auto generated write-only Go binding around an Core contract. 162 type {{.Type}}Transactor struct { 163 contract *bind.BoundContract // Generic contract wrapper for the low level calls 164 } 165 166 // {{.Type}}Filterer is an auto generated log filtering Go binding around an Core contract events. 167 type {{.Type}}Filterer struct { 168 contract *bind.BoundContract // Generic contract wrapper for the low level calls 169 } 170 171 // {{.Type}}Session is an auto generated Go binding around an Core contract, 172 // with pre-set call and transact options. 173 type {{.Type}}Session struct { 174 Contract *{{.Type}} // Generic contract binding to set the session for 175 CallOpts bind.CallOpts // Call options to use throughout this session 176 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 177 } 178 179 // {{.Type}}CallerSession is an auto generated read-only Go binding around an Core contract, 180 // with pre-set call options. 181 type {{.Type}}CallerSession struct { 182 Contract *{{.Type}}Caller // Generic contract caller binding to set the session for 183 CallOpts bind.CallOpts // Call options to use throughout this session 184 } 185 186 // {{.Type}}TransactorSession is an auto generated write-only Go binding around an Core contract, 187 // with pre-set transact options. 188 type {{.Type}}TransactorSession struct { 189 Contract *{{.Type}}Transactor // Generic contract transactor binding to set the session for 190 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 191 } 192 193 // {{.Type}}Raw is an auto generated low-level Go binding around an Core contract. 194 type {{.Type}}Raw struct { 195 Contract *{{.Type}} // Generic contract binding to access the raw methods on 196 } 197 198 // {{.Type}}CallerRaw is an auto generated low-level read-only Go binding around an Core contract. 199 type {{.Type}}CallerRaw struct { 200 Contract *{{.Type}}Caller // Generic read-only contract binding to access the raw methods on 201 } 202 203 // {{.Type}}TransactorRaw is an auto generated low-level write-only Go binding around an Core contract. 204 type {{.Type}}TransactorRaw struct { 205 Contract *{{.Type}}Transactor // Generic write-only contract binding to access the raw methods on 206 } 207 208 // New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract. 209 func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) { 210 contract, err := bind{{.Type}}(address, backend, backend, backend) 211 if err != nil { 212 return nil, err 213 } 214 return &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 215 } 216 217 // New{{.Type}}Caller creates a new read-only instance of {{.Type}}, bound to a specific deployed contract. 218 func New{{.Type}}Caller(address common.Address, caller bind.ContractCaller) (*{{.Type}}Caller, error) { 219 contract, err := bind{{.Type}}(address, caller, nil, nil) 220 if err != nil { 221 return nil, err 222 } 223 return &{{.Type}}Caller{contract: contract}, nil 224 } 225 226 // New{{.Type}}Transactor creates a new write-only instance of {{.Type}}, bound to a specific deployed contract. 227 func New{{.Type}}Transactor(address common.Address, transactor bind.ContractTransactor) (*{{.Type}}Transactor, error) { 228 contract, err := bind{{.Type}}(address, nil, transactor, nil) 229 if err != nil { 230 return nil, err 231 } 232 return &{{.Type}}Transactor{contract: contract}, nil 233 } 234 235 // New{{.Type}}Filterer creates a new log filterer instance of {{.Type}}, bound to a specific deployed contract. 236 func New{{.Type}}Filterer(address common.Address, filterer bind.ContractFilterer) (*{{.Type}}Filterer, error) { 237 contract, err := bind{{.Type}}(address, nil, nil, filterer) 238 if err != nil { 239 return nil, err 240 } 241 return &{{.Type}}Filterer{contract: contract}, nil 242 } 243 244 // bind{{.Type}} binds a generic wrapper to an already deployed contract. 245 func bind{{.Type}}(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { 246 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 247 if err != nil { 248 return nil, err 249 } 250 return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil 251 } 252 253 // Call invokes the (constant) contract method with params as input values and 254 // sets the output to result. The result type might be a single field for simple 255 // returns, a slice of interfaces for anonymous returns and a struct for named 256 // returns. 257 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { 258 return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...) 259 } 260 261 // Transfer initiates a plain transaction to move funds to the contract, calling 262 // its default method if one is available. 263 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 264 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts) 265 } 266 267 // Transact invokes the (paid) contract method with params as input values. 268 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 269 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...) 270 } 271 272 // Call invokes the (constant) contract method with params as input values and 273 // sets the output to result. The result type might be a single field for simple 274 // returns, a slice of interfaces for anonymous returns and a struct for named 275 // returns. 276 func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error { 277 return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...) 278 } 279 280 // Transfer initiates a plain transaction to move funds to the contract, calling 281 // its default method if one is available. 282 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 283 return _{{$contract.Type}}.Contract.contract.Transfer(opts) 284 } 285 286 // Transact invokes the (paid) contract method with params as input values. 287 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 288 return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...) 289 } 290 291 {{range .Calls}} 292 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}. 293 // 294 // Ylem: {{.Original.String}} 295 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) { 296 var out []interface{} 297 err := _{{$contract.Type}}.contract.Call(opts, &out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 298 {{if .Structured}} 299 outstruct := new(struct{ {{range .Normalized.Outputs}} {{.Name}} {{bindtype .Type $structs}}; {{end}} }) 300 {{range $i, $t := .Normalized.Outputs}} 301 outstruct.{{.Name}} = out[{{$i}}].({{bindtype .Type $structs}}){{end}} 302 303 return *outstruct, err 304 {{else}} 305 if err != nil { 306 return {{range $i, $_ := .Normalized.Outputs}}*new({{bindtype .Type $structs}}), {{end}} err 307 } 308 {{range $i, $t := .Normalized.Outputs}} 309 out{{$i}} := *abi.ConvertType(out[{{$i}}], new({{bindtype .Type $structs}})).(*{{bindtype .Type $structs}}){{end}} 310 311 return {{range $i, $t := .Normalized.Outputs}}out{{$i}}, {{end}} err 312 {{end}} 313 } 314 315 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}. 316 // 317 // Ylem: {{.Original.String}} 318 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) { 319 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 320 } 321 322 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}. 323 // 324 // Ylem: {{.Original.String}} 325 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) { 326 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 327 } 328 {{end}} 329 330 {{range .Transacts}} 331 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}. 332 // 333 // Ylem: {{.Original.String}} 334 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) { 335 return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 336 } 337 338 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}. 339 // 340 // Ylem: {{.Original.String}} 341 func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type $structs}} {{end}}) (*types.Transaction, error) { 342 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 343 } 344 345 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}. 346 // 347 // Ylem: {{.Original.String}} 348 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) { 349 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 350 } 351 {{end}} 352 353 {{if .Fallback}} 354 // Fallback is a paid mutator transaction binding the contract fallback function. 355 // 356 // Ylem: {{.Fallback.Original.String}} 357 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Fallback(opts *bind.TransactOpts, calldata []byte) (*types.Transaction, error) { 358 return _{{$contract.Type}}.contract.RawTransact(opts, calldata) 359 } 360 361 // Fallback is a paid mutator transaction binding the contract fallback function. 362 // 363 // Ylem: {{.Fallback.Original.String}} 364 func (_{{$contract.Type}} *{{$contract.Type}}Session) Fallback(calldata []byte) (*types.Transaction, error) { 365 return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata) 366 } 367 368 // Fallback is a paid mutator transaction binding the contract fallback function. 369 // 370 // Ylem: {{.Fallback.Original.String}} 371 func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Fallback(calldata []byte) (*types.Transaction, error) { 372 return _{{$contract.Type}}.Contract.Fallback(&_{{$contract.Type}}.TransactOpts, calldata) 373 } 374 {{end}} 375 376 {{if .Receive}} 377 // Receive is a paid mutator transaction binding the contract receive function. 378 // 379 // Ylem: {{.Receive.Original.String}} 380 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) Receive(opts *bind.TransactOpts) (*types.Transaction, error) { 381 return _{{$contract.Type}}.contract.RawTransact(opts, nil) // calldata is disallowed for receive function 382 } 383 384 // Receive is a paid mutator transaction binding the contract receive function. 385 // 386 // Ylem: {{.Receive.Original.String}} 387 func (_{{$contract.Type}} *{{$contract.Type}}Session) Receive() (*types.Transaction, error) { 388 return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts) 389 } 390 391 // Receive is a paid mutator transaction binding the contract receive function. 392 // 393 // Ylem: {{.Receive.Original.String}} 394 func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) Receive() (*types.Transaction, error) { 395 return _{{$contract.Type}}.Contract.Receive(&_{{$contract.Type}}.TransactOpts) 396 } 397 {{end}} 398 399 {{range .Events}} 400 // {{$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. 401 type {{$contract.Type}}{{.Normalized.Name}}Iterator struct { 402 Event *{{$contract.Type}}{{.Normalized.Name}} // Event containing the contract specifics and raw log 403 404 contract *bind.BoundContract // Generic contract to use for unpacking event data 405 event string // Event name to use for unpacking event data 406 407 logs chan types.Log // Log channel receiving the found contract events 408 sub core.Subscription // Subscription for errors, completion and termination 409 done bool // Whether the subscription completed delivering logs 410 fail error // Occurred error to stop iteration 411 } 412 // Next advances the iterator to the subsequent event, returning whether there 413 // are any more events found. In case of a retrieval or parsing error, false is 414 // returned and Error() can be queried for the exact failure. 415 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Next() bool { 416 // If the iterator failed, stop iterating 417 if (it.fail != nil) { 418 return false 419 } 420 // If the iterator completed, deliver directly whatever's available 421 if (it.done) { 422 select { 423 case log := <-it.logs: 424 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 425 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 426 it.fail = err 427 return false 428 } 429 it.Event.Raw = log 430 return true 431 432 default: 433 return false 434 } 435 } 436 // Iterator still in progress, wait for either a data or an error event 437 select { 438 case log := <-it.logs: 439 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 440 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 441 it.fail = err 442 return false 443 } 444 it.Event.Raw = log 445 return true 446 447 case err := <-it.sub.Err(): 448 it.done = true 449 it.fail = err 450 return it.Next() 451 } 452 } 453 // Error returns any retrieval or parsing error occurred during filtering. 454 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Error() error { 455 return it.fail 456 } 457 // Close terminates the iteration process, releasing any pending underlying 458 // resources. 459 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Close() error { 460 it.sub.Unsubscribe() 461 return nil 462 } 463 464 // {{$contract.Type}}{{.Normalized.Name}} represents a {{.Normalized.Name}} event raised by the {{$contract.Type}} contract. 465 type {{$contract.Type}}{{.Normalized.Name}} struct { {{range .Normalized.Inputs}} 466 {{capitalise .Name}} {{if .Indexed}}{{bindtopictype .Type $structs}}{{else}}{{bindtype .Type $structs}}{{end}}; {{end}} 467 Raw types.Log // Blockchain specific contextual infos 468 } 469 470 // Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.ID}}. 471 // 472 // Ylem: {{.Original.String}} 473 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) { 474 {{range .Normalized.Inputs}} 475 {{if .Indexed}}var {{.Name}}Rule []interface{} 476 for _, {{.Name}}Item := range {{.Name}} { 477 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 478 }{{end}}{{end}} 479 480 logs, sub, err := _{{$contract.Type}}.contract.FilterLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 481 if err != nil { 482 return nil, err 483 } 484 return &{{$contract.Type}}{{.Normalized.Name}}Iterator{contract: _{{$contract.Type}}.contract, event: "{{.Original.Name}}", logs: logs, sub: sub}, nil 485 } 486 487 // Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}. 488 // 489 // Ylem: {{.Original.String}} 490 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) { 491 {{range .Normalized.Inputs}} 492 {{if .Indexed}}var {{.Name}}Rule []interface{} 493 for _, {{.Name}}Item := range {{.Name}} { 494 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 495 }{{end}}{{end}} 496 497 logs, sub, err := _{{$contract.Type}}.contract.WatchLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 498 if err != nil { 499 return nil, err 500 } 501 return event.NewSubscription(func(quit <-chan struct{}) error { 502 defer sub.Unsubscribe() 503 for { 504 select { 505 case log := <-logs: 506 // New log arrived, parse the event and forward to the user 507 event := new({{$contract.Type}}{{.Normalized.Name}}) 508 if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil { 509 return err 510 } 511 event.Raw = log 512 513 select { 514 case sink <- event: 515 case err := <-sub.Err(): 516 return err 517 case <-quit: 518 return nil 519 } 520 case err := <-sub.Err(): 521 return err 522 case <-quit: 523 return nil 524 } 525 } 526 }), nil 527 } 528 529 // Parse{{.Normalized.Name}} is a log parse operation binding the contract event 0x{{printf "%x" .Original.ID}}. 530 // 531 // Ylem: {{.Original.String}} 532 func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Parse{{.Normalized.Name}}(log types.Log) (*{{$contract.Type}}{{.Normalized.Name}}, error) { 533 event := new({{$contract.Type}}{{.Normalized.Name}}) 534 if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil { 535 return nil, err 536 } 537 event.Raw = log 538 return event, nil 539 } 540 541 {{end}} 542 {{end}} 543 `