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