func extractData(buf *ledgerutil.Buffer) (*common.BlockData, []*txindexInfo, error) { data := &common.BlockData{} var txOffsets []*txindexInfo var numItems uint64 var err error if numItems, err = buf.DecodeVarint(); err != nil { return nil, nil, err } for i := uint64(0); i < numItems; i++ { var txEnvBytes []byte var txid string txOffset := buf.GetBytesConsumed() if txEnvBytes, err = buf.DecodeRawBytes(false); err != nil { return nil, nil, err } if txid, err = extractTxID(txEnvBytes); err != nil { return nil, nil, err } data.Data = append(data.Data, txEnvBytes) idxInfo := &txindexInfo{txid, &locPointer{txOffset, buf.GetBytesConsumed() - txOffset}} txOffsets = append(txOffsets, idxInfo) } return data, txOffsets, nil }
func extractMetadata(buf *ledgerutil.Buffer) (*common.BlockMetadata, error) { metadata := &common.BlockMetadata{} var numItems uint64 var metadataEntry []byte var err error if numItems, err = buf.DecodeVarint(); err != nil { return nil, err } for i := uint64(0); i < numItems; i++ { if metadataEntry, err = buf.DecodeRawBytes(false); err != nil { return nil, err } metadata.Metadata = append(metadata.Metadata, metadataEntry) } return metadata, nil }
func extractHeader(buf *ledgerutil.Buffer) (*common.BlockHeader, error) { header := &common.BlockHeader{} var err error if header.Number, err = buf.DecodeVarint(); err != nil { return nil, err } if header.DataHash, err = buf.DecodeRawBytes(false); err != nil { return nil, err } if header.PreviousHash, err = buf.DecodeRawBytes(false); err != nil { return nil, err } return header, nil }