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