3

I'm using the Hyperledger Golang SDK for implementing a client to work with the ledger. My application relies on events being sent, however, I want to use BlockEvents so that I can be sure that the given data is written to the ledger already instead of chaincode events. Unfortunately, the documentation on these type of events is very limited. I registered for BlockEvents using func (c *Client) RegisterBlockEvent()... and get BlockEvent responses with a Block struct referenced in each of them. The block struct looks like this:

type Block struct {
    Header               *BlockHeader   `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"`
    Data                 *BlockData     `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
    Metadata             *BlockMetadata `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"`
    XXX_NoUnkeyedLiteral struct{}       `json:"-"`
    XXX_unrecognized     []byte         `json:"-"`
    XXX_sizecache        int32          `json:"-"`
}

I can navigate to BlockData:

type BlockData struct {
    Data                 [][]byte `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
    XXX_NoUnkeyedLiteral struct{} `json:"-"`
    XXX_unrecognized     []byte   `json:"-"`
    XXX_sizecache        int32    `json:"-"`
}

However, at this point I am lost, having only a raw array of byte-arrays as data. I want to upon a specific asset creation event and need to parse the block data to search for the data. What struct or structure is used for this data? I assume every array entry represents a transaction, but without a struct to map onto it, parsing is extremely difficult.

Roper
  • 109
  • 5

1 Answers1

1

write a function ParseBlock with protolator

// import "github.com/hyperledger/fabric-sdk-go/pkg/util/protolator"


func ParseBlock(block *common.Block)  {
    if err := protolator.DeepMarshalJSON(os.Stdout, block); err != nil {
        log.Fatalln("DeepMarshalJSON err:", err)
    }
}