diff --git a/abidecoder.go b/abidecoder.go index 4c7adfac..98dda949 100644 --- a/abidecoder.go +++ b/abidecoder.go @@ -37,6 +37,10 @@ func (a *ABI) DecodeTableRowTyped(tableType string, data []byte) ([]byte, error) return a.decode(binaryDecoder, tableType) } +func (a *ABI) Decode(binaryDecoder *Decoder, structName string) ([]byte, error) { + return a.decode(binaryDecoder, structName) +} + func (a *ABI) decode(binaryDecoder *Decoder, structName string) ([]byte, error) { if loggingEnabled { abiDecoderLog.Debug("decode struct", zap.String("name", structName)) diff --git a/encoder.go b/encoder.go index 5aa5ebc1..fbdc9a5a 100644 --- a/encoder.go +++ b/encoder.go @@ -42,6 +42,12 @@ func (e *Encoder) writeName(name Name) error { func (e *Encoder) Encode(v interface{}) (err error) { switch cv := v.(type) { + case BaseVariant: + err = e.writeUVarInt(int(cv.TypeID)) + if err != nil { + return + } + return e.Encode(cv.Impl) case Name: return e.writeName(cv) case AccountName: diff --git a/init_test.go b/init_test.go index abf09a5e..cc2966f8 100644 --- a/init_test.go +++ b/init_test.go @@ -8,11 +8,7 @@ import ( func init() { if os.Getenv("DEBUG") != "" { - coreLog, _ = zap.NewDevelopment() - encoderLog, _ = zap.NewDevelopment() - decoderLog, _ = zap.NewDevelopment() - abiEncoderLog, _ = zap.NewDevelopment() - abiDecoderLog, _ = zap.NewDevelopment() - loggingEnabled = true + logger, _ := zap.NewDevelopment() + EnableDebugLogging(logger) } } diff --git a/logger.go b/logger.go index 65717fd2..07ae3639 100644 --- a/logger.go +++ b/logger.go @@ -13,6 +13,15 @@ var abiEncoderLog = zap.NewNop() var abiDecoderLog = zap.NewNop() var loggingEnabled = false +func EnableDebugLogging(l *zap.Logger) { + coreLog = l + encoderLog = l + decoderLog = l + abiEncoderLog = l + abiDecoderLog = l + loggingEnabled = true +} + func EnableCoreLogging() { coreLog = newLogger(false) enableLogging(coreLog) diff --git a/p2ptypes.go b/p2ptypes.go index 1f7814b8..c62eb3de 100644 --- a/p2ptypes.go +++ b/p2ptypes.go @@ -317,7 +317,7 @@ type BlockSigningAuthority struct { BaseVariant } -var blockSigningVariantFactoryImplMap = map[uint]VariantImplFactory{ +var blockSigningVariantFactoryImplMap = map[uint32]VariantImplFactory{ BlockSigningAuthorityV0Type: func() interface{} { return new(BlockSigningAuthorityV0) }, } diff --git a/ship/types.go b/ship/types.go new file mode 100644 index 00000000..ac6b8371 --- /dev/null +++ b/ship/types.go @@ -0,0 +1,167 @@ +package ship + +import ( + "github.com/eoscanada/eos-go" + "github.com/eoscanada/eos-go/ecc" +) + +// State History Plugin Requests + +type GetStatusRequestV0 struct { +} + +type GetBlocksAckRequestV0 struct { + NumMessages uint32 +} + +type GetBlocksRequestV0 struct { + StartBlockNum uint32 + EndBlockNum uint32 + MaxMessagesInFlight uint32 + HavePositions []*BlockPosition + IrreversibleOnly bool + FetchBlock bool + FetchTraces bool + FetchDeltas bool +} + +// State History Plugin Results +type GetStatusResultV0 struct { + Head *BlockPosition + LastIrreversible *BlockPosition + TraceBeginBlock uint32 + TraceEndBlock uint32 + ChainStateBeginBlock uint32 + ChainStateEndBlock uint32 +} + +type GetBlocksResultV0 struct { + Head *BlockPosition + LastIrreversible *BlockPosition + ThisBlock *BlockPosition `eos:"optional"` + PrevBlock *BlockPosition `eos:"optional"` + Block *SignedBlockBytes `eos:"optional"` + Traces *TransactionTraceArray `eos:"optional"` + Deltas *TableDeltaArray `eos:"optional"` +} + +// State History Plugin version of EOS structs +type BlockPosition struct { + BlockNum uint32 + BlockID eos.Checksum256 +} + +type Row struct { + Present bool + Data []byte +} + +type ActionTraceV0 struct { + ActionOrdinal eos.Varuint32 + CreatorActionOrdinal eos.Varuint32 + Receipt *ActionReceipt `eos:"optional"` + Receiver eos.Name + Act *Action + ContextFree bool + Elapsed int64 + Console string + AccountRamDeltas []*eos.AccountRAMDelta + Except string `eos:"optional"` + ErrorCode uint64 `eos:"optional"` +} + +type Action struct { + Account eos.AccountName + Name eos.ActionName + Authorization []eos.PermissionLevel + Data []byte +} + +type ActionReceiptV0 struct { + Receiver eos.Name + ActDigest eos.Checksum256 + GlobalSequence uint64 + RecvSequence uint64 + AuthSequence []AccountAuthSequence + CodeSequence eos.Varuint32 + ABISequence eos.Varuint32 +} + +type AccountAuthSequence struct { + Account eos.Name + Sequence uint64 +} + +type TableDeltaV0 struct { + Name string + Rows []Row +} + +type PartialTransactionV0 struct { + Expiration uint32 + RefBlockNum uint16 + RefBlockPrefix uint32 + MaxNetUsageWords eos.Varuint32 + MaxCpuUsageMs uint8 + DelaySec eos.Varuint32 + TransactionExtensions []*Extension + Signatures []ecc.Signature + ContextFreeData []byte +} + +type TransactionTraceV0 struct { + ID eos.Checksum256 `json:"id"` + Status eos.TransactionStatus + CPUUsageUS uint32 `json:"cpu_usage_us"` + NetUsageWords eos.Varuint32 `json:"net_usage_words"` + Elapsed eos.Int64 `json:"elapsed"` + NetUsage uint64 `json:"net_usage"` + Scheduled bool `json:"scheduled"` + ActionTraces []*ActionTrace `json:"action_traces"` + AccountDelta *eos.AccountRAMDelta `json:"account_delta" eos:"optional"` + Except string `json:"except" eos:"optional"` + ErrorCode uint64 `json:"error_code" eos:"optional"` + FailedDtrxTrace *TransactionTrace `json:"failed_dtrx_trace" eos:"optional"` + Partial *PartialTransaction `json:"partial" eos:"optional"` +} + +type SignedBlockHeader struct { + eos.BlockHeader + ProducerSignature ecc.Signature // no pointer!! +} + +type TransactionReceipt struct { + eos.TransactionReceiptHeader + Trx *TransactionVariant +} + +//type TransactionID eos.Checksum256 + +type SignedBlock struct { + SignedBlockHeader + Transactions []*TransactionReceipt + BlockExtensions []*Extension +} + +type SignedBlockBytes SignedBlock + +func (s *SignedBlockBytes) AsSignedBlock() *SignedBlock { + if s == nil { + return nil + } + ss := SignedBlock(*s) + return &ss +} + +func (s *SignedBlockBytes) UnmarshalBinary(decoder *eos.Decoder) error { + data, err := decoder.ReadByteArray() + if err != nil { + return err + } + return eos.UnmarshalBinary(data, s) +} + +type Extension struct { + Type uint16 + Data []byte +} diff --git a/ship/utils.go b/ship/utils.go new file mode 100644 index 00000000..e96ca258 --- /dev/null +++ b/ship/utils.go @@ -0,0 +1,50 @@ +package ship + +import ( + "fmt" + + "github.com/eoscanada/eos-go" +) + +func NewGetBlocksAck(num uint32) []byte { + myReq := &Request{ + BaseVariant: eos.BaseVariant{ + TypeID: GetBlocksAckRequestV0Type, + Impl: &GetBlocksAckRequestV0{ + NumMessages: num, + }, + }, + } + bytes, err := eos.MarshalBinary(myReq) + if err != nil { + panic(err) + } + + return bytes +} + +func NewRequest(req *GetBlocksRequestV0) []byte { + myReq := &Request{ + BaseVariant: eos.BaseVariant{ + TypeID: GetBlocksRequestV0Type, + Impl: req, + }, + } + bytes, err := eos.MarshalBinary(myReq) + if err != nil { + panic(err) + } + + return bytes +} + +func ParseGetBlockResultV0(in []byte) (*GetBlocksResultV0, error) { + variant := &Result{} + if err := eos.UnmarshalBinary(in, &variant); err != nil { + return nil, err + } + if variant.TypeID != GetBlocksResultV0Type { + return nil, fmt.Errorf("invalid response type: %d", variant.TypeID) + } + return variant.Impl.(*GetBlocksResultV0), nil +} diff --git a/ship/variant_helpers.go b/ship/variant_helpers.go new file mode 100644 index 00000000..7e014a84 --- /dev/null +++ b/ship/variant_helpers.go @@ -0,0 +1,200 @@ +package ship + +import ( + "github.com/eoscanada/eos-go" +) + +// Request + +type Request struct { + eos.BaseVariant +} + +const ( + GetStatusRequestV0Type = iota + GetBlocksRequestV0Type + GetBlocksAckRequestV0Type +) + +var requestVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + GetStatusRequestV0Type: func() interface{} { return new(GetStatusRequestV0) }, + GetBlocksRequestV0Type: func() interface{} { return new(GetBlocksRequestV0) }, + GetBlocksAckRequestV0Type: func() interface{} { return new(GetBlocksAckRequestV0) }, +} + +func (r *Request) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, requestVariantFactoryImplMap) +} + +// Result +const ( + GetStatusResultV0Type = iota + GetBlocksResultV0Type +) + +var resultVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + GetStatusResultV0Type: func() interface{} { return new(GetStatusResultV0) }, + GetBlocksResultV0Type: func() interface{} { return new(GetBlocksResultV0) }, +} + +type Result struct { + eos.BaseVariant +} + +func (r *Result) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, resultVariantFactoryImplMap) +} + +// TransactionTrace +const ( + TransactionTraceV0Type = iota +) + +var TransactionTraceVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + TransactionTraceV0Type: func() interface{} { return new(TransactionTraceV0) }, +} + +type TransactionTraceArray struct { + Elem []*TransactionTrace +} + +func (t *TransactionTraceArray) AsTransactionTracesV0() (out []*TransactionTraceV0) { + if t == nil || t.Elem == nil { + return nil + } + for _, e := range t.Elem { + if e.TypeID != TransactionTraceV0Type { + panic("wrong type for conversion") + } + out = append(out, e.Impl.(*TransactionTraceV0)) + } + return out +} + +func (r *TransactionTraceArray) UnmarshalBinary(decoder *eos.Decoder) error { + data, err := decoder.ReadByteArray() + if err != nil { + return err + } + return eos.UnmarshalBinary(data, &r.Elem) +} + +type TransactionTrace struct { + eos.BaseVariant +} + +func (r *TransactionTrace) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, TransactionTraceVariantFactoryImplMap) +} + +// ActionTrace +const ( + ActionTraceV0Type = iota +) + +var ActionTraceVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + ActionTraceV0Type: func() interface{} { return new(ActionTraceV0) }, +} + +type ActionTrace struct { + eos.BaseVariant +} + +func (r *ActionTrace) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, ActionTraceVariantFactoryImplMap) +} + +// PartialTransaction +const ( + PartialTransactionV0Type = iota +) + +var PartialTransactionVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + PartialTransactionV0Type: func() interface{} { return new(PartialTransactionV0) }, +} + +type PartialTransaction struct { + eos.BaseVariant +} + +func (r *PartialTransaction) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, PartialTransactionVariantFactoryImplMap) +} + +// TableDelta +const ( + TableDeltaV0Type = iota +) + +var TableDeltaVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + TableDeltaV0Type: func() interface{} { return new(TableDeltaV0) }, +} + +type TableDelta struct { + eos.BaseVariant +} + +func (d *TableDelta) UnmarshalBinary(decoder *eos.Decoder) error { + return d.BaseVariant.UnmarshalBinaryVariant(decoder, TableDeltaVariantFactoryImplMap) +} + +type TableDeltaArray struct { + Elem []*TableDelta +} + +func (d *TableDeltaArray) UnmarshalBinary(decoder *eos.Decoder) error { + data, err := decoder.ReadByteArray() + if err != nil { + return err + } + return eos.UnmarshalBinary(data, &d.Elem) +} + +func (t *TableDeltaArray) AsTableDeltasV0() (out []*TableDeltaV0) { + if t == nil || t.Elem == nil { + return nil + } + for _, e := range t.Elem { + if e.TypeID != TableDeltaV0Type { + panic("wrong type for conversion") + } + out = append(out, e.Impl.(*TableDeltaV0)) + } + return out +} + +// TransactionVariant +const ( + TransactionIDType = iota + PackedTransactionType +) + +var TransactionVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + TransactionIDType: func() interface{} { return new(eos.Checksum256) }, + PackedTransactionType: func() interface{} { return new(eos.PackedTransaction) }, +} + +type TransactionVariant struct { + eos.BaseVariant +} + +func (d *TransactionVariant) UnmarshalBinary(decoder *eos.Decoder) error { + return d.BaseVariant.UnmarshalBinaryVariant(decoder, TransactionVariantFactoryImplMap) +} + +// ActionReceipt +const ( + ActionReceiptV0Type = iota +) + +var ActionReceiptVariantFactoryImplMap = map[uint32]eos.VariantImplFactory{ + ActionReceiptV0Type: func() interface{} { return new(ActionReceiptV0) }, +} + +type ActionReceipt struct { + eos.BaseVariant +} + +func (r *ActionReceipt) UnmarshalBinary(decoder *eos.Decoder) error { + return r.BaseVariant.UnmarshalBinaryVariant(decoder, ActionReceiptVariantFactoryImplMap) +} diff --git a/ship/wsabi.json b/ship/wsabi.json new file mode 100644 index 00000000..86f5c2f0 --- /dev/null +++ b/ship/wsabi.json @@ -0,0 +1,558 @@ +{ + "version": "eosio::abi/1.1", + "structs": [ + { + "name": "get_status_request_v0", "fields": [] + }, + { + "name": "block_position", "fields": [ + { "name": "block_num", "type": "uint32" }, + { "name": "block_id", "type": "checksum256" } + ] + }, + { + "name": "get_status_result_v0", "fields": [ + { "name": "head", "type": "block_position" }, + { "name": "last_irreversible", "type": "block_position" }, + { "name": "trace_begin_block", "type": "uint32" }, + { "name": "trace_end_block", "type": "uint32" }, + { "name": "chain_state_begin_block", "type": "uint32" }, + { "name": "chain_state_end_block", "type": "uint32" } + ] + }, + { + "name": "get_blocks_request_v0", "fields": [ + { "name": "start_block_num", "type": "uint32" }, + { "name": "end_block_num", "type": "uint32" }, + { "name": "max_messages_in_flight", "type": "uint32" }, + { "name": "have_positions", "type": "block_position[]" }, + { "name": "irreversible_only", "type": "bool" }, + { "name": "fetch_block", "type": "bool" }, + { "name": "fetch_traces", "type": "bool" }, + { "name": "fetch_deltas", "type": "bool" } + ] + }, + { + "name": "get_blocks_ack_request_v0", "fields": [ + { "name": "num_messages", "type": "uint32" } + ] + }, + { + "name": "get_blocks_result_v0", "fields": [ + { "name": "head", "type": "block_position" }, + { "name": "last_irreversible", "type": "block_position" }, + { "name": "this_block", "type": "block_position?" }, + { "name": "prev_block", "type": "block_position?" }, + { "name": "block", "type": "bytes?" }, + { "name": "traces", "type": "bytes?" }, + { "name": "deltas", "type": "bytes?" } + ] + }, + { + "name": "row", "fields": [ + { "name": "present", "type": "bool" }, + { "name": "data", "type": "bytes" } + ] + }, + { + "name": "table_delta_v0", "fields": [ + { "name": "name", "type": "string" }, + { "name": "rows", "type": "row[]" } + ] + }, + { + "name": "action", "fields": [ + { "name": "account", "type": "name" }, + { "name": "name", "type": "name" }, + { "name": "authorization", "type": "permission_level[]" }, + { "name": "data", "type": "bytes" } + ] + }, + { + "name": "account_auth_sequence", "fields": [ + { "name": "account", "type": "name" }, + { "name": "sequence", "type": "uint64" } + ] + }, + { + "name": "action_receipt_v0", "fields": [ + { "name": "receiver", "type": "name" }, + { "name": "act_digest", "type": "checksum256" }, + { "name": "global_sequence", "type": "uint64" }, + { "name": "recv_sequence", "type": "uint64" }, + { "name": "auth_sequence", "type": "account_auth_sequence[]" }, + { "name": "code_sequence", "type": "varuint32" }, + { "name": "abi_sequence", "type": "varuint32" } + ] + }, + { + "name": "account_delta", "fields": [ + { "name": "account", "type": "name" }, + { "name": "delta", "type": "int64" } + ] + }, + { + "name": "action_trace_v0", "fields": [ + { "name": "action_ordinal", "type": "varuint32" }, + { "name": "creator_action_ordinal", "type": "varuint32" }, + { "name": "receipt", "type": "action_receipt?" }, + { "name": "receiver", "type": "name" }, + { "name": "act", "type": "action" }, + { "name": "context_free", "type": "bool" }, + { "name": "elapsed", "type": "int64" }, + { "name": "console", "type": "string" }, + { "name": "account_ram_deltas", "type": "account_delta[]" }, + { "name": "except", "type": "string?" }, + { "name": "error_code", "type": "uint64?" } + ] + }, + { + "name": "partial_transaction_v0", "fields": [ + { "name": "expiration", "type": "time_point_sec" }, + { "name": "ref_block_num", "type": "uint16" }, + { "name": "ref_block_prefix", "type": "uint32" }, + { "name": "max_net_usage_words", "type": "varuint32" }, + { "name": "max_cpu_usage_ms", "type": "uint8" }, + { "name": "delay_sec", "type": "varuint32" }, + { "name": "transaction_extensions", "type": "extension[]" }, + { "name": "signatures", "type": "signature[]" }, + { "name": "context_free_data", "type": "bytes[]" } + ] + }, + { + "name": "transaction_trace_v0", "fields": [ + { "name": "id", "type": "checksum256" }, + { "name": "status", "type": "uint8" }, + { "name": "cpu_usage_us", "type": "uint32" }, + { "name": "net_usage_words", "type": "varuint32" }, + { "name": "elapsed", "type": "int64" }, + { "name": "net_usage", "type": "uint64" }, + { "name": "scheduled", "type": "bool" }, + { "name": "action_traces", "type": "action_trace[]" }, + { "name": "account_ram_delta", "type": "account_delta?" }, + { "name": "except", "type": "string?" }, + { "name": "error_code", "type": "uint64?" }, + { "name": "failed_dtrx_trace", "type": "transaction_trace?" }, + { "name": "partial", "type": "partial_transaction?" } + ] + }, + { + "name": "packed_transaction", "fields": [ + { "name": "signatures", "type": "signature[]" }, + { "name": "compression", "type": "uint8" }, + { "name": "packed_context_free_data", "type": "bytes" }, + { "name": "packed_trx", "type": "bytes" } + ] + }, + { + "name": "transaction_receipt_header", "fields": [ + { "name": "status", "type": "uint8" }, + { "name": "cpu_usage_us", "type": "uint32" }, + { "name": "net_usage_words", "type": "varuint32" } + ] + }, + { + "name": "transaction_receipt", "base": "transaction_receipt_header", "fields": [ + { "name": "trx", "type": "transaction_variant" } + ] + }, + { + "name": "extension", "fields": [ + { "name": "type", "type": "uint16" }, + { "name": "data", "type": "bytes" } + ] + }, + { + "name": "block_header", "fields": [ + { "name": "timestamp", "type": "block_timestamp_type" }, + { "name": "producer", "type": "name" }, + { "name": "confirmed", "type": "uint16" }, + { "name": "previous", "type": "checksum256" }, + { "name": "transaction_mroot", "type": "checksum256" }, + { "name": "action_mroot", "type": "checksum256" }, + { "name": "schedule_version", "type": "uint32" }, + { "name": "new_producers", "type": "producer_schedule?" }, + { "name": "header_extensions", "type": "extension[]" } + ] + }, + { + "name": "signed_block_header", "base": "block_header", "fields": [ + { "name": "producer_signature", "type": "signature" } + ] + }, + { + "name": "signed_block", "base": "signed_block_header", "fields": [ + { "name": "transactions", "type": "transaction_receipt[]" }, + { "name": "block_extensions", "type": "extension[]" } + ] + }, + { "name": "transaction_header", "fields": [ + { "name": "expiration", "type": "time_point_sec" }, + { "name": "ref_block_num", "type": "uint16" }, + { "name": "ref_block_prefix", "type": "uint32" }, + { "name": "max_net_usage_words", "type": "varuint32" }, + { "name": "max_cpu_usage_ms", "type": "uint8" }, + { "name": "delay_sec", "type": "varuint32" } + ] + }, + { "name": "transaction", "base": "transaction_header", "fields": [ + { "name": "context_free_actions", "type": "action[]" }, + { "name": "actions", "type": "action[]" }, + { "name": "transaction_extensions", "type": "extension[]" } + ] + }, + { + "name": "code_id", "fields": [ + { "type": "uint8", "name": "vm_type" }, + { "type": "uint8", "name": "vm_version" }, + { "type": "checksum256", "name": "code_hash" } + ] + }, + { + "name": "account_v0", "fields": [ + { "type": "name", "name": "name" }, + { "type": "block_timestamp_type", "name": "creation_date" }, + { "type": "bytes", "name": "abi" } + ] + }, + { + "name": "account_metadata_v0", "fields": [ + { "type": "name", "name": "name" }, + { "type": "bool", "name": "privileged" }, + { "type": "time_point", "name": "last_code_update" }, + { "type": "code_id?", "name": "code" } + ] + }, + { + "name": "code_v0", "fields": [ + { "type": "uint8", "name": "vm_type" }, + { "type": "uint8", "name": "vm_version" }, + { "type": "checksum256", "name": "code_hash" }, + { "type": "bytes", "name": "code" } + ] + }, + { + "name": "contract_table_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "name", "name": "payer" } + ] + }, + { + "name": "contract_row_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "bytes", "name": "value" } + ] + }, + { + "name": "contract_index64_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "uint64", "name": "secondary_key" } + ] + }, + { + "name": "contract_index128_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "uint128", "name": "secondary_key" } + ] + }, + { + "name": "contract_index256_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "checksum256", "name": "secondary_key" } + ] + }, + { + "name": "contract_index_double_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "float64", "name": "secondary_key" } + ] + }, + { + "name": "contract_index_long_double_v0", "fields": [ + { "type": "name", "name": "code" }, + { "type": "name", "name": "scope" }, + { "type": "name", "name": "table" }, + { "type": "uint64", "name": "primary_key" }, + { "type": "name", "name": "payer" }, + { "type": "float128", "name": "secondary_key" } + ] + }, + { + "name": "producer_key", "fields": [ + { "type": "name", "name": "producer_name" }, + { "type": "public_key", "name": "block_signing_key" } + ] + }, + { + "name": "producer_schedule", "fields": [ + { "type": "uint32", "name": "version" }, + { "type": "producer_key[]", "name": "producers" } + ] + }, + { + "name": "block_signing_authority_v0", "fields": [ + { "type": "uint32", "name": "threshold" }, + { "type": "key_weight[]", "name": "keys" } + ] + }, + { + "name": "producer_authority", "fields": [ + { "type": "name", "name": "producer_name" }, + { "type": "block_signing_authority", "name": "authority" } + ] + }, + { + "name": "producer_authority_schedule", "fields": [ + { "type": "uint32", "name": "version" }, + { "type": "producer_authority[]", "name": "producers" } + ] + }, + { + "name": "chain_config_v0", "fields": [ + { "type": "uint64", "name": "max_block_net_usage" }, + { "type": "uint32", "name": "target_block_net_usage_pct" }, + { "type": "uint32", "name": "max_transaction_net_usage" }, + { "type": "uint32", "name": "base_per_transaction_net_usage" }, + { "type": "uint32", "name": "net_usage_leeway" }, + { "type": "uint32", "name": "context_free_discount_net_usage_num" }, + { "type": "uint32", "name": "context_free_discount_net_usage_den" }, + { "type": "uint32", "name": "max_block_cpu_usage" }, + { "type": "uint32", "name": "target_block_cpu_usage_pct" }, + { "type": "uint32", "name": "max_transaction_cpu_usage" }, + { "type": "uint32", "name": "min_transaction_cpu_usage" }, + { "type": "uint32", "name": "max_transaction_lifetime" }, + { "type": "uint32", "name": "deferred_trx_expiration_window" }, + { "type": "uint32", "name": "max_transaction_delay" }, + { "type": "uint32", "name": "max_inline_action_size" }, + { "type": "uint16", "name": "max_inline_action_depth" }, + { "type": "uint16", "name": "max_authority_depth" } + ] + }, + { + "name": "global_property_v0", "fields": [ + { "type": "uint32?", "name": "proposed_schedule_block_num" }, + { "type": "producer_schedule", "name": "proposed_schedule" }, + { "type": "chain_config", "name": "configuration" } + ] + }, + { + "name": "global_property_v1", "fields": [ + { "type": "uint32?", "name": "proposed_schedule_block_num" }, + { "type": "producer_authority_schedule", "name": "proposed_schedule" }, + { "type": "chain_config", "name": "configuration" }, + { "type": "checksum256", "name": "chain_id" } + ] + }, + { + "name": "generated_transaction_v0", "fields": [ + { "type": "name", "name": "sender" }, + { "type": "uint128", "name": "sender_id" }, + { "type": "name", "name": "payer" }, + { "type": "checksum256", "name": "trx_id" }, + { "type": "bytes", "name": "packed_trx" } + ] + }, + { + "name": "activated_protocol_feature_v0", "fields": [ + { "type": "checksum256", "name": "feature_digest" }, + { "type": "uint32", "name": "activation_block_num" } + ] + }, + { + "name": "protocol_state_v0", "fields": [ + { "type": "activated_protocol_feature[]", "name": "activated_protocol_features" } + ] + }, + { + "name": "key_weight", "fields": [ + { "type": "public_key", "name": "key" }, + { "type": "uint16", "name": "weight" } + ] + }, + { + "name": "permission_level", "fields": [ + { "type": "name", "name": "actor" }, + { "type": "name", "name": "permission" } + ] + }, + { + "name": "permission_level_weight", "fields": [ + { "type": "permission_level", "name": "permission" }, + { "type": "uint16", "name": "weight" } + ] + }, + { + "name": "wait_weight", "fields": [ + { "type": "uint32", "name": "wait_sec" }, + { "type": "uint16", "name": "weight" } + ] + }, + { + "name": "authority", "fields": [ + { "type": "uint32", "name": "threshold" }, + { "type": "key_weight[]", "name": "keys" }, + { "type": "permission_level_weight[]", "name": "accounts" }, + { "type": "wait_weight[]", "name": "waits" } + ] + }, + { + "name": "permission_v0", "fields": [ + { "type": "name", "name": "owner" }, + { "type": "name", "name": "name" }, + { "type": "name", "name": "parent" }, + { "type": "time_point", "name": "last_updated" }, + { "type": "authority", "name": "auth" } + ] + }, + { + "name": "permission_link_v0", "fields": [ + { "type": "name", "name": "account" }, + { "type": "name", "name": "code" }, + { "type": "name", "name": "message_type" }, + { "type": "name", "name": "required_permission" } + ] + }, + { + "name": "resource_limits_v0", "fields": [ + { "type": "name", "name": "owner" }, + { "type": "int64", "name": "net_weight" }, + { "type": "int64", "name": "cpu_weight" }, + { "type": "int64", "name": "ram_bytes" } + ] + }, + { + "name": "usage_accumulator_v0", "fields": [ + { "type": "uint32", "name": "last_ordinal" }, + { "type": "uint64", "name": "value_ex" }, + { "type": "uint64", "name": "consumed" } + ] + }, + { + "name": "resource_usage_v0", "fields": [ + { "type": "name", "name": "owner" }, + { "type": "usage_accumulator", "name": "net_usage" }, + { "type": "usage_accumulator", "name": "cpu_usage" }, + { "type": "uint64", "name": "ram_usage" } + ] + }, + { + "name": "resource_limits_state_v0", "fields": [ + { "type": "usage_accumulator", "name": "average_block_net_usage" }, + { "type": "usage_accumulator", "name": "average_block_cpu_usage" }, + { "type": "uint64", "name": "total_net_weight" }, + { "type": "uint64", "name": "total_cpu_weight" }, + { "type": "uint64", "name": "total_ram_bytes" }, + { "type": "uint64", "name": "virtual_net_limit" }, + { "type": "uint64", "name": "virtual_cpu_limit" } + ] + }, + { + "name": "resource_limits_ratio_v0", "fields": [ + { "type": "uint64", "name": "numerator" }, + { "type": "uint64", "name": "denominator" } + ] + }, + { + "name": "elastic_limit_parameters_v0", "fields": [ + { "type": "uint64", "name": "target" }, + { "type": "uint64", "name": "max" }, + { "type": "uint32", "name": "periods" }, + { "type": "uint32", "name": "max_multiplier" }, + { "type": "resource_limits_ratio", "name": "contract_rate" }, + { "type": "resource_limits_ratio", "name": "expand_rate" } + ] + }, + { + "name": "resource_limits_config_v0", "fields": [ + { "type": "elastic_limit_parameters", "name": "cpu_limit_parameters" }, + { "type": "elastic_limit_parameters", "name": "net_limit_parameters" }, + { "type": "uint32", "name": "account_cpu_usage_average_window" }, + { "type": "uint32", "name": "account_net_usage_average_window" } + ] + } + ], + "types": [ + { "new_type_name": "transaction_id", "type": "checksum256" } + ], + "variants": [ + { "name": "request", "types": ["get_status_request_v0", "get_blocks_request_v0", "get_blocks_ack_request_v0"] }, + { "name": "result", "types": ["get_status_result_v0", "get_blocks_result_v0"] }, + + { "name": "action_receipt", "types": ["action_receipt_v0"] }, + { "name": "action_trace", "types": ["action_trace_v0"] }, + { "name": "partial_transaction", "types": ["partial_transaction_v0"] }, + { "name": "transaction_trace", "types": ["transaction_trace_v0"] }, + { "name": "transaction_variant", "types": ["transaction_id", "packed_transaction"] }, + + { "name": "table_delta", "types": ["table_delta_v0"] }, + { "name": "account", "types": ["account_v0"] }, + { "name": "account_metadata", "types": ["account_metadata_v0"] }, + { "name": "code", "types": ["code_v0"] }, + { "name": "contract_table", "types": ["contract_table_v0"] }, + { "name": "contract_row", "types": ["contract_row_v0"] }, + { "name": "contract_index64", "types": ["contract_index64_v0"] }, + { "name": "contract_index128", "types": ["contract_index128_v0"] }, + { "name": "contract_index256", "types": ["contract_index256_v0"] }, + { "name": "contract_index_double", "types": ["contract_index_double_v0"] }, + { "name": "contract_index_long_double", "types": ["contract_index_long_double_v0"] }, + { "name": "chain_config", "types": ["chain_config_v0"] }, + { "name": "global_property", "types": ["global_property_v0", "global_property_v1"] }, + { "name": "generated_transaction", "types": ["generated_transaction_v0"] }, + { "name": "activated_protocol_feature", "types": ["activated_protocol_feature_v0"] }, + { "name": "protocol_state", "types": ["protocol_state_v0"] }, + { "name": "permission", "types": ["permission_v0"] }, + { "name": "permission_link", "types": ["permission_link_v0"] }, + { "name": "resource_limits", "types": ["resource_limits_v0"] }, + { "name": "usage_accumulator", "types": ["usage_accumulator_v0"] }, + { "name": "resource_usage", "types": ["resource_usage_v0"] }, + { "name": "resource_limits_state", "types": ["resource_limits_state_v0"] }, + { "name": "resource_limits_ratio", "types": ["resource_limits_ratio_v0"] }, + { "name": "elastic_limit_parameters", "types": ["elastic_limit_parameters_v0"] }, + { "name": "resource_limits_config", "types": ["resource_limits_config_v0"] }, + { "name": "block_signing_authority", "types": ["block_signing_authority_v0"] } + ], + "tables": [ + { "name": "account", "type": "account", "key_names": ["name"] }, + { "name": "account_metadata", "type": "account_metadata", "key_names": ["name"] }, + { "name": "code", "type": "code", "key_names": ["vm_type", "vm_version", "code_hash"] }, + { "name": "contract_table", "type": "contract_table", "key_names": ["code", "scope", "table"] }, + { "name": "contract_row", "type": "contract_row", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "contract_index64", "type": "contract_index64", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "contract_index128", "type": "contract_index128", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "contract_index256", "type": "contract_index256", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "contract_index_double", "type": "contract_index_double", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "contract_index_long_double", "type": "contract_index_long_double", "key_names": ["code", "scope", "table", "primary_key"] }, + { "name": "global_property", "type": "global_property", "key_names": [] }, + { "name": "generated_transaction", "type": "generated_transaction", "key_names": ["sender", "sender_id"] }, + { "name": "protocol_state", "type": "protocol_state", "key_names": [] }, + { "name": "permission", "type": "permission", "key_names": ["owner", "name"] }, + { "name": "permission_link", "type": "permission_link", "key_names": ["account", "code", "message_type"] }, + { "name": "resource_limits", "type": "resource_limits", "key_names": ["owner"] }, + { "name": "resource_usage", "type": "resource_usage", "key_names": ["owner"] }, + { "name": "resource_limits_state", "type": "resource_limits_state", "key_names": [] }, + { "name": "resource_limits_config", "type": "resource_limits_config", "key_names": [] } + ] +} + diff --git a/types.go b/types.go index e2b3cf07..f3c7175e 100644 --- a/types.go +++ b/types.go @@ -1093,20 +1093,20 @@ type VariantImplFactory = func() interface{} type OnVariant = func(impl interface{}) error type BaseVariant struct { - TypeID uint + TypeID uint32 Impl interface{} } -func (a *BaseVariant) Assign(typeID uint, impl interface{}) { +func (a *BaseVariant) Assign(typeID uint32, impl interface{}) { a.TypeID = typeID a.Impl = impl } -func (a *BaseVariant) Obtain() (typeID uint, impl interface{}) { - return uint(a.TypeID), a.Impl +func (a *BaseVariant) Obtain() (typeID uint32, impl interface{}) { + return uint32(a.TypeID), a.Impl } -func (a *BaseVariant) DoFor(doers map[uint]OnVariant) error { +func (a *BaseVariant) DoFor(doers map[uint32]OnVariant) error { if doer, found := doers[a.TypeID]; found { return doer(a.Impl) } @@ -1119,7 +1119,7 @@ func (a *BaseVariant) MarshalJSON() ([]byte, error) { return json.Marshal(elements) } -func (a *BaseVariant) UnmarshalJSON(data []byte, newImplPointer map[uint]VariantImplFactory) error { +func (a *BaseVariant) UnmarshalJSON(data []byte, newImplPointer map[uint32]VariantImplFactory) error { typeIDResult := gjson.GetBytes(data, "0") implResult := gjson.GetBytes(data, "1") @@ -1127,7 +1127,7 @@ func (a *BaseVariant) UnmarshalJSON(data []byte, newImplPointer map[uint]Variant return fmt.Errorf("invalid format, expected '[, ]' pair, got %q", string(data)) } - a.TypeID = uint(typeIDResult.Uint()) + a.TypeID = uint32(typeIDResult.Uint()) implFactory := newImplPointer[a.TypeID] if implFactory == nil { return fmt.Errorf("newImplPointer should have returned an non-nil pointer for type %d", a.TypeID) @@ -1142,13 +1142,13 @@ func (a *BaseVariant) UnmarshalJSON(data []byte, newImplPointer map[uint]Variant return nil } -func (a *BaseVariant) UnmarshalBinaryVariant(decoder *Decoder, newImplPointer map[uint]VariantImplFactory) error { +func (a *BaseVariant) UnmarshalBinaryVariant(decoder *Decoder, newImplPointer map[uint32]VariantImplFactory) error { typeID, err := decoder.ReadUvarint32() if err != nil { return fmt.Errorf("unable to read variant type ID: %s", err) } - a.TypeID = uint(typeID) + a.TypeID = uint32(typeID) implFactory := newImplPointer[a.TypeID] if implFactory == nil { return fmt.Errorf("newImplPointer should have returned an non-nil pointer for type %d", a.TypeID)