Пример #1
0
func (b *IncreaseBalance) MarshalBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	buf.Write(b.ECPubKey[:])

	buf.Write(b.TXID.Bytes())

	primitives.EncodeVarInt(buf, b.Index)

	primitives.EncodeVarInt(buf, b.NumEC)

	return buf.DeepCopyBytes(), nil
}
Пример #2
0
// Write out the ABlockHeader to binary.
func (b *ABlockHeader) MarshalBinary() (data []byte, err error) {
	var buf primitives.Buffer

	data, err = b.GetAdminChainID().MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(data)

	data, err = b.PrevBackRefHash.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(data)

	binary.Write(&buf, binary.BigEndian, b.DBHeight)

	primitives.EncodeVarInt(&buf, b.HeaderExpansionSize)
	buf.Write(b.HeaderExpansionArea)

	binary.Write(&buf, binary.BigEndian, b.MessageCount)
	binary.Write(&buf, binary.BigEndian, b.BodySize)

	return buf.DeepCopyBytes(), err
}
Пример #3
0
// MarshalBinary.  'nuff said
func (a TransAddress) MarshalBinary() ([]byte, error) {
	var out bytes.Buffer

	err := primitives.EncodeVarInt(&out, a.Amount)
	if err != nil {
		return nil, err
	}
	data, err := a.Address.MarshalBinary()
	out.Write(data)

	return out.Bytes(), err
}
Пример #4
0
func (b *FBlock) MarshalHeader() ([]byte, error) {
	var out bytes.Buffer

	b.EndOfPeriod(0) // Clean up end of minute markers, if needed.

	out.Write(constants.FACTOID_CHAINID)

	if b.BodyMR == nil {
		b.BodyMR = new(primitives.Hash)
	}
	data, err := b.BodyMR.MarshalBinary()
	if err != nil {
		return nil, err
	}
	out.Write(data)

	if b.PrevKeyMR == nil {
		b.PrevKeyMR = new(primitives.Hash)
	}
	data, err = b.PrevKeyMR.MarshalBinary()
	if err != nil {
		return nil, err
	}
	out.Write(data)

	if b.PrevLedgerKeyMR == nil {
		b.PrevLedgerKeyMR = new(primitives.Hash)
	}
	data, err = b.PrevLedgerKeyMR.MarshalBinary()
	if err != nil {
		return nil, err
	}
	out.Write(data)

	binary.Write(&out, binary.BigEndian, uint64(b.ExchRate))
	binary.Write(&out, binary.BigEndian, uint32(b.DBHeight))

	primitives.EncodeVarInt(&out, 0) // At this point in time, nothing in the Expansion Header
	// so we just write out a zero.

	binary.Write(&out, binary.BigEndian, uint32(len(b.Transactions)))

	transdata, err := b.MarshalTrans() // first get trans data
	if err != nil {
		return nil, err
	}

	binary.Write(&out, binary.BigEndian, uint32(len(transdata))) // write out its length

	return out.Bytes(), nil
}
Пример #5
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
}
Пример #6
0
// This is what Gets Signed.  Yet signature blocks are part of the transaction.
// We don't include them here, and tack them on later.
func (t *Transaction) MarshalBinarySig() (newData []byte, err error) {
	var out primitives.Buffer

	primitives.EncodeVarInt(&out, t.GetVersion())

	hd := uint32(t.MilliTimestamp >> 16)
	ld := uint16(t.MilliTimestamp & 0xFFFF)
	binary.Write(&out, binary.BigEndian, uint32(hd))
	binary.Write(&out, binary.BigEndian, uint16(ld))

	out.WriteByte(byte(len(t.Inputs)))
	out.WriteByte(byte(len(t.Outputs)))
	out.WriteByte(byte(len(t.OutECs)))

	for _, input := range t.Inputs {
		data, err := input.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
	}

	for _, output := range t.Outputs {
		data, err := output.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
	}

	for _, outEC := range t.OutECs {
		data, err := outEC.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
	}

	return out.DeepCopyBytes(), nil
}