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