//Copyright2016Thego-ethereumAuthors//Thisfileispartofthego-ethereumlibrary.////Thego-ethereumlibraryisfreesoftware:youcanredistributeitand/ormodify//itunderthetermsoftheGNULesserGeneralPublicLicenseaspublishedby//theFreeSoftwareFoundation,eitherversion3oftheLicense,or//anylaterversion.////Thego-ethereumlibraryisdistributedinthehopethatitwillbeuseful,//butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof//MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSSeethe//GNULesserGeneralPublicLicenseformoredetails.////YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense//alongwiththego-ethereumlibrary.Ifnot,see.package量化投资接口,bindimport"github.com/ethereum/go-ethereum/accounts/abi"//tmplDataisthedatastructurerequiredtofillthe量化投资接口,bindingtemplate.//tmplData是填充绑定模板所需的数据结构。typetmplDatastruct{Packagestring//Nameofthepackagetoplacethegeneratedfilein要放置生成的文件的包的名称Contractsmap[string]*tmplContract//Listofcontractstogenerateintothisfile要生成到此文件的合约列表Librariesmap[string]string//Mapthebytecode"slinkpatterntothelibraryname将字节码的链接模式映射到库名称Structsmap[string]*tmplStruct//Contractstructtypedefinitions合约结构类型定义}//tmplContractcontainsthedataneededtogenerateaninpidualcontractbinding.tmplContract包含生成单个合约绑定所需的数据。typetmplContractstruct{Typestring//Typenameofthemaincontractbinding主合约绑定的类型名称InputABIstring//JSONABIusedastheinputtogeneratethebindingfromJSONABI用作从生成绑定的输入InputBinstring//OptionalEVMbytecodeusedtogeneratedeploycodefrom用于从生成部署代码的可选EVM字节码FuncSigsmap[string]string//Optionalmap:stringsignature->4-bytesignature可选映射:字符串签名->4字节签名Constructorabi.Method//Contractconstructorfordeployparametrization部署参数化的合约构造函数Callsmap[string]*tmplMethod//Contractcallsthatonlyreadstatedata仅读取状态数据的协定调用Transactsmap[string]*tmplMethod//Contractcallsthatwritestatedata写入状态数据的协定调用Fallback*tmplMethod//Additionalspecialfallbackfunction附加的特殊回退功能Receive*tmplMethod//Additionalspecialreceivefunction额外的特殊接收功能Eventsmap[string]*tmplEvent//Contracteventsaccessors合约事件访问者Librariesmap[string]string//SameastmplData,butfilteredtoonlykeepwhatthecontractneeds与tmplData相同,但经过筛选以仅保留合约所需内容Librarybool//Indicatorwhetherthecontractisalibrary指示合约是否为库}//tmplMethodisawrapperaroundanabi.Methodthatcontainsafewpreprocessed//andcacheddatafields.//tmplMethod是一个围绕abi.Method的包装器,该方法包含一些预处理和缓存的数据字段。typetmplMethodstruct{Originalabi.Method//Originalmethodasparsedbytheabipackageabi包解析的原始方法Normalizedabi.Method//Normalizedversionoftheparsedmethod解析方法的规范化版本Structuredbool//Whetherthereturnsshouldbeaccumulatedintoastruct返回值是否应累积到结构中}//tmplEventisawrapperaroundanabi.Eventthatcontainsafewpreprocessed//andcacheddatafields.tmplEvent是一个abi.Event的包装器,它包含一些预处理和缓存的数据字段。typetmplEventstruct{Originalabi.Event//Originaleventasparsedbytheabipackageabi包解析的原始事件Normalizedabi.Event//Normalizedversionoftheparsedfields已解析字段的规范化版本}//tmplFieldisawrapperaroundastructfieldwithbindinglanguage//structtypedefinitionandrelativefiledname.//tmplField是一个结构字段的包装器,该字段具有绑定语言结构类型定义和相对字段名。typetmplFieldstruct{Typestring//Fieldtyperepresentationdependsontargetbindinglanguage字段类型表示取决于目标绑定语言Namestring//Fieldnameconvertedfromtherawuser-definedfieldname从原始用户定义字段名称转换而来的字段名称SolKindabi.Type//Rawabitypeinformation原始abi类型信息}//tmplStructisawrapperaroundanabi.tupleandcontainsanauto-generated//structname.//tmplStruct是abi.tuple的包装器,包含一个自动生成的结构名称。typetmplStructstruct{Namestring//Auto-generatedstructnameorrawname.自动生成的结构体名称或原始名称。Fields[]*tmplField//Structfieldsdefinitiondependsonthebindinglanguage.结构字段的定义取决于绑定语言。}//tmplSourceislanguagetotemplatemappingcontainingallthesupported//programminglanguagesthepackagecangenerateto.//tmplSource是语言到模板的映射,包含包可以生成的所有支持的编程语言。vartmplSource=map[Lang]string{LangGo:tmplSourceGo,}//tmplSourceGoistheGosourcetemplatethatthegeneratedGocontractbinding//isbasedon.//tmplSourceGo是生成的Go合约绑定所基于的Go源模板。consttmplSourceGo=`//Codegenerated-DONOTEDIT.//Thisfileisageneratedbindingandanymanualchangeswillbelost.package{{.Package}}import//Referenceimportstosuppresserrorsiftheyarenototherwiseused.var{{$structs:=.Structs}}{{range$structs}}//{{.Name}}isanautogeneratedlow-levelGobindingaroundanuser-definedstruct.type{{.Name}}struct{{{range$field:=.Fields}}{{$field.Name}}{{$field.Type}}{{end}}}{{end}}{{range$contract:=.Contracts}}//{{.Type}}MetaDatacontainsallmetadataconcerningthe{{.Type}}contract.var{{.Type}}MetaData=&bind.MetaData{ABI:"{{.InputABI}}",{{if$contract.FuncSigs-}}Sigs:map[string]string{{{range$strsig,$binsig:=.FuncSigs}}"{{$binsig}}":"{{$strsig}}",{{end}}},{{end-}}{{if.InputBin-}}Bin:"0x{{.InputBin}}",{{end}}}//{{.Type}}ABIistheinputABIusedtogeneratethebindingfrom.//Deprecated:Use{{.Type}}MetaData.ABIinstead.var{{.Type}}ABI={{.Type}}MetaData.ABI{{if$contract.FuncSigs}}//Deprecated:Use{{.Type}}MetaData.Sigsinstead.//{{.Type}}FuncSigsmapsthe4-bytefunctionsignaturetoitsstringrepresentation.var{{.Type}}FuncSigs={{.Type}}MetaData.Sigs{{end}}{{if.InputBin}}//{{.Type}}Binisthecompiledbytecodeusedfordeployingnewcontracts.//Deprecated:Use{{.Type}}MetaData.Bininstead.var{{.Type}}Bin={{.Type}}MetaData.Bin//Deploy{{.Type}}deploysanewEthereumcontract,bindinganinstanceof{{.Type}}toit.funcDeploy{{.Type}}{parsed,err:={{.Type}}MetaData.GetAbiiferr!=nil{returncommon.Address{},nil,nil,err}ifparsed==nil{returncommon.Address{},nil,nil,errors.New}{{range$pattern,$name:=.Libraries}}{{decapitalise$name}}Addr,_,_,_:=Deploy{{capitalise$name}}{{$contract.Type}}Bin=strings.ReplaceAll[2:]){{end}}address,tx,contract,err:=bind.DeployContract,backend{{range.Constructor.Inputs}},{{.Name}}{{end}})iferr!=nil{returncommon.Address{},nil,nil,err}returnaddress,tx,&{{.Type}}{{{.Type}}Caller:{{.Type}}Caller{contract:contract},{{.Type}}Transactor:{{.Type}}Transactor{contract:contract},{{.Type}}Filterer:{{.Type}}Filterer{contract:contract}},nil}{{end}}//{{.Type}}isanautogeneratedGobindingaroundanEthereumcontract.type{{.Type}}struct{{{.Type}}Caller//Read-onlybindingtothecontract{{.Type}}Transactor//Write-onlybindingtothecontract{{.Type}}Filterer//Logfiltererforcontractevents}//{{.Type}}Callerisanautogeneratedread-onlyGobindingaroundanEthereumcontract.type{{.Type}}Callerstruct{contract*bind.BoundContract//Genericcontractwrapperforthelowlevelcalls}//{{.Type}}Transactorisanautogeneratedwrite-onlyGobindingaroundanEthereumcontract.type{{.Type}}Transactorstruct{contract*bind.BoundContract//Genericcontractwrapperforthelowlevelcalls}//{{.Type}}FiltererisanautogeneratedlogfilteringGobindingaroundanEthereumcontractevents.type{{.Type}}Filtererstruct{contract*bind.BoundContract//Genericcontractwrapperforthelowlevelcalls}//{{.Type}}SessionisanautogeneratedGobindingaroundanEthereumcontract,//withpre-setcallandtransactoptions.type{{.Type}}Sessionstruct{Contract*{{.Type}}//GenericcontractbindingtosetthesessionforCallOptsbind.CallOpts//CalloptionstousethroughoutthissessionTransactOptsbind.TransactOpts//Transactionauthoptionstousethroughoutthissession}//{{.Type}}CallerSessionisanautogeneratedread-onlyGobindingaroundanEthereumcontract,//withpre-setcalloptions.type{{.Type}}CallerSessionstruct{Contract*{{.Type}}Caller//GenericcontractcallerbindingtosetthesessionforCallOptsbind.CallOpts//Calloptionstousethroughoutthissession}//{{.Type}}TransactorSessionisanautogeneratedwrite-onlyGobindingaroundanEthereumcontract,//withpre-settransactoptions.type{{.Type}}TransactorSessionstruct{Contract*{{.Type}}Transactor//GenericcontracttransactorbindingtosetthesessionforTransactOptsbind.TransactOpts//Transactionauthoptionstousethroughoutthissession}//{{.Type}}Rawisanautogeneratedlow-levelGobindingaroundanEthereumcontract.type{{.Type}}Rawstruct{Contract*{{.Type}}//Genericcontractbindingtoaccesstherawmethodson}//{{.Type}}CallerRawisanautogeneratedlow-levelread-onlyGobindingaroundanEthereumcontract.type{{.Type}}CallerRawstruct{Contract*{{.Type}}Caller//Genericread-onlycontractbindingtoaccesstherawmethodson}//{{.Type}}TransactorRawisanautogeneratedlow-levelwrite-onlyGobindingaroundanEthereumcontract.type{{.Type}}TransactorRawstruct{Contract*{{.Type}}Transactor//Genericwrite-onlycontractbindingtoaccesstherawmethodson}//New{{.Type}}createsanewinstanceof{{.Type}},boundtoaspecificdeployedcontract.funcNew{{.Type}}{contract,err:=bind{{.Type}}iferr!=nil{returnnil,err}return&{{.Type}}{{{.Type}}Caller:{{.Type}}Caller{contract:contract},{{.Type}}Transactor:{{.Type}}Transactor{contract:contract},{{.Type}}Filterer:{{.Type}}Filterer{contract:contract}},nil}//New{{.Type}}Callercreatesanewread-onlyinstanceof{{.Type}},boundtoaspecificdeployedcontract.funcNew{{.Type}}Caller{contract,err:=bind{{.Type}}iferr!=nil{returnnil,err}return&{{.Type}}Caller{contract:contract},nil}//New{{.Type}}Transactorcreatesanewwrite-onlyinstanceof{{.Type}},boundtoaspecificdeployedcontract.funcNew{{.Type}}Transactor{contract,err:=bind{{.Type}}iferr!=nil{returnnil,err}return&{{.Type}}Transactor{contract:contract},nil}//New{{.Type}}Filterercreatesanewlogfiltererinstanceof{{.Type}},boundtoaspecificdeployedcontract.funcNew{{.Type}}Filterer{contract,err:=bind{{.Type}}iferr!=nil{returnnil,err}return&{{.Type}}Filterer{contract:contract},nil}//bind{{.Type}}bindsagenericwrappertoanalreadydeployedcontract.funcbind{{.Type}}{parsed,err:={{.Type}}MetaData.GetAbiiferr!=nil{returnnil,err}returnbind.NewBoundContract,nil}//Callinvokesthecontractmethodwithparamsasinputvaluesand//setstheoutputtoresult.Theresulttypemightbeasinglefieldforsimple//returns,asliceofinterfacesforanonymousreturnsandastructfornamed//returns.funcCallerror{return_{{$contract.Type}}.Contract.{{$contract.Type}}Caller.contract.Call}//Transferinitiatesaplaintransactiontomovefundstothecontract,calling//itsdefaultmethodifoneisavailable.funcTransfer{return_{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transfer}//Transactinvokesthecontractmethodwithparamsasinputvalues.funcTransact{return_{{$contract.Type}}.Contract.{{$contract.Type}}Transactor.contract.Transact}//Callinvokesthecontractmethodwithparamsasinputvaluesand//setstheoutputtoresult.Theresulttypemightbeasinglefieldforsimple//returns,asliceofinterfacesforanonymousreturnsandastructfornamed//returns.funcCallerror{return_{{$contract.Type}}.Contract.contract.Call}//Transferinitiatesaplaintransactiontomovefundstothecontract,calling//itsdefaultmethodifoneisavailable.funcTransfer{return_{{$contract.Type}}.Contract.contract.Transfer}//Transactinvokesthecontractmethodwithparamsasinputvalues.funcTransact{return_{{$contract.Type}}.Contract.contract.Transact}{{range.Calls}}//{{.Normalized.Name}}isafreedataretrievalcallbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{varout[]interface{}err:=_{{$contract.Type}}.contract.Call{{if.Structured}}outstruct:=newiferr!=nil{return*outstruct,err}{{range$i,$t:=.Normalized.Outputs}}outstruct.{{.Name}}=*abi.ConvertType).{{end}}return*outstruct,err{{else}}iferr!=nil{return{{range$i,$_:=.Normalized.Outputs}}*new,{{end}}err}{{range$i,$t:=.Normalized.Outputs}}out{{$i}}:=*abi.ConvertType).{{end}}return{{range$i,$t:=.Normalized.Outputs}}out{{$i}},{{end}}err{{end}}}//{{.Normalized.Name}}isafreedataretrievalcallbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{return_{{$contract.Type}}.Contract.{{.Normalized.Name}}}//{{.Normalized.Name}}isafreedataretrievalcallbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{return_{{$contract.Type}}.Contract.{{.Normalized.Name}}}{{end}}{{range.Transacts}}//{{.Normalized.Name}}isapaidmutatortransactionbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{return_{{$contract.Type}}.contract.Transact}//{{.Normalized.Name}}isapaidmutatortransactionbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{return_{{$contract.Type}}.Contract.{{.Normalized.Name}}}//{{.Normalized.Name}}isapaidmutatortransactionbindingthecontractmethod0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}func{{.Normalized.Name}}{return_{{$contract.Type}}.Contract.{{.Normalized.Name}}}{{end}}{{if.Fallback}}//Fallbackisapaidmutatortransactionbindingthecontractfallbackfunction.////Solidity:{{.Fallback.Original.String}}funcFallback{return_{{$contract.Type}}.contract.RawTransact}//Fallbackisapaidmutatortransactionbindingthecontractfallbackfunction.////Solidity:{{.Fallback.Original.String}}funcFallback{return_{{$contract.Type}}.Contract.Fallback}//Fallbackisapaidmutatortransactionbindingthecontractfallbackfunction.////Solidity:{{.Fallback.Original.String}}funcFallback{return_{{$contract.Type}}.Contract.Fallback}{{end}}{{if.Receive}}//Receiveisapaidmutatortransactionbindingthecontractreceivefunction.////Solidity:{{.Receive.Original.String}}funcReceive{return_{{$contract.Type}}.contract.RawTransact//calldataisdisallowedforreceivefunction}//Receiveisapaidmutatortransactionbindingthecontractreceivefunction.////Solidity:{{.Receive.Original.String}}funcReceive{return_{{$contract.Type}}.Contract.Receive}//Receiveisapaidmutatortransactionbindingthecontractreceivefunction.////Solidity:{{.Receive.Original.String}}funcReceive{return_{{$contract.Type}}.Contract.Receive}{{end}}{{range.Events}}//{{$contract.Type}}{{.Normalized.Name}}IteratorisreturnedfromFilter{{.Normalized.Name}}andisusedtoiterateovertherawlogsandunpackeddatafor{{.Normalized.Name}}eventsraisedbythe{{$contract.Type}}contract.type{{$contract.Type}}{{.Normalized.Name}}Iteratorstruct{Event*{{$contract.Type}}{{.Normalized.Name}}//Eventcontainingthecontractspecificsandrawlogcontract*bind.BoundContract//Genericcontracttouseforunpackingeventdataeventstring//Eventnametouseforunpackingeventdatalogschantypes.Log//Logchannelreceivingthefoundcontracteventssubethereum.Subscription//Subscriptionforerrors,completionandterminationdonebool//Whetherthesubscriptioncompleteddeliveringlogsfailerror//Occurrederrortostopiteration}//Nextadvancestheiteratortothesubsequentevent,returningwhetherthere//areanymoreeventsfound.Incaseofaretrievalorparsingerror,falseis//returnedandErrorcanbequeriedfortheexactfailure.funcNextbool{//Iftheiteratorfailed,stopiteratingif{returnfalse}//Iftheiteratorcompleted,deliverdirectlywhatever"savailableif{select{caselog:=<-it.logs:it.Event=newiferr:=it.contract.UnpackLog;err!=nil{it.fail=errreturnfalse}it.Event.Raw=logreturntruedefault:returnfalse}}//Iteratorstillinprogress,waitforeitheradataoranerroreventselect{caselog:=<-it.logs:it.Event=newiferr:=it.contract.UnpackLog;err!=nil{it.fail=errreturnfalse}it.Event.Raw=logreturntruecaseerr:=<-it.sub.Err:it.done=trueit.fail=errreturnit.Next}}//Errorreturnsanyretrievalorparsingerroroccurredduringfiltering.funcErrorerror{returnit.fail}//Closeterminatestheiterationprocess,releasinganypendingunderlying//resources.funcCloseerror{it.sub.Unsubscribereturnnil}//{{$contract.Type}}{{.Normalized.Name}}representsa{{.Normalized.Name}}eventraisedbythe{{$contract.Type}}contract.type{{$contract.Type}}{{.Normalized.Name}}struct{{{range.Normalized.Inputs}}{{capitalise.Name}}{{if.Indexed}}{{bindtopictype.Type$structs}}{{else}}{{bindtype.Type$structs}}{{end}};{{end}}Rawtypes.Log//Blockchainspecificcontextualinfos}//Filter{{.Normalized.Name}}isafreelogretrievaloperationbindingthecontractevent0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}funcFilter{{.Normalized.Name}}{{{range.Normalized.Inputs}}{{if.Indexed}}var{{.Name}}Rule[]interface{}for_,{{.Name}}Item:=range{{.Name}}{{{.Name}}Rule=append}{{end}}{{end}}logs,sub,err:=_{{$contract.Type}}.contract.FilterLogsiferr!=nil{returnnil,err}return&{{$contract.Type}}{{.Normalized.Name}}Iterator{contract:_{{$contract.Type}}.contract,event:"{{.Original.Name}}",logs:logs,sub:sub},nil}//Watch{{.Normalized.Name}}isafreelogsubscriptionoperationbindingthecontractevent0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}funcWatch{{.Normalized.Name}}{{{range.Normalized.Inputs}}{{if.Indexed}}var{{.Name}}Rule[]interface{}for_,{{.Name}}Item:=range{{.Name}}{{{.Name}}Rule=append}{{end}}{{end}}logs,sub,err:=_{{$contract.Type}}.contract.WatchLogsiferr!=nil{returnnil,err}returnevent.NewSubscriptionerror{defersub.Unsubscribefor{select{caselog:=<-logs://Newlogarrived,parsetheeventandforwardtotheuserevent:=newiferr:=_{{$contract.Type}}.contract.UnpackLog;err!=nil{returnerr}event.Raw=logselect{casesink<-event:caseerr:=<-sub.Err:returnerrcase<-quit:returnnil}caseerr:=<-sub.Err:returnerrcase<-quit:returnnil}}}),nil}//Parse{{.Normalized.Name}}isalogparseoperationbindingthecontractevent0x{{printf"%x".Original.ID}}.////Solidity:{{.Original.String}}funcParse{{.Normalized.Name}}{event:=newiferr:=_{{$contract.Type}}.contract.UnpackLog;err!=nil{returnnil,err}event.Raw=logreturnevent,nil}{{end}}{{end}}`
文章为作者独立观点,不代表股票自动交易程序化数据接口观点