github.com/codingfuture/orig-energi3@v0.8.4/accounts/abi/bind/template.go (about) 1 // Copyright 2018 The Energi Core Authors 2 // Copyright 2016 The go-ethereum Authors 3 // This file is part of the Energi Core library. 4 // 5 // The Energi Core 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 Energi Core 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 Energi Core library. If not, see <http://www.gnu.org/licenses/>. 17 18 package bind 19 20 import "github.com/ethereum/go-ethereum/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 } 27 28 // tmplContract contains the data needed to generate an individual contract binding. 29 type tmplContract struct { 30 Type string // Type name of the main contract binding 31 InputABI string // JSON ABI used as the input to generate the binding from 32 InputBin string // Optional EVM bytecode used to denetare deploy code from 33 RuntimeBin string // Optional EVM bytecode of deployed contract 34 Constructor abi.Method // Contract constructor for deploy parametrization 35 Calls map[string]*tmplMethod // Contract calls that only read state data 36 Transacts map[string]*tmplMethod // Contract calls that write state data 37 Events map[string]*tmplEvent // Contract events accessors 38 } 39 40 // tmplMethod is a wrapper around an abi.Method that contains a few preprocessed 41 // and cached data fields. 42 type tmplMethod struct { 43 Original abi.Method // Original method as parsed by the abi package 44 Normalized abi.Method // Normalized version of the parsed method (capitalized names, non-anonymous args/returns) 45 Structured bool // Whether the returns should be accumulated into a struct 46 } 47 48 // tmplEvent is a wrapper around an a 49 type tmplEvent struct { 50 Original abi.Event // Original event as parsed by the abi package 51 Normalized abi.Event // Normalized version of the parsed fields 52 } 53 54 // tmplSource is language to template mapping containing all the supported 55 // programming languages the package can generate to. 56 var tmplSource = map[Lang]string{ 57 LangGo: tmplSourceGo, 58 LangJava: tmplSourceJava, 59 } 60 61 // tmplSourceGo is the Go source template use to generate the contract binding 62 // based on. 63 const tmplSourceGo = ` 64 // Code generated - DO NOT EDIT. 65 // This file is a generated binding and any manual changes will be lost. 66 67 package {{.Package}} 68 69 import ( 70 "math/big" 71 "strings" 72 73 ethereum "github.com/ethereum/go-ethereum" 74 "github.com/ethereum/go-ethereum/accounts/abi" 75 "github.com/ethereum/go-ethereum/accounts/abi/bind" 76 "github.com/ethereum/go-ethereum/common" 77 "github.com/ethereum/go-ethereum/core/types" 78 "github.com/ethereum/go-ethereum/event" 79 ) 80 81 // Reference imports to suppress errors if they are not otherwise used. 82 var ( 83 _ = big.NewInt 84 _ = strings.NewReader 85 _ = ethereum.NotFound 86 _ = abi.U256 87 _ = bind.Bind 88 _ = common.Big1 89 _ = types.BloomLookup 90 _ = event.NewSubscription 91 ) 92 93 {{range $contract := .Contracts}} 94 // {{.Type}}ABI is the input ABI used to generate the binding from. 95 const {{.Type}}ABI = "{{.InputABI}}" 96 97 {{if .InputBin}} 98 // {{.Type}}Bin is the compiled bytecode used for deploying new contracts. 99 const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + ` 100 101 // Deploy{{.Type}} deploys a new Ethereum contract, binding an instance of {{.Type}} to it. 102 func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) { 103 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 104 if err != nil { 105 return common.Address{}, nil, nil, err 106 } 107 address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) 108 if err != nil { 109 return common.Address{}, nil, nil, err 110 } 111 return address, tx, &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 112 } 113 {{end}} 114 115 {{if .RuntimeBin}} 116 // {{.Type}}Bin is the compiled bytecode of contract after deployment. 117 const {{.Type}}RuntimeBin = ` + "`" + `{{.RuntimeBin}}` + "`" + ` 118 {{end}} 119 120 // {{.Type}} is an auto generated Go binding around an Ethereum contract. 121 type {{.Type}} struct { 122 {{.Type}}Caller // Read-only binding to the contract 123 {{.Type}}Transactor // Write-only binding to the contract 124 {{.Type}}Filterer // Log filterer for contract events 125 } 126 127 // {{.Type}}Caller is an auto generated read-only Go binding around an Ethereum contract. 128 type {{.Type}}Caller struct { 129 contract *bind.BoundContract // Generic contract wrapper for the low level calls 130 } 131 132 // {{.Type}}Transactor is an auto generated write-only Go binding around an Ethereum contract. 133 type {{.Type}}Transactor struct { 134 contract *bind.BoundContract // Generic contract wrapper for the low level calls 135 } 136 137 // {{.Type}}Filterer is an auto generated log filtering Go binding around an Ethereum contract events. 138 type {{.Type}}Filterer struct { 139 contract *bind.BoundContract // Generic contract wrapper for the low level calls 140 } 141 142 // {{.Type}}Session is an auto generated Go binding around an Ethereum contract, 143 // with pre-set call and transact options. 144 type {{.Type}}Session struct { 145 Contract *{{.Type}} // Generic contract binding to set the session for 146 CallOpts bind.CallOpts // Call options to use throughout this session 147 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 148 } 149 150 // {{.Type}}CallerSession is an auto generated read-only Go binding around an Ethereum contract, 151 // with pre-set call options. 152 type {{.Type}}CallerSession struct { 153 Contract *{{.Type}}Caller // Generic contract caller binding to set the session for 154 CallOpts bind.CallOpts // Call options to use throughout this session 155 } 156 157 // {{.Type}}TransactorSession is an auto generated write-only Go binding around an Ethereum contract, 158 // with pre-set transact options. 159 type {{.Type}}TransactorSession struct { 160 Contract *{{.Type}}Transactor // Generic contract transactor binding to set the session for 161 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 162 } 163 164 // {{.Type}}Raw is an auto generated low-level Go binding around an Ethereum contract. 165 type {{.Type}}Raw struct { 166 Contract *{{.Type}} // Generic contract binding to access the raw methods on 167 } 168 169 // {{.Type}}CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. 170 type {{.Type}}CallerRaw struct { 171 Contract *{{.Type}}Caller // Generic read-only contract binding to access the raw methods on 172 } 173 174 // {{.Type}}TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. 175 type {{.Type}}TransactorRaw struct { 176 Contract *{{.Type}}Transactor // Generic write-only contract binding to access the raw methods on 177 } 178 179 // New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract. 180 func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) { 181 contract, err := bind{{.Type}}(address, backend, backend, backend) 182 if err != nil { 183 return nil, err 184 } 185 return &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 186 } 187 188 // New{{.Type}}Caller creates a new read-only instance of {{.Type}}, bound to a specific deployed contract. 189 func New{{.Type}}Caller(address common.Address, caller bind.ContractCaller) (*{{.Type}}Caller, error) { 190 contract, err := bind{{.Type}}(address, caller, nil, nil) 191 if err != nil { 192 return nil, err 193 } 194 return &{{.Type}}Caller{contract: contract}, nil 195 } 196 197 // New{{.Type}}Transactor creates a new write-only instance of {{.Type}}, bound to a specific deployed contract. 198 func New{{.Type}}Transactor(address common.Address, transactor bind.ContractTransactor) (*{{.Type}}Transactor, error) { 199 contract, err := bind{{.Type}}(address, nil, transactor, nil) 200 if err != nil { 201 return nil, err 202 } 203 return &{{.Type}}Transactor{contract: contract}, nil 204 } 205 206 // New{{.Type}}Filterer creates a new log filterer instance of {{.Type}}, bound to a specific deployed contract. 207 func New{{.Type}}Filterer(address common.Address, filterer bind.ContractFilterer) (*{{.Type}}Filterer, error) { 208 contract, err := bind{{.Type}}(address, nil, nil, filterer) 209 if err != nil { 210 return nil, err 211 } 212 return &{{.Type}}Filterer{contract: contract}, nil 213 } 214 215 // bind{{.Type}} binds a generic wrapper to an already deployed contract. 216 func bind{{.Type}}(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { 217 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 218 if err != nil { 219 return nil, err 220 } 221 return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil 222 } 223 224 // Call invokes the (constant) contract method with params as input values and 225 // sets the output to result. The result type might be a single field for simple 226 // returns, a slice of interfaces for anonymous returns and a struct for named 227 // returns. 228 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 229 return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...) 230 } 231 232 // Transfer initiates a plain transaction to move funds to the contract, calling 233 // its default method if one is available. 234 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 235 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts) 236 } 237 238 // Transact invokes the (paid) contract method with params as input values. 239 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 240 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...) 241 } 242 243 // Call invokes the (constant) contract method with params as input values and 244 // sets the output to result. The result type might be a single field for simple 245 // returns, a slice of interfaces for anonymous returns and a struct for named 246 // returns. 247 func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 248 return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...) 249 } 250 251 // Transfer initiates a plain transaction to move funds to the contract, calling 252 // its default method if one is available. 253 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 254 return _{{$contract.Type}}.Contract.contract.Transfer(opts) 255 } 256 257 // Transact invokes the (paid) contract method with params as input values. 258 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 259 return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...) 260 } 261 262 {{range .Calls}} 263 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 264 // 265 // Solidity: {{.Original.String}} 266 func (_{{$contract.Type}} *{{$contract.Type}}Caller) {{.Normalized.Name}}(opts *bind.CallOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}};{{end}} },{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}},{{end}}{{end}} error) { 267 {{if .Structured}}ret := new(struct{ 268 {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}} 269 {{end}} 270 }){{else}}var ( 271 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type}}) 272 {{end}} 273 ){{end}} 274 out := {{if .Structured}}ret{{else}}{{if eq (len .Normalized.Outputs) 1}}ret0{{else}}&[]interface{}{ 275 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}}, 276 {{end}} 277 }{{end}}{{end}} 278 err := _{{$contract.Type}}.contract.Call(opts, out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 279 return {{if .Structured}}*ret,{{else}}{{range $i, $_ := .Normalized.Outputs}}*ret{{$i}},{{end}}{{end}} err 280 } 281 282 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 283 // 284 // Solidity: {{.Original.String}} 285 func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}};{{end}} }, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) { 286 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 287 } 288 289 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 290 // 291 // Solidity: {{.Original.String}} 292 func (_{{$contract.Type}} *{{$contract.Type}}CallerSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}struct{ {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}};{{end}} }, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) { 293 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 294 } 295 {{end}} 296 297 {{range .Transacts}} 298 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 299 // 300 // Solidity: {{.Original.String}} 301 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 302 return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 303 } 304 305 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 306 // 307 // Solidity: {{.Original.String}} 308 func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 309 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 310 } 311 312 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 313 // 314 // Solidity: {{.Original.String}} 315 func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 316 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 317 } 318 {{end}} 319 320 {{range .Events}} 321 // {{$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. 322 type {{$contract.Type}}{{.Normalized.Name}}Iterator struct { 323 Event *{{$contract.Type}}{{.Normalized.Name}} // Event containing the contract specifics and raw log 324 325 contract *bind.BoundContract // Generic contract to use for unpacking event data 326 event string // Event name to use for unpacking event data 327 328 logs chan types.Log // Log channel receiving the found contract events 329 sub ethereum.Subscription // Subscription for errors, completion and termination 330 done bool // Whether the subscription completed delivering logs 331 fail error // Occurred error to stop iteration 332 } 333 // Next advances the iterator to the subsequent event, returning whether there 334 // are any more events found. In case of a retrieval or parsing error, false is 335 // returned and Error() can be queried for the exact failure. 336 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Next() bool { 337 // If the iterator failed, stop iterating 338 if (it.fail != nil) { 339 return false 340 } 341 // If the iterator completed, deliver directly whatever's available 342 if (it.done) { 343 select { 344 case log := <-it.logs: 345 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 346 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 347 it.fail = err 348 return false 349 } 350 it.Event.Raw = log 351 return true 352 353 default: 354 return false 355 } 356 } 357 // Iterator still in progress, wait for either a data or an error event 358 select { 359 case log := <-it.logs: 360 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 361 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 362 it.fail = err 363 return false 364 } 365 it.Event.Raw = log 366 return true 367 368 case err := <-it.sub.Err(): 369 it.done = true 370 it.fail = err 371 return it.Next() 372 } 373 } 374 // Error returns any retrieval or parsing error occurred during filtering. 375 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Error() error { 376 return it.fail 377 } 378 // Close terminates the iteration process, releasing any pending underlying 379 // resources. 380 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Close() error { 381 it.sub.Unsubscribe() 382 return nil 383 } 384 385 // {{$contract.Type}}{{.Normalized.Name}} represents a {{.Normalized.Name}} event raised by the {{$contract.Type}} contract. 386 type {{$contract.Type}}{{.Normalized.Name}} struct { {{range .Normalized.Inputs}} 387 {{capitalise .Name}} {{if .Indexed}}{{bindtopictype .Type}}{{else}}{{bindtype .Type}}{{end}}; {{end}} 388 Raw types.Log // Blockchain specific contextual infos 389 } 390 391 // Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.Id}}. 392 // 393 // Solidity: {{.Original.String}} 394 func (_{{$contract.Type}} *{{$contract.Type}}Filterer) Filter{{.Normalized.Name}}(opts *bind.FilterOpts{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}} []{{bindtype .Type}}{{end}}{{end}}) (*{{$contract.Type}}{{.Normalized.Name}}Iterator, error) { 395 {{range .Normalized.Inputs}} 396 {{if .Indexed}}var {{.Name}}Rule []interface{} 397 for _, {{.Name}}Item := range {{.Name}} { 398 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 399 }{{end}}{{end}} 400 401 logs, sub, err := _{{$contract.Type}}.contract.FilterLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 402 if err != nil { 403 return nil, err 404 } 405 return &{{$contract.Type}}{{.Normalized.Name}}Iterator{contract: _{{$contract.Type}}.contract, event: "{{.Original.Name}}", logs: logs, sub: sub}, nil 406 } 407 408 // Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.Id}}. 409 // 410 // Solidity: {{.Original.String}} 411 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}}{{end}}{{end}}) (event.Subscription, error) { 412 {{range .Normalized.Inputs}} 413 {{if .Indexed}}var {{.Name}}Rule []interface{} 414 for _, {{.Name}}Item := range {{.Name}} { 415 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 416 }{{end}}{{end}} 417 418 logs, sub, err := _{{$contract.Type}}.contract.WatchLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 419 if err != nil { 420 return nil, err 421 } 422 return event.NewSubscription(func(quit <-chan struct{}) error { 423 defer sub.Unsubscribe() 424 for { 425 select { 426 case log := <-logs: 427 // New log arrived, parse the event and forward to the user 428 event := new({{$contract.Type}}{{.Normalized.Name}}) 429 if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil { 430 return err 431 } 432 event.Raw = log 433 434 select { 435 case sink <- event: 436 case err := <-sub.Err(): 437 return err 438 case <-quit: 439 return nil 440 } 441 case err := <-sub.Err(): 442 return err 443 case <-quit: 444 return nil 445 } 446 } 447 }), nil 448 } 449 {{end}} 450 {{end}} 451 ` 452 453 // tmplSourceJava is the Java source template use to generate the contract binding 454 // based on. 455 const tmplSourceJava = ` 456 // This file is an automatically generated Java binding. Do not modify as any 457 // change will likely be lost upon the next re-generation! 458 459 package {{.Package}}; 460 461 import org.ethereum.geth.*; 462 import org.ethereum.geth.internal.*; 463 464 {{range $contract := .Contracts}} 465 public class {{.Type}} { 466 // ABI is the input ABI used to generate the binding from. 467 public final static String ABI = "{{.InputABI}}"; 468 469 {{if .InputBin}} 470 // BYTECODE is the compiled bytecode used for deploying new contracts. 471 public final static byte[] BYTECODE = "{{.InputBin}}".getBytes(); 472 473 // deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it. 474 public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 475 Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}}); 476 {{range $index, $element := .Constructor.Inputs}} 477 args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 478 {{end}} 479 return new {{.Type}}(Geth.deployContract(auth, ABI, BYTECODE, client, args)); 480 } 481 482 // Internal constructor used by contract deployment. 483 private {{.Type}}(BoundContract deployment) { 484 this.Address = deployment.getAddress(); 485 this.Deployer = deployment.getDeployer(); 486 this.Contract = deployment; 487 } 488 {{end}} 489 490 // Ethereum address where this contract is located at. 491 public final Address Address; 492 493 // Ethereum transaction in which this contract was deployed (if known!). 494 public final Transaction Deployer; 495 496 // Contract instance bound to a blockchain address. 497 private final BoundContract Contract; 498 499 // Creates a new instance of {{.Type}}, bound to a specific deployed contract. 500 public {{.Type}}(Address address, EthereumClient client) throws Exception { 501 this(Geth.bindContract(address, ABI, client)); 502 } 503 504 {{range .Calls}} 505 {{if gt (len .Normalized.Outputs) 1}} 506 // {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}. 507 public class {{capitalise .Normalized.Name}}Results { 508 {{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}}; 509 {{end}} 510 } 511 {{end}} 512 513 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 514 // 515 // Solidity: {{.Original.String}} 516 public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 517 Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}}); 518 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 519 {{end}} 520 521 Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}}); 522 {{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}}); 523 {{end}} 524 525 if (opts == null) { 526 opts = Geth.newCallOpts(); 527 } 528 this.Contract.call(opts, results, "{{.Original.Name}}", args); 529 {{if gt (len .Normalized.Outputs) 1}} 530 {{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results(); 531 {{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}(); 532 {{end}} 533 return result; 534 {{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}} 535 {{end}} 536 } 537 {{end}} 538 539 {{range .Transacts}} 540 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 541 // 542 // Solidity: {{.Original.String}} 543 public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 544 Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}}); 545 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 546 {{end}} 547 548 return this.Contract.transact(opts, "{{.Original.Name}}" , args); 549 } 550 {{end}} 551 } 552 {{end}} 553 `