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