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