├── tests ├── chain │ ├── .gitignore │ ├── hello.lua │ ├── test1.lua │ ├── test2.lua │ └── test.lua ├── keyBag │ └── keyBag.go └── wallet │ └── wallet_api.go ├── .gitignore ├── operations ├── assetsettlecanceloperation.go ├── crontabcanceloperation.go ├── crontabcreateoperation.go ├── crontabrecoveroperation.go ├── registernhassetcreatoroperation.go ├── temporaryauthoritychangeoperation.go ├── committeemembercreateoperation.go ├── assetsettleoperation.go ├── assetreserveoperation.go ├── limitordercanceloperation.go ├── witnesscreateoperation.go ├── vestingbalancewithdrawoperation.go ├── executebidoperation.go ├── deletenhassetoperation.go ├── assetpublishfeedoperation.go ├── vestingbalancecreateoperation.go ├── assetglobalsettleoperation.go ├── createworldviewoperation.go ├── bidcolatteraloperation.go ├── callorderupdateoperation.go ├── proposaldeleteoperation.go ├── transfernhassetoperation.go ├── assetupdatebitassetoperation.go ├── assetupdatefeedproduceroperation.go ├── relateworldviewoperation.go ├── balanceclaimoperation.go ├── cancelnhassetorderoperation.go ├── committeememberupdateoperation.go ├── createfileoperation.go ├── filesignatureoperation.go ├── relateparentfileoperation.go ├── assetclaimfeesoperation.go ├── updatecollateralforgasoperation.go ├── fillorderoperation.go ├── witnessupdateoperation.go ├── accountupgradeoperation.go ├── revisecontractoperation.go ├── workercreateoperation.go ├── accountauthenticationoperation.go ├── addfilerelateaccountoperation.go ├── contractcreateoperation.go ├── createnhassetoperation.go ├── assetissueoperation.go ├── callcontractfunctionoperation.go ├── assetupdateoperation.go ├── createnhassetorderoperation.go ├── transferoperation.go └── assetupdaterestrictedoperation.go ├── types ├── instance.go ├── signature_ffjson.go ├── extensions_ffjson.go ├── contractbincode.go ├── balance.go ├── markettrade.go ├── volume24.go ├── vestingbalance.go ├── broadcastresponse.go ├── callorder.go ├── objectid_test.go ├── orderbook.go ├── forcesettlementorder.go ├── limitorder.go ├── accountbalance.go ├── marketticker.go ├── address_test.go ├── file.go ├── chainproperty.go ├── info.go ├── asset.go ├── signature.go ├── operationfee.go ├── types_test.go ├── accountstatistics.go ├── accountoptions.go ├── operationhistory.go ├── price.go ├── nhasset.go ├── contract.go ├── pricefeed.go ├── spacetype_string.go ├── block.go ├── assettype_string.go ├── assetamount.go ├── callorderupdateextensions.go ├── extensions.go ├── transaction.go ├── signature_test.go ├── account.go ├── assetfeed.go ├── network.go ├── publickey_test.go ├── committeemember.go ├── assetoptions.go ├── assetpermission_string.go ├── fullaccount.go ├── dynamicglobalproperties.go ├── gen_fileid.go ├── gen_assetid.go ├── gen_customid.go ├── gen_workerid.go ├── gen_accountid.go ├── gen_balanceid.go ├── gen_nhassetid.go ├── gen_witnessid.go ├── gen_contractid.go ├── gen_proposalid.go ├── bitassetdata.go ├── gen_callorderid.go ├── gen_limitorderid.go ├── gen_transactionid.go ├── gen_blocksummaryid.go ├── gen_budgetrecordid.go ├── gen_nhassetorderid.go ├── gen_chainpropertyid.go └── gen_accountbalanceid.go ├── gen ├── samples │ ├── meta.go │ ├── customoperation.go │ ├── transferoperation.go │ ├── fillorderoperation.go │ ├── assetissueoperation.go │ ├── assetcreateoperation.go │ ├── assetsettleoperation.go │ ├── assetupdateoperation.go │ ├── assetreserveoperation.go │ ├── balanceclaimoperation.go │ ├── workercreateoperation.go │ ├── accountcreateoperation.go │ ├── accountupdateoperation.go │ ├── bidcollateraloperation.go │ ├── witnesscreateoperation.go │ ├── witnessupdateoperation.go │ ├── accountupgradeoperation.go │ ├── assetclaimfeesoperation.go │ ├── proposalcreateoperation.go │ ├── proposaldeleteoperation.go │ ├── proposalupdateoperation.go │ ├── callorderupdateoperation.go │ ├── accountwhitelistoperation.go │ ├── assetfundfeepooloperation.go │ ├── assetpublishfeedoperation.go │ ├── limitordercanceloperation.go │ ├── limitordercreateoperation.go │ ├── overridetransferoperation.go │ ├── assetglobalsettleoperation.go │ ├── assetupdatebitassetoperation.go │ ├── vestingbalancecreateoperation.go │ ├── committeemembercreateoperation.go │ ├── vestingbalancewithdrawoperation.go │ └── assetupdatefeedproducersoperation.go ├── README.md ├── templates │ ├── meta.go.tmpl │ ├── opsampledata.go.tmpl │ ├── opsamplemain.go.tmpl │ └── objectid.go.tmpl └── data │ └── data.go ├── util ├── binary.go └── stringbuilder.go ├── crypto └── helper.go ├── .vscode └── settings.json ├── LICENSE ├── memobuilder.go ├── config └── chaincconfig.go ├── api └── rpcclient.go └── go.mod /tests/chain/.gitignore: -------------------------------------------------------------------------------- 1 | /chain 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | ffjson-* 3 | bot 4 | gen/debug 5 | debug.test -------------------------------------------------------------------------------- /operations/assetsettlecanceloperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /operations/crontabcanceloperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /operations/crontabcreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /operations/crontabrecoveroperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /operations/registernhassetcreatoroperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /operations/temporaryauthoritychangeoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | -------------------------------------------------------------------------------- /tests/chain/hello.lua: -------------------------------------------------------------------------------- 1 | function hello() 2 | chainhelper:log('create contract test') 3 | end -------------------------------------------------------------------------------- /types/instance.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | var ( 4 | CoreAsset = NewAssetID("1.3.0") 5 | GasAsset = NewAssetID("1.3.1") 6 | ) 7 | -------------------------------------------------------------------------------- /tests/chain/test1.lua: -------------------------------------------------------------------------------- 1 | function param() 2 | str = "20 < 30 is True. test str" 3 | chainhelper:log("no param test. str:"..str) 4 | end -------------------------------------------------------------------------------- /gen/samples/meta.go: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | //keep this file to avoid "no *.go files in samples directory" error 4 | 5 | var ( 6 | LastScannedBlock uint64 = 11383458 7 | ) 8 | -------------------------------------------------------------------------------- /types/signature_ffjson.go: -------------------------------------------------------------------------------- 1 | // Code generated by ffjson . DO NOT EDIT. 2 | // source: signature.go 3 | 4 | package types 5 | 6 | import () 7 | -------------------------------------------------------------------------------- /types/extensions_ffjson.go: -------------------------------------------------------------------------------- 1 | // Code generated by ffjson . DO NOT EDIT. 2 | // source: extensions.go 3 | 4 | package types 5 | 6 | import () 7 | -------------------------------------------------------------------------------- /gen/README.md: -------------------------------------------------------------------------------- 1 | ## gen 2 | 3 | Helper service to create operation samples for lib testing. 4 | 5 | ## run 6 | 7 | ``` 8 | make opsamples 9 | ``` 10 | from library package root. -------------------------------------------------------------------------------- /gen/templates/meta.go.tmpl: -------------------------------------------------------------------------------- 1 | package samples 2 | 3 | //keep this file to avoid "no *.go files in samples directory" error 4 | 5 | var( 6 | LastScannedBlock uint64 = {{.LastScannedBlock}} 7 | ) -------------------------------------------------------------------------------- /util/binary.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | // byte -- 8 bits 4 | func PutUvarintByByte(buf []byte, x uint64) int { 5 | i := 0 6 | for x > 0xff { 7 | buf[i] = byte(x) 8 | x >>= 8 9 | i++ 10 | } 11 | buf[i] = byte(x) 12 | return i + 1 13 | } 14 | -------------------------------------------------------------------------------- /types/contractbincode.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type ContractBinCode struct { 6 | ID ContractBinCodeID `json:"id"` 7 | ContractID ContractID `json:"contract_id"` 8 | LuaCodeB CharListType `json:"lua_code_b"` 9 | } 10 | -------------------------------------------------------------------------------- /gen/templates/opsampledata.go.tmpl: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for {{.SampleDataOpType}} 3 | 4 | package samples 5 | 6 | func init(){ 7 | 8 | {{.SampleDataVarName}}[{{.SampleDataIdx}}] = {{.SampleData}} 9 | 10 | } 11 | 12 | //end of file 13 | -------------------------------------------------------------------------------- /types/balance.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Balance struct { 6 | ID BalanceID `json:"id"` 7 | Balance AssetAmount `json:"balance"` 8 | LastClaimDate Time `json:"last_claim_date"` 9 | Owner Address `json:"owner"` 10 | } 11 | -------------------------------------------------------------------------------- /types/markettrade.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type MarketTrades []MarketTrade 6 | 7 | type MarketTrade struct { 8 | DateTime Time `json:"date"` 9 | Price Float64 `json:"price"` 10 | Amount Float64 `json:"amount"` 11 | Value Float64 `json:"value"` 12 | } 13 | -------------------------------------------------------------------------------- /types/volume24.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Volume24 struct { 6 | Base String `json:"base"` 7 | BaseVolume Float64 `json:"base_volume"` 8 | Quote String `json:"quote"` 9 | QuoteVolume Float64 `json:"quote_volume"` 10 | Time Time `json:"time"` 11 | } 12 | -------------------------------------------------------------------------------- /types/vestingbalance.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type VestingBalances []VestingBalance 6 | 7 | type VestingBalance struct { 8 | ID VestingBalanceID `json:"id"` 9 | Balance AssetAmount `json:"balance"` 10 | Owner AccountID `json:"owner"` 11 | Policy VestingPolicy `json:"policy"` 12 | } 13 | -------------------------------------------------------------------------------- /types/broadcastresponse.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type BroadcastResponse struct { 6 | ID string `json:"id"` 7 | BlockNum UInt64 `json:"block_num"` 8 | TrxNum UInt32 `json:"trx_num"` 9 | Expired bool `json:"expired"` 10 | Trx SignedTransaction `json:"trx"` 11 | } 12 | -------------------------------------------------------------------------------- /types/callorder.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type CallOrders []CallOrder 6 | type CallOrder struct { 7 | ID CallOrderID `json:"id"` 8 | Borrower AccountID `json:"borrower"` 9 | Collateral Int64 `json:"collateral"` 10 | Debt Int64 `json:"debt"` 11 | CallPrice Price `json:"call_price"` 12 | } 13 | -------------------------------------------------------------------------------- /types/objectid_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func Test_ObjectID(t *testing.T) { 10 | id := NewObjectID("1.5.29874") 11 | assert.Equal(t, id.SpaceType(), SpaceTypeProtocol) 12 | assert.Equal(t, id.ObjectType(), ObjectTypeCommitteeMember) 13 | assert.Equal(t, id.Instance(), UInt64(29874)) 14 | } 15 | -------------------------------------------------------------------------------- /types/orderbook.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Order struct { 6 | Base Float64 `json:"base"` 7 | Quote Float64 `json:"quote"` 8 | Price Float64 `json:"price"` 9 | } 10 | 11 | type OrderBook struct { 12 | Base AssetID `json:"base"` 13 | Asks []Order `json:"asks"` 14 | Quote AssetID `json:"quote"` 15 | Bids []Order `json:"bids"` 16 | } 17 | -------------------------------------------------------------------------------- /types/forcesettlementorder.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type ForceSettlementOrders []ForceSettlementOrder 6 | 7 | type ForceSettlementOrder struct { 8 | ID ForceSettlementID `json:"id"` 9 | Owner AccountID `json:"owner"` 10 | SettlementDate Time `json:"settlement_date"` 11 | Balance AssetAmount `json:"balance"` 12 | } 13 | -------------------------------------------------------------------------------- /types/limitorder.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type LimitOrders []LimitOrder 6 | 7 | type LimitOrder struct { 8 | ID LimitOrderID `json:"id"` 9 | Seller AccountID `json:"seller"` 10 | Expiration Time `json:"expiration"` 11 | ForSale UInt64 `json:"for_sale"` 12 | DeferredFee UInt64 `json:"deferred_fee"` 13 | SellPrice Price `json:"sell_price"` 14 | } 15 | -------------------------------------------------------------------------------- /types/accountbalance.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type AccountBalances []AccountBalance 6 | 7 | type AccountBalance struct { 8 | ID AccountBalanceID `json:"id"` 9 | Owner AccountID `json:"owner"` 10 | AssetType AssetID `json:"asset_type"` 11 | Balance UInt64 `json:"balance"` 12 | MaintenanceFlag bool `json:"maintenance_flag"` 13 | } 14 | -------------------------------------------------------------------------------- /gen/samples/customoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeCustom 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataCustomOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeCustom] = 17 | sampleDataCustomOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /types/marketticker.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type MarketTicker struct { 4 | Time Time `json:"time"` 5 | Base String `json:"base"` 6 | Quote String `json:"quote"` 7 | Latest Float64 `json:"latest"` 8 | LowestAsk Float64 `json:"lowest_ask"` 9 | HighestBid Float64 `json:"highest_bid"` 10 | PercentChange Float64 `json:"percent_change"` 11 | BaseVolume Float64 `json:"base_volume"` 12 | QuoteVolume Float64 `json:"quote_volume"` 13 | } 14 | -------------------------------------------------------------------------------- /gen/samples/transferoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeTransfer 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataTransferOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeTransfer] = 17 | sampleDataTransferOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/templates/opsamplemain.go.tmpl: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for {{.SampleDataOpType}} 3 | 4 | package samples 5 | 6 | import( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var( 12 | {{.SampleDataVarName}} = make(map[int]string) 13 | ) 14 | 15 | func init(){ 16 | data.OpSampleMap[types.{{.SampleDataOpType}}] = 17 | {{.SampleDataVarName}} 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/fillorderoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeFillOrder 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataFillOrderOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeFillOrder] = 17 | sampleDataFillOrderOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetissueoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetIssue 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetIssueOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetIssue] = 17 | sampleDataAssetIssueOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetcreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetCreate] = 17 | sampleDataAssetCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetsettleoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetSettle 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetSettleOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetSettle] = 17 | sampleDataAssetSettleOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetupdateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetUpdate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetUpdateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetUpdate] = 17 | sampleDataAssetUpdateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetreserveoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetReserve 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetReserveOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetReserve] = 17 | sampleDataAssetReserveOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/balanceclaimoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeBalanceClaim 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataBalanceClaimOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeBalanceClaim] = 17 | sampleDataBalanceClaimOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/workercreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeWorkerCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataWorkerCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeWorkerCreate] = 17 | sampleDataWorkerCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/accountcreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAccountCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAccountCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAccountCreate] = 17 | sampleDataAccountCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/accountupdateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAccountUpdate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAccountUpdateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAccountUpdate] = 17 | sampleDataAccountUpdateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/bidcollateraloperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeBidCollateral 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataBidCollateralOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeBidCollateral] = 17 | sampleDataBidCollateralOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/witnesscreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeWitnessCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataWitnessCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeWitnessCreate] = 17 | sampleDataWitnessCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/witnessupdateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeWitnessUpdate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataWitnessUpdateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeWitnessUpdate] = 17 | sampleDataWitnessUpdateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/accountupgradeoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAccountUpgrade 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAccountUpgradeOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAccountUpgrade] = 17 | sampleDataAccountUpgradeOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetclaimfeesoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetClaimFees 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetClaimFeesOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetClaimFees] = 17 | sampleDataAssetClaimFeesOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/proposalcreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeProposalCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataProposalCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeProposalCreate] = 17 | sampleDataProposalCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/proposaldeleteoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeProposalDelete 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataProposalDeleteOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeProposalDelete] = 17 | sampleDataProposalDeleteOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/proposalupdateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeProposalUpdate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataProposalUpdateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeProposalUpdate] = 17 | sampleDataProposalUpdateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/callorderupdateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeCallOrderUpdate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataCallOrderUpdateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeCallOrderUpdate] = 17 | sampleDataCallOrderUpdateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/accountwhitelistoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAccountWhitelist 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAccountWhitelistOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAccountWhitelist] = 17 | sampleDataAccountWhitelistOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetfundfeepooloperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetFundFeePool 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetFundFeePoolOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetFundFeePool] = 17 | sampleDataAssetFundFeePoolOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetpublishfeedoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetPublishFeed 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetPublishFeedOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetPublishFeed] = 17 | sampleDataAssetPublishFeedOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/limitordercanceloperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeLimitOrderCancel 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataLimitOrderCancelOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeLimitOrderCancel] = 17 | sampleDataLimitOrderCancelOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/limitordercreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeLimitOrderCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataLimitOrderCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeLimitOrderCreate] = 17 | sampleDataLimitOrderCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/overridetransferoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeOverrideTransfer 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataOverrideTransferOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeOverrideTransfer] = 17 | sampleDataOverrideTransferOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetglobalsettleoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetGlobalSettle 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetGlobalSettleOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetGlobalSettle] = 17 | sampleDataAssetGlobalSettleOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetupdatebitassetoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetUpdateBitasset 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetUpdateBitassetOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetUpdateBitasset] = 17 | sampleDataAssetUpdateBitassetOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/vestingbalancecreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeVestingBalanceCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataVestingBalanceCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeVestingBalanceCreate] = 17 | sampleDataVestingBalanceCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/committeemembercreateoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeCommitteeMemberCreate 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataCommitteeMemberCreateOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeCommitteeMemberCreate] = 17 | sampleDataCommitteeMemberCreateOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/vestingbalancewithdrawoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeVestingBalanceWithdraw 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataVestingBalanceWithdrawOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeVestingBalanceWithdraw] = 17 | sampleDataVestingBalanceWithdrawOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /gen/samples/assetupdatefeedproducersoperation.go: -------------------------------------------------------------------------------- 1 | //This file is generated by btsgen. DO NOT EDIT. 2 | //operation sample data for OperationTypeAssetUpdateFeedProducers 3 | 4 | package samples 5 | 6 | import ( 7 | "github.com/Cocos-BCX/cocos-go/gen/data" 8 | "github.com/Cocos-BCX/cocos-go/types" 9 | ) 10 | 11 | var ( 12 | sampleDataAssetUpdateFeedProducersOperation = make(map[int]string) 13 | ) 14 | 15 | func init() { 16 | data.OpSampleMap[types.OperationTypeAssetUpdateFeedProducers] = 17 | sampleDataAssetUpdateFeedProducersOperation 18 | } 19 | 20 | //end of file 21 | -------------------------------------------------------------------------------- /types/address_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/Cocos-BCX/cocos-go/config" 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | var addresses = []string{ 11 | "BTSFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi", 12 | } 13 | 14 | func TestAddress(t *testing.T) { 15 | config.SetCurrent(config.ChainIDBTS) 16 | 17 | for _, add := range addresses { 18 | address, err := NewAddressFromString(add) 19 | if err != nil { 20 | assert.FailNow(t, err.Error(), "NewAddressFromString") 21 | } 22 | 23 | assert.Equal(t, add, address.String()) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /types/file.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type File struct { 6 | ID FileID `json:"id"` 7 | FileName String `json:"file_name"` 8 | FileOwner AccountID `json:"file_owner"` 9 | CreateTime Time `json:"create_time"` 10 | FileContent string `json:"file_content"` 11 | RelatedAccount AccountIDArray `json:"related_account"` 12 | Signature SignaturesType `json:"signature"` 13 | ParentFile *FileID `json:"parent_file"` 14 | SubFile FileIDArray `json:"sub_file"` 15 | } 16 | 17 | -------------------------------------------------------------------------------- /types/chainproperty.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type ImmutableChainParametersType struct { 6 | MinCommitteeMemberCount UInt16 `json:"min_committee_member_count"` 7 | MinWitnessCount UInt16 `json:"min_witness_count"` 8 | } 9 | 10 | type ChainProperty struct { 11 | ID ChainPropertyID `json:"id"` 12 | ChainID string `json:"chain_id"` 13 | ImmutableParameters ImmutableChainParametersType `json:"immutable_parameters"` 14 | BaseContract string `json:"base_contract"` 15 | } 16 | -------------------------------------------------------------------------------- /types/info.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type Info struct { 4 | ActiveCommitteeMembers CommitteeMemberIDs `json:"active_committee_members"` 5 | ActiveWitnesses WitnessIDs `json:"active_witnesses"` 6 | ChainID string `json:"chain_id"` 7 | HeadBlockAge Time `json:"head_block_age"` 8 | HeadBlockID string `json:"head_block_id"` 9 | HeadBlockNum UInt32 `json:"head_block_num"` 10 | NextMaintenanceTime Time `json:"next_maintenance_time"` 11 | Participation string `json:"participation"` 12 | } 13 | -------------------------------------------------------------------------------- /types/asset.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Assets []Asset 6 | 7 | type Asset struct { 8 | ID AssetID `json:"id"` 9 | Symbol String `json:"symbol"` 10 | Precision int `json:"precision"` 11 | Issuer AccountID `json:"issuer"` 12 | Options AssetOptions `json:"options"` 13 | DynamicAssetDataID AssetDynamicDataID `json:"dynamic_asset_data_id"` 14 | BitassetDataID AssetBitAssetDataID `json:"bitasset_data_id"` 15 | BuybackAccount AccountID `json:"buyback_account"` 16 | } 17 | -------------------------------------------------------------------------------- /types/signature.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | 10 | type Signatures []Buffer 11 | 12 | func (p Signatures) Marshal(enc *util.TypeEncoder) error { 13 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 14 | return errors.Annotate(err, "encode length") 15 | } 16 | 17 | for _, sig := range p { 18 | if err := enc.Encode(sig.Bytes()); err != nil { 19 | return errors.Annotate(err, "encode Signature") 20 | } 21 | } 22 | 23 | return nil 24 | } 25 | 26 | func (p *Signatures) Reset() { 27 | *p = []Buffer{} 28 | } 29 | -------------------------------------------------------------------------------- /types/operationfee.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | type OperationFee struct { 9 | Fee *AssetAmount `json:"fee,omitempty"` 10 | } 11 | 12 | func (p OperationFee) GetFee() AssetAmount { 13 | return *p.Fee 14 | } 15 | 16 | func (p *OperationFee) SetFee(fee AssetAmount) { 17 | p.Fee = &fee 18 | } 19 | 20 | func (p *OperationFee) MarshalFeeScheduleParams(params M, enc *util.TypeEncoder) error { 21 | if fee, ok := params["fee"]; ok { 22 | if err := enc.Encode(UInt64(fee.(float64))); err != nil { 23 | return errors.Annotate(err, "encode Fee") 24 | } 25 | } 26 | 27 | return nil 28 | } 29 | -------------------------------------------------------------------------------- /types/types_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "bytes" 5 | "testing" 6 | 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | func TestBuffer_MarshalUnmarshal(t *testing.T) { 12 | 13 | b1 := Buffer("TestMarshalUnmarshal") 14 | 15 | var buf bytes.Buffer 16 | enc := util.NewTypeEncoder(&buf) 17 | 18 | if err := b1.Marshal(enc); err != nil { 19 | assert.FailNow(t, err.Error(), "Marshal") 20 | } 21 | 22 | dec := util.NewTypeDecoder(&buf) 23 | var b2 Buffer 24 | if err := b2.Unmarshal(dec); err != nil { 25 | assert.FailNow(t, err.Error(), "Unmarshal") 26 | } 27 | 28 | assert.Equal(t, b1.Bytes(), b2.Bytes()) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /util/stringbuilder.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "bytes" 5 | "strings" 6 | "text/template" 7 | ) 8 | 9 | type StringBuilder []string 10 | 11 | func (sb *StringBuilder) Append(s string) { 12 | *sb = append(*sb, s) 13 | } 14 | 15 | func (sb *StringBuilder) Join(s *StringBuilder) { 16 | *sb = append(*sb, *s...) 17 | } 18 | 19 | func (sb *StringBuilder) String() string { 20 | return strings.Join(*sb, "") 21 | } 22 | 23 | func (sb *StringBuilder) AddTemplate(t *template.Template, name string, data interface{}) error { 24 | buf := &bytes.Buffer{} 25 | err := t.ExecuteTemplate(buf, name, data) 26 | if err != nil { 27 | return err 28 | } 29 | sb.Append(buf.String()) 30 | return nil 31 | } 32 | -------------------------------------------------------------------------------- /gen/data/data.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/types" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | type OperationSampleMap map[types.OperationType]map[int]string 9 | 10 | var ( 11 | OpSampleMap OperationSampleMap 12 | ErrNoSampleDataAvailable = errors.New("no sample data available") 13 | ) 14 | 15 | func init() { 16 | OpSampleMap = make(OperationSampleMap) 17 | } 18 | 19 | //GetSampleByType returns a Operation data sample by OperationID 20 | func GetSamplesByType(typ types.OperationType) (map[int]string, error) { 21 | ret := make(map[int]string) 22 | if s, ok := OpSampleMap[typ]; ok { 23 | return s, nil 24 | } 25 | 26 | return ret, ErrNoSampleDataAvailable 27 | } 28 | -------------------------------------------------------------------------------- /types/accountstatistics.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type AccountStatistics struct { 6 | ID AccountStatisticsID `json:"id"` 7 | MostRecentOp AccountTransactionHistoryID `json:"most_recent_op"` 8 | Owner AccountID `json:"owner"` 9 | LifetimeFeesPaid UInt64 `json:"lifetime_fees_paid"` 10 | PendingFees UInt64 `json:"pending_fees"` 11 | PendingVestedFees UInt64 `json:"pending_vested_fees"` 12 | RemovedOps UInt64 `json:"removed_ops"` 13 | TotalOps UInt64 `json:"total_ops"` 14 | TotalCoreInOrders UInt64 `json:"total_core_in_orders"` 15 | } 16 | -------------------------------------------------------------------------------- /types/accountoptions.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/util" 7 | "github.com/juju/errors" 8 | ) 9 | 10 | type AccountOptions struct { 11 | MemoKey PublicKey `json:"memo_key"` 12 | Votes Votes `json:"votes"` 13 | Extensions Extensions `json:"extensions"` 14 | } 15 | 16 | func (p AccountOptions) Marshal(enc *util.TypeEncoder) error { 17 | if err := enc.Encode(p.MemoKey); err != nil { 18 | return errors.Annotate(err, "encode MemoKey") 19 | } 20 | 21 | if err := enc.Encode(p.Votes); err != nil { 22 | return errors.Annotate(err, "encode Votes") 23 | } 24 | 25 | if err := enc.Encode(p.Extensions); err != nil { 26 | return errors.Annotate(err, "encode Extensions") 27 | } 28 | 29 | return nil 30 | } 31 | -------------------------------------------------------------------------------- /types/operationhistory.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type OperationHistories []OperationHistory 6 | type OperationRelativeHistories []OperationRelativeHistory 7 | 8 | type OperationHistory struct { 9 | ID OperationHistoryID `json:"id"` 10 | BlockNum UInt32 `json:"block_num"` 11 | TrxInBlock UInt16 `json:"trx_in_block"` 12 | OpInTrx UInt16 `json:"op_in_trx"` 13 | VirtualOp UInt16 `json:"virtual_op"` 14 | Operation OperationEnvelope `json:"op"` 15 | Result OperationResult `json:"result"` 16 | } 17 | 18 | type OperationRelativeHistory struct { 19 | Memo Buffer `json:"memo"` 20 | Description String `json:"description"` 21 | Op OperationHistory `json:"op"` 22 | } 23 | -------------------------------------------------------------------------------- /types/price.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/util" 7 | "github.com/juju/errors" 8 | ) 9 | 10 | type Price struct { 11 | Base AssetAmount `json:"base"` 12 | Quote AssetAmount `json:"quote"` 13 | } 14 | 15 | func (p Price) Rate(precBase, precQuote float64) Rate { 16 | return Rate(p.Base.Rate(precBase) / p.Quote.Rate(precQuote)) 17 | } 18 | 19 | func (p Price) Valid() bool { 20 | return p.Base.Valid() && p.Quote.Valid() 21 | } 22 | 23 | func (p Price) Marshal(enc *util.TypeEncoder) error { 24 | if err := enc.Encode(p.Base); err != nil { 25 | return errors.Annotate(err, "encode Base") 26 | } 27 | if err := enc.Encode(p.Quote); err != nil { 28 | return errors.Annotate(err, "encode Quote") 29 | } 30 | 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /types/nhasset.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type NHAsset struct { 6 | ID NHAssetID `json:"id"` 7 | NhAssetCreator AccountID `json:"nh_asset_creator"` 8 | NhAssetOwner AccountID `json:"nh_asset_owner"` 9 | NhAssetActive AccountID `json:"nh_asset_active"` 10 | Dealership AccountID `json:"dealership"` 11 | AssetQualifier string `json:"asset_qualifier"` 12 | WorldView string `json:"world_view"` 13 | BaseDescribe string `json:"base_describe"` 14 | Parent NHAssetMapType `json:"parent"` 15 | Child NHAssetMapType `json:"child"` 16 | CreateTime Time `json:"create_time"` 17 | LimitList ContractIDListType `json:"limit_list"` 18 | } 19 | -------------------------------------------------------------------------------- /types/contract.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Contract struct { 6 | ID ContractID `json:"id"` 7 | CreationDate Time `json:"creation_date"` 8 | Owner AccountID `json:"owner"` 9 | Name string `json:"name"` 10 | UserInvokeSharePercent uint32 `json:"user_invoke_share_percent"` 11 | IsRelease bool `json:"is_release"` 12 | CurrentVersion string `json:"current_version"` 13 | CheckContractAuthority bool `json:"check_contract_authority"` 14 | ContractAuthority PublicKey `json:"contract_authority"` 15 | ContractData LuaMap `json:"contract_data"` 16 | ContractABI LuaMap `json:"contract_ABI"` 17 | LuaCodeBID ContractBinCodeID `json:"lua_code_b_id"` 18 | } 19 | -------------------------------------------------------------------------------- /types/pricefeed.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | 10 | type PriceFeed struct { 11 | SettlementPrice Price `json:"settlement_price"` 12 | MaintenanceCollateralRatio UInt16 `json:"maintenance_collateral_ratio"` 13 | MaximumShortSqueezeRatio UInt16 `json:"maximum_short_squeeze_ratio"` 14 | } 15 | 16 | func (p PriceFeed) Marshal(enc *util.TypeEncoder) error { 17 | if err := enc.Encode(p.SettlementPrice); err != nil { 18 | return errors.Annotate(err, "encode SettlementPrice") 19 | } 20 | 21 | if err := enc.Encode(p.MaintenanceCollateralRatio); err != nil { 22 | return errors.Annotate(err, "encode MaintenanceCollateralRatio") 23 | } 24 | 25 | if err := enc.Encode(p.MaximumShortSqueezeRatio); err != nil { 26 | return errors.Annotate(err, "encode MaximumShortSqueezeRatio") 27 | } 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /tests/chain/test2.lua: -------------------------------------------------------------------------------- 1 | function param1(str) 2 | chainhelper:log("param1 test. str:"..str) 3 | end 4 | 5 | function param2(str, flag) 6 | if (flag) 7 | then 8 | chainhelper:log("param2 test. flag true. str:"..str) 9 | else 10 | chainhelper:log("param2 test. flag false. str:"..str) 11 | end 12 | end 13 | 14 | function param3(in_str, in_bool, in_num) 15 | chainhelper:log("test param3, in_str: " .. tostring(in_str) .. ", type: " .. type(in_str)) 16 | chainhelper:log("test param3, in_bool: " .. tostring(in_bool) .. ", type: " .. type(in_bool)) 17 | chainhelper:log("test param3, in_num: " .. tostring(in_num) .. ", type: " .. type(in_num)) 18 | end 19 | 20 | 21 | function test_luatype_function(func) 22 | chainhelper:log("test luatype_function, func: " .. tostring(func) .. ", type: " .. type(func)) 23 | end 24 | 25 | function test_luatype(obj) 26 | chainhelper:log("test luatype, object: " .. tostring(obj) .. ", type: " .. type(obj)) 27 | end 28 | 29 | -------------------------------------------------------------------------------- /crypto/helper.go: -------------------------------------------------------------------------------- 1 | package crypto 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/config" 5 | "github.com/Cocos-BCX/cocos-go/types" 6 | "github.com/juju/errors" 7 | ) 8 | 9 | //SignWithKeys signs a given transaction with given private keys. 10 | func SignWithKeys(keys types.PrivateKeys, tx *types.SignedTransaction) error { 11 | signer := NewTransactionSigner(tx) 12 | if err := signer.Sign(keys, config.Current()); err != nil { 13 | return errors.Annotate(err, "Sign") 14 | } 15 | 16 | return nil 17 | } 18 | 19 | //VerifySignedTransaction verifies a signed transaction against all available keys in keyBag. 20 | //If all required keys are found the function returns true, otherwise false. 21 | func VerifySignedTransaction(keyBag *KeyBag, tx *types.SignedTransaction) (bool, error) { 22 | signer := NewTransactionSigner(tx) 23 | verified, err := signer.Verify(keyBag, config.Current()) 24 | if err != nil { 25 | return false, errors.Annotate(err, "Verify") 26 | } 27 | 28 | return verified, nil 29 | } 30 | -------------------------------------------------------------------------------- /types/spacetype_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=SpaceType"; DO NOT EDIT. 2 | 3 | package types 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[SpaceTypeRelativeProtocol-0] 12 | _ = x[SpaceTypeProtocol-1] 13 | _ = x[SpaceTypeImplementation-2] 14 | _ = x[SpaceTypeExtension-3] 15 | _ = x[SpaceTypeNHAssetProtocol-4] 16 | _ = x[SpaceTypeMarketHistory-5] 17 | } 18 | 19 | const _SpaceType_name = "SpaceTypeRelativeProtocolSpaceTypeProtocolSpaceTypeImplementationSpaceTypeExtensionSpaceTypeNHAssetProtocolSpaceTypeMarketHistory" 20 | 21 | var _SpaceType_index = [...]uint8{0, 25, 42, 65, 83, 107, 129} 22 | 23 | func (i SpaceType) String() string { 24 | if i >= SpaceType(len(_SpaceType_index)-1) { 25 | return "SpaceType(" + strconv.FormatInt(int64(i), 10) + ")" 26 | } 27 | return _SpaceType_name[_SpaceType_index[i]:_SpaceType_index[i+1]] 28 | } 29 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // Controls the font size in pixels. 3 | "editor.fontSize": 18, 4 | "git.confirmSync": false, 5 | "git.autofetch": true, 6 | "git.enableSmartCommit": true, 7 | "explorer.confirmDragAndDrop": false, 8 | "explorer.confirmDelete": false, 9 | "gitlens.advanced.messages": { 10 | "suppressCommitHasNoPreviousCommitWarning": false, 11 | "suppressCommitNotFoundWarning": false, 12 | "suppressFileNotUnderSourceControlWarning": false, 13 | "suppressGitVersionWarning": false, 14 | "suppressLineUncommittedWarning": false, 15 | "suppressNoRepositoryWarning": false, 16 | "suppressResultsExplorerNotice": false, 17 | "suppressShowKeyBindingsNotice": true 18 | }, 19 | 20 | "gitlens.historyExplorer.enabled": true, 21 | "go.testTimeout": "3m", 22 | "go.buildFlags": [ 23 | "-v" 24 | ], 25 | "go.enableCodeLens": { 26 | "references": false, 27 | "runtest": true 28 | }, 29 | "go.testEnvVars": { 30 | "GO111MODULE": "on" 31 | }, 32 | "go.inferGopath": false, 33 | 34 | } -------------------------------------------------------------------------------- /types/block.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type BlockHeader struct { 6 | Previous Buffer `json:"previous"` 7 | TimeStamp Time `json:"timestamp"` 8 | Witness WitnessID `json:"witness"` 9 | TransactionMerkleRoot Buffer `json:"transaction_merkle_root"` 10 | Extensions Extensions `json:"extensions"` 11 | } 12 | 13 | type Block struct { 14 | Previous Buffer `json:"previous"` 15 | TimeStamp Time `json:"timestamp"` 16 | Witness WitnessID `json:"witness"` 17 | TransactionMerkleRoot Buffer `json:"transaction_merkle_root"` 18 | WitnessSignature Buffer `json:"witness_signature"` 19 | BlockID Buffer `json:"block_id"` 20 | Transactions SignedTransactionsWithTrxID `json:"transactions"` 21 | Extensions Extensions `json:"extensions"` 22 | } 23 | -------------------------------------------------------------------------------- /types/assettype_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=AssetType"; DO NOT EDIT. 2 | 3 | package types 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[AssetTypeUndefined - -1] 12 | _ = x[AssetTypeCoreAsset-1] 13 | _ = x[AssetTypeUIA-2] 14 | _ = x[AssetTypeSmartCoin-3] 15 | _ = x[AssetTypePredictionMarket-4] 16 | } 17 | 18 | const ( 19 | _AssetType_name_0 = "AssetTypeUndefined" 20 | _AssetType_name_1 = "AssetTypeCoreAssetAssetTypeUIAAssetTypeSmartCoinAssetTypePredictionMarket" 21 | ) 22 | 23 | var ( 24 | _AssetType_index_1 = [...]uint8{0, 18, 30, 48, 73} 25 | ) 26 | 27 | func (i AssetType) String() string { 28 | switch { 29 | case i == -1: 30 | return _AssetType_name_0 31 | case 1 <= i && i <= 4: 32 | i -= 1 33 | return _AssetType_name_1[_AssetType_index_1[i]:_AssetType_index_1[i+1]] 34 | default: 35 | return "AssetType(" + strconv.FormatInt(int64(i), 10) + ")" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 denkhaus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/keyBag/keyBag.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | "github.com/Cocos-BCX/cocos-go/config" 8 | "github.com/Cocos-BCX/cocos-go/crypto" 9 | "github.com/Cocos-BCX/cocos-go/types" 10 | ) 11 | 12 | func main() { 13 | config.SetCurrent(config.ChainIDBCXTest) 14 | 15 | // testAccount := "nicotest" 16 | privateKey := "5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo" 17 | publicKey := "COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx" 18 | 19 | // key bag 测试 20 | log.Println("------- key bag test ----------") 21 | localKeyBag := crypto.NewKeyBag() 22 | err := localKeyBag.Add(privateKey) 23 | if err != nil { 24 | log.Println(err) 25 | return 26 | } 27 | 28 | publics := localKeyBag.Publics() 29 | fmt.Printf("publics: %v %v\n", publics, publicKey) 30 | 31 | privates := localKeyBag.Privates() 32 | fmt.Printf("privates: %v\n", privates) 33 | 34 | sPubKey, err := types.NewPublicKeyFromString(publicKey) 35 | if err != nil { 36 | fmt.Println(err) 37 | } else { 38 | fmt.Printf("sPubKey: %v\n", sPubKey.String()) 39 | // priKey := localKeyBag.PrivatesByPublics(sPubKey) 40 | // fmt.Printf("publicKey: %v, priKey: %v\n", publicKey, priKey) 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /types/assetamount.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "math" 7 | 8 | "github.com/Cocos-BCX/cocos-go/util" 9 | "github.com/juju/errors" 10 | ) 11 | 12 | type AssetAmounts []AssetAmount 13 | 14 | type AssetAmount struct { 15 | Amount Int64 `json:"amount"` 16 | Asset AssetID `json:"asset_id"` 17 | } 18 | 19 | func (p AssetAmount) Valid() bool { 20 | return p.Asset.Valid() && p.Amount != 0 21 | } 22 | 23 | func (p AssetAmount) Rate(prec float64) float64 { 24 | return float64(p.Amount) / math.Pow(10, prec) 25 | } 26 | 27 | func (p AssetAmount) Marshal(enc *util.TypeEncoder) error { 28 | if err := enc.Encode(p.Amount); err != nil { 29 | return errors.Annotate(err, "encode Amount") 30 | } 31 | 32 | if err := enc.Encode(p.Asset); err != nil { 33 | return errors.Annotate(err, "encode Asset") 34 | } 35 | 36 | return nil 37 | } 38 | 39 | func NewZeroCoreAsset() AssetAmount { 40 | return AssetAmount{ 41 | Amount: Int64(0), 42 | Asset: AssetIDFromObject(NewAssetID("1.3.0")), 43 | } 44 | } 45 | 46 | func NewAsset(amount int64, assetID string) AssetAmount { 47 | return AssetAmount{ 48 | Amount: Int64(amount), 49 | Asset: AssetIDFromObject(NewAssetID(assetID)), 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /types/callorderupdateextensions.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | 10 | type TargetCollRatio UInt16 11 | 12 | func (p TargetCollRatio) Marshal(enc *util.TypeEncoder) error { 13 | if err := enc.Encode(int8(CallOrderUpdateExtensionsTypeTargetRatio)); err != nil { 14 | return errors.Annotate(err, "encode type") 15 | } 16 | if err := enc.Encode(UInt16(p)); err != nil { 17 | return errors.Annotate(err, "encode value") 18 | } 19 | 20 | return nil 21 | } 22 | 23 | type CallOrderUpdateExtensions struct { 24 | TargetCollateralRatio *TargetCollRatio `json:"target_collateral_ratio,omitempty"` 25 | } 26 | 27 | func (p CallOrderUpdateExtensions) Length() int { 28 | fields := 0 29 | if p.TargetCollateralRatio != nil { 30 | fields++ 31 | } 32 | 33 | return fields 34 | } 35 | 36 | func (p CallOrderUpdateExtensions) Marshal(enc *util.TypeEncoder) error { 37 | if err := enc.EncodeUVarint(uint64(p.Length())); err != nil { 38 | return errors.Annotate(err, "encode length") 39 | } 40 | 41 | if p.TargetCollateralRatio != nil { 42 | if err := enc.Encode(p.TargetCollateralRatio); err != nil { 43 | return errors.Annotate(err, "encode TargetCollateralRatio") 44 | } 45 | } 46 | 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /types/extensions.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/pquerna/ffjson/ffjson" 7 | 8 | "github.com/Cocos-BCX/cocos-go/util" 9 | "github.com/juju/errors" 10 | ) 11 | 12 | type Extensions struct { 13 | ext interface{} 14 | } 15 | 16 | //TODO refactor and test 17 | func (p Extensions) Marshal(enc *util.TypeEncoder) error { 18 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 19 | return errors.Annotate(err, "encode length") 20 | } 21 | 22 | // for _, ex := range p { 23 | // if err := enc.Encode(ex); err != nil { 24 | // return errors.Annotate(err, "encode Extension") 25 | // } 26 | // } 27 | 28 | // if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 29 | // return errors.Annotate(err, "encode length") 30 | // } 31 | 32 | // for _, ex := range p { 33 | // if err := enc.Encode(ex); err != nil { 34 | // return errors.Annotate(err, "encode Extension") 35 | // } 36 | // } 37 | 38 | return nil 39 | } 40 | 41 | func (p Extensions) MarshalJSON() ([]byte, error) { 42 | if p.ext == nil { 43 | p.ext = make([]interface{}, 0) 44 | } 45 | 46 | return ffjson.Marshal(p.ext) 47 | } 48 | 49 | // UnmarshalJSON sets *m to a copy of data. 50 | func (p *Extensions) UnmarshalJSON(data []byte) error { 51 | return ffjson.Unmarshal(data, &p.ext) 52 | } 53 | -------------------------------------------------------------------------------- /operations/committeemembercreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCommitteeMemberCreate] = func() types.Operation { 13 | op := &CommitteeMemberCreateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CommitteeMemberCreateOperation struct { 19 | types.OperationFee 20 | CommitteeMemberAccount types.AccountID `json:"committee_member_account"` 21 | URL string `json:"url"` 22 | } 23 | 24 | func (p CommitteeMemberCreateOperation) Type() types.OperationType { 25 | return types.OperationTypeCommitteeMemberCreate 26 | } 27 | 28 | func (p CommitteeMemberCreateOperation) Marshal(enc *util.TypeEncoder) error { 29 | if err := enc.Encode(int8(p.Type())); err != nil { 30 | return errors.Annotate(err, "encode OperationType") 31 | } 32 | if err := enc.Encode(p.Fee); err != nil { 33 | return errors.Annotate(err, "encode Fee") 34 | } 35 | if err := enc.Encode(p.CommitteeMemberAccount); err != nil { 36 | return errors.Annotate(err, "encode CommitteeMemberAccount") 37 | } 38 | if err := enc.Encode(p.URL); err != nil { 39 | return errors.Annotate(err, "encode URL") 40 | } 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /types/transaction.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "time" 7 | 8 | "github.com/Cocos-BCX/cocos-go/util" 9 | "github.com/juju/errors" 10 | ) 11 | 12 | type Transaction struct { 13 | RefBlockNum UInt16 `json:"ref_block_num"` 14 | RefBlockPrefix UInt32 `json:"ref_block_prefix"` 15 | Expiration Time `json:"expiration"` 16 | Operations Operations `json:"operations"` 17 | Extensions Extensions `json:"extensions"` 18 | } 19 | 20 | func (p Transaction) Marshal(enc *util.TypeEncoder) error { 21 | if err := enc.Encode(p.RefBlockNum); err != nil { 22 | return errors.Annotate(err, "encode RefBlockNum") 23 | } 24 | 25 | if err := enc.Encode(p.RefBlockPrefix); err != nil { 26 | return errors.Annotate(err, "encode RefBlockPrefix") 27 | } 28 | 29 | if err := enc.Encode(p.Expiration); err != nil { 30 | return errors.Annotate(err, "encode Expiration") 31 | } 32 | 33 | if err := enc.Encode(p.Operations); err != nil { 34 | return errors.Annotate(err, "encode Operations") 35 | } 36 | 37 | if err := enc.Encode(p.Extensions); err != nil { 38 | return errors.Annotate(err, "encode Extension") 39 | } 40 | 41 | return nil 42 | } 43 | 44 | //AdjustExpiration extends expiration by given duration. 45 | func (p *Transaction) AdjustExpiration(dur time.Duration) { 46 | p.Expiration = p.Expiration.Add(dur) 47 | } 48 | -------------------------------------------------------------------------------- /types/signature_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/hex" 5 | "testing" 6 | 7 | "github.com/btcsuite/btcd/btcec" 8 | "github.com/Cocos-BCX/cocos-go/config" 9 | "github.com/stretchr/testify/assert" 10 | ) 11 | 12 | var ( 13 | digSig = [][]string{ 14 | { 15 | "aa2036ea32d635ef8094883a75a7aa7e9b7f034e0087c43c08872ccd344a486f", 16 | "1f49954c9f1df0a8d9f73833173eb40625036b4c718723772c4e3bfb687442637027b9f4aef10c282251fc2a3ad5f77deed5e369f2ac75903e3670818609a3f7ad", 17 | "TEST5Z3vsgH6xj6HLXcsU38yo4TyoZs9AUzpfbaXbuxsAYPbutWvEP", 18 | }, 19 | } 20 | ) 21 | 22 | func Test_SignatureVerify(t *testing.T) { 23 | config.SetCurrent(config.ChainIDTest) 24 | 25 | for _, ds := range digSig { 26 | digHex := ds[0] 27 | sigHex := ds[1] 28 | pub := ds[2] 29 | 30 | dig, err := hex.DecodeString(digHex) 31 | if err != nil { 32 | assert.FailNow(t, err.Error(), "DecodeString") 33 | } 34 | 35 | sig, err := hex.DecodeString(sigHex) 36 | if err != nil { 37 | assert.FailNow(t, err.Error(), "DecodeString") 38 | } 39 | 40 | p, _, err := btcec.RecoverCompact(btcec.S256(), sig, dig) 41 | if err != nil { 42 | assert.FailNow(t, err.Error(), "RecoverCompact") 43 | } 44 | 45 | pubKey, err := NewPublicKey(p) 46 | if err != nil { 47 | assert.FailNow(t, err.Error(), "NewPublicKey") 48 | } 49 | 50 | assert.Equal(t, pub, pubKey.String()) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/chain/test.lua: -------------------------------------------------------------------------------- 1 | COCOS_ACCURACY = 100000 2 | 3 | function init() 4 | assert(chainhelper:is_owner(),'no auth') 5 | read_list = {public_data={rate=true,max_bet=true}} 6 | chainhelper:read_chain() 7 | public_data.rate = 98 8 | public_data.max_bet = 1000000 9 | write_list = {public_data={rate=true,max_bet=true}} 10 | chainhelper:write_chain() 11 | end 12 | 13 | 14 | function bet(num, amount) 15 | 16 | chainhelper:log('Hello World!'..contract_base_info.invoker_contract_id) 17 | 18 | assert(contract_base_info.invoker_contract_id == "1.16.0",'can not call by other contract!') 19 | 20 | read_list = {public_data={rate=true,max_bet=true}} 21 | chainhelper:read_chain() 22 | 23 | num = tonumber(num) 24 | amount = tonumber(amount) * COCOS_ACCURACY 25 | 26 | assert( 1 < num and num < 97, "num must in [2,96] " ) 27 | assert( 0 < amount and amount < public_data.max_bet * COCOS_ACCURACY, "amount must in [1, max]") 28 | 29 | chainhelper:transfer_from_caller(contract_base_info.owner, amount, 'COCOS', true) 30 | 31 | result_num = chainhelper:random() % 100 32 | 33 | if result_num < num then 34 | win_chance = num 35 | reward_ratio = public_data.rate*1.0/win_chance 36 | reward = amount*reward_ratio 37 | chainhelper:transfer_from_owner(contract_base_info.caller, reward, 'COCOS', true) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /operations/assetsettleoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetSettle] = func() types.Operation { 13 | op := &AssetSettleOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetSettleOperation struct { 19 | types.OperationFee 20 | Account types.AccountID `json:"account"` 21 | Amount types.AssetAmount `json:"amount"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p AssetSettleOperation) Type() types.OperationType { 26 | return types.OperationTypeAssetSettle 27 | } 28 | 29 | func (p AssetSettleOperation) Marshal(enc *util.TypeEncoder) error { 30 | if err := enc.Encode(int8(p.Type())); err != nil { 31 | return errors.Annotate(err, "encode OperationType") 32 | } 33 | 34 | if err := enc.Encode(p.Fee); err != nil { 35 | return errors.Annotate(err, "encode fee") 36 | } 37 | 38 | if err := enc.Encode(p.Account); err != nil { 39 | return errors.Annotate(err, "encode Account") 40 | } 41 | 42 | if err := enc.Encode(p.Amount); err != nil { 43 | return errors.Annotate(err, "encode Amount") 44 | } 45 | 46 | if err := enc.Encode(p.Extensions); err != nil { 47 | return errors.Annotate(err, "encode Extensions") 48 | } 49 | 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /types/account.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type Accounts []Account 6 | 7 | func (p Accounts) Lookup(ID GrapheneObject) *Account { 8 | for _, acct := range p { 9 | if acct.ID.Equals(ID) { 10 | return &acct 11 | } 12 | } 13 | 14 | return nil 15 | } 16 | 17 | type Account struct { 18 | ID AccountID `json:"id"` 19 | MembershipExpirationDate Time `json:"membership_expiration_date"` 20 | Registrar AccountID `json:"registrar"` 21 | Name String `json:"name"` 22 | Owner Authority `json:"owner"` 23 | Active Authority `json:"active"` 24 | Options AccountOptions `json:"options"` 25 | Statistics ObjectID `json:"statistics"` 26 | CashbackGAS VestingBalanceID `json:"cashback_gas"` 27 | CashbackVB VestingBalanceID `json:"cashback_vb"` 28 | CashbackVote VestingBalanceID `json:"cashback_vote"` 29 | OwnerSpecialAuthority OwnerSpecialAuthority `json:"owner_special_authority"` 30 | ActiveSpecialAuthority ActiveSpecialAuthority `json:"active_special_authority"` 31 | TopNControlFlags UInt64 `json:"top_n_control_flags"` 32 | } 33 | 34 | type LockWithVotePairType struct { 35 | Number UInt32 36 | Asset AssetAmount 37 | } 38 | -------------------------------------------------------------------------------- /tests/wallet/wallet_api.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | sdk "github.com/Cocos-BCX/cocos-go" 8 | "github.com/Cocos-BCX/cocos-go/config" 9 | "github.com/Cocos-BCX/cocos-go/crypto" 10 | ) 11 | 12 | func main() { 13 | // config.SetCurrent(config.ChainIDBCXDev) 14 | // wsURL := "ws://127.0.0.1:8049" 15 | // // wsURL := "ws://test.cocosbcx.net" 16 | // walletURL := "http://127.0.0.1:8048" 17 | 18 | config.SetCurrent(config.ChainIDBCXTest) 19 | walletURL := "http://127.0.0.1:8048" 20 | 21 | // testAccount := "nicotest" 22 | privateKey := "5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo" 23 | publicKey := "COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx" 24 | 25 | // 1. key bag 测试 26 | log.Println("------- key bag test ----------") 27 | localKeyBag := crypto.NewKeyBag() 28 | err := localKeyBag.Add(privateKey) 29 | if err != nil { 30 | log.Println(err) 31 | } else { 32 | publics := localKeyBag.Publics() 33 | fmt.Printf("publics: %v %v\n", publics, publicKey) 34 | } 35 | 36 | // wallet api 测试 37 | log.Println("------- wallet api test ----------") 38 | walletAPI := sdk.NewWalletAPI(walletURL) 39 | if err := walletAPI.Connect(); err != nil { 40 | log.Println(err) 41 | } 42 | 43 | info, err := walletAPI.Info() 44 | if err != nil { 45 | log.Fatal(err) 46 | } 47 | log.Printf("info: %v", info) 48 | 49 | block, err := walletAPI.GetBlock(uint64(4497)) 50 | log.Printf("block: %v, err: %v\n", block, err) 51 | } 52 | -------------------------------------------------------------------------------- /operations/assetreserveoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetReserve] = func() types.Operation { 13 | op := &AssetReserveOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetReserveOperation struct { 19 | types.OperationFee 20 | Payer types.AccountID `json:"payer"` 21 | AmountToReserve types.AssetAmount `json:"amount_to_reserve"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p AssetReserveOperation) Type() types.OperationType { 26 | return types.OperationTypeAssetReserve 27 | } 28 | 29 | func (p AssetReserveOperation) Marshal(enc *util.TypeEncoder) error { 30 | if err := enc.Encode(int8(p.Type())); err != nil { 31 | return errors.Annotate(err, "encode OperationType") 32 | } 33 | 34 | if err := enc.Encode(p.Fee); err != nil { 35 | return errors.Annotate(err, "encode fee") 36 | } 37 | 38 | if err := enc.Encode(p.Payer); err != nil { 39 | return errors.Annotate(err, "encode payer") 40 | } 41 | 42 | if err := enc.Encode(p.AmountToReserve); err != nil { 43 | return errors.Annotate(err, "encode amount to reverse") 44 | } 45 | 46 | if err := enc.Encode(p.Extensions); err != nil { 47 | return errors.Annotate(err, "encode extensions") 48 | } 49 | 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /operations/limitordercanceloperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeLimitOrderCancel] = func() types.Operation { 13 | op := &LimitOrderCancelOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type LimitOrderCancelOperation struct { 19 | types.OperationFee 20 | Order types.LimitOrderID `json:"order"` 21 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p LimitOrderCancelOperation) Type() types.OperationType { 26 | return types.OperationTypeLimitOrderCancel 27 | } 28 | 29 | func (p LimitOrderCancelOperation) Marshal(enc *util.TypeEncoder) error { 30 | if err := enc.Encode(int8(p.Type())); err != nil { 31 | return errors.Annotate(err, "encode OperationType") 32 | } 33 | if err := enc.Encode(p.Fee); err != nil { 34 | return errors.Annotate(err, "encode Fee") 35 | } 36 | if err := enc.Encode(p.Order); err != nil { 37 | return errors.Annotate(err, "encode Order") 38 | } 39 | if err := enc.Encode(p.FeePayingAccount); err != nil { 40 | return errors.Annotate(err, "encode FeePayingAccount") 41 | } 42 | if err := enc.Encode(p.Extensions); err != nil { 43 | return errors.Annotate(err, "encode Extensions") 44 | } 45 | 46 | return nil 47 | } 48 | -------------------------------------------------------------------------------- /types/assetfeed.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/juju/errors" 7 | "github.com/pquerna/ffjson/ffjson" 8 | ) 9 | 10 | type AssetFeeds []AssetFeed 11 | 12 | type AssetFeed struct { 13 | ProviderID AccountID 14 | DateTime Time 15 | FeedInfo PriceFeed 16 | } 17 | 18 | func (p AssetFeed) MarshalJSON() ([]byte, error) { 19 | data := make([]interface{}, 2) 20 | data[0] = p.DateTime 21 | data[1] = p.FeedInfo 22 | 23 | ret := make([]interface{}, 2) 24 | ret[0] = p.ProviderID 25 | ret[1] = data 26 | 27 | return ffjson.Marshal(ret) 28 | } 29 | 30 | func (p *AssetFeed) UnmarshalJSON(data []byte) error { 31 | 32 | raw := make([]json.RawMessage, 2) 33 | if err := ffjson.Unmarshal(data, &raw); err != nil { 34 | return errors.Annotate(err, "unmarshal AssetFeed [unmarshal]") 35 | } 36 | 37 | if err := ffjson.Unmarshal(raw[0], &p.ProviderID); err != nil { 38 | return errors.Annotate(err, "unmarshal AssetFeed [provider id]") 39 | } 40 | 41 | feedData := make([]json.RawMessage, 2) 42 | if err := ffjson.Unmarshal(raw[1], &feedData); err != nil { 43 | return errors.Annotate(err, "unmarshal AssetFeed [feed data]") 44 | } 45 | 46 | if err := ffjson.Unmarshal(feedData[0], &p.DateTime); err != nil { 47 | return errors.Annotate(err, "unmarshal AssetFeed [feed time]") 48 | } 49 | 50 | if err := ffjson.Unmarshal(feedData[1], &p.FeedInfo); err != nil { 51 | return errors.Annotate(err, "unmarshal AssetFeed [feed info]") 52 | } 53 | 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /operations/witnesscreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeWitnessCreate] = func() types.Operation { 13 | op := &WitnessCreateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type WitnessCreateOperation struct { 19 | types.OperationFee 20 | WitnessAccount types.AccountID `json:"witness_account"` 21 | URL string `json:"url"` 22 | BlockSigningKey types.PublicKey `json:"block_signing_key"` 23 | } 24 | 25 | func (p WitnessCreateOperation) Type() types.OperationType { 26 | return types.OperationTypeWitnessCreate 27 | } 28 | 29 | //TODO: verify order 30 | func (p WitnessCreateOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode fee") 37 | } 38 | 39 | if err := enc.Encode(p.WitnessAccount); err != nil { 40 | return errors.Annotate(err, "encode WitnessAccount") 41 | } 42 | 43 | if err := enc.Encode(p.URL); err != nil { 44 | return errors.Annotate(err, "encode URL") 45 | } 46 | 47 | if err := enc.Encode(p.BlockSigningKey); err != nil { 48 | return errors.Annotate(err, "encode BlockSigningKey") 49 | } 50 | 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /types/network.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | type PeerInfo struct { 6 | Addr string `json:"addr"` 7 | AddrLocal string `json:"addrlocal"` 8 | RPCPort int `json:"rpc-port"` 9 | Services int `json:"services"` 10 | LastSend uint64 `json:"lastsend"` 11 | LastRecv uint64 `json:"lastrecv"` 12 | BytesSent uint64 `json:"bytessent"` 13 | BytesRecv uint64 `json:"bytesrecv"` 14 | Conntime Time `json:"conntime"` 15 | Version string `json:"version"` 16 | Subver string `json:"subver"` 17 | Inbound bool `json:"inbound"` 18 | FirewallStatus string `json:"firewall_status"` 19 | FCGitRevisionSha string `json:"fc_git_revision_sha"` 20 | FCGitRevisionUnixTimestamp Time `json:"fc_git_revision_unix_timestamp"` 21 | FCGitRevisionAge string `json:"fc_git_revision_age"` 22 | Platform string `json:"platform"` 23 | CurrentHeadBlock string `json:"current_head_block"` 24 | CurrentHeadBlockNumber uint64 `json:"current_head_block_number"` 25 | CurrentHeadBlockTime Time `json:"current_head_block_time"` 26 | } 27 | 28 | type NetWorkPeer struct { 29 | Version int `json:"version"` 30 | Host string `json:"host"` 31 | Info PeerInfo `json:"info"` 32 | } 33 | 34 | type NetWorkPeers []NetWorkPeer 35 | -------------------------------------------------------------------------------- /operations/vestingbalancewithdrawoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeVestingBalanceWithdraw] = func() types.Operation { 13 | op := &VestingBalanceWithdrawOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type VestingBalanceWithdrawOperation struct { 19 | types.OperationFee 20 | VestingBalance types.VestingBalanceID `json:"vesting_balance"` 21 | Owner types.AccountID `json:"owner"` 22 | Amount types.AssetAmount `json:"amount"` 23 | } 24 | 25 | func (p VestingBalanceWithdrawOperation) Type() types.OperationType { 26 | return types.OperationTypeVestingBalanceWithdraw 27 | } 28 | 29 | func (p VestingBalanceWithdrawOperation) Marshal(enc *util.TypeEncoder) error { 30 | if err := enc.Encode(int8(p.Type())); err != nil { 31 | return errors.Annotate(err, "encode OperationType") 32 | } 33 | 34 | if err := enc.Encode(p.Fee); err != nil { 35 | return errors.Annotate(err, "encode fee") 36 | } 37 | 38 | if err := enc.Encode(p.VestingBalance); err != nil { 39 | return errors.Annotate(err, "encode VestingBalance") 40 | } 41 | 42 | if err := enc.Encode(p.Owner); err != nil { 43 | return errors.Annotate(err, "encode Owner") 44 | } 45 | 46 | if err := enc.Encode(p.Amount); err != nil { 47 | return errors.Annotate(err, "encode Amount") 48 | } 49 | 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /operations/executebidoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeExecuteBid] = func() types.Operation { 13 | op := &ExecuteBidOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type ExecuteBidOperation struct { 19 | types.OperationFee 20 | Bidder types.AccountID `json:"bidder"` 21 | Debt types.AssetAmount `json:"debt"` 22 | Collateral types.AssetAmount `json:"collateral"` 23 | } 24 | 25 | func (p ExecuteBidOperation) Type() types.OperationType { 26 | return types.OperationTypeExecuteBid 27 | } 28 | 29 | func (p ExecuteBidOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | return nil 31 | } 32 | 33 | func (p ExecuteBidOperation) Marshal(enc *util.TypeEncoder) error { 34 | if err := enc.Encode(int8(p.Type())); err != nil { 35 | return errors.Annotate(err, "encode OperationType") 36 | } 37 | 38 | if err := enc.Encode(p.Fee); err != nil { 39 | return errors.Annotate(err, "encode Fee") 40 | } 41 | 42 | if err := enc.Encode(p.Bidder); err != nil { 43 | return errors.Annotate(err, "encode Bidder") 44 | } 45 | 46 | if err := enc.Encode(p.Debt); err != nil { 47 | return errors.Annotate(err, "encode Debt") 48 | } 49 | 50 | if err := enc.Encode(p.Collateral); err != nil { 51 | return errors.Annotate(err, "encode Collateral") 52 | } 53 | 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /memobuilder.go: -------------------------------------------------------------------------------- 1 | package cocos 2 | 3 | import ( 4 | "math/rand" 5 | 6 | "github.com/Cocos-BCX/cocos-go/crypto" 7 | "github.com/Cocos-BCX/cocos-go/types" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | // MemoBuilder is a memo factory 12 | type MemoBuilder struct { 13 | from types.GrapheneObject 14 | to types.GrapheneObject 15 | api WebsocketAPI 16 | memo string 17 | } 18 | 19 | //NewMemoBuilder creates a new MemoBuilder 20 | func (p *websocketAPI) NewMemoBuilder(from, to types.GrapheneObject, memo string) *MemoBuilder { 21 | builder := MemoBuilder{ 22 | from: from, 23 | to: to, 24 | memo: memo, 25 | api: p, 26 | } 27 | 28 | return &builder 29 | } 30 | 31 | // Encrypt encrypts the memo message with the corresponding private key found in keyBag 32 | func (p *MemoBuilder) Encrypt(keyBag *crypto.KeyBag) (*types.Memo, error) { 33 | accts, err := p.api.GetAccounts(p.from, p.to) 34 | if err != nil { 35 | return nil, errors.Annotate(err, "GetAccounts") 36 | } 37 | 38 | from := accts.Lookup(p.from) 39 | if from == nil { 40 | return nil, errors.Errorf("can't retrieve account infos for %s", p.from) 41 | } 42 | 43 | to := accts.Lookup(p.to) 44 | if to == nil { 45 | return nil, errors.Errorf("can't retrieve account infos for %s", p.to) 46 | } 47 | 48 | memo := types.Memo{ 49 | From: from.Options.MemoKey, 50 | To: to.Options.MemoKey, 51 | Nonce: types.UInt64(rand.Uint64()), 52 | } 53 | 54 | if err := keyBag.EncryptMemo(&memo, p.memo); err != nil { 55 | return nil, errors.Annotate(err, "EncryptMemo") 56 | } 57 | 58 | return &memo, nil 59 | } 60 | -------------------------------------------------------------------------------- /operations/deletenhassetoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeDeleteNhAsset] = func() types.Operation { 13 | op := &DeleteNhAssetOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type DeleteNhAssetOperation struct { 19 | types.OperationFee 20 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 21 | NHAsset types.NHAssetID `json:"nh_asset"` 22 | } 23 | 24 | func (p DeleteNhAssetOperation) Type() types.OperationType { 25 | return types.OperationTypeDeleteNhAsset 26 | } 27 | 28 | func (p DeleteNhAssetOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 29 | if fee, ok := params["fee"]; ok { 30 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 31 | return errors.Annotate(err, "encode Fee") 32 | } 33 | } 34 | 35 | return nil 36 | } 37 | 38 | func (p DeleteNhAssetOperation) Marshal(enc *util.TypeEncoder) error { 39 | if err := enc.Encode(int8(p.Type())); err != nil { 40 | return errors.Annotate(err, "encode OperationType") 41 | } 42 | 43 | if err := enc.Encode(p.Fee); err != nil { 44 | return errors.Annotate(err, "encode fee") 45 | } 46 | 47 | if err := enc.Encode(p.FeePayingAccount); err != nil { 48 | return errors.Annotate(err, "encode FeePayingAccount") 49 | } 50 | 51 | if err := enc.Encode(p.NHAsset); err != nil { 52 | return errors.Annotate(err, "encode NHAsset") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/assetpublishfeedoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetPublishFeed] = func() types.Operation { 13 | op := &AssetPublishFeedOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetPublishFeedOperation struct { 19 | types.OperationFee 20 | Publisher types.AccountID `json:"publisher"` 21 | AssetID types.AssetID `json:"asset_id"` 22 | Feed types.PriceFeed `json:"feed"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p AssetPublishFeedOperation) Type() types.OperationType { 27 | return types.OperationTypeAssetPublishFeed 28 | } 29 | 30 | func (p AssetPublishFeedOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode Fee") 37 | } 38 | 39 | if err := enc.Encode(p.Publisher); err != nil { 40 | return errors.Annotate(err, "encode Publisher") 41 | } 42 | 43 | if err := enc.Encode(p.AssetID); err != nil { 44 | return errors.Annotate(err, "encode AssetID") 45 | } 46 | 47 | if err := enc.Encode(p.Feed); err != nil { 48 | return errors.Annotate(err, "encode Feed") 49 | } 50 | 51 | if err := enc.Encode(p.Extensions); err != nil { 52 | return errors.Annotate(err, "encode Extensions") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /types/publickey_test.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/Cocos-BCX/cocos-go/config" 7 | "github.com/juju/errors" 8 | "github.com/stretchr/testify/assert" 9 | ) 10 | 11 | const ( 12 | BTSNullKey = "BTS1111111111111111111111111111111114T1Anm" 13 | ) 14 | 15 | var keys = []string{ 16 | "BTS6K35Bajw29N4fjP4XADHtJ7bEj2xHJ8CoY2P2s1igXTB5oMBhR", 17 | "BTS4txNeAoSWcDX7oWceKppMb956z5oRx6mQyCJXCUB7aUh1EJp5y", 18 | "BTS6iUXJDmAPNbHWHtDDcmPTQ6F3nMBqi6pUHdhSkzWNd6grob2JP", 19 | "BTS5KCRzL27VLBvhPJ1DaXViuUPxyEXjDvVtWaifUkouNr2MkMGSH", 20 | "BTS6ThjMq97v6dLQUAmdsZfWG9ENq8nghVUhmLMQi52MDqXvtRGNc", 21 | "BTS5zzvbDtkbUVU1gFFsKqCE55U7JbjTp6mTh1usFv7KGgXL7HDQk", 22 | "BTS5yXqEBShUgcVm7Mve8Fg4RzQ2ftPpmo77aMbz884eX9aeGVvwD", 23 | "BTS5Z3vsgH6xj6HLXcsU38yo4TyoZs9AUzpfbaXbuxsAYPbutWvEP", 24 | "BTS5shffTjVoT4J8Zrj3f2mQJw4UVKrnbx5FWYhVgov45EpBf2NYi", 25 | "BTS56fy8qpkLzNoguGMPgPNkkznxnx2woEg1qPq7E6gF2SeGSRyK5", 26 | } 27 | 28 | func TestNewPublicKey(t *testing.T) { 29 | config.SetCurrent(config.ChainIDBTS) 30 | for _, k := range keys { 31 | key, err := NewPublicKeyFromString(k) 32 | if err != nil { 33 | assert.FailNow(t, errors.Annotate(err, "NewPublicKeyFromString").Error()) 34 | } 35 | 36 | assert.NotNil(t, key) 37 | assert.Equal(t, k, key.String()) 38 | } 39 | } 40 | 41 | func TestNullPublicKey(t *testing.T) { 42 | config.SetCurrent(config.ChainIDBTS) 43 | key, err := NewPublicKeyFromString(BTSNullKey) 44 | if err != nil { 45 | assert.FailNow(t, errors.Annotate(err, "NewPublicKeyFromString").Error()) 46 | } 47 | 48 | assert.NotNil(t, key) 49 | assert.Equal(t, BTSNullKey, key.String()) 50 | } 51 | -------------------------------------------------------------------------------- /operations/vestingbalancecreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeVestingBalanceCreate] = func() types.Operation { 13 | op := &VestingBalanceCreateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type VestingBalanceCreateOperation struct { 19 | types.OperationFee 20 | Amount types.AssetAmount `json:"amount"` 21 | Creator types.AccountID `json:"creator"` 22 | Owner types.AccountID `json:"owner"` 23 | Policy types.VestingPolicy `json:"policy"` 24 | } 25 | 26 | func (p VestingBalanceCreateOperation) Type() types.OperationType { 27 | return types.OperationTypeVestingBalanceCreate 28 | } 29 | 30 | func (p VestingBalanceCreateOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode fee") 37 | } 38 | 39 | if err := enc.Encode(p.Creator); err != nil { 40 | return errors.Annotate(err, "encode Creator") 41 | } 42 | 43 | if err := enc.Encode(p.Owner); err != nil { 44 | return errors.Annotate(err, "encode Owner") 45 | } 46 | 47 | if err := enc.Encode(p.Amount); err != nil { 48 | return errors.Annotate(err, "encode Amount") 49 | } 50 | 51 | if err := enc.Encode(p.Policy); err != nil { 52 | return errors.Annotate(err, "encode Policy") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/assetglobalsettleoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetGlobalSettle] = func() types.Operation { 13 | op := &AssetGlobalSettleOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetGlobalSettleOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | AssetToSettle types.AssetID `json:"asset_to_settle"` 22 | SettlePrice types.Price `json:"settle_price"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p AssetGlobalSettleOperation) Type() types.OperationType { 27 | return types.OperationTypeAssetGlobalSettle 28 | } 29 | 30 | func (p AssetGlobalSettleOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | if err := enc.Encode(p.Fee); err != nil { 35 | return errors.Annotate(err, "encode Fee") 36 | } 37 | if err := enc.Encode(p.Issuer); err != nil { 38 | return errors.Annotate(err, "encode Issuer") 39 | } 40 | if err := enc.Encode(p.AssetToSettle); err != nil { 41 | return errors.Annotate(err, "encode AssetToSettle") 42 | } 43 | if err := enc.Encode(p.SettlePrice); err != nil { 44 | return errors.Annotate(err, "encode SettlePrice") 45 | } 46 | if err := enc.Encode(p.Extensions); err != nil { 47 | return errors.Annotate(err, "encode Extensions") 48 | } 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /operations/createworldviewoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCreateWorldView] = func() types.Operation { 13 | op := &CreateWorldViewOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CreateWorldViewOperation struct { 19 | types.OperationFee 20 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 21 | WorldView string `json:"world_view"` 22 | } 23 | 24 | func (p CreateWorldViewOperation) Type() types.OperationType { 25 | return types.OperationTypeCreateWorldView 26 | } 27 | 28 | func (p CreateWorldViewOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 29 | if fee, ok := params["fee"]; ok { 30 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 31 | return errors.Annotate(err, "encode Fee") 32 | } 33 | } 34 | 35 | return nil 36 | } 37 | 38 | func (p CreateWorldViewOperation) Marshal(enc *util.TypeEncoder) error { 39 | if err := enc.Encode(int8(p.Type())); err != nil { 40 | return errors.Annotate(err, "encode OperationType") 41 | } 42 | 43 | if err := enc.Encode(p.Fee); err != nil { 44 | return errors.Annotate(err, "encode fee") 45 | } 46 | 47 | if err := enc.Encode(p.FeePayingAccount); err != nil { 48 | return errors.Annotate(err, "encode FeePayingAccount") 49 | } 50 | 51 | if err := enc.Encode(p.WorldView); err != nil { 52 | return errors.Annotate(err, "encode WorldView") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /types/committeemember.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | type CommitteeMember struct { 10 | ID CommitteeMemberID `json:"id"` 11 | CommitteeMemberAccount AccountID `json:"committee_member_account"` 12 | VoteID VoteID `json:"vote_id"` 13 | TotalVotes UInt64 `json:"total_votes"` 14 | URL String `json:"url"` 15 | WorkStatus bool `json:"work_status"` 16 | NextMaintenanceTime Time `json:"next_maintenance_time"` 17 | Supporters SupporterType `json:"supporters"` 18 | } 19 | 20 | func (p CommitteeMember) Marshal(enc *util.TypeEncoder) error { 21 | if err := enc.Encode(p.CommitteeMemberAccount); err != nil { 22 | return errors.Annotate(err, "encode CommitteeMemberAccount") 23 | } 24 | if err := enc.Encode(p.VoteID); err != nil { 25 | return errors.Annotate(err, "encode VoteID") 26 | } 27 | if err := enc.Encode(p.TotalVotes); err != nil { 28 | return errors.Annotate(err, "encode TotalVotes") 29 | } 30 | if err := enc.Encode(p.URL); err != nil { 31 | return errors.Annotate(err, "encode URL") 32 | } 33 | if err := enc.Encode(p.WorkStatus); err != nil { 34 | return errors.Annotate(err, "encode WorkStatus") 35 | } 36 | if err := enc.Encode(p.NextMaintenanceTime); err != nil { 37 | return errors.Annotate(err, "encode NextMaintenanceTime") 38 | } 39 | if err := enc.Encode(p.Supporters); err != nil { 40 | return errors.Annotate(err, "encode Supporters") 41 | } 42 | 43 | return nil 44 | } 45 | -------------------------------------------------------------------------------- /operations/bidcolatteraloperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeBidCollateral] = func() types.Operation { 13 | op := &BidCollateralOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type BidCollateralOperation struct { 19 | types.OperationFee 20 | Bidder types.AccountID `json:"bidder"` 21 | AdditionalCollateral types.AssetAmount `json:"additional_collateral"` 22 | DebtCovered types.AssetAmount `json:"debt_covered"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p BidCollateralOperation) Type() types.OperationType { 27 | return types.OperationTypeBidCollateral 28 | } 29 | 30 | func (p BidCollateralOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode fee") 37 | } 38 | 39 | if err := enc.Encode(p.Bidder); err != nil { 40 | return errors.Annotate(err, "encode Bidder") 41 | } 42 | 43 | if err := enc.Encode(p.AdditionalCollateral); err != nil { 44 | return errors.Annotate(err, "encode AdditionalCollateral") 45 | } 46 | 47 | if err := enc.Encode(p.DebtCovered); err != nil { 48 | return errors.Annotate(err, "encode DebtCovered") 49 | } 50 | 51 | if err := enc.Encode(p.Extensions); err != nil { 52 | return errors.Annotate(err, "encode Extensions") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/callorderupdateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCallOrderUpdate] = func() types.Operation { 13 | op := &CallOrderUpdateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CallOrderUpdateOperation struct { 19 | types.OperationFee 20 | FundingAccount types.AccountID `json:"funding_account"` 21 | DeltaCollateral types.AssetAmount `json:"delta_collateral"` 22 | DeltaDebt types.AssetAmount `json:"delta_debt"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p CallOrderUpdateOperation) Type() types.OperationType { 27 | return types.OperationTypeCallOrderUpdate 28 | } 29 | 30 | func (p CallOrderUpdateOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode fee") 37 | } 38 | 39 | if err := enc.Encode(p.FundingAccount); err != nil { 40 | return errors.Annotate(err, "encode funding account") 41 | } 42 | 43 | if err := enc.Encode(p.DeltaCollateral); err != nil { 44 | return errors.Annotate(err, "encode delta collateral") 45 | } 46 | 47 | if err := enc.Encode(p.DeltaDebt); err != nil { 48 | return errors.Annotate(err, "encode delta debt") 49 | } 50 | 51 | if err := enc.Encode(p.Extensions); err != nil { 52 | return errors.Annotate(err, "encode extensions") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/proposaldeleteoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeProposalDelete] = func() types.Operation { 13 | op := &ProposalDeleteOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type ProposalDeleteOperation struct { 19 | types.OperationFee 20 | Extensions types.Extensions `json:"extensions"` 21 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 22 | Proposal types.ProposalID `json:"proposal"` 23 | UsingOwnerAuthority bool `json:"using_owner_authority"` 24 | } 25 | 26 | func (p ProposalDeleteOperation) Type() types.OperationType { 27 | return types.OperationTypeProposalDelete 28 | } 29 | 30 | func (p ProposalDeleteOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode Fee") 37 | } 38 | 39 | if err := enc.Encode(p.FeePayingAccount); err != nil { 40 | return errors.Annotate(err, "encode FeePayingAccount") 41 | } 42 | 43 | if err := enc.Encode(p.UsingOwnerAuthority); err != nil { 44 | return errors.Annotate(err, "encode UsingOwnerAuthority") 45 | } 46 | 47 | if err := enc.Encode(p.Proposal); err != nil { 48 | return errors.Annotate(err, "encode Proposal") 49 | } 50 | 51 | if err := enc.Encode(p.Extensions); err != nil { 52 | return errors.Annotate(err, "encode Extensions") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/transfernhassetoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeTransferNhAsset] = func() types.Operation { 13 | op := &CreateNhAssetOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type TransferNhAssetOperation struct { 19 | types.OperationFee 20 | From types.AccountID `json:"from"` 21 | To types.AccountID `json:"to"` 22 | NHAsset types.NHAssetID `json:"nh_asset"` 23 | } 24 | 25 | func (p TransferNhAssetOperation) Type() types.OperationType { 26 | return types.OperationTypeTransferNhAsset 27 | } 28 | 29 | func (p TransferNhAssetOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | return nil 37 | } 38 | 39 | func (p TransferNhAssetOperation) Marshal(enc *util.TypeEncoder) error { 40 | if err := enc.Encode(int8(p.Type())); err != nil { 41 | return errors.Annotate(err, "encode OperationType") 42 | } 43 | 44 | if err := enc.Encode(p.Fee); err != nil { 45 | return errors.Annotate(err, "encode fee") 46 | } 47 | 48 | if err := enc.Encode(p.From); err != nil { 49 | return errors.Annotate(err, "encode From") 50 | } 51 | 52 | if err := enc.Encode(p.To); err != nil { 53 | return errors.Annotate(err, "encode To") 54 | } 55 | 56 | if err := enc.Encode(p.NHAsset); err != nil { 57 | return errors.Annotate(err, "encode NHAsset") 58 | } 59 | 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /operations/assetupdatebitassetoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetUpdateBitasset] = func() types.Operation { 13 | op := &AssetUpdateBitassetOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetUpdateBitassetOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | AssetToUpdate types.AssetID `json:"asset_to_update"` 22 | NewOptions types.BitassetOptions `json:"new_options"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p AssetUpdateBitassetOperation) Type() types.OperationType { 27 | return types.OperationTypeAssetUpdateBitasset 28 | } 29 | 30 | //TODO: validate order 31 | func (p AssetUpdateBitassetOperation) Marshal(enc *util.TypeEncoder) error { 32 | if err := enc.Encode(int8(p.Type())); err != nil { 33 | return errors.Annotate(err, "encode OperationType") 34 | } 35 | 36 | if err := enc.Encode(p.Fee); err != nil { 37 | return errors.Annotate(err, "encode fee") 38 | } 39 | 40 | if err := enc.Encode(p.Issuer); err != nil { 41 | return errors.Annotate(err, "encode issuer") 42 | } 43 | 44 | if err := enc.Encode(p.AssetToUpdate); err != nil { 45 | return errors.Annotate(err, "encode AssetToUpdate") 46 | } 47 | 48 | if err := enc.Encode(p.NewOptions); err != nil { 49 | return errors.Annotate(err, "encode new options") 50 | } 51 | 52 | if err := enc.Encode(p.Extensions); err != nil { 53 | return errors.Annotate(err, "encode extensions") 54 | } 55 | 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /operations/assetupdatefeedproduceroperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetUpdateFeedProducers] = func() types.Operation { 13 | op := &AssetUpdateFeedProducersOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetUpdateFeedProducersOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | AssetToUpdate types.AssetID `json:"asset_to_update"` 22 | NewFeedProducers types.AccountIDs `json:"new_feed_producers"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p AssetUpdateFeedProducersOperation) Type() types.OperationType { 27 | return types.OperationTypeAssetUpdateFeedProducers 28 | } 29 | 30 | func (p AssetUpdateFeedProducersOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | 35 | if err := enc.Encode(p.Fee); err != nil { 36 | return errors.Annotate(err, "encode Fee") 37 | } 38 | 39 | if err := enc.Encode(p.Issuer); err != nil { 40 | return errors.Annotate(err, "encode Issuer") 41 | } 42 | 43 | if err := enc.Encode(p.AssetToUpdate); err != nil { 44 | return errors.Annotate(err, "encode AssetToUpdate") 45 | } 46 | 47 | if err := enc.Encode(p.NewFeedProducers); err != nil { 48 | return errors.Annotate(err, "encode NewFeedProducers") 49 | } 50 | 51 | if err := enc.Encode(p.Extensions); err != nil { 52 | return errors.Annotate(err, "encode Extensions") 53 | } 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /operations/relateworldviewoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeRelateWorldView] = func() types.Operation { 13 | op := &RelateWorldViewOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type RelateWorldViewOperation struct { 19 | types.OperationFee 20 | RelatedAccount types.AccountID `json:"related_account"` 21 | WorldView string `json:"world_view"` 22 | ViewOwner types.AccountID `json:"view_owner"` 23 | } 24 | 25 | func (p RelateWorldViewOperation) Type() types.OperationType { 26 | return types.OperationTypeRelateWorldView 27 | } 28 | 29 | func (p RelateWorldViewOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | return nil 37 | } 38 | 39 | func (p RelateWorldViewOperation) Marshal(enc *util.TypeEncoder) error { 40 | if err := enc.Encode(int8(p.Type())); err != nil { 41 | return errors.Annotate(err, "encode OperationType") 42 | } 43 | 44 | if err := enc.Encode(p.Fee); err != nil { 45 | return errors.Annotate(err, "encode fee") 46 | } 47 | 48 | if err := enc.Encode(p.RelatedAccount); err != nil { 49 | return errors.Annotate(err, "encode RelatedAccount") 50 | } 51 | 52 | if err := enc.Encode(p.WorldView); err != nil { 53 | return errors.Annotate(err, "encode WorldView") 54 | } 55 | 56 | if err := enc.Encode(p.ViewOwner); err != nil { 57 | return errors.Annotate(err, "encode ViewOwner") 58 | } 59 | 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /operations/balanceclaimoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeBalanceClaim] = func() types.Operation { 13 | op := &BalanceClaimOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type BalanceClaimOperation struct { 19 | types.OperationFee 20 | DepositToAccount types.AccountID `json:"deposit_to_account"` 21 | BalanceToClaim types.BalanceID `json:"balance_to_claim"` 22 | BalanceOwnerKey types.PublicKey `json:"balance_owner_key"` 23 | TotalClaimed types.AssetAmount `json:"total_claimed"` 24 | } 25 | 26 | func (p BalanceClaimOperation) Type() types.OperationType { 27 | return types.OperationTypeBalanceClaim 28 | } 29 | 30 | func (p BalanceClaimOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 31 | return nil 32 | } 33 | 34 | func (p BalanceClaimOperation) Marshal(enc *util.TypeEncoder) error { 35 | if err := enc.Encode(int8(p.Type())); err != nil { 36 | return errors.Annotate(err, "encode OperationType") 37 | } 38 | 39 | if err := enc.Encode(p.Fee); err != nil { 40 | return errors.Annotate(err, "encode fee") 41 | } 42 | 43 | if err := enc.Encode(p.DepositToAccount); err != nil { 44 | return errors.Annotate(err, "encode DepositToAccount") 45 | } 46 | 47 | if err := enc.Encode(p.BalanceToClaim); err != nil { 48 | return errors.Annotate(err, "encode BalanceToClaim") 49 | } 50 | 51 | if err := enc.Encode(p.BalanceOwnerKey); err != nil { 52 | return errors.Annotate(err, "encode BalanceOwnerKey") 53 | } 54 | 55 | if err := enc.Encode(p.TotalClaimed); err != nil { 56 | return errors.Annotate(err, "encode TotalClaimed") 57 | } 58 | 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /operations/cancelnhassetorderoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCancelNhAssetOrder] = func() types.Operation { 13 | op := &CancelNhAssetOrderOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CancelNhAssetOrderOperation struct { 19 | types.OperationFee 20 | Order types.NHAssetOrderID `json:"order"` 21 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p CancelNhAssetOrderOperation) Type() types.OperationType { 26 | return types.OperationTypeCancelNhAssetOrder 27 | } 28 | 29 | func (p CancelNhAssetOrderOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | return nil 37 | } 38 | 39 | func (p CancelNhAssetOrderOperation) Marshal(enc *util.TypeEncoder) error { 40 | if err := enc.Encode(int8(p.Type())); err != nil { 41 | return errors.Annotate(err, "encode OperationType") 42 | } 43 | 44 | if err := enc.Encode(p.Fee); err != nil { 45 | return errors.Annotate(err, "encode fee") 46 | } 47 | 48 | if err := enc.Encode(p.Order); err != nil { 49 | return errors.Annotate(err, "encode Order") 50 | } 51 | 52 | if err := enc.Encode(p.FeePayingAccount); err != nil { 53 | return errors.Annotate(err, "encode FeePayingAccount") 54 | } 55 | 56 | if err := enc.Encode(p.Extensions); err != nil { 57 | return errors.Annotate(err, "encode Extensions") 58 | } 59 | 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /operations/committeememberupdateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCommitteeMemberUpdate] = func() types.Operation { 13 | op := &CommitteeMemberUpdateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CommitteeMemberUpdateOperation struct { 19 | types.OperationFee 20 | CommitteeMember types.CommitteeMember `json:"committee_member"` 21 | CommitteeMemberAccount types.AccountID `json:"committee_member_account"` 22 | NewURL *string `json:"new_url,omitempty"` 23 | WorkStatus bool `json:"work_status"` 24 | } 25 | 26 | func (p CommitteeMemberUpdateOperation) Type() types.OperationType { 27 | return types.OperationTypeCommitteeMemberUpdate 28 | } 29 | 30 | func (p CommitteeMemberUpdateOperation) Marshal(enc *util.TypeEncoder) error { 31 | if err := enc.Encode(int8(p.Type())); err != nil { 32 | return errors.Annotate(err, "encode OperationType") 33 | } 34 | if err := enc.Encode(p.Fee); err != nil { 35 | return errors.Annotate(err, "encode Fee") 36 | } 37 | if err := enc.Encode(p.CommitteeMember); err != nil { 38 | return errors.Annotate(err, "encode CommitteeMember") 39 | } 40 | if err := enc.Encode(p.CommitteeMemberAccount); err != nil { 41 | return errors.Annotate(err, "encode CommitteeMemberAccount") 42 | } 43 | if err := enc.Encode(p.NewURL != nil); err != nil { 44 | return errors.Annotate(err, "encode NewURL available") 45 | } 46 | if err := enc.Encode(p.NewURL); err != nil { 47 | return errors.Annotate(err, "encode NewURL") 48 | } 49 | if err := enc.Encode(p.WorkStatus); err != nil { 50 | return errors.Annotate(err, "encode WorkStatus") 51 | } 52 | 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /types/assetoptions.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | 10 | type AssetOptions struct { 11 | MaxSupply Int64 `json:"max_supply"` 12 | MarketFeePercent UInt16 `json:"market_fee_percent"` 13 | MaxMarketFee Int64 `json:"max_market_fee"` 14 | IssuerPermissions UInt16 `json:"issuer_permissions"` 15 | Flags UInt16 `json:"flags"` 16 | CoreExchangeRate *Price `json:"core_exchange_rate,omitempty"` 17 | Description String `json:"description"` 18 | Extensions Extensions `json:"extensions"` 19 | } 20 | 21 | func (p AssetOptions) Marshal(enc *util.TypeEncoder) error { 22 | if err := enc.Encode(p.MaxSupply); err != nil { 23 | return errors.Annotate(err, "encode MaxSupply") 24 | } 25 | 26 | if err := enc.Encode(p.MarketFeePercent); err != nil { 27 | return errors.Annotate(err, "encode MarketFeePercent") 28 | } 29 | 30 | if err := enc.Encode(p.MaxMarketFee); err != nil { 31 | return errors.Annotate(err, "encode MaxMarketFee") 32 | } 33 | 34 | if err := enc.Encode(p.IssuerPermissions); err != nil { 35 | return errors.Annotate(err, "encode IssuerPermissions") 36 | } 37 | 38 | if err := enc.Encode(p.Flags); err != nil { 39 | return errors.Annotate(err, "encode Flags") 40 | } 41 | 42 | if err := enc.Encode(p.CoreExchangeRate != nil); err != nil { 43 | return errors.Annotate(err, "encode have CoreExchangeRate") 44 | } 45 | 46 | if err := enc.Encode(p.CoreExchangeRate); err != nil { 47 | return errors.Annotate(err, "encode CoreExchangeRate") 48 | } 49 | 50 | if err := enc.Encode(p.Description); err != nil { 51 | return errors.Annotate(err, "encode Description") 52 | } 53 | 54 | if err := enc.Encode(p.Extensions); err != nil { 55 | return errors.Annotate(err, "encode extensions") 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /operations/createfileoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCreateFile] = func() types.Operation { 13 | op := &CreateFileOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CreateFileOperation struct { 19 | types.OperationFee 20 | FileOwner types.AccountID `json:"file_owner"` 21 | FileName string `json:"file_name"` 22 | FileContent string `json:"file_content"` 23 | } 24 | 25 | func (p CreateFileOperation) Type() types.OperationType { 26 | return types.OperationTypeCreateFile 27 | } 28 | 29 | func (p CreateFileOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | if ppk, ok := params["price_per_kbyte"]; ok { 37 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 38 | return errors.Annotate(err, "encode PricePerKByte") 39 | } 40 | } 41 | 42 | return nil 43 | } 44 | 45 | func (p CreateFileOperation) Marshal(enc *util.TypeEncoder) error { 46 | if err := enc.Encode(int8(p.Type())); err != nil { 47 | return errors.Annotate(err, "encode OperationType") 48 | } 49 | 50 | if err := enc.Encode(p.Fee); err != nil { 51 | return errors.Annotate(err, "encode fee") 52 | } 53 | 54 | if err := enc.Encode(p.FileOwner); err != nil { 55 | return errors.Annotate(err, "encode FileOwner") 56 | } 57 | 58 | if err := enc.Encode(p.FileName); err != nil { 59 | return errors.Annotate(err, "encode FileName") 60 | } 61 | 62 | if err := enc.Encode(p.FileContent); err != nil { 63 | return errors.Annotate(err, "encode FileContent") 64 | } 65 | 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /operations/filesignatureoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeFileSignature] = func() types.Operation { 13 | op := &FileSignatureOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type FileSignatureOperation struct { 19 | types.OperationFee 20 | SignatureAccount types.AccountID `json:"signature_account"` 21 | FileID types.FileID `json:"file_id"` 22 | Signature string `json:"signature"` 23 | } 24 | 25 | func (p FileSignatureOperation) Type() types.OperationType { 26 | return types.OperationTypeFileSignature 27 | } 28 | 29 | func (p FileSignatureOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | if ppk, ok := params["price_per_kbyte"]; ok { 37 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 38 | return errors.Annotate(err, "encode PricePerKByte") 39 | } 40 | } 41 | 42 | return nil 43 | } 44 | 45 | func (p FileSignatureOperation) Marshal(enc *util.TypeEncoder) error { 46 | if err := enc.Encode(int8(p.Type())); err != nil { 47 | return errors.Annotate(err, "encode OperationType") 48 | } 49 | 50 | if err := enc.Encode(p.Fee); err != nil { 51 | return errors.Annotate(err, "encode fee") 52 | } 53 | 54 | if err := enc.Encode(p.SignatureAccount); err != nil { 55 | return errors.Annotate(err, "encode SignatureAccount") 56 | } 57 | 58 | if err := enc.Encode(p.FileID); err != nil { 59 | return errors.Annotate(err, "encode FileID") 60 | } 61 | 62 | if err := enc.Encode(p.Signature); err != nil { 63 | return errors.Annotate(err, "encode Signature") 64 | } 65 | 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /operations/relateparentfileoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeRelateParentFile] = func() types.Operation { 13 | op := &RelateParentFileOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type RelateParentFileOperation struct { 19 | types.OperationFee 20 | SubFileOwner types.AccountID `json:"sub_file_owner"` 21 | ParentFile types.FileID `json:"parent_file"` 22 | ParentFileOwner types.AccountID `json:"parent_file_owner"` 23 | SubFile types.FileID `json:"sub_file"` 24 | } 25 | 26 | func (p RelateParentFileOperation) Type() types.OperationType { 27 | return types.OperationTypeRelateParentFile 28 | } 29 | 30 | func (p RelateParentFileOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 31 | if fee, ok := params["fee"]; ok { 32 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 33 | return errors.Annotate(err, "encode Fee") 34 | } 35 | } 36 | 37 | return nil 38 | } 39 | 40 | func (p RelateParentFileOperation) Marshal(enc *util.TypeEncoder) error { 41 | if err := enc.Encode(int8(p.Type())); err != nil { 42 | return errors.Annotate(err, "encode OperationType") 43 | } 44 | 45 | if err := enc.Encode(p.Fee); err != nil { 46 | return errors.Annotate(err, "encode fee") 47 | } 48 | 49 | if err := enc.Encode(p.SubFileOwner); err != nil { 50 | return errors.Annotate(err, "encode SubFileOwner") 51 | } 52 | 53 | if err := enc.Encode(p.ParentFile); err != nil { 54 | return errors.Annotate(err, "encode ParentFile") 55 | } 56 | 57 | if err := enc.Encode(p.ParentFileOwner); err != nil { 58 | return errors.Annotate(err, "encode ParentFileOwner") 59 | } 60 | 61 | if err := enc.Encode(p.SubFile); err != nil { 62 | return errors.Annotate(err, "encode SubFile") 63 | } 64 | 65 | return nil 66 | } 67 | -------------------------------------------------------------------------------- /operations/assetclaimfeesoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetClaimFees] = func() types.Operation { 13 | op := &AssetClaimFeesOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetClaimFeesOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | AmountToClaim types.AssetAmount `json:"amount_to_claim"` 22 | Extensions types.AccountUpdateExtensions `json:"extensions"` 23 | } 24 | 25 | func (p AssetClaimFeesOperation) Type() types.OperationType { 26 | return types.OperationTypeAssetClaimFees 27 | } 28 | 29 | func (p AssetClaimFeesOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | if ppk, ok := params["price_per_kbyte"]; ok { 37 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 38 | return errors.Annotate(err, "encode PricePerKByte") 39 | } 40 | } 41 | 42 | return nil 43 | } 44 | 45 | func (p AssetClaimFeesOperation) Marshal(enc *util.TypeEncoder) error { 46 | if err := enc.Encode(int8(p.Type())); err != nil { 47 | return errors.Annotate(err, "encode OperationType") 48 | } 49 | 50 | if err := enc.Encode(p.Fee); err != nil { 51 | return errors.Annotate(err, "encode Fee") 52 | } 53 | 54 | if err := enc.Encode(p.Issuer); err != nil { 55 | return errors.Annotate(err, "encode Issuer") 56 | } 57 | 58 | if err := enc.Encode(p.AmountToClaim); err != nil { 59 | return errors.Annotate(err, "encode AmountToClaim") 60 | } 61 | 62 | if err := enc.Encode(p.Extensions); err != nil { 63 | return errors.Annotate(err, "encode extensions") 64 | } 65 | 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /operations/updatecollateralforgasoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeUpdateCollateralForGas] = func() types.Operation { 13 | op := &UpdateCollateralForGasOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type UpdateCollateralForGasOperation struct { 19 | types.OperationFee 20 | Mortgager types.AccountID `json:"mortgager"` 21 | Beneficiary types.AccountID `json:"beneficiary"` 22 | Collateral types.Int64 `json:"collateral"` 23 | } 24 | 25 | func (p UpdateCollateralForGasOperation) Type() types.OperationType { 26 | return types.OperationTypeUpdateCollateralForGas 27 | } 28 | 29 | func (p UpdateCollateralForGasOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if fee, ok := params["fee"]; ok { 31 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode Fee") 33 | } 34 | } 35 | 36 | if ppk, ok := params["price_per_kbyte"]; ok { 37 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 38 | return errors.Annotate(err, "encode PricePerKByte") 39 | } 40 | } 41 | 42 | return nil 43 | } 44 | 45 | func (p UpdateCollateralForGasOperation) Marshal(enc *util.TypeEncoder) error { 46 | if err := enc.Encode(int8(p.Type())); err != nil { 47 | return errors.Annotate(err, "encode OperationType") 48 | } 49 | 50 | if err := enc.Encode(p.Fee); err != nil { 51 | return errors.Annotate(err, "encode fee") 52 | } 53 | 54 | if err := enc.Encode(p.Mortgager); err != nil { 55 | return errors.Annotate(err, "encode Mortgager") 56 | } 57 | 58 | if err := enc.Encode(p.Beneficiary); err != nil { 59 | return errors.Annotate(err, "encode Beneficiary") 60 | } 61 | 62 | if err := enc.Encode(p.Collateral); err != nil { 63 | return errors.Annotate(err, "encode Collateral") 64 | } 65 | 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /config/chaincconfig.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "github.com/juju/errors" 5 | ) 6 | 7 | var current *ChainConfig 8 | 9 | type ChainConfig struct { 10 | Name string `json:"name"` 11 | CoreAsset string `json:"core_asset"` 12 | Prefix string `json:"prefix"` 13 | ID string `json:"id"` 14 | } 15 | 16 | const ( 17 | ChainIDUnknown = "0000000000000000000000000000000000000000000000000000000000000000" 18 | ChainIDMainnet = "6057d856c398875cac2650fe33caef3d5f6b403d184c5154abbff526ec1143c4" 19 | ChainIDTestnet = "1ae3653a3105800f5722c5bda2b55530d0e9e8654314e2f3dc6d2b010da641c5" 20 | ChainIDLocal = "9f487f4cca8ababac23d3806a901e9044ab4d82be33cf2abb5cc3185e04fbafd" 21 | ) 22 | 23 | var ( 24 | knownNetworks = []ChainConfig{ 25 | ChainConfig{ 26 | Name: "Unknown", 27 | CoreAsset: "n/a", 28 | Prefix: "n/a", 29 | ID: ChainIDUnknown, 30 | }, 31 | ChainConfig{ 32 | Name: "BCXMainnet", 33 | CoreAsset: "COCOS", 34 | Prefix: "COCOS", 35 | ID: ChainIDMainnet, 36 | }, 37 | ChainConfig{ 38 | Name: "BCXTestnet", 39 | CoreAsset: "COCOS", 40 | Prefix: "COCOS", 41 | ID: ChainIDTestnet, 42 | }, 43 | ChainConfig{ 44 | Name: "BCXLocal", 45 | CoreAsset: "COCOS", 46 | Prefix: "COCOS", 47 | ID: ChainIDLocal, 48 | }, 49 | } 50 | ) 51 | 52 | func Current() *ChainConfig { 53 | return current 54 | } 55 | 56 | func Add(cnf ChainConfig) error { 57 | if FindByID(cnf.ID) != nil { 58 | return errors.Errorf("ChainConfig for ID %q already available", cnf.ID) 59 | } 60 | 61 | knownNetworks = append(knownNetworks, cnf) 62 | return nil 63 | } 64 | 65 | func FindByID(chainID string) *ChainConfig { 66 | for _, cnf := range knownNetworks { 67 | if cnf.ID == chainID { 68 | return &cnf 69 | } 70 | } 71 | 72 | return nil 73 | } 74 | 75 | func SetCurrent(chainID string) error { 76 | current = FindByID(chainID) 77 | if current != nil { 78 | return nil 79 | } 80 | 81 | return errors.Errorf("ChainConfig for ID %q not found", chainID) 82 | } 83 | -------------------------------------------------------------------------------- /operations/fillorderoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeFillOrder] = func() types.Operation { 13 | op := &FillOrderOperation{} 14 | return op 15 | } 16 | } 17 | 18 | //virtual order 19 | type FillOrderOperation struct { 20 | types.OperationFee 21 | OrderID types.ObjectID `json:"order_id"` 22 | AccountID types.AccountID `json:"account_id"` 23 | Pays types.AssetAmount `json:"pays"` 24 | Receives types.AssetAmount `json:"receives"` 25 | FillPrice types.Price `json:"fill_price"` 26 | IsMaker bool `json:"is_maker"` 27 | } 28 | 29 | func (p FillOrderOperation) Type() types.OperationType { 30 | return types.OperationTypeFillOrder 31 | } 32 | 33 | func (p FillOrderOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 34 | return nil 35 | } 36 | 37 | func (p FillOrderOperation) Marshal(enc *util.TypeEncoder) error { 38 | if err := enc.Encode(int8(p.Type())); err != nil { 39 | return errors.Annotate(err, "encode OperationType") 40 | } 41 | 42 | if err := enc.Encode(p.Fee); err != nil { 43 | return errors.Annotate(err, "encode Fee") 44 | } 45 | 46 | if err := enc.Encode(p.OrderID); err != nil { 47 | return errors.Annotate(err, "encode OrderID") 48 | } 49 | 50 | if err := enc.Encode(p.AccountID); err != nil { 51 | return errors.Annotate(err, "encode AccountID") 52 | } 53 | 54 | if err := enc.Encode(p.Pays); err != nil { 55 | return errors.Annotate(err, "encode Pays") 56 | } 57 | 58 | if err := enc.Encode(p.Receives); err != nil { 59 | return errors.Annotate(err, "encode Receives") 60 | } 61 | 62 | if err := enc.Encode(p.FillPrice); err != nil { 63 | return errors.Annotate(err, "encode fillprice") 64 | } 65 | 66 | if err := enc.Encode(p.IsMaker); err != nil { 67 | return errors.Annotate(err, "encode ismaker") 68 | } 69 | 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /types/assetpermission_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=AssetPermission"; DO NOT EDIT. 2 | 3 | package types 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[AssetPermissionChargeMarketFee-1] 12 | _ = x[AssetPermissionWhiteList-2] 13 | _ = x[AssetPermissionOverrideAuthority-4] 14 | _ = x[AssetPermissionTransferRestricted-8] 15 | _ = x[AssetPermissionDisableForceSettle-16] 16 | _ = x[AssetPermissionGlobalSettle-32] 17 | _ = x[AssetPermissionDisableConfidential-64] 18 | _ = x[AssetPermissionWitnessFedAsset-128] 19 | _ = x[AssetPermissionComiteeFedAsset-256] 20 | } 21 | 22 | const ( 23 | _AssetPermission_name_0 = "AssetPermissionChargeMarketFeeAssetPermissionWhiteList" 24 | _AssetPermission_name_1 = "AssetPermissionOverrideAuthority" 25 | _AssetPermission_name_2 = "AssetPermissionTransferRestricted" 26 | _AssetPermission_name_3 = "AssetPermissionDisableForceSettle" 27 | _AssetPermission_name_4 = "AssetPermissionGlobalSettle" 28 | _AssetPermission_name_5 = "AssetPermissionDisableConfidential" 29 | _AssetPermission_name_6 = "AssetPermissionWitnessFedAsset" 30 | _AssetPermission_name_7 = "AssetPermissionComiteeFedAsset" 31 | ) 32 | 33 | var ( 34 | _AssetPermission_index_0 = [...]uint8{0, 30, 54} 35 | ) 36 | 37 | func (i AssetPermission) String() string { 38 | switch { 39 | case 1 <= i && i <= 2: 40 | i -= 1 41 | return _AssetPermission_name_0[_AssetPermission_index_0[i]:_AssetPermission_index_0[i+1]] 42 | case i == 4: 43 | return _AssetPermission_name_1 44 | case i == 8: 45 | return _AssetPermission_name_2 46 | case i == 16: 47 | return _AssetPermission_name_3 48 | case i == 32: 49 | return _AssetPermission_name_4 50 | case i == 64: 51 | return _AssetPermission_name_5 52 | case i == 128: 53 | return _AssetPermission_name_6 54 | case i == 256: 55 | return _AssetPermission_name_7 56 | default: 57 | return "AssetPermission(" + strconv.FormatInt(int64(i), 10) + ")" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /types/fullaccount.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "encoding/json" 7 | 8 | "github.com/juju/errors" 9 | "github.com/pquerna/ffjson/ffjson" 10 | ) 11 | 12 | type FullAccountInfos []FullAccountInfo 13 | 14 | type FullAccountInfo struct { 15 | ID AccountID 16 | AccountInfo AccountInfo 17 | } 18 | 19 | type AccountInfo struct { 20 | Account Account `json:"account"` 21 | RegistrarName String `json:"registrar_name"` 22 | ReferrerName String `json:"referrer_name"` 23 | LifetimeReferrerName String `json:"lifetime_referrer_name"` 24 | CashbackBalance VestingBalance `json:"cashback_balance"` 25 | Balances AccountBalances `json:"balances"` 26 | VestingBalances VestingBalances `json:"vesting_balances"` 27 | LimitOrders LimitOrders `json:"limit_orders"` 28 | CallOrders CallOrders `json:"call_orders"` 29 | SettleOrders ForceSettlementOrders `json:"settle_orders"` 30 | Statistics AccountStatistics `json:"statistics"` 31 | Assets AssetIDs `json:"assets"` 32 | //Proposals []interface{} `json:"proposals"` 33 | //Withdraws []interface{} `json:"withdraws"` 34 | // Votes Votes `json:"votes"` 35 | } 36 | 37 | func (p FullAccountInfo) MarshalJSON() ([]byte, error) { 38 | ret := make([]interface{}, 2) 39 | ret[0] = p.ID.ID() 40 | ret[1] = p.AccountInfo 41 | 42 | return ffjson.Marshal(ret) 43 | } 44 | 45 | func (p *FullAccountInfo) UnmarshalJSON(data []byte) error { 46 | raw := make([]json.RawMessage, 2) 47 | if err := ffjson.Unmarshal(data, &raw); err != nil { 48 | return errors.Annotate(err, "unmarshal [raw]") 49 | } 50 | if err := ffjson.Unmarshal(raw[0], &p.ID); err != nil { 51 | return errors.Annotate(err, "unmarshal [id]") 52 | } 53 | if err := ffjson.Unmarshal(raw[1], &p.AccountInfo); err != nil { 54 | return errors.Annotate(err, "unmarshal [AccountInfo]") 55 | } 56 | 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /operations/witnessupdateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeWitnessUpdate] = func() types.Operation { 13 | op := &WitnessUpdateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type WitnessUpdateOperation struct { 19 | types.OperationFee 20 | Witness types.WitnessID `json:"witness"` 21 | WitnessAccount types.AccountID `json:"witness_account"` 22 | NewSigningKey *types.PublicKey `json:"new_signing_key,omitempty"` 23 | NewURL *string `json:"new_url,omitempty"` 24 | WorkStatus bool `json:"work_status"` 25 | } 26 | 27 | func (p WitnessUpdateOperation) Type() types.OperationType { 28 | return types.OperationTypeWitnessUpdate 29 | } 30 | 31 | func (p WitnessUpdateOperation) Marshal(enc *util.TypeEncoder) error { 32 | if err := enc.Encode(int8(p.Type())); err != nil { 33 | return errors.Annotate(err, "encode OperationType") 34 | } 35 | 36 | if err := enc.Encode(p.Fee); err != nil { 37 | return errors.Annotate(err, "encode fee") 38 | } 39 | 40 | if err := enc.Encode(p.Witness); err != nil { 41 | return errors.Annotate(err, "encode new options") 42 | } 43 | 44 | if err := enc.Encode(p.WitnessAccount); err != nil { 45 | return errors.Annotate(err, "encode WitnessAccount") 46 | } 47 | 48 | if err := enc.Encode(p.NewURL != nil); err != nil { 49 | return errors.Annotate(err, "encode have NewURL") 50 | } 51 | 52 | if err := enc.Encode(p.NewURL); err != nil { 53 | return errors.Annotate(err, "encode NewURL") 54 | } 55 | 56 | if err := enc.Encode(p.NewSigningKey != nil); err != nil { 57 | return errors.Annotate(err, "encode have NewSigningKey") 58 | } 59 | 60 | if err := enc.Encode(p.NewSigningKey); err != nil { 61 | return errors.Annotate(err, "encode NewSigningKey") 62 | } 63 | 64 | if err := enc.Encode(p.WorkStatus); err != nil { 65 | return errors.Annotate(err, "encode WorkStatus") 66 | } 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /operations/accountupgradeoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAccountUpgrade] = func() types.Operation { 13 | op := &AccountUpgradeOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AccountUpgradeOperation struct { 19 | types.OperationFee 20 | AccountToUpgrade types.AccountID `json:"account_to_upgrade"` 21 | UpgradeToLifetimeMember bool `json:"upgrade_to_lifetime_member"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p AccountUpgradeOperation) Type() types.OperationType { 26 | return types.OperationTypeAccountUpgrade 27 | } 28 | 29 | func (p AccountUpgradeOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if maf, ok := params["membership_annual_fee"]; ok { 31 | if err := enc.Encode(types.UInt64(maf.(float64))); err != nil { 32 | return errors.Annotate(err, "encode MembershipAnnualFee") 33 | } 34 | } 35 | if mlf, ok := params["membership_lifetime_fee"]; ok { 36 | if err := enc.Encode(types.UInt64(mlf.(float64))); err != nil { 37 | return errors.Annotate(err, "encode MembershipLifetimeFee") 38 | } 39 | } 40 | 41 | return nil 42 | } 43 | 44 | func (p AccountUpgradeOperation) Marshal(enc *util.TypeEncoder) error { 45 | if err := enc.Encode(int8(p.Type())); err != nil { 46 | return errors.Annotate(err, "encode OperationType") 47 | } 48 | 49 | if err := enc.Encode(p.Fee); err != nil { 50 | return errors.Annotate(err, "encode Fee") 51 | } 52 | 53 | if err := enc.Encode(p.AccountToUpgrade); err != nil { 54 | return errors.Annotate(err, "encode AccountToUpgrade") 55 | } 56 | 57 | if err := enc.Encode(p.UpgradeToLifetimeMember); err != nil { 58 | return errors.Annotate(err, "encode UpgradeToLifetimeMember") 59 | } 60 | 61 | if err := enc.Encode(p.Extensions); err != nil { 62 | return errors.Annotate(err, "encode extensions") 63 | } 64 | 65 | return nil 66 | } 67 | -------------------------------------------------------------------------------- /operations/revisecontractoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeReviseContract] = func() types.Operation { 13 | op := &ReviseContractOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type ReviseContractOperation struct { 19 | types.OperationFee 20 | Reviser types.AccountID `json:"reviser"` 21 | ContractID types.ContractID `json:"contract_id"` 22 | Data string `json:"data"` 23 | Extensions types.Extensions `json:"extensions"` 24 | } 25 | 26 | func (p ReviseContractOperation) Type() types.OperationType { 27 | return types.OperationTypeReviseContract 28 | } 29 | 30 | func (p ReviseContractOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 31 | if fee, ok := params["fee"]; ok { 32 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 33 | return errors.Annotate(err, "encode Fee") 34 | } 35 | } 36 | 37 | if ppk, ok := params["price_per_kbyte"]; ok { 38 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 39 | return errors.Annotate(err, "encode PricePerKByte") 40 | } 41 | } 42 | 43 | return nil 44 | } 45 | 46 | func (p ReviseContractOperation) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.Encode(int8(p.Type())); err != nil { 48 | return errors.Annotate(err, "encode OperationType") 49 | } 50 | 51 | if err := enc.Encode(p.Fee); err != nil { 52 | return errors.Annotate(err, "encode fee") 53 | } 54 | 55 | if err := enc.Encode(p.Reviser); err != nil { 56 | return errors.Annotate(err, "encode Reviser") 57 | } 58 | 59 | if err := enc.Encode(p.ContractID); err != nil { 60 | return errors.Annotate(err, "encode ContractID") 61 | } 62 | 63 | if err := enc.Encode(p.Data); err != nil { 64 | return errors.Annotate(err, "encode Data") 65 | } 66 | 67 | if err := enc.Encode(p.Extensions); err != nil { 68 | return errors.Annotate(err, "encode extensions") 69 | } 70 | 71 | return nil 72 | } 73 | -------------------------------------------------------------------------------- /operations/workercreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeWorkerCreate] = func() types.Operation { 13 | op := &WorkerCreateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type WorkerCreateOperation struct { 19 | types.OperationFee 20 | DailyPay types.UInt64 `json:"daily_pay"` 21 | Initializer types.WorkerInitializer `json:"initializer"` 22 | Name string `json:"name"` 23 | Owner types.AccountID `json:"owner"` 24 | URL string `json:"url"` 25 | WorkBeginDate types.Time `json:"work_begin_date"` 26 | WorkEndDate types.Time `json:"work_end_date"` 27 | } 28 | 29 | func (p WorkerCreateOperation) Type() types.OperationType { 30 | return types.OperationTypeWorkerCreate 31 | } 32 | 33 | func (p WorkerCreateOperation) Marshal(enc *util.TypeEncoder) error { 34 | if err := enc.Encode(int8(p.Type())); err != nil { 35 | return errors.Annotate(err, "encode OperationType") 36 | } 37 | 38 | if err := enc.Encode(p.Fee); err != nil { 39 | return errors.Annotate(err, "encode fee") 40 | } 41 | 42 | if err := enc.Encode(p.Owner); err != nil { 43 | return errors.Annotate(err, "encode Owner") 44 | } 45 | 46 | if err := enc.Encode(p.WorkBeginDate); err != nil { 47 | return errors.Annotate(err, "encode WorkBeginDate") 48 | } 49 | 50 | if err := enc.Encode(p.WorkEndDate); err != nil { 51 | return errors.Annotate(err, "encode WorkEndDate") 52 | } 53 | 54 | if err := enc.Encode(p.DailyPay); err != nil { 55 | return errors.Annotate(err, "encode DailyPay") 56 | } 57 | 58 | if err := enc.Encode(p.Name); err != nil { 59 | return errors.Annotate(err, "encode Name") 60 | } 61 | 62 | if err := enc.Encode(p.URL); err != nil { 63 | return errors.Annotate(err, "encode URL") 64 | } 65 | 66 | if err := enc.Encode(p.Initializer); err != nil { 67 | return errors.Annotate(err, "encode Initializer") 68 | } 69 | 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /operations/accountauthenticationoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAccountAuthentication] = func() types.Operation { 13 | op := &AccountAuthenticationOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AccountAuthenticationOperation struct { 19 | types.OperationFee 20 | AccountID types.AccountID `json:"account_id"` 21 | Data types.String `json:"data"` 22 | Extensions types.Extensions `json:"extensions"` 23 | } 24 | 25 | func (p AccountAuthenticationOperation) Type() types.OperationType { 26 | return types.OperationTypeAccountAuthentication 27 | } 28 | 29 | func (p AccountAuthenticationOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if bfee, ok := params["basic_fee"]; ok { 31 | if err := enc.Encode(types.UInt64(bfee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode BasicFee") 33 | } 34 | } 35 | if pfee, ok := params["premium_fee"]; ok { 36 | if err := enc.Encode(types.UInt64(pfee.(float64))); err != nil { 37 | return errors.Annotate(err, "encode PremiumFee") 38 | } 39 | } 40 | if ppk, ok := params["price_per_kbyte"]; ok { 41 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 42 | return errors.Annotate(err, "encode PricePerKByte") 43 | } 44 | } 45 | 46 | return nil 47 | } 48 | 49 | func (p AccountAuthenticationOperation) Marshal(enc *util.TypeEncoder) error { 50 | if err := enc.Encode(int8(p.Type())); err != nil { 51 | return errors.Annotate(err, "encode Type") 52 | } 53 | if err := enc.Encode(p.Fee); err != nil { 54 | return errors.Annotate(err, "encode Fee") 55 | } 56 | if err := enc.Encode(p.AccountID); err != nil { 57 | return errors.Annotate(err, "encode AccountID") 58 | } 59 | 60 | if err := enc.Encode(p.Data); err != nil { 61 | return errors.Annotate(err, "encode Data") 62 | } 63 | 64 | if err := enc.Encode(p.Extensions); err != nil { 65 | return errors.Annotate(err, "encode Extensions") 66 | } 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /operations/addfilerelateaccountoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAddFileRelateAccount] = func() types.Operation { 13 | op := &AddFileRelateAccountOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AddFileRelateAccountOperation struct { 19 | types.OperationFee 20 | FileOwner types.AccountID `json:"file_owner"` 21 | FileID types.FileID `json:"file_id"` 22 | RelatedAccount types.AccountIDArray `json:"related_account"` 23 | } 24 | 25 | func (p AddFileRelateAccountOperation) Type() types.OperationType { 26 | return types.OperationTypeAddFileRelateAccount 27 | } 28 | 29 | func (p AddFileRelateAccountOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 30 | if bfee, ok := params["basic_fee"]; ok { 31 | if err := enc.Encode(types.UInt64(bfee.(float64))); err != nil { 32 | return errors.Annotate(err, "encode BasicFee") 33 | } 34 | } 35 | if pfee, ok := params["premium_fee"]; ok { 36 | if err := enc.Encode(types.UInt64(pfee.(float64))); err != nil { 37 | return errors.Annotate(err, "encode PremiumFee") 38 | } 39 | } 40 | if ppk, ok := params["price_per_kbyte"]; ok { 41 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 42 | return errors.Annotate(err, "encode PricePerKByte") 43 | } 44 | } 45 | 46 | return nil 47 | } 48 | 49 | func (p AddFileRelateAccountOperation) Marshal(enc *util.TypeEncoder) error { 50 | if err := enc.Encode(int8(p.Type())); err != nil { 51 | return errors.Annotate(err, "encode Type") 52 | } 53 | if err := enc.Encode(p.Fee); err != nil { 54 | return errors.Annotate(err, "encode Fee") 55 | } 56 | if err := enc.Encode(p.FileOwner); err != nil { 57 | return errors.Annotate(err, "encode FileOwner") 58 | } 59 | 60 | if err := enc.Encode(p.FileID); err != nil { 61 | return errors.Annotate(err, "encode FileID") 62 | } 63 | 64 | if err := enc.Encode(p.RelatedAccount); err != nil { 65 | return errors.Annotate(err, "encode RelatedAccount") 66 | } 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /api/rpcclient.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "math/rand" 7 | "net/http" 8 | "time" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/juju/errors" 12 | "github.com/pquerna/ffjson/ffjson" 13 | ) 14 | 15 | //RPCClient allows you to access wallett functions 16 | type RPCClient interface { 17 | CallAPI(method string, args ...interface{}) (*json.RawMessage, error) 18 | Close() error 19 | Connect() error 20 | } 21 | 22 | type rpcClient struct { 23 | *http.Client 24 | *ffjson.Encoder 25 | *ffjson.Decoder 26 | encBuf *bytes.Buffer 27 | endpointURL string 28 | timeout int 29 | } 30 | 31 | func (p *rpcClient) Connect() error { 32 | p.Client = &http.Client{ 33 | Timeout: 10 * time.Second, 34 | } 35 | 36 | p.encBuf = new(bytes.Buffer) 37 | p.Encoder = ffjson.NewEncoder(p.encBuf) 38 | p.Decoder = ffjson.NewDecoder() 39 | 40 | return nil 41 | } 42 | 43 | func (p *rpcClient) Close() error { 44 | return nil 45 | } 46 | 47 | func (p *rpcClient) CallAPI(method string, args ...interface{}) (*json.RawMessage, error) { 48 | req := rpcRequest{ 49 | Method: method, 50 | ID: uint64(rand.Uint64()), 51 | Params: args, 52 | } 53 | 54 | if err := p.Encode(req); err != nil { 55 | return nil, errors.Annotate(err, "Encode") 56 | } 57 | 58 | logging.DDumpJSON("rpc req >", req) 59 | 60 | r, err := http.NewRequest("POST", p.endpointURL, p.encBuf) 61 | if err != nil { 62 | return nil, errors.Annotate(err, "NewRequest") 63 | } 64 | 65 | r.Close = true 66 | r.Header.Set("Content-Type", "application/json") 67 | r.Header.Set("Accept", "application/json") 68 | 69 | resp, err := p.Do(r) 70 | if err != nil { 71 | return nil, errors.Annotate(err, "do request") 72 | } 73 | 74 | defer resp.Body.Close() 75 | 76 | var ret rpcResponseString 77 | if err := p.DecodeReader(resp.Body, &ret); err != nil { 78 | return nil, errors.Annotate(err, "Decode") 79 | } 80 | 81 | if ret.Error != nil { 82 | return nil, ret.Error 83 | } 84 | 85 | logging.DDumpJSON("rpc resp <", ret.Result) 86 | return ret.Result, nil 87 | } 88 | 89 | //NewRPCClient creates a new RPC Client 90 | func NewRPCClient(rpcEndpointURL string) RPCClient { 91 | cli := rpcClient{ 92 | endpointURL: rpcEndpointURL, 93 | } 94 | 95 | return &cli 96 | } 97 | -------------------------------------------------------------------------------- /gen/templates/objectid.go.tmpl: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/cheekybits/genny/generic" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/Cocos-BCX/cocos-go/logging" 9 | "github.com/juju/errors" 10 | ) 11 | 12 | type T1 generic.Type 13 | 14 | type T1ID struct { 15 | ObjectID 16 | } 17 | 18 | func (p T1ID) Marshal(enc *util.TypeEncoder) error { 19 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 20 | if err != nil { 21 | return errors.Annotate(err, "encode instance") 22 | } 23 | 24 | for i := 0; i < 8-n; i++ { 25 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 26 | return errors.Annotate(err, "encode zero") 27 | } 28 | } 29 | 30 | return nil 31 | } 32 | 33 | func (p *T1ID) Unmarshal(dec *util.TypeDecoder) error { 34 | var instance uint64 35 | if err := dec.DecodeUVarint(&instance); err != nil { 36 | return errors.Annotate(err, "decode instance") 37 | } 38 | 39 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeT1) << 48) | instance) 40 | return nil 41 | } 42 | 43 | type T1IDs []T1ID 44 | 45 | func (p T1IDs) Marshal(enc *util.TypeEncoder) error { 46 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 47 | return errors.Annotate(err, "encode length") 48 | } 49 | 50 | for _, ex := range p { 51 | if err := enc.Encode(ex); err != nil { 52 | return errors.Annotate(err, "encode T1ID") 53 | } 54 | } 55 | 56 | return nil 57 | } 58 | 59 | func T1IDFromObject(ob GrapheneObject) T1ID { 60 | id, ok := ob.(*T1ID) 61 | if ok { 62 | return *id 63 | } 64 | 65 | p := T1ID{} 66 | p.MustFromObject(ob) 67 | if p.ObjectType() != ObjectTypeT1 { 68 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeT1'", p.ID())) 69 | } 70 | 71 | return p 72 | } 73 | 74 | //NewT1ID creates an new T1ID object 75 | func NewT1ID(id string) GrapheneObject { 76 | gid := new(T1ID) 77 | if err := gid.Parse(id); err != nil { 78 | logging.Errorf( 79 | "T1ID parser error %v", 80 | errors.Annotate(err, "Parse"), 81 | ) 82 | return nil 83 | } 84 | 85 | if gid.ObjectType() != ObjectTypeT1 { 86 | logging.Errorf( 87 | "T1ID parser error %s", 88 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeT1'", id), 89 | ) 90 | return nil 91 | } 92 | 93 | return gid 94 | } 95 | -------------------------------------------------------------------------------- /operations/contractcreateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeContractCreate] = func() types.Operation { 13 | op := &ContractCreateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type ContractCreateOperation struct { 19 | types.OperationFee 20 | Owner types.AccountID `json:"owner"` 21 | Name string `json:"name"` 22 | Data string `json:"data"` 23 | ContractAuthority types.PublicKey `json:"contract_authority"` 24 | Extensions types.Extensions `json:"extensions"` 25 | } 26 | 27 | func (p ContractCreateOperation) Type() types.OperationType { 28 | return types.OperationTypeContractCreate 29 | } 30 | 31 | func (p ContractCreateOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 32 | if fee, ok := params["fee"]; ok { 33 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 34 | return errors.Annotate(err, "encode Fee") 35 | } 36 | } 37 | 38 | if ppk, ok := params["price_per_kbyte"]; ok { 39 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 40 | return errors.Annotate(err, "encode PricePerKByte") 41 | } 42 | } 43 | 44 | return nil 45 | } 46 | 47 | func (p ContractCreateOperation) Marshal(enc *util.TypeEncoder) error { 48 | if err := enc.Encode(int8(p.Type())); err != nil { 49 | return errors.Annotate(err, "encode OperationType") 50 | } 51 | 52 | if err := enc.Encode(p.Fee); err != nil { 53 | return errors.Annotate(err, "encode fee") 54 | } 55 | 56 | if err := enc.Encode(p.Owner); err != nil { 57 | return errors.Annotate(err, "encode Owner") 58 | } 59 | 60 | if err := enc.Encode(p.Name); err != nil { 61 | return errors.Annotate(err, "encode Name") 62 | } 63 | 64 | if err := enc.Encode(p.Data); err != nil { 65 | return errors.Annotate(err, "encode Data") 66 | } 67 | 68 | if err := enc.Encode(p.ContractAuthority); err != nil { 69 | return errors.Annotate(err, "encode ContractAuthority") 70 | } 71 | 72 | if err := enc.Encode(p.Extensions); err != nil { 73 | return errors.Annotate(err, "encode extensions") 74 | } 75 | 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /types/dynamicglobalproperties.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "bytes" 5 | "encoding/binary" 6 | "encoding/hex" 7 | 8 | "github.com/juju/errors" 9 | ) 10 | 11 | //go:generate ffjson $GOFILE 12 | 13 | type VariantInt interface{} 14 | 15 | type DynamicGlobalProperties struct { 16 | ID DynamicGlobalPropertyID `json:"id"` 17 | HeadBlockNumber UInt32 `json:"head_block_number"` 18 | HeadBlockID string `json:"head_block_id"` 19 | Time Time `json:"time"` 20 | CurrentWitness WitnessID `json:"current_witness"` 21 | CurrentTransactionCount UInt32 `json:"current_transaction_count"` 22 | NextMaintenanceTime Time `json:"next_maintenance_time"` 23 | LastBudgetTime Time `json:"last_budget_time"` 24 | WitnessBudget VariantInt `json:"witness_budget"` 25 | AccountsRegisteredThisInterval int `json:"accounts_registered_this_interval"` 26 | RecentlyMissedCount int64 `json:"recently_missed_count"` 27 | CurrentAslot int64 `json:"current_aslot"` 28 | RecentSlotsFilled string `json:"recent_slots_filled"` 29 | DynamicFlags int `json:"dynamic_flags"` 30 | LastIrreversibleBlockNum UInt32 `json:"last_irreversible_block_num"` 31 | } 32 | 33 | func (p DynamicGlobalProperties) RefBlockNum() UInt16 { 34 | return UInt16(p.HeadBlockNumber) 35 | } 36 | 37 | func (p DynamicGlobalProperties) RefBlockPrefix() (UInt32, error) { 38 | rawBlockID, err := hex.DecodeString(p.HeadBlockID) 39 | if err != nil { 40 | return 0, errors.Annotatef(err, "DecodeString HeadBlockID: %v", p.HeadBlockID) 41 | } 42 | 43 | if len(rawBlockID) < 8 { 44 | return 0, errors.Errorf("invalid HeadBlockID: %v", p.HeadBlockID) 45 | } 46 | 47 | rawPrefix := rawBlockID[4:8] 48 | 49 | var prefix uint32 50 | if err := binary.Read(bytes.NewReader(rawPrefix), binary.LittleEndian, &prefix); err != nil { 51 | return 0, errors.Annotatef(err, "failed to read block prefix: %v", rawPrefix) 52 | } 53 | 54 | return UInt32(prefix), nil 55 | } 56 | -------------------------------------------------------------------------------- /operations/createnhassetoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCreateNhAsset] = func() types.Operation { 13 | op := &CreateNhAssetOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CreateNhAssetOperation struct { 19 | types.OperationFee 20 | FeePayingAccount types.AccountID `json:"fee_paying_account"` 21 | Owner types.AccountID `json:"owner"` 22 | AssetID string `json:"asset_id"` 23 | WorldView string `json:"world_view"` 24 | BaseDescribe string `json:"base_describe"` 25 | Collateral types.Int64 `json:"collateral"` 26 | } 27 | 28 | func (p CreateNhAssetOperation) Type() types.OperationType { 29 | return types.OperationTypeCreateNhAsset 30 | } 31 | 32 | func (p CreateNhAssetOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 33 | if fee, ok := params["fee"]; ok { 34 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 35 | return errors.Annotate(err, "encode Fee") 36 | } 37 | } 38 | 39 | if ppk, ok := params["price_per_kbyte"]; ok { 40 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 41 | return errors.Annotate(err, "encode PricePerKByte") 42 | } 43 | } 44 | 45 | return nil 46 | } 47 | 48 | func (p CreateNhAssetOperation) Marshal(enc *util.TypeEncoder) error { 49 | if err := enc.Encode(int8(p.Type())); err != nil { 50 | return errors.Annotate(err, "encode OperationType") 51 | } 52 | 53 | if err := enc.Encode(p.Fee); err != nil { 54 | return errors.Annotate(err, "encode fee") 55 | } 56 | 57 | if err := enc.Encode(p.FeePayingAccount); err != nil { 58 | return errors.Annotate(err, "encode FeePayingAccount") 59 | } 60 | 61 | if err := enc.Encode(p.Owner); err != nil { 62 | return errors.Annotate(err, "encode Owner") 63 | } 64 | 65 | if err := enc.Encode(p.AssetID); err != nil { 66 | return errors.Annotate(err, "encode AssetID") 67 | } 68 | 69 | if err := enc.Encode(p.WorldView); err != nil { 70 | return errors.Annotate(err, "encode WorldView") 71 | } 72 | 73 | if err := enc.Encode(p.BaseDescribe); err != nil { 74 | return errors.Annotate(err, "encode BaseDescribe") 75 | } 76 | 77 | return nil 78 | } 79 | -------------------------------------------------------------------------------- /types/gen_fileid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type FileID struct { 16 | ObjectID 17 | } 18 | 19 | func (p FileID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *FileID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeFile) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type FileIDs []FileID 45 | 46 | func (p FileIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode FileID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func FileIDFromObject(ob GrapheneObject) FileID { 61 | id, ok := ob.(*FileID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := FileID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeFile { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeFile'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewFileID creates an new FileID object 76 | func NewFileID(id string) GrapheneObject { 77 | gid := new(FileID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "FileID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeFile { 87 | logging.Errorf( 88 | "FileID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeFile'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_assetid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type AssetID struct { 16 | ObjectID 17 | } 18 | 19 | func (p AssetID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *AssetID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeAsset) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type AssetIDs []AssetID 45 | 46 | func (p AssetIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode AssetID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func AssetIDFromObject(ob GrapheneObject) AssetID { 61 | id, ok := ob.(*AssetID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := AssetID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeAsset { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeAsset'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewAssetID creates an new AssetID object 76 | func NewAssetID(id string) GrapheneObject { 77 | gid := new(AssetID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "AssetID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeAsset { 87 | logging.Errorf( 88 | "AssetID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeAsset'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /operations/assetissueoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetIssue] = func() types.Operation { 13 | op := &AssetIssueOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetIssueOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | IssueToAccount types.AccountID `json:"issue_to_account"` 22 | AssetToIssue types.AssetAmount `json:"asset_to_issue"` 23 | Memo types.MemoPair `json:"memo,omitempty"` 24 | Extensions types.Extensions `json:"extensions"` 25 | } 26 | 27 | func (p AssetIssueOperation) Type() types.OperationType { 28 | return types.OperationTypeAssetIssue 29 | } 30 | 31 | func (p AssetIssueOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 32 | if fee, ok := params["fee"]; ok { 33 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 34 | return errors.Annotate(err, "encode Fee") 35 | } 36 | } 37 | 38 | if ppk, ok := params["price_per_kbyte"]; ok { 39 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 40 | return errors.Annotate(err, "encode PricePerKByte") 41 | } 42 | } 43 | 44 | return nil 45 | } 46 | 47 | func (p AssetIssueOperation) Marshal(enc *util.TypeEncoder) error { 48 | if err := enc.Encode(int8(p.Type())); err != nil { 49 | return errors.Annotate(err, "encode OperationType") 50 | } 51 | 52 | if err := enc.Encode(p.Fee); err != nil { 53 | return errors.Annotate(err, "encode fee") 54 | } 55 | 56 | if err := enc.Encode(p.Issuer); err != nil { 57 | return errors.Annotate(err, "encode issuer") 58 | } 59 | 60 | if err := enc.Encode(p.AssetToIssue); err != nil { 61 | return errors.Annotate(err, "encode asset to issue") 62 | } 63 | 64 | if err := enc.Encode(p.IssueToAccount); err != nil { 65 | return errors.Annotate(err, "encode issue to account") 66 | } 67 | 68 | if err := enc.Encode(p.Memo != nil); err != nil { 69 | return errors.Annotate(err, "encode have memo") 70 | } 71 | 72 | if err := enc.Encode(p.Memo); err != nil { 73 | return errors.Annotate(err, "encode memo") 74 | } 75 | 76 | if err := enc.Encode(p.Extensions); err != nil { 77 | return errors.Annotate(err, "encode extensions") 78 | } 79 | 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /operations/callcontractfunctionoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCallContractFunction] = func() types.Operation { 13 | op := &ReviseContractOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type LuaTypes struct { 19 | } 20 | 21 | type LuaTypesVec []LuaTypes 22 | 23 | type CallContractFunctionOperation struct { 24 | types.OperationFee 25 | Caller types.AccountID `json:"caller"` 26 | ContractID types.ContractID `json:"contract_id"` 27 | FunctionName string `json:"function_name"` 28 | ValueList LuaTypesVec `json:"value_list"` 29 | Extensions types.Extensions `json:"extensions"` 30 | } 31 | 32 | func (p CallContractFunctionOperation) Type() types.OperationType { 33 | return types.OperationTypeCallContractFunction 34 | } 35 | 36 | func (p CallContractFunctionOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 37 | if fee, ok := params["fee"]; ok { 38 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 39 | return errors.Annotate(err, "encode Fee") 40 | } 41 | } 42 | 43 | if ppk, ok := params["price_per_kbyte"]; ok { 44 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 45 | return errors.Annotate(err, "encode PricePerKByte") 46 | } 47 | } 48 | 49 | return nil 50 | } 51 | 52 | func (p CallContractFunctionOperation) Marshal(enc *util.TypeEncoder) error { 53 | if err := enc.Encode(int8(p.Type())); err != nil { 54 | return errors.Annotate(err, "encode OperationType") 55 | } 56 | 57 | if err := enc.Encode(p.Fee); err != nil { 58 | return errors.Annotate(err, "encode fee") 59 | } 60 | 61 | if err := enc.Encode(p.Caller); err != nil { 62 | return errors.Annotate(err, "encode Caller") 63 | } 64 | 65 | if err := enc.Encode(p.ContractID); err != nil { 66 | return errors.Annotate(err, "encode ContractID") 67 | } 68 | 69 | if err := enc.Encode(p.FunctionName); err != nil { 70 | return errors.Annotate(err, "encode FunctionName") 71 | } 72 | 73 | if err := enc.Encode(p.ValueList); err != nil { 74 | return errors.Annotate(err, "encode ValueList") 75 | } 76 | 77 | if err := enc.Encode(p.Extensions); err != nil { 78 | return errors.Annotate(err, "encode extensions") 79 | } 80 | 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /types/gen_customid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type CustomID struct { 16 | ObjectID 17 | } 18 | 19 | func (p CustomID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *CustomID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeCustom) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type CustomIDs []CustomID 45 | 46 | func (p CustomIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode CustomID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func CustomIDFromObject(ob GrapheneObject) CustomID { 61 | id, ok := ob.(*CustomID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := CustomID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeCustom { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeCustom'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewCustomID creates an new CustomID object 76 | func NewCustomID(id string) GrapheneObject { 77 | gid := new(CustomID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "CustomID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeCustom { 87 | logging.Errorf( 88 | "CustomID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeCustom'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_workerid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type WorkerID struct { 16 | ObjectID 17 | } 18 | 19 | func (p WorkerID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *WorkerID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeWorker) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type WorkerIDs []WorkerID 45 | 46 | func (p WorkerIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode WorkerID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func WorkerIDFromObject(ob GrapheneObject) WorkerID { 61 | id, ok := ob.(*WorkerID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := WorkerID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeWorker { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeWorker'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewWorkerID creates an new WorkerID object 76 | func NewWorkerID(id string) GrapheneObject { 77 | gid := new(WorkerID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "WorkerID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeWorker { 87 | logging.Errorf( 88 | "WorkerID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeWorker'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /operations/assetupdateoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetUpdate] = func() types.Operation { 13 | op := &AssetUpdateOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type AssetUpdateOperation struct { 19 | types.OperationFee 20 | Issuer types.AccountID `json:"issuer"` 21 | AssetToUpdate types.AssetID `json:"asset_to_update"` 22 | NewIssuer *types.AccountID `json:"new_issuer,omitempty"` 23 | NewOptions types.AssetOptions `json:"new_options"` 24 | Extensions types.Extensions `json:"extensions"` 25 | } 26 | 27 | func (p AssetUpdateOperation) Type() types.OperationType { 28 | return types.OperationTypeAssetUpdate 29 | } 30 | 31 | func (p AssetUpdateOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 32 | if fee, ok := params["fee"]; ok { 33 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 34 | return errors.Annotate(err, "encode Fee") 35 | } 36 | } 37 | 38 | if ppk, ok := params["price_per_kbyte"]; ok { 39 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 40 | return errors.Annotate(err, "encode PricePerKByte") 41 | } 42 | } 43 | 44 | return nil 45 | } 46 | 47 | func (p AssetUpdateOperation) Marshal(enc *util.TypeEncoder) error { 48 | if err := enc.Encode(int8(p.Type())); err != nil { 49 | return errors.Annotate(err, "encode OperationType") 50 | } 51 | 52 | if err := enc.Encode(p.Fee); err != nil { 53 | return errors.Annotate(err, "encode Fee") 54 | } 55 | 56 | if err := enc.Encode(p.Issuer); err != nil { 57 | return errors.Annotate(err, "encode Issuer") 58 | } 59 | 60 | if err := enc.Encode(p.AssetToUpdate); err != nil { 61 | return errors.Annotate(err, "encode AssetToUpdate") 62 | } 63 | 64 | if err := enc.Encode(p.NewIssuer != nil); err != nil { 65 | return errors.Annotate(err, "encode have NewIssuer") 66 | } 67 | 68 | if err := enc.Encode(p.NewIssuer); err != nil { 69 | return errors.Annotate(err, "NewIssuer") 70 | } 71 | 72 | if err := enc.Encode(p.NewOptions); err != nil { 73 | return errors.Annotate(err, "encode new NewOptions") 74 | } 75 | 76 | if err := enc.Encode(p.Extensions); err != nil { 77 | return errors.Annotate(err, "encode Extensions") 78 | } 79 | 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /types/gen_accountid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type AccountID struct { 16 | ObjectID 17 | } 18 | 19 | func (p AccountID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *AccountID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeAccount) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type AccountIDs []AccountID 45 | 46 | func (p AccountIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode AccountID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func AccountIDFromObject(ob GrapheneObject) AccountID { 61 | id, ok := ob.(*AccountID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := AccountID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeAccount { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeAccount'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewAccountID creates an new AccountID object 76 | func NewAccountID(id string) GrapheneObject { 77 | gid := new(AccountID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "AccountID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeAccount { 87 | logging.Errorf( 88 | "AccountID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeAccount'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_balanceid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type BalanceID struct { 16 | ObjectID 17 | } 18 | 19 | func (p BalanceID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *BalanceID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeBalance) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type BalanceIDs []BalanceID 45 | 46 | func (p BalanceIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode BalanceID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func BalanceIDFromObject(ob GrapheneObject) BalanceID { 61 | id, ok := ob.(*BalanceID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := BalanceID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeBalance { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeBalance'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewBalanceID creates an new BalanceID object 76 | func NewBalanceID(id string) GrapheneObject { 77 | gid := new(BalanceID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "BalanceID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeBalance { 87 | logging.Errorf( 88 | "BalanceID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeBalance'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_nhassetid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type NHAssetID struct { 16 | ObjectID 17 | } 18 | 19 | func (p NHAssetID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *NHAssetID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeNHAsset) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type NHAssetIDs []NHAssetID 45 | 46 | func (p NHAssetIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode NHAssetID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func NHAssetIDFromObject(ob GrapheneObject) NHAssetID { 61 | id, ok := ob.(*NHAssetID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := NHAssetID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeNHAsset { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeNHAsset'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewNHAssetID creates an new NHAssetID object 76 | func NewNHAssetID(id string) GrapheneObject { 77 | gid := new(NHAssetID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "NHAssetID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeNHAsset { 87 | logging.Errorf( 88 | "NHAssetID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeNHAsset'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_witnessid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type WitnessID struct { 16 | ObjectID 17 | } 18 | 19 | func (p WitnessID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *WitnessID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeWitness) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type WitnessIDs []WitnessID 45 | 46 | func (p WitnessIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode WitnessID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func WitnessIDFromObject(ob GrapheneObject) WitnessID { 61 | id, ok := ob.(*WitnessID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := WitnessID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeWitness { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeWitness'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewWitnessID creates an new WitnessID object 76 | func NewWitnessID(id string) GrapheneObject { 77 | gid := new(WitnessID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "WitnessID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeWitness { 87 | logging.Errorf( 88 | "WitnessID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeWitness'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_contractid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type ContractID struct { 16 | ObjectID 17 | } 18 | 19 | func (p ContractID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *ContractID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeContract) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type ContractIDs []ContractID 45 | 46 | func (p ContractIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode ContractID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func ContractIDFromObject(ob GrapheneObject) ContractID { 61 | id, ok := ob.(*ContractID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := ContractID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeContract { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeContract'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewContractID creates an new ContractID object 76 | func NewContractID(id string) GrapheneObject { 77 | gid := new(ContractID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "ContractID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeContract { 87 | logging.Errorf( 88 | "ContractID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeContract'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_proposalid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type ProposalID struct { 16 | ObjectID 17 | } 18 | 19 | func (p ProposalID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *ProposalID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeProposal) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type ProposalIDs []ProposalID 45 | 46 | func (p ProposalIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode ProposalID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func ProposalIDFromObject(ob GrapheneObject) ProposalID { 61 | id, ok := ob.(*ProposalID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := ProposalID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeProposal { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeProposal'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewProposalID creates an new ProposalID object 76 | func NewProposalID(id string) GrapheneObject { 77 | gid := new(ProposalID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "ProposalID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeProposal { 87 | logging.Errorf( 88 | "ProposalID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeProposal'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/bitassetdata.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "github.com/Cocos-BCX/cocos-go/util" 5 | "github.com/juju/errors" 6 | ) 7 | 8 | //go:generate ffjson $GOFILE 9 | 10 | type BitassetOptions struct { 11 | FeedLifetimeSec UInt32 `json:"feed_lifetime_sec"` 12 | MinimumFeeds UInt8 `json:"minimum_feeds"` 13 | ForceSettlementDelaySec UInt32 `json:"force_settlement_delay_sec"` 14 | ForceSettlementOffsetPercent UInt16 `json:"force_settlement_offset_percent"` 15 | MaximumForceSettlementVolume UInt16 `json:"maximum_force_settlement_volume"` 16 | ShortBackingAsset AssetID `json:"short_backing_asset"` 17 | Extensions Extensions `json:"extensions"` 18 | } 19 | 20 | func (p BitassetOptions) Marshal(enc *util.TypeEncoder) error { 21 | if err := enc.Encode(p.FeedLifetimeSec); err != nil { 22 | return errors.Annotate(err, "encode FeedLifetimeSec") 23 | } 24 | 25 | if err := enc.Encode(p.MinimumFeeds); err != nil { 26 | return errors.Annotate(err, "encode MinimumFeeds") 27 | } 28 | 29 | if err := enc.Encode(p.ForceSettlementDelaySec); err != nil { 30 | return errors.Annotate(err, "encode ForceSettlementDelaySec") 31 | } 32 | 33 | if err := enc.Encode(p.ForceSettlementOffsetPercent); err != nil { 34 | return errors.Annotate(err, "encode ForceSettlementOffsetPercent") 35 | } 36 | 37 | if err := enc.Encode(p.MaximumForceSettlementVolume); err != nil { 38 | return errors.Annotate(err, "encode MaximumForceSettlementVolume") 39 | } 40 | 41 | if err := enc.Encode(p.ShortBackingAsset); err != nil { 42 | return errors.Annotate(err, "encode ShortBackingAsset") 43 | } 44 | 45 | if err := enc.Encode(p.Extensions); err != nil { 46 | return errors.Annotate(err, "encode Extensions") 47 | } 48 | 49 | return nil 50 | } 51 | 52 | type BitAssetData struct { 53 | ID AssetBitAssetDataID `json:"id"` 54 | MembershipExpirationDate Time `json:"current_feed_publication_time"` 55 | IsPredictionMarket bool `json:"is_prediction_market"` 56 | SettlementPrice Price `json:"settlement_price"` 57 | Feeds AssetFeeds `json:"feeds"` 58 | Options BitassetOptions `json:"options"` 59 | CurrentFeed PriceFeed `json:"current_feed"` 60 | ForcedSettledVolume UInt64 `json:"force_settled_volume"` 61 | SettlementFund UInt64 `json:"settlement_fund"` 62 | } 63 | -------------------------------------------------------------------------------- /types/gen_callorderid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type CallOrderID struct { 16 | ObjectID 17 | } 18 | 19 | func (p CallOrderID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *CallOrderID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeCallOrder) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type CallOrderIDs []CallOrderID 45 | 46 | func (p CallOrderIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode CallOrderID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func CallOrderIDFromObject(ob GrapheneObject) CallOrderID { 61 | id, ok := ob.(*CallOrderID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := CallOrderID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeCallOrder { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeCallOrder'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewCallOrderID creates an new CallOrderID object 76 | func NewCallOrderID(id string) GrapheneObject { 77 | gid := new(CallOrderID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "CallOrderID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeCallOrder { 87 | logging.Errorf( 88 | "CallOrderID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeCallOrder'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /operations/createnhassetorderoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeCreateNhAssetOrder] = func() types.Operation { 13 | op := &CreateNhAssetOrderOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type CreateNhAssetOrderOperation struct { 19 | types.OperationFee 20 | Seller types.AccountID `json:"seller"` 21 | OTCAccount types.AccountID `json:"otcaccount"` 22 | PendingOrdersFee types.AssetAmount `json:"pending_orders_fee"` 23 | NHAsset types.NHAssetID `json:"nh_asset"` 24 | Memo string `json:"memo"` 25 | Price types.AssetAmount `json:"price"` 26 | Expiration types.Time `json:"expiration"` 27 | } 28 | 29 | func (p CreateNhAssetOrderOperation) Type() types.OperationType { 30 | return types.OperationTypeCreateNhAssetOrder 31 | } 32 | 33 | func (p CreateNhAssetOrderOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 34 | if fee, ok := params["fee"]; ok { 35 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 36 | return errors.Annotate(err, "encode Fee") 37 | } 38 | } 39 | 40 | return nil 41 | } 42 | 43 | func (p CreateNhAssetOrderOperation) Marshal(enc *util.TypeEncoder) error { 44 | if err := enc.Encode(int8(p.Type())); err != nil { 45 | return errors.Annotate(err, "encode OperationType") 46 | } 47 | 48 | if err := enc.Encode(p.Fee); err != nil { 49 | return errors.Annotate(err, "encode fee") 50 | } 51 | 52 | if err := enc.Encode(p.Seller); err != nil { 53 | return errors.Annotate(err, "encode Seller") 54 | } 55 | 56 | if err := enc.Encode(p.OTCAccount); err != nil { 57 | return errors.Annotate(err, "encode OTCAccount") 58 | } 59 | 60 | if err := enc.Encode(p.PendingOrdersFee); err != nil { 61 | return errors.Annotate(err, "encode PendingOrdersFee") 62 | } 63 | 64 | if err := enc.Encode(p.NHAsset); err != nil { 65 | return errors.Annotate(err, "encode NHAsset") 66 | } 67 | 68 | if err := enc.Encode(p.Memo); err != nil { 69 | return errors.Annotate(err, "encode Memo") 70 | } 71 | 72 | if err := enc.Encode(p.Price); err != nil { 73 | return errors.Annotate(err, "encode Price") 74 | } 75 | 76 | if err := enc.Encode(p.Expiration); err != nil { 77 | return errors.Annotate(err, "encode Expiration") 78 | } 79 | 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /types/gen_limitorderid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type LimitOrderID struct { 16 | ObjectID 17 | } 18 | 19 | func (p LimitOrderID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *LimitOrderID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeLimitOrder) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type LimitOrderIDs []LimitOrderID 45 | 46 | func (p LimitOrderIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode LimitOrderID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func LimitOrderIDFromObject(ob GrapheneObject) LimitOrderID { 61 | id, ok := ob.(*LimitOrderID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := LimitOrderID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeLimitOrder { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeLimitOrder'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewLimitOrderID creates an new LimitOrderID object 76 | func NewLimitOrderID(id string) GrapheneObject { 77 | gid := new(LimitOrderID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "LimitOrderID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeLimitOrder { 87 | logging.Errorf( 88 | "LimitOrderID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeLimitOrder'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_transactionid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type TransactionID struct { 16 | ObjectID 17 | } 18 | 19 | func (p TransactionID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *TransactionID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeTransaction) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type TransactionIDs []TransactionID 45 | 46 | func (p TransactionIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode TransactionID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func TransactionIDFromObject(ob GrapheneObject) TransactionID { 61 | id, ok := ob.(*TransactionID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := TransactionID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeTransaction { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeTransaction'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewTransactionID creates an new TransactionID object 76 | func NewTransactionID(id string) GrapheneObject { 77 | gid := new(TransactionID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "TransactionID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeTransaction { 87 | logging.Errorf( 88 | "TransactionID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeTransaction'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /operations/transferoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeTransfer] = func() types.Operation { 13 | op := &TransferOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type TransferOperation struct { 19 | types.OperationFee 20 | From types.AccountID `json:"from"` 21 | To types.AccountID `json:"to"` 22 | Amount types.AssetAmount `json:"amount"` 23 | Memo types.MemoPair `json:"memo,omitempty"` 24 | Extensions types.Extensions `json:"extensions"` 25 | } 26 | 27 | func (p TransferOperation) Type() types.OperationType { 28 | return types.OperationTypeTransfer 29 | } 30 | 31 | func (p TransferOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 32 | if fee, ok := params["fee"]; ok { 33 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 34 | return errors.Annotate(err, "encode Fee") 35 | } 36 | } 37 | 38 | if ppk, ok := params["price_per_kbyte"]; ok { 39 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 40 | return errors.Annotate(err, "encode PricePerKByte") 41 | } 42 | } 43 | 44 | return nil 45 | } 46 | 47 | func (p TransferOperation) Marshal(enc *util.TypeEncoder) error { 48 | if err := enc.Encode(int8(p.Type())); err != nil { 49 | return errors.Annotate(err, "encode OperationType") 50 | } 51 | 52 | if err := enc.Encode(p.Fee); err != nil { 53 | return errors.Annotate(err, "encode fee") 54 | } 55 | 56 | if err := enc.Encode(p.From); err != nil { 57 | return errors.Annotate(err, "encode from") 58 | } 59 | 60 | if err := enc.Encode(p.To); err != nil { 61 | return errors.Annotate(err, "encode to") 62 | } 63 | 64 | if err := enc.Encode(p.Amount); err != nil { 65 | return errors.Annotate(err, "encode amount") 66 | } 67 | 68 | if err := enc.Encode(p.Memo != nil); err != nil { 69 | return errors.Annotate(err, "encode have Memo") 70 | } 71 | 72 | if err := enc.Encode(p.Memo); err != nil { 73 | return errors.Annotate(err, "encode memo") 74 | } 75 | 76 | if err := enc.Encode(p.Extensions); err != nil { 77 | return errors.Annotate(err, "encode extensions") 78 | } 79 | 80 | return nil 81 | } 82 | 83 | func (p *TransferOperation) SetFee(fee types.AssetAmount) { 84 | p.OperationFee.SetFee(fee) 85 | } 86 | 87 | func (p TransferOperation) GetFee() types.AssetAmount { 88 | return p.OperationFee.GetFee() 89 | } 90 | -------------------------------------------------------------------------------- /types/gen_blocksummaryid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type BlockSummaryID struct { 16 | ObjectID 17 | } 18 | 19 | func (p BlockSummaryID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *BlockSummaryID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeBlockSummary) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type BlockSummaryIDs []BlockSummaryID 45 | 46 | func (p BlockSummaryIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode BlockSummaryID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func BlockSummaryIDFromObject(ob GrapheneObject) BlockSummaryID { 61 | id, ok := ob.(*BlockSummaryID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := BlockSummaryID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeBlockSummary { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeBlockSummary'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewBlockSummaryID creates an new BlockSummaryID object 76 | func NewBlockSummaryID(id string) GrapheneObject { 77 | gid := new(BlockSummaryID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "BlockSummaryID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeBlockSummary { 87 | logging.Errorf( 88 | "BlockSummaryID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeBlockSummary'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_budgetrecordid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type BudgetRecordID struct { 16 | ObjectID 17 | } 18 | 19 | func (p BudgetRecordID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *BudgetRecordID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeBudgetRecord) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type BudgetRecordIDs []BudgetRecordID 45 | 46 | func (p BudgetRecordIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode BudgetRecordID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func BudgetRecordIDFromObject(ob GrapheneObject) BudgetRecordID { 61 | id, ok := ob.(*BudgetRecordID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := BudgetRecordID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeBudgetRecord { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeBudgetRecord'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewBudgetRecordID creates an new BudgetRecordID object 76 | func NewBudgetRecordID(id string) GrapheneObject { 77 | gid := new(BudgetRecordID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "BudgetRecordID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeBudgetRecord { 87 | logging.Errorf( 88 | "BudgetRecordID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeBudgetRecord'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_nhassetorderid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type NHAssetOrderID struct { 16 | ObjectID 17 | } 18 | 19 | func (p NHAssetOrderID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *NHAssetOrderID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeNHAssetOrder) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type NHAssetOrderIDs []NHAssetOrderID 45 | 46 | func (p NHAssetOrderIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode NHAssetOrderID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func NHAssetOrderIDFromObject(ob GrapheneObject) NHAssetOrderID { 61 | id, ok := ob.(*NHAssetOrderID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := NHAssetOrderID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeNHAssetOrder { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeNHAssetOrder'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewNHAssetOrderID creates an new NHAssetOrderID object 76 | func NewNHAssetOrderID(id string) GrapheneObject { 77 | gid := new(NHAssetOrderID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "NHAssetOrderID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeNHAssetOrder { 87 | logging.Errorf( 88 | "NHAssetOrderID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeNHAssetOrder'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /types/gen_chainpropertyid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type ChainPropertyID struct { 16 | ObjectID 17 | } 18 | 19 | func (p ChainPropertyID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *ChainPropertyID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeChainProperty) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type ChainPropertyIDs []ChainPropertyID 45 | 46 | func (p ChainPropertyIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode ChainPropertyID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func ChainPropertyIDFromObject(ob GrapheneObject) ChainPropertyID { 61 | id, ok := ob.(*ChainPropertyID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := ChainPropertyID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeChainProperty { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeChainProperty'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewChainPropertyID creates an new ChainPropertyID object 76 | func NewChainPropertyID(id string) GrapheneObject { 77 | gid := new(ChainPropertyID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "ChainPropertyID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeChainProperty { 87 | logging.Errorf( 88 | "ChainPropertyID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeChainProperty'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Cocos-BCX/cocos-go 2 | 3 | require ( 4 | github.com/bradhe/stopwatch v0.0.0-20190618212248-a58cccc508ea 5 | github.com/btcsuite/btcd v0.0.0-20181130015935-7d2daa5bfef2 6 | github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a 7 | github.com/cespare/reflex v0.2.0 // indirect 8 | github.com/cheekybits/genny v1.0.0 // indirect 9 | github.com/cheggaaa/pb v2.0.7+incompatible // indirect 10 | github.com/creack/pty v1.1.9 // indirect 11 | github.com/davecgh/go-spew v1.1.1 12 | 13 | github.com/denkhaus/gojson v1.0.0 14 | // github.com/Cocos-BCX/cocos-go/logging v0.0.0-20180714213349-14bfb935047c 15 | github.com/emirpasic/gods v1.12.0 16 | github.com/fatih/color v1.7.0 // indirect 17 | github.com/fsnotify/fsnotify v1.4.7 // indirect 18 | github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 19 | github.com/juju/loggo v0.0.0-20180524022052-584905176618 // indirect 20 | github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 // indirect 21 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect 22 | github.com/kr/pretty v0.1.0 // indirect 23 | github.com/kr/pty v1.1.8 // indirect 24 | github.com/mattn/go-colorable v0.1.4 // indirect 25 | github.com/mattn/go-isatty v0.0.11 // indirect 26 | github.com/mattn/go-runewidth v0.0.4 // indirect 27 | github.com/mitchellh/reflectwalk v1.0.1 28 | github.com/ogier/pflag v0.0.1 // indirect 29 | github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect 30 | github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 31 | github.com/sasha-s/go-deadlock v0.2.0 32 | github.com/sirupsen/logrus v1.2.0 33 | github.com/stretchr/objx v0.2.0 34 | github.com/stretchr/testify v1.4.0 35 | github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 36 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 37 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859 38 | golang.org/x/sys v0.0.0-20191224085550-c709ea063b76 // indirect 39 | golang.org/x/tools v0.0.0-20191224055732-dd894d0a8a40 // indirect 40 | gopkg.in/VividCortex/ewma.v1 v1.1.1 // indirect 41 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect 42 | gopkg.in/cheggaaa/pb.v1 v1.0.28 43 | gopkg.in/cheggaaa/pb.v2 v2.0.7 // indirect 44 | gopkg.in/fatih/color.v1 v1.7.0 // indirect 45 | gopkg.in/mattn/go-colorable.v0 v0.1.0 // indirect 46 | gopkg.in/mattn/go-isatty.v0 v0.0.4 // indirect 47 | gopkg.in/mattn/go-runewidth.v0 v0.0.4 // indirect 48 | gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect 49 | gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 50 | gopkg.in/yaml.v2 v2.2.7 // indirect 51 | ) 52 | 53 | go 1.13 54 | -------------------------------------------------------------------------------- /operations/assetupdaterestrictedoperation.go: -------------------------------------------------------------------------------- 1 | package operations 2 | 3 | //go:generate ffjson $GOFILE 4 | 5 | import ( 6 | "github.com/Cocos-BCX/cocos-go/types" 7 | "github.com/Cocos-BCX/cocos-go/util" 8 | "github.com/juju/errors" 9 | ) 10 | 11 | func init() { 12 | types.OperationMap[types.OperationTypeAssetUpdateRestricted] = func() types.Operation { 13 | op := &AssetUpdateRestrictedOperation{} 14 | return op 15 | } 16 | } 17 | 18 | type ObjectIDs []types.ObjectID 19 | 20 | type AssetUpdateRestrictedOperation struct { 21 | types.OperationFee 22 | Payer types.AccountID `json:"payer"` 23 | TargetAsset types.AssetID `json:"target_asset"` 24 | IsAdd bool `json:"isadd"` 25 | RestrictedType types.UInt8 `json:"restricted_type"` 26 | RestrictedList ObjectIDs `json:"restricted_List"` 27 | Extensions types.Extensions `json:"extensions"` 28 | } 29 | 30 | func (p AssetUpdateRestrictedOperation) Type() types.OperationType { 31 | return types.OperationTypeAssetUpdateRestricted 32 | } 33 | 34 | func (p AssetUpdateRestrictedOperation) MarshalFeeScheduleParams(params types.M, enc *util.TypeEncoder) error { 35 | if fee, ok := params["fee"]; ok { 36 | if err := enc.Encode(types.UInt64(fee.(float64))); err != nil { 37 | return errors.Annotate(err, "encode Fee") 38 | } 39 | } 40 | 41 | if ppk, ok := params["price_per_kbyte"]; ok { 42 | if err := enc.Encode(types.UInt32(ppk.(float64))); err != nil { 43 | return errors.Annotate(err, "encode PricePerKByte") 44 | } 45 | } 46 | 47 | return nil 48 | } 49 | 50 | func (p AssetUpdateRestrictedOperation) Marshal(enc *util.TypeEncoder) error { 51 | if err := enc.Encode(int8(p.Type())); err != nil { 52 | return errors.Annotate(err, "encode OperationType") 53 | } 54 | 55 | if err := enc.Encode(p.Fee); err != nil { 56 | return errors.Annotate(err, "encode fee") 57 | } 58 | 59 | if err := enc.Encode(p.Payer); err != nil { 60 | return errors.Annotate(err, "encode Payer") 61 | } 62 | 63 | if err := enc.Encode(p.TargetAsset); err != nil { 64 | return errors.Annotate(err, "encode TargetAsset") 65 | } 66 | 67 | if err := enc.Encode(p.IsAdd); err != nil { 68 | return errors.Annotate(err, "encode IsAdd") 69 | } 70 | 71 | if err := enc.Encode(p.RestrictedType); err != nil { 72 | return errors.Annotate(err, "encode RestrictedType") 73 | } 74 | 75 | if err := enc.Encode(p.RestrictedList); err != nil { 76 | return errors.Annotate(err, "encode RestrictedList") 77 | } 78 | 79 | if err := enc.Encode(p.Extensions); err != nil { 80 | return errors.Annotate(err, "encode extensions") 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /types/gen_accountbalanceid.go: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by genny. 2 | // Any changes will be lost if this file is regenerated. 3 | // see https://github.com/cheekybits/genny 4 | 5 | package types 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/Cocos-BCX/cocos-go/logging" 11 | "github.com/Cocos-BCX/cocos-go/util" 12 | "github.com/juju/errors" 13 | ) 14 | 15 | type AccountBalanceID struct { 16 | ObjectID 17 | } 18 | 19 | func (p AccountBalanceID) Marshal(enc *util.TypeEncoder) error { 20 | n, err := enc.EncodeUVarintByByte(uint64(p.Instance())) 21 | if err != nil { 22 | return errors.Annotate(err, "encode instance") 23 | } 24 | 25 | for i := 0; i < 8-n; i++ { 26 | if err := enc.EncodeUVarint(uint64(0)); err != nil { 27 | return errors.Annotate(err, "encode zero") 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | func (p *AccountBalanceID) Unmarshal(dec *util.TypeDecoder) error { 35 | var instance uint64 36 | if err := dec.DecodeUVarint(&instance); err != nil { 37 | return errors.Annotate(err, "decode instance") 38 | } 39 | 40 | p.number = UInt64((uint64(SpaceTypeProtocol) << 56) | (uint64(ObjectTypeAccountBalance) << 48) | instance) 41 | return nil 42 | } 43 | 44 | type AccountBalanceIDs []AccountBalanceID 45 | 46 | func (p AccountBalanceIDs) Marshal(enc *util.TypeEncoder) error { 47 | if err := enc.EncodeUVarint(uint64(len(p))); err != nil { 48 | return errors.Annotate(err, "encode length") 49 | } 50 | 51 | for _, ex := range p { 52 | if err := enc.Encode(ex); err != nil { 53 | return errors.Annotate(err, "encode AccountBalanceID") 54 | } 55 | } 56 | 57 | return nil 58 | } 59 | 60 | func AccountBalanceIDFromObject(ob GrapheneObject) AccountBalanceID { 61 | id, ok := ob.(*AccountBalanceID) 62 | if ok { 63 | return *id 64 | } 65 | 66 | p := AccountBalanceID{} 67 | p.MustFromObject(ob) 68 | if p.ObjectType() != ObjectTypeAccountBalance { 69 | panic(fmt.Sprintf("invalid ObjectType: %q has no ObjectType 'ObjectTypeAccountBalance'", p.ID())) 70 | } 71 | 72 | return p 73 | } 74 | 75 | //NewAccountBalanceID creates an new AccountBalanceID object 76 | func NewAccountBalanceID(id string) GrapheneObject { 77 | gid := new(AccountBalanceID) 78 | if err := gid.Parse(id); err != nil { 79 | logging.Errorf( 80 | "AccountBalanceID parser error %v", 81 | errors.Annotate(err, "Parse"), 82 | ) 83 | return nil 84 | } 85 | 86 | if gid.ObjectType() != ObjectTypeAccountBalance { 87 | logging.Errorf( 88 | "AccountBalanceID parser error %s", 89 | fmt.Sprintf("%q has no ObjectType 'ObjectTypeAccountBalance'", id), 90 | ) 91 | return nil 92 | } 93 | 94 | return gid 95 | } 96 | --------------------------------------------------------------------------------