Exemplo n.º 1
0
func (b *FBlock) MarshalTrans() ([]byte, error) {
	var out bytes.Buffer
	var periodMark = 0
	var i int
	var trans interfaces.ITransaction
	for i, trans = range b.Transactions {

		for periodMark < len(b.endOfPeriod) &&
			b.endOfPeriod[periodMark] > 0 && // Ignore if markers are not set
			i == b.endOfPeriod[periodMark] {

			out.WriteByte(constants.MARKER)
			periodMark++
		}

		data, err := trans.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
		if err != nil {
			return nil, err
		}
	}
	for periodMark < len(b.endOfPeriod) {
		out.WriteByte(constants.MARKER)
		periodMark++
	}
	return out.Bytes(), nil
}
Exemplo n.º 2
0
func (b *FBlock) MarshalTrans() ([]byte, error) {
	var out primitives.Buffer
	var periodMark = 0
	var i int
	var trans interfaces.ITransaction

	// 	for _, v := range b.GetEndOfPeriod() {
	// 		if v == 0 {
	// 			return nil, fmt.Errorf("Factoid Block is incomplete.  Missing EOM markers detected: %v",b.endOfPeriod)
	// 		}
	// 	}

	for i, trans = range b.Transactions {

		for periodMark < len(b.endOfPeriod) &&
			b.endOfPeriod[periodMark] > 0 && // Ignore if markers are not set
			i == b.endOfPeriod[periodMark] {

			out.WriteByte(constants.MARKER)
			periodMark++
		}

		data, err := trans.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
		if err != nil {
			return nil, err
		}
	}
	for periodMark < len(b.endOfPeriod) {
		out.WriteByte(constants.MARKER)
		periodMark++
	}
	return out.DeepCopyBytes(), nil
}