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