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