github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/accounts/abi/bind/template.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:31</date> 10 //</624450061148884992> 11 12 13 package bind 14 15 import "github.com/ethereum/go-ethereum/accounts/abi" 16 17 //tmpldata是填充绑定模板所需的数据结构。 18 type tmplData struct { 19 Package string //要将生成的文件放入其中的包的名称 20 Contracts map[string]*tmplContract //要生成到此文件中的合同列表 21 } 22 23 //tmplcontract包含生成单个合同绑定所需的数据。 24 type tmplContract struct { 25 Type string //主合同绑定的类型名称 26 InputABI string //json abi用作从中生成绑定的输入 27 InputBin string //可选的EVM字节码,用于从中重新部署代码 28 Constructor abi.Method //部署参数化的契约构造函数 29 Calls map[string]*tmplMethod //合同调用只读取状态数据 30 Transacts map[string]*tmplMethod //写状态数据的合同调用 31 Events map[string]*tmplEvent //合同事件访问器 32 } 33 34 //tmplmethod是一个abi.method的包装,其中包含一些预处理的 35 //和缓存的数据字段。 36 type tmplMethod struct { 37 Original abi.Method //ABI包解析的原始方法 38 Normalized abi.Method //解析方法的规范化版本(大写名称、非匿名参数/返回) 39 Structured bool //返回值是否应累积到结构中 40 } 41 42 //tmplevent是围绕 43 type tmplEvent struct { 44 Original abi.Event //ABI包解析的原始事件 45 Normalized abi.Event //解析字段的规范化版本 46 } 47 48 //tmplsource是语言到模板的映射,包含所有支持的 49 //程序包可以生成的编程语言。 50 var tmplSource = map[Lang]string{ 51 LangGo: tmplSourceGo, 52 LangJava: tmplSourceJava, 53 } 54 55 //tmplsourcego是用于生成合同绑定的go源模板 56 //基于。 57 const tmplSourceGo = ` 58 //代码生成-不要编辑。 59 //此文件是生成的绑定,任何手动更改都将丢失。 60 61 package {{.Package}} 62 63 import ( 64 "math/big" 65 "strings" 66 67 ethereum "github.com/ethereum/go-ethereum" 68 "github.com/ethereum/go-ethereum/accounts/abi" 69 "github.com/ethereum/go-ethereum/accounts/abi/bind" 70 "github.com/ethereum/go-ethereum/common" 71 "github.com/ethereum/go-ethereum/core/types" 72 "github.com/ethereum/go-ethereum/event" 73 ) 74 75 //引用导入以禁止错误(如果未使用)。 76 var ( 77 _ = big.NewInt 78 _ = strings.NewReader 79 _ = ethereum.NotFound 80 _ = abi.U256 81 _ = bind.Bind 82 _ = common.Big1 83 _ = types.BloomLookup 84 _ = event.NewSubscription 85 ) 86 87 {{range $contract := .Contracts}} 88 //.type abi是用于生成绑定的输入abi。 89 const {{.Type}}ABI = "{{.InputABI}}" 90 91 {{if .InputBin}} 92 //.type bin是用于部署新合同的编译字节码。 93 const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + ` 94 95 //部署。类型部署新的以太坊契约,将类型的实例绑定到它。 96 func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) { 97 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 98 if err != nil { 99 return common.Address{}, nil, nil, err 100 } 101 address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) 102 if err != nil { 103 return common.Address{}, nil, nil, err 104 } 105 return address, tx, &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 106 } 107 {{end}} 108 109 //.type是围绕以太坊合约自动生成的go绑定。 110 type {{.Type}} struct { 111 {{.Type}}Caller //对合同具有只读约束力 112 {{.Type}}Transactor //只写对合同有约束力 113 {{.Type}}Filterer //合同事件的日志筛选程序 114 } 115 116 //.类型调用者是围绕以太坊契约自动生成的只读Go绑定。 117 type {{.Type}}Caller struct { 118 contract *bind.BoundContract //用于低级调用的通用协定包装器 119 } 120 121 //.type Transactior是围绕以太坊合同自动生成的只写Go绑定。 122 type {{.Type}}Transactor struct { 123 contract *bind.BoundContract //用于低级调用的通用协定包装器 124 } 125 126 //.type filter是围绕以太坊合同事件自动生成的日志筛选go绑定。 127 type {{.Type}}Filterer struct { 128 contract *bind.BoundContract //用于低级调用的通用协定包装器 129 } 130 131 //.type session是围绕以太坊合约自动生成的go绑定, 132 //具有预设的调用和事务处理选项。 133 type {{.Type}}Session struct { 134 Contract *{{.Type}} //为其设置会话的通用约定绑定 135 CallOpts bind.CallOpts //在整个会话中使用的调用选项 136 TransactOpts bind.TransactOpts //要在此会话中使用的事务验证选项 137 } 138 139 //.类型Callersession是围绕以太坊契约自动生成的只读Go绑定, 140 //带预设通话选项。 141 type {{.Type}}CallerSession struct { 142 Contract *{{.Type}}Caller //用于设置会话的通用协定调用方绑定 143 CallOpts bind.CallOpts //在整个会话中使用的调用选项 144 } 145 146 //.类型事务会话是围绕以太坊合同自动生成的只写即用绑定, 147 //具有预设的Transact选项。 148 type {{.Type}}TransactorSession struct { 149 Contract *{{.Type}}Transactor //用于设置会话的通用合同事务处理程序绑定 150 TransactOpts bind.TransactOpts //要在此会话中使用的事务验证选项 151 } 152 153 //.type raw是围绕以太坊合约自动生成的低级go绑定。 154 type {{.Type}}Raw struct { 155 Contract *{{.Type}} //用于访问上的原始方法的通用合同绑定 156 } 157 158 //.type Callerraw是围绕以太坊合约自动生成的低级只读Go绑定。 159 type {{.Type}}CallerRaw struct { 160 Contract *{{.Type}}Caller //用于访问上的原始方法的通用只读协定绑定 161 } 162 163 //.type transactorraw是围绕以太坊合同自动生成的低级只写即用绑定。 164 type {{.Type}}TransactorRaw struct { 165 Contract *{{.Type}}Transactor //用于访问上的原始方法的通用只写协定绑定 166 } 167 168 //new。type创建绑定到特定部署合同的.type的新实例。 169 func New{{.Type}}(address common.Address, backend bind.ContractBackend) (*{{.Type}}, error) { 170 contract, err := bind{{.Type}}(address, backend, backend, backend) 171 if err != nil { 172 return nil, err 173 } 174 return &{{.Type}}{ {{.Type}}Caller: {{.Type}}Caller{contract: contract}, {{.Type}}Transactor: {{.Type}}Transactor{contract: contract}, {{.Type}}Filterer: {{.Type}}Filterer{contract: contract} }, nil 175 } 176 177 //new.type调用者创建绑定到特定部署的协定的.type的新只读实例。 178 func New{{.Type}}Caller(address common.Address, caller bind.ContractCaller) (*{{.Type}}Caller, error) { 179 contract, err := bind{{.Type}}(address, caller, nil, nil) 180 if err != nil { 181 return nil, err 182 } 183 return &{{.Type}}Caller{contract: contract}, nil 184 } 185 186 //新建。类型事务处理程序创建绑定到特定部署合同的类型的新只写实例。 187 func New{{.Type}}Transactor(address common.Address, transactor bind.ContractTransactor) (*{{.Type}}Transactor, error) { 188 contract, err := bind{{.Type}}(address, nil, transactor, nil) 189 if err != nil { 190 return nil, err 191 } 192 return &{{.Type}}Transactor{contract: contract}, nil 193 } 194 195 //new。type filter创建绑定到特定部署合同的.type的新日志筛选器实例。 196 func New{{.Type}}Filterer(address common.Address, filterer bind.ContractFilterer) (*{{.Type}}Filterer, error) { 197 contract, err := bind{{.Type}}(address, nil, nil, filterer) 198 if err != nil { 199 return nil, err 200 } 201 return &{{.Type}}Filterer{contract: contract}, nil 202 } 203 204 //bind。type将通用包装绑定到已部署的合同。 205 func bind{{.Type}}(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { 206 parsed, err := abi.JSON(strings.NewReader({{.Type}}ABI)) 207 if err != nil { 208 return nil, err 209 } 210 return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil 211 } 212 213 //调用调用(常量)contract方法,参数作为输入值,并且 214 //将输出设置为结果。结果类型可能是用于 215 //返回、匿名返回的接口切片和命名的结构 216 //返回。 217 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 218 return _{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call(opts, result, method, params...) 219 } 220 221 //转账启动普通交易以将资金转移到合同,调用 222 //它的默认方法(如果有)。 223 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 224 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer(opts) 225 } 226 227 //Transact使用参数作为输入值调用(付费)Contract方法。 228 func (_{{$contract.Type}} *{{$contract.Type}}Raw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 229 return _{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact(opts, method, params...) 230 } 231 232 //调用调用(常量)contract方法,参数作为输入值,并且 233 //将输出设置为结果。结果类型可能是用于 234 //返回、匿名返回的接口切片和命名的结构 235 //返回。 236 func (_{{$contract.Type}} *{{$contract.Type}}CallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { 237 return _{{$contract.Type}}.Contract.contract.Call(opts, result, method, params...) 238 } 239 240 //转账启动普通交易以将资金转移到合同,调用 241 //它的默认方法(如果有)。 242 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { 243 return _{{$contract.Type}}.Contract.contract.Transfer(opts) 244 } 245 246 //Transact使用参数作为输入值调用(付费)Contract方法。 247 func (_{{$contract.Type}} *{{$contract.Type}}TransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { 248 return _{{$contract.Type}}.Contract.contract.Transact(opts, method, params...) 249 } 250 251 {{range .Calls}} 252 //.normalized.name是绑定协定方法0x printf“%x”.original.id的免费数据检索调用。 253 // 254 //坚固性:.original.string 255 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) { 256 {{if .Structured}}ret := new(struct{ 257 {{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}} 258 {{end}} 259 }){{else}}var ( 260 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type}}) 261 {{end}} 262 ){{end}} 263 out := {{if .Structured}}ret{{else}}{{if eq (len .Normalized.Outputs) 1}}ret0{{else}}&[]interface{}{ 264 {{range $i, $_ := .Normalized.Outputs}}ret{{$i}}, 265 {{end}} 266 }{{end}}{{end}} 267 err := _{{$contract.Type}}.contract.Call(opts, out, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 268 return {{if .Structured}}*ret,{{else}}{{range $i, $_ := .Normalized.Outputs}}*ret{{$i}},{{end}}{{end}} err 269 } 270 271 //.normalized.name是绑定协定方法0x printf“%x”.original.id的免费数据检索调用。 272 // 273 //坚固性:.original.string 274 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) { 275 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 276 } 277 278 //.normalized.name是绑定协定方法0x printf“%x”.original.id的免费数据检索调用。 279 // 280 //坚固性:.original.string 281 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) { 282 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 283 } 284 {{end}} 285 286 {{range .Transacts}} 287 //.normalized.name是一个付费的转换程序事务,绑定合同方法0x printf“%x”.original.id。 288 // 289 //坚固性:.original.string 290 func (_{{$contract.Type}} *{{$contract.Type}}Transactor) {{.Normalized.Name}}(opts *bind.TransactOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 291 return _{{$contract.Type}}.contract.Transact(opts, "{{.Original.Name}}" {{range .Normalized.Inputs}}, {{.Name}}{{end}}) 292 } 293 294 //.normalized.name是一个付费的转换程序事务,绑定合同方法0x printf“%x”.original.id。 295 // 296 //坚固性:.original.string 297 func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 298 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 299 } 300 301 //.normalized.name是一个付费的转换程序事务,绑定合同方法0x printf“%x”.original.id。 302 // 303 //坚固性:.original.string 304 func (_{{$contract.Type}} *{{$contract.Type}}TransactorSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) (*types.Transaction, error) { 305 return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.TransactOpts {{range $i, $_ := .Normalized.Inputs}}, {{.Name}}{{end}}) 306 } 307 {{end}} 308 309 {{range .Events}} 310 //$contract.type.normalized.name迭代器从filter.normalized.name返回,用于迭代.normalized.name contract.type合同引发的原始日志和未打包数据。 311 type {{$contract.Type}}{{.Normalized.Name}}Iterator struct { 312 Event *{{$contract.Type}}{{.Normalized.Name}} //包含合同细节和原始日志的事件 313 314 contract *bind.BoundContract //用于解包事件数据的通用合同 315 event string //用于解包事件数据的事件名称 316 317 logs chan types.Log //日志通道接收找到的合同事件 318 sub ethereum.Subscription //错误、完成和终止订阅 319 done bool //订阅是否完成传递日志 320 fail error //停止迭代时出错 321 } 322 //next将迭代器前进到后续事件,返回是否存在 323 //是否找到更多事件。在检索或分析错误的情况下,false是 324 //返回错误(),可以查询错误()的确切错误。 325 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Next() bool { 326 //如果迭代器失败,请停止迭代 327 if (it.fail != nil) { 328 return false 329 } 330 //如果迭代器已完成,则直接传递可用的 331 if (it.done) { 332 select { 333 case log := <-it.logs: 334 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 335 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 336 it.fail = err 337 return false 338 } 339 it.Event.Raw = log 340 return true 341 342 default: 343 return false 344 } 345 } 346 //迭代器仍在进行中,请等待数据或错误事件 347 select { 348 case log := <-it.logs: 349 it.Event = new({{$contract.Type}}{{.Normalized.Name}}) 350 if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { 351 it.fail = err 352 return false 353 } 354 it.Event.Raw = log 355 return true 356 357 case err := <-it.sub.Err(): 358 it.done = true 359 it.fail = err 360 return it.Next() 361 } 362 } 363 //错误返回筛选期间发生的任何检索或分析错误。 364 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Error() error { 365 return it.fail 366 } 367 //关闭终止迭代过程,释放任何挂起的基础 368 //资源。 369 func (it *{{$contract.Type}}{{.Normalized.Name}}Iterator) Close() error { 370 it.sub.Unsubscribe() 371 return nil 372 } 373 374 //$contract.type.normalized.name表示.normalized.name由$contract.type contract引发的事件。 375 type {{$contract.Type}}{{.Normalized.Name}} struct { {{range .Normalized.Inputs}} 376 {{capitalise .Name}} {{if .Indexed}}{{bindtopictype .Type}}{{else}}{{bindtype .Type}}{{end}}; {{end}} 377 Raw types.Log //区块链特定的上下文信息 378 } 379 380 //filter.normalized.name是绑定协定事件0x printf“%x”.original.id的自由日志检索操作。 381 // 382 //坚固性:.original.string 383 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) { 384 {{range .Normalized.Inputs}} 385 {{if .Indexed}}var {{.Name}}Rule []interface{} 386 for _, {{.Name}}Item := range {{.Name}} { 387 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 388 }{{end}}{{end}} 389 390 logs, sub, err := _{{$contract.Type}}.contract.FilterLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 391 if err != nil { 392 return nil, err 393 } 394 return &{{$contract.Type}}{{.Normalized.Name}}Iterator{contract: _{{$contract.Type}}.contract, event: "{{.Original.Name}}", logs: logs, sub: sub}, nil 395 } 396 397 //watch.normalized.name是绑定合同事件0x printf“%x”.original.id的自由日志订阅操作。 398 // 399 //坚固性:.original.string 400 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) { 401 {{range .Normalized.Inputs}} 402 {{if .Indexed}}var {{.Name}}Rule []interface{} 403 for _, {{.Name}}Item := range {{.Name}} { 404 {{.Name}}Rule = append({{.Name}}Rule, {{.Name}}Item) 405 }{{end}}{{end}} 406 407 logs, sub, err := _{{$contract.Type}}.contract.WatchLogs(opts, "{{.Original.Name}}"{{range .Normalized.Inputs}}{{if .Indexed}}, {{.Name}}Rule{{end}}{{end}}) 408 if err != nil { 409 return nil, err 410 } 411 return event.NewSubscription(func(quit <-chan struct{}) error { 412 defer sub.Unsubscribe() 413 for { 414 select { 415 case log := <-logs: 416 //新日志到达,分析事件并转发给用户 417 event := new({{$contract.Type}}{{.Normalized.Name}}) 418 if err := _{{$contract.Type}}.contract.UnpackLog(event, "{{.Original.Name}}", log); err != nil { 419 return err 420 } 421 event.Raw = log 422 423 select { 424 case sink <- event: 425 case err := <-sub.Err(): 426 return err 427 case <-quit: 428 return nil 429 } 430 case err := <-sub.Err(): 431 return err 432 case <-quit: 433 return nil 434 } 435 } 436 }), nil 437 } 438 {{end}} 439 {{end}} 440 ` 441 442 //TMPLSURCEJAVA是用于生成合同绑定的Java源模板 443 //基于。 444 const tmplSourceJava = ` 445 //这个文件是一个自动生成的Java绑定。不要修改为任何 446 //下一代人可能会失去变革! 447 448 package {{.Package}}; 449 450 import org.ethereum.geth.*; 451 import org.ethereum.geth.internal.*; 452 453 {{range $contract := .Contracts}} 454 public class {{.Type}} { 455 //abi是用于从中生成绑定的输入abi。 456 public final static String ABI = "{{.InputABI}}"; 457 458 {{if .InputBin}} 459 //字节码是用于部署新合同的已编译字节码。 460 public final static byte[] BYTECODE = "{{.InputBin}}".getBytes(); 461 462 //Deploy部署一个新的以太坊契约,将.type的实例绑定到它。 463 public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 464 Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}}); 465 {{range $index, $element := .Constructor.Inputs}} 466 args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 467 {{end}} 468 return new {{.Type}}(Geth.deployContract(auth, ABI, BYTECODE, client, args)); 469 } 470 471 //合同部署使用的内部构造函数。 472 private {{.Type}}(BoundContract deployment) { 473 this.Address = deployment.getAddress(); 474 this.Deployer = deployment.getDeployer(); 475 this.Contract = deployment; 476 } 477 {{end}} 478 479 //本合同所在的以太坊地址。 480 public final Address Address; 481 482 //部署此合同的以太坊事务(如果知道!). 483 public final Transaction Deployer; 484 485 //绑定到区块链地址的合同实例。 486 private final BoundContract Contract; 487 488 //创建绑定到特定部署合同的.Type的新实例。 489 public {{.Type}}(Address address, EthereumClient client) throws Exception { 490 this(Geth.bindContract(address, ABI, client)); 491 } 492 493 {{range .Calls}} 494 {{if gt (len .Normalized.Outputs) 1}} 495 //capitale.normalized.name results是对.normalized.name的调用的输出。 496 public class {{capitalise .Normalized.Name}}Results { 497 {{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}}; 498 {{end}} 499 } 500 {{end}} 501 502 //.normalized.name是绑定协定方法0x printf“%x”.original.id的免费数据检索调用。 503 // 504 //坚固性:.original.string 505 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 { 506 Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}}); 507 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 508 {{end}} 509 510 Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}}); 511 {{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}}); 512 {{end}} 513 514 if (opts == null) { 515 opts = Geth.newCallOpts(); 516 } 517 this.Contract.call(opts, results, "{{.Original.Name}}", args); 518 {{if gt (len .Normalized.Outputs) 1}} 519 {{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results(); 520 {{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}(); 521 {{end}} 522 return result; 523 {{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}} 524 {{end}} 525 } 526 {{end}} 527 528 {{range .Transacts}} 529 //.normalized.name是一个付费的转换程序事务,绑定合同方法0x printf“%x”.original.id。 530 // 531 //坚固性:.original.string 532 public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception { 533 Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}}); 534 {{range $index, $item := .Normalized.Inputs}}args.set({{$index}}, Geth.newInterface()); args.get({{$index}}).set{{namedtype (bindtype .Type) .Type}}({{.Name}}); 535 {{end}} 536 537 return this.Contract.transact(opts, "{{.Original.Name}}" , args); 538 } 539 {{end}} 540 } 541 {{end}} 542 ` 543