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