github.com/digdeepmining/go-atheios@v1.5.13-0.20180902133602-d5687a2e6f43/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/atheioschain/go-atheios/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 } 36 37 // tmplMethod is a wrapper around an abi.Method that contains a few preprocessed 38 // and cached data fields. 39 type tmplMethod struct { 40 Original abi.Method // Original method as parsed by the abi package 41 Normalized abi.Method // Normalized version of the parsed method (capitalized names, non-anonymous args/returns) 42 Structured bool // Whether the returns should be accumulated into a contract 43 } 44 45 // tmplSource is language to template mapping containing all the supported 46 // programming languages the package can generate to. 47 var tmplSource = map[Lang]string{ 48 LangGo: tmplSourceGo, 49 LangJava: tmplSourceJava, 50 } 51 52 // tmplSourceGo is the Go source template use to generate the contract binding 53 // based on. 54 const tmplSourceGo = ` 55 // This file is an automatically generated Go binding. Do not modify as any 56 // change will likely be lost upon the next re-generation! 57 58 package {{.Package}} 59 60 {{range $contract := .Contracts}} 61 // {{.Type}}ABI is the input ABI used to generate the binding from. 62 const {{.Type}}ABI = "{{.InputABI}}" 63 64 {{if .InputBin}} 65 // {{.Type}}Bin is the compiled bytecode used for deploying new contracts. 66 const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + ` 67 68 // Deploy{{.Type}} deploys a new Ethereum contract, binding an instance of {{.Type}} to it. 69 func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) { 70 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 71 if err != nil { 72 return common.Address{}, nil, nil, err 73 } 74 address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) 75 if err != nil { 76 return common.Address{}, nil, nil, err 77 } 78 return address, tx, &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract} }, nil 79 } 80 {{end}} 81 82 // {{.Type}} is an auto generated Go binding around an Ethereum contract. 83 type {{.Type}} struct { 84 {{.Type}}Caller // Read-only binding to the contract 85 {{.Type}}Transactor // Write-only binding to the contract 86 } 87 88 // {{.Type}}Caller is an auto generated read-only Go binding around an Ethereum contract. 89 type {{.Type}}Caller struct { 90 contract *bind.BoundContract // Generic contract wrapper for the low level calls 91 } 92 93 // {{.Type}}Transactor is an auto generated write-only Go binding around an Ethereum contract. 94 type {{.Type}}Transactor struct { 95 contract *bind.BoundContract // Generic contract wrapper for the low level calls 96 } 97 98 // {{.Type}}Session is an auto generated Go binding around an Ethereum contract, 99 // with pre-set call and transact options. 100 type {{.Type}}Session struct { 101 Contract *{{.Type}} // Generic contract binding to set the session for 102 CallOpts bind.CallOpts // Call options to use throughout this session 103 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 104 } 105 106 // {{.Type}}CallerSession is an auto generated read-only Go binding around an Ethereum contract, 107 // with pre-set call options. 108 type {{.Type}}CallerSession struct { 109 Contract *{{.Type}}Caller // Generic contract caller binding to set the session for 110 CallOpts bind.CallOpts // Call options to use throughout this session 111 } 112 113 // {{.Type}}TransactorSession is an auto generated write-only Go binding around an Ethereum contract, 114 // with pre-set transact options. 115 type {{.Type}}TransactorSession struct { 116 Contract *{{.Type}}Transactor // Generic contract transactor binding to set the session for 117 TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session 118 } 119 120 // {{.Type}}Raw is an auto generated low-level Go binding around an Ethereum contract. 121 type {{.Type}}Raw struct { 122 Contract *{{.Type}} // Generic contract binding to access the raw methods on 123 } 124 125 // {{.Type}}CallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. 126 type {{.Type}}CallerRaw struct { 127 Contract *{{.Type}}Caller // Generic read-only contract binding to access the raw methods on 128 } 129 130 // {{.Type}}TransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. 131 type {{.Type}}TransactorRaw struct { 132 Contract *{{.Type}}Transactor // Generic write-only contract binding to access the raw methods on 133 } 134 135 // New{{.Type}} creates a new instance of {{.Type}}, bound to a specific deployed contract. 136 func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) { 137 contract, err := bind{{.Type}}(address, backend, backend) 138 if err != nil { 139 return nil, err 140 } 141 return &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract} }, nil 142 } 143 144 // New{{.Type}}Caller creates a new read-only instance of {{.Type}}, bound to a specific deployed contract. 145 func New{{.Type}}Caller(address common.Address, caller bind.ContractCaller) (*{{.Type}}Caller, error) { 146 contract, err := bind{{.Type}}(address, caller, nil) 147 if err != nil { 148 return nil, err 149 } 150 return &{{.Type}}Caller{contract: contract}, nil 151 } 152 153 // New{{.Type}}Transactor creates a new write-only instance of {{.Type}}, bound to a specific deployed contract. 154 func New{{.Type}}Transactor(address common.Address, transactor bind.ContractTransactor) (*{{.Type}}Transactor, error) { 155 contract, err := bind{{.Type}}(address, nil, transactor) 156 if err != nil { 157 return nil, err 158 } 159 return &{{.Type}}Transactor{contract: contract}, nil 160 } 161 162 // bind{{.Type}} binds a generic wrapper to an already deployed contract. 163 func bind{{.Type}}(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) { 164 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 165 if err != nil { 166 return nil, err 167 } 168 return bind.NewBoundContract(address, parsed, caller, transactor), nil 169 } 170 171 // Call invokes the (constant) contract method with params as input values and 172 // sets the output to result. The result type might be a single field for simple 173 // returns, a slice of interfaces for anonymous returns and a struct for named 174 // returns. 175 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 176 return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...) 177 } 178 179 // Transfer initiates a plain transaction to move funds to the contract, calling 180 // its default method if one is available. 181 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 182 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts) 183 } 184 185 // Transact invokes the (paid) contract method with params as input values. 186 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 187 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...) 188 } 189 190 // Call invokes the (constant) contract method with params as input values and 191 // sets the output to result. The result type might be a single field for simple 192 // returns, a slice of interfaces for anonymous returns and a struct for named 193 // returns. 194 func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 195 return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...) 196 } 197 198 // Transfer initiates a plain transaction to move funds to the contract, calling 199 // its default method if one is available. 200 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 201 return _{{$contract.Type}}.Contract.contract.Transfer(opts) 202 } 203 204 // Transact invokes the (paid) contract method with params as input values. 205 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 206 return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...) 207 } 208 209 {{range .Calls}} 210 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 211 // 212 // Solidity: {{.Original.String}} 213 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) { 214 {{if .Structured}}ret := new(struct{ 215 {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}} 216 {{end}} 217 }){{else}}var ( 218 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type}}) 219 {{end}} 220 ){{end}} 221 out := {{if .Structured}}ret{{else}}{{if eq (len .Normalized.Outputs) 1}}ret0{{else}}&[]interface{}{ 222 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}}, 223 {{end}} 224 }{{end}}{{end}} 225 err := _{{$contract.Type}}.contract.Call(opts, out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 226 return {{if .Structured}}*ret,{{else}}{{range $i, $_ := .Normalized.Outputs}}*ret{{$i}},{{end}}{{end}} err 227 } 228 229 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 230 // 231 // Solidity: {{.Original.String}} 232 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) { 233 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 234 } 235 236 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 237 // 238 // Solidity: {{.Original.String}} 239 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) { 240 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 241 } 242 {{end}} 243 244 {{range .Transacts}} 245 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 246 // 247 // Solidity: {{.Original.String}} 248 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 249 return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 250 } 251 252 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 253 // 254 // Solidity: {{.Original.String}} 255 func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 256 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 257 } 258 259 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 260 // 261 // Solidity: {{.Original.String}} 262 func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 263 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 264 } 265 {{end}} 266 {{end}} 267 ` 268 269 // tmplSourceJava is the Java source template use to generate the contract binding 270 // based on. 271 const tmplSourceJava = ` 272 // This file is an automatically generated Java binding. Do not modify as any 273 // change will likely be lost upon the next re-generation! 274 275 package {{.Package}}; 276 277 import org.ethereum.gath.*; 278 import org.ethereum.gath.internal.*; 279 280 {{range $contract := .Contracts}} 281 public class {{.Type}} { 282 // ABI is the input ABI used to generate the binding from. 283 public final static String ABI = "{{.InputABI}}"; 284 285 {{if .InputBin}} 286 // BYTECODE is the compiled bytecode used for deploying new contracts. 287 public final static byte[] BYTECODE = "{{.InputBin}}".getBytes(); 288 289 // deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it. 290 public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 291 Interfaces args = gath.newInterfaces({{(len .Constructor.Inputs)}}); 292 {{range $index, $element := .Constructor.Inputs}} 293 args.set({{$index}}, gath.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 294 {{end}} 295 return new {{.Type}}(gath.deployContract(auth, ABI, BYTECODE, client, args)); 296 } 297 298 // Internal constructor used by contract deployment. 299 private {{.Type}}(BoundContract deployment) { 300 this.Address = deployment.getAddress(); 301 this.Deployer = deployment.getDeployer(); 302 this.Contract = deployment; 303 } 304 {{end}} 305 306 // Ethereum address where this contract is located at. 307 public final Address Address; 308 309 // Ethereum transaction in which this contract was deployed (if known!). 310 public final Transaction Deployer; 311 312 // Contract instance bound to a blockchain address. 313 private final BoundContract Contract; 314 315 // Creates a new instance of {{.Type}}, bound to a specific deployed contract. 316 public {{.Type}}(Address address, EthereumClient client) throws Exception { 317 this(gath.bindContract(address, ABI, client)); 318 } 319 320 {{range .Calls}} 321 {{if gt (len .Normalized.Outputs) 1}} 322 // {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}. 323 public class {{capitalise .Normalized.Name}}Results { 324 {{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}}; 325 {{end}} 326 } 327 {{end}} 328 329 // {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}. 330 // 331 // Solidity: {{.Original.String}} 332 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 { 333 Interfaces args = gath.newInterfaces({{(len .Normalized.Inputs)}}); 334 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, gath.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 335 {{end}} 336 337 Interfaces results = gath.newInterfaces({{(len .Normalized.Outputs)}}); 338 {{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = gath.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}}); 339 {{end}} 340 341 if (opts == null) { 342 opts = gath.newCallOpts(); 343 } 344 this.Contract.call(opts, results, "{{.Original.Name}}", args); 345 {{if gt (len .Normalized.Outputs) 1}} 346 {{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results(); 347 {{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}(); 348 {{end}} 349 return result; 350 {{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}} 351 {{end}} 352 } 353 {{end}} 354 355 {{range .Transacts}} 356 // {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}. 357 // 358 // Solidity: {{.Original.String}} 359 public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 360 Interfaces args = gath.newInterfaces({{(len .Normalized.Inputs)}}); 361 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, gath.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 362 {{end}} 363 364 return this.Contract.transact(opts, "{{.Original.Name}}" , args); 365 } 366 {{end}} 367 } 368 {{end}} 369 `