示例#1
0
func (a RCD_1) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer
	out.WriteByte(byte(1)) // The First Authorization method
	out.Write(a.PublicKey[:])

	return out.DeepCopyBytes(), nil
}
示例#2
0
func (m *ServerFault) MarshalCore() (data []byte, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("Error marshalling Server Fault Core: %v", r)
		}
	}()

	var buf primitives.Buffer

	if d, err := m.ServerID.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}
	if d, err := m.AuditServerID.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}

	buf.WriteByte(m.VMIndex)
	binary.Write(&buf, binary.BigEndian, uint32(m.DBHeight))
	binary.Write(&buf, binary.BigEndian, uint32(m.Height))

	return buf.DeepCopyBytes(), nil
}
示例#3
0
func (m *MissingMsg) MarshalBinary() ([]byte, error) {
	var buf primitives.Buffer

	binary.Write(&buf, binary.BigEndian, m.Type())

	t := m.GetTimestamp()
	data, err := t.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(data)

	if m.Asking == nil {
		m.Asking = primitives.NewHash(constants.ZERO_HASH)
	}
	data, err = m.Asking.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(data)

	buf.WriteByte(uint8(m.VMIndex))
	binary.Write(&buf, binary.BigEndian, m.DBHeight)
	binary.Write(&buf, binary.BigEndian, m.SystemHeight)

	binary.Write(&buf, binary.BigEndian, uint32(len(m.ProcessListHeight)))
	for _, h := range m.ProcessListHeight {
		binary.Write(&buf, binary.BigEndian, h)
	}

	bb := buf.DeepCopyBytes()

	return bb, nil
}
示例#4
0
func (m *ServerFault) PreMarshalBinary() (data []byte, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("Error marshalling Invalid Server Fault: %v", r)
		}
	}()

	var buf primitives.Buffer

	buf.Write([]byte{m.Type()})
	if d, err := m.ServerID.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}
	if d, err := m.AuditServerID.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}

	buf.WriteByte(m.VMIndex)
	binary.Write(&buf, binary.BigEndian, uint32(m.DBHeight))
	binary.Write(&buf, binary.BigEndian, uint32(m.Height))
	binary.Write(&buf, binary.BigEndian, uint32(m.SystemHeight))
	if d, err := m.Timestamp.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}

	return buf.DeepCopyBytes(), nil
}
示例#5
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
}
func (m *MissingMsgResponse) MarshalBinary() ([]byte, error) {
	var buf primitives.Buffer

	binary.Write(&buf, binary.BigEndian, m.Type())

	t := m.GetTimestamp()
	data, err := t.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(data)

	if m.AckResponse == nil {
		buf.WriteByte(0)
	} else {
		buf.WriteByte(1)

		ackData, err := m.AckResponse.MarshalBinary()
		if err != nil {
			return nil, err
		}
		buf.Write(ackData)
	}

	msgData, err := m.MsgResponse.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.Write(msgData)

	var mmm MissingMsgResponse

	bb := buf.DeepCopyBytes()

	//TODO: delete this once we have unit tests
	if unmarshalErr := mmm.UnmarshalBinary(bb); unmarshalErr != nil {
		fmt.Println("MissingMsgResponse failed to marshal/unmarshal: ", unmarshalErr)
		return nil, unmarshalErr
	}

	return bb, nil
}
示例#7
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
}
func (b *DBlockHeader) MarshalBinary() ([]byte, error) {
	var buf primitives.Buffer

	buf.WriteByte(b.Version)
	binary.Write(&buf, binary.BigEndian, b.NetworkID)

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

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

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

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

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

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

	if b.BlockCount > 100000 {
		panic("Send: Blockcount too great in directory block")
	}

	return buf.DeepCopyBytes(), err
}
示例#9
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
}
示例#10
0
//Construct the entry and submit it to the server
func (a *Anchor) submitEntryToAnchorChain(aRecord *AnchorRecord) error {
	jsonARecord, err := json.Marshal(aRecord)
	//anchorLog.Debug("submitEntryToAnchorChain - jsonARecord: ", string(jsonARecord))
	if err != nil {
		return err
	}
	bufARecord := new(primitives.Buffer)
	bufARecord.Write(jsonARecord)
	aRecordSig := a.serverPrivKey.Sign(jsonARecord)

	//Create a new entry
	entry := entryBlock.NewEntry()
	entry.ChainID = a.anchorChainID
	anchorLog.Debug("anchorChainID: ", a.anchorChainID)
	// instead of append signature at the end of anchor record
	// it can be added as the first entry.ExtIDs[0]
	entry.ExtIDs = append(entry.ExtIDs, primitives.ByteSlice{Bytes: aRecordSig.Bytes()})
	entry.Content = primitives.ByteSlice{Bytes: bufARecord.DeepCopyBytes()}
	//anchorLog.Debug("entry: ", spew.Sdump(entry))

	buf := new(primitives.Buffer)
	// 1 byte version
	buf.Write([]byte{0})
	// 6 byte milliTimestamp (truncated unix time)
	buf.Write(milliTime())
	// 32 byte Entry Hash
	buf.Write(entry.GetHash().Bytes())
	// 1 byte number of entry credits to pay
	binaryEntry, err := entry.MarshalBinary()
	if err != nil {
		return err
	}

	anchorLog.Debug("jsonARecord binary entry: ", hex.EncodeToString(binaryEntry))
	if c, err := util.EntryCost(binaryEntry); err == nil {
		buf.WriteByte(byte(c))
	} else {
		return err
	}

	tmp := buf.DeepCopyBytes()
	sig := a.serverECKey.Sign(tmp).(*primitives.Signature)
	buf = primitives.NewBuffer(tmp)
	buf.Write(a.serverECKey.Pub[:])
	buf.Write(sig.Sig[:])

	commit := entryCreditBlock.NewCommitEntry()
	err = commit.UnmarshalBinary(buf.DeepCopyBytes())
	if err != nil {
		return err
	}

	// create a CommitEntry msg and send it to the local inmsgQ
	cm := messages.NewCommitEntryMsg()
	cm.CommitEntry = commit
	a.state.InMsgQueue() <- cm

	// create a RevealEntry msg and send it to the local inmsgQ
	rm := messages.NewRevealEntryMsg()
	rm.Entry = entry
	a.state.InMsgQueue() <- rm

	return nil
}
示例#11
0
func (m *MinuteNumber) MarshalBinary() ([]byte, error) {
	buf := new(primitives.Buffer)
	buf.WriteByte(m.Number)
	return buf.DeepCopyBytes(), nil
}
示例#12
0
func (s *ServerIndexNumber) MarshalBinary() ([]byte, error) {
	buf := new(primitives.Buffer)
	buf.WriteByte(s.ServerIndexNumber)
	return buf.DeepCopyBytes(), nil
}