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