Example #1
0
func (e *ECBlock) marshalBodyBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	for _, v := range e.GetBody().GetEntries() {
		p, err := v.MarshalBinary()
		if err != nil {
			return buf.Bytes(), err
		}
		buf.WriteByte(v.ECID())
		buf.Write(p)
	}

	return buf.DeepCopyBytes(), nil
}
Example #2
0
func (e *ECBlock) marshalHeaderBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	// 32 byte ECChainID
	buf.Write(e.GetHeader().GetECChainID().Bytes())

	// 32 byte BodyHash
	buf.Write(e.GetHeader().GetBodyHash().Bytes())

	// 32 byte Previous Header Hash
	buf.Write(e.GetHeader().GetPrevHeaderHash().Bytes())

	// 32 byte Previous Full Hash
	buf.Write(e.GetHeader().GetPrevFullHash().Bytes())

	// 4 byte Directory Block Height
	if err := binary.Write(buf, binary.BigEndian, e.GetHeader().GetDBHeight()); err != nil {
		return buf.Bytes(), err
	}

	// variable Header Expansion Size
	if err := primitives.EncodeVarInt(buf,
		uint64(len(e.GetHeader().GetHeaderExpansionArea()))); err != nil {
		return buf.Bytes(), err
	}

	// varable byte Header Expansion Area
	buf.Write(e.Header.GetHeaderExpansionArea())

	// 8 byte Object Count
	if err := binary.Write(buf, binary.BigEndian, e.Header.GetObjectCount()); err != nil {
		return nil, err
	}

	// 8 byte size of the Body
	if err := binary.Write(buf, binary.BigEndian, e.Header.GetBodySize()); err != nil {
		return nil, err
	}

	return buf.DeepCopyBytes(), nil
}