github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/accounts/abi/bind/template.go (about)

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