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