Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Edit GetOpsInBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
asuleymanov committed Sep 19, 2017
1 parent b547a53 commit 4244660
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apis/database/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ func (api *API) GetBlock(blockNum uint32) (*Block, error) {
}

//get_ops_in_block
func (api *API) GetOpsInBlock(blockNum uint32, only_virtual bool) ([]*OpsInBlock, error) {
func (api *API) GetOpsInBlock(blockNum uint32, only_virtual bool) ([]*types.OperationObject, error) {
raw, err := api.Raw("get_ops_in_block", []interface{}{blockNum, only_virtual})
if err != nil {
return nil, err
}
var resp []*OpsInBlock
var resp []*types.OperationObject
if err := json.Unmarshal([]byte(*raw), &resp); err != nil {
return nil, errors.Wrapf(err, "golos-go: %v: failed to unmarshal get_ops_in_block response", APIID)
}
Expand Down
10 changes: 0 additions & 10 deletions apis/database/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,6 @@ type TrendingTags struct {
Comments *types.Int `json:"comments"`
}

type OpsInBlock struct {
TrxID string `json:"trx_id"`
Block *types.Int `json:"block"`
TrxInBlock *types.Int `json:"trx_in_block"`
OpInTrx *types.Int `json:"op_in_trx"`
VirtualOp *types.Int `json:"virtual_op"`
Timestamp string `json:"timestamp"`
Op []*interface{} `json:"op"`
}

type Categories struct {
ID *types.Int `json:"id"`
Name string `json:"name"`
Expand Down
53 changes: 53 additions & 0 deletions types/operation_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package types

import (
"encoding/json"
)

type OperationObject struct {
BlockNumber uint32 `json:"block"`
TransactionID string `json:"trx_id"`
TransactionInBlock uint32 `json:"trx_in_block"`
Operation Operation `json:"op"`
OperationInTransaction uint16 `json:"op_in_trx"`
VirtualOperation uint64 `json:"virtual_op"`
Timestamp *Time `json:"timestamp"`
}

type rawOperationObject struct {
BlockNumber uint32 `json:"block"`
TransactionID string `json:"trx_id"`
TransactionInBlock uint32 `json:"trx_in_block"`
Operation *operationTuple `json:"op"`
OperationInTransaction uint16 `json:"op_in_trx"`
VirtualOperation uint64 `json:"virtual_op"`
Timestamp *Time `json:"timestamp"`
}

func (op *OperationObject) UnmarshalJSON(p []byte) error {
var raw rawOperationObject
if err := json.Unmarshal(p, &raw); err != nil {
return err
}

op.BlockNumber = raw.BlockNumber
op.TransactionID = raw.TransactionID
op.TransactionInBlock = raw.TransactionInBlock
op.Operation = raw.Operation.Data
op.OperationInTransaction = raw.OperationInTransaction
op.VirtualOperation = raw.VirtualOperation
op.Timestamp = raw.Timestamp
return nil
}

func (op *OperationObject) MarshalJSON() ([]byte, error) {
return json.Marshal(&rawOperationObject{
BlockNumber: op.BlockNumber,
TransactionID: op.TransactionID,
TransactionInBlock: op.TransactionInBlock,
Operation: &operationTuple{op.Operation.Type(), op.Operation},
OperationInTransaction: op.OperationInTransaction,
VirtualOperation: op.VirtualOperation,
Timestamp: op.Timestamp,
})
}

0 comments on commit 4244660

Please sign in to comment.