コード例 #1
0
ファイル: signature.go プロジェクト: FactomProject/factomd
func (s FactoidSignature) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer

	out.Write(s.Signature[:])

	return out.DeepCopyBytes(), nil
}
コード例 #2
0
ファイル: ecblockBody.go プロジェクト: FactomProject/factomd
func (e *ECBlockBody) String() string {
	var out primitives.Buffer
	for _, v := range e.Entries {
		out.WriteString(v.String())
	}
	return string(out.DeepCopyBytes())
}
コード例 #3
0
ファイル: eblockBody.go プロジェクト: FactomProject/factomd
func (e *EBlockBody) String() string {
	var out primitives.Buffer
	for _, eh := range e.EBEntries {
		out.WriteString(fmt.Sprintf("    %20s: %x\n", "Entry Hash", eh.Bytes()[:3]))
	}
	return (string)(out.DeepCopyBytes())
}
コード例 #4
0
ファイル: anchorChain.go プロジェクト: FactomProject/factomd
// MilliTime returns a 6 byte slice representing the unix time in milliseconds
func milliTime() (r []byte) {
	buf := new(primitives.Buffer)
	t := time.Now().UnixNano()
	m := t / 1e6
	binary.Write(buf, binary.BigEndian, m)
	return buf.DeepCopyBytes()[2:]
}
コード例 #5
0
func (e *AddReplaceMatryoshkaHash) String() string {
	var out primitives.Buffer
	out.WriteString(fmt.Sprintf("    E: %35s -- %17s %8x %12s %8s\n",
		"AddReplaceMatryoshkaHash",
		"IdentityChainID", e.IdentityChainID.Bytes()[:4],
		"MHash", e.MHash.String()[:8]))
	return (string)(out.DeepCopyBytes())
}
コード例 #6
0
func (e *IncreaseServerCount) MarshalBinary() (data []byte, err error) {
	var buf primitives.Buffer

	buf.Write([]byte{e.Type()})
	buf.Write([]byte{e.Amount})

	return buf.DeepCopyBytes(), nil
}
コード例 #7
0
ファイル: addresses.go プロジェクト: FactomProject/factomd
func NewPrivKeyString(n uint64) string {
	buf := new(primitives.Buffer)
	if err := binary.Write(buf, binary.BigEndian, n); err != nil {
		panic(err)
	}

	priv := fmt.Sprintf("000000000000000000000000000000000000000000000000%x", buf.DeepCopyBytes())
	return priv
}
コード例 #8
0
ファイル: eblock.go プロジェクト: FactomProject/factomd
// marshalBodyBinary returns a serialized binary Entry Block Body
func (e *EBlock) marshalBodyBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	for _, v := range e.Body.EBEntries {
		buf.Write(v.Bytes())
	}

	return buf.DeepCopyBytes(), nil
}
コード例 #9
0
func (e *AddFederatedServerSigningKey) String() string {
	var out primitives.Buffer
	out.WriteString(fmt.Sprintf("    E: %35s -- %17s %8x %12s %8x %12s %8s %12s %d\n",
		"AddFederatedServerSigningKey",
		"IdentityChainID", e.IdentityChainID.Bytes()[:4],
		"KeyPriority", e.KeyPriority,
		"PublicKey", e.PublicKey.String()[:8],
		"DBHeight", e.DBHeight))
	return (string)(out.DeepCopyBytes())
}
コード例 #10
0
func (e *AddFederatedServerBitcoinAnchorKey) String() string {
	var out primitives.Buffer
	out.WriteString(fmt.Sprintf("    E: %35s -- %17s %8x %12s %8x %12s %8x %12s %8s\n",
		"AddFederatedServerBitcoinAnchorKey",
		"IdentityChainID", e.IdentityChainID.Bytes()[:4],
		"KeyPriority", e.KeyPriority,
		"KeyType", e.KeyType,
		"ECDSAPublicKey", e.ECDSAPublicKey.String()[:8]))
	return (string)(out.DeepCopyBytes())
}
コード例 #11
0
ファイル: missingMsg.go プロジェクト: FactomProject/factomd
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
}
コード例 #12
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
}
コード例 #13
0
ファイル: transaction.go プロジェクト: FactomProject/factomd
// This just Marshals what gets signed, i.e. MarshalBinarySig(), then
// Marshals the signatures and the RCDs for this transaction.
func (t Transaction) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer

	data, err := t.MarshalBinarySig()
	if err != nil {
		return nil, err
	}
	out.Write(data)

	for i, rcd := range t.RCDs {

		// Write the RCD
		data, err := rcd.MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)

		// Then write its signature blocks.  This needs to be
		// reworked so we use the information from the RCD block
		// to control the writing of the signatures.  After all,
		// we don't want to restrict what might be required to
		// sign an input.
		if len(t.SigBlocks) <= i {
			t.SigBlocks = append(t.SigBlocks, new(SignatureBlock))
		}
		data, err = t.SigBlocks[i].MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
	}

	return out.DeepCopyBytes(), nil
}
コード例 #14
0
ファイル: eom.go プロジェクト: FactomProject/factomd
func (m *EOM) MarshalBinary() (data []byte, err error) {
	var buf primitives.Buffer
	resp, err := m.MarshalForSignature()
	if err != nil {
		return nil, err
	}
	buf.Write(resp)

	binary.Write(&buf, binary.BigEndian, m.DBHeight)
	binary.Write(&buf, binary.BigEndian, m.SysHeight)

	if m.SysHash == nil {
		m.SysHash = primitives.NewHash(constants.ZERO_HASH)
	}
	if d, err := m.SysHash.MarshalBinary(); err != nil {
		return nil, err
	} else {
		buf.Write(d)
	}

	sig := m.GetSignature()
	if sig != nil {
		sigBytes, err := sig.MarshalBinary()
		if err != nil {
			return nil, err
		}
		buf.Write(sigBytes)
	}
	return buf.DeepCopyBytes(), nil
}
コード例 #15
0
ファイル: entry.go プロジェクト: FactomProject/factomd
func (e *Entry) MarshalBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	// 1 byte Version
	if err := binary.Write(buf, binary.BigEndian, e.Version); err != nil {
		return nil, err
	}

	// 32 byte ChainID
	buf.Write(e.ChainID.Bytes())

	// ExtIDs
	if ext, err := e.MarshalExtIDsBinary(); err != nil {
		return nil, err
	} else {
		// 2 byte size of ExtIDs
		if err := binary.Write(buf, binary.BigEndian, int16(len(ext))); err != nil {
			return nil, err
		}

		// binary ExtIDs
		buf.Write(ext)
	}

	// Content
	buf.Write(e.Content.Bytes)

	return buf.DeepCopyBytes(), nil
}
コード例 #16
0
ファイル: bounce.go プロジェクト: FactomProject/factomd
func (m *Bounce) MarshalForSignature() ([]byte, error) {
	var buf primitives.Buffer

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

	var buff [32]byte

	copy(buff[:32], []byte(fmt.Sprintf("%32s", m.Name)))
	buf.Write(buff[:])

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

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

	binary.Write(&buf, binary.BigEndian, int32(len(m.Stamps)))

	for _, ts := range m.Stamps {
		data, err := ts.MarshalBinary()
		if err != nil {
			return nil, err
		}
		buf.Write(data)
	}

	return buf.DeepCopyBytes(), nil
}
コード例 #17
0
func (m *EntryBlockResponse) MarshalForSignature() ([]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)

	m.EBlockCount = uint32(len(m.EBlocks))
	binary.Write(&buf, binary.BigEndian, m.EBlockCount)
	for _, eb := range m.EBlocks {
		bin, err := eb.MarshalBinary()
		if err != nil {
			return nil, err
		}
		buf.Write(bin)
	}

	m.EntryCount = uint32(len(m.Entries))
	binary.Write(&buf, binary.BigEndian, m.EntryCount)
	for _, e := range m.Entries {
		bin, err := e.MarshalBinary()
		if err != nil {
			return nil, err
		}
		buf.Write(bin)
	}

	return buf.DeepCopyBytes(), nil
}
コード例 #18
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
}
コード例 #19
0
func (m *ChangeServerKeyMsg) MarshalForSignature() ([]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)

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

	binary.Write(&buf, binary.BigEndian, uint8(m.AdminBlockChange))
	binary.Write(&buf, binary.BigEndian, uint8(m.KeyType))
	binary.Write(&buf, binary.BigEndian, uint8(m.KeyPriority))

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

	return buf.DeepCopyBytes(), nil
}
コード例 #20
0
ファイル: dbInfo.go プロジェクト: FactomProject/factomd
func (e *DirBlockInfo) MarshalBinary() ([]byte, error) {
	var data primitives.Buffer

	enc := gob.NewEncoder(&data)

	err := enc.Encode(newDirBlockInfoCopyFromDBI(e))
	if err != nil {
		return nil, err
	}
	return data.DeepCopyBytes(), nil
}
コード例 #21
0
ファイル: transaddress.go プロジェクト: FactomProject/factomd
// MarshalBinary.  'nuff said
func (a TransAddress) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer

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

	return out.DeepCopyBytes(), err
}
コード例 #22
0
ファイル: signature.go プロジェクト: FactomProject/factomd
func (s FactoidSignature) CustomMarshalText() ([]byte, error) {
	var out primitives.Buffer

	out.WriteString(" FactoidSignature: ")
	out.WriteString(hex.EncodeToString(s.Signature[:]))
	out.WriteString("\n")

	return out.DeepCopyBytes(), nil
}
コード例 #23
0
func (e *RevealMatryoshkaHash) MarshalBinary() (data []byte, err error) {
	var buf primitives.Buffer

	buf.Write([]byte{e.Type()})
	buf.Write(e.IdentityChainID.Bytes())
	buf.Write(e.MHash.Bytes())

	return buf.DeepCopyBytes(), nil
}
コード例 #24
0
ファイル: commitEntry.go プロジェクト: FactomProject/factomd
func (m *CommitEntryMsg) MarshalForSignature() (data []byte, err error) {
	var buf primitives.Buffer

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

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

	return buf.DeepCopyBytes(), nil
}
コード例 #25
0
func (e *IncreaseBalance) String() string {
	var out primitives.Buffer
	out.WriteString(fmt.Sprintf(" %-20s\n", "IncreaseBalance"))
	out.WriteString(fmt.Sprintf("   %-20s %x\n", "ECPubKey", e.ECPubKey[:3]))
	out.WriteString(fmt.Sprintf("   %-20s %x\n", "TXID", e.TXID.Bytes()[:3]))
	out.WriteString(fmt.Sprintf("   %-20s %d\n", "Index", e.Index))
	out.WriteString(fmt.Sprintf("   %-20s %x\n", "NumEC", e.NumEC))

	return (string)(out.DeepCopyBytes())
}
コード例 #26
0
func (a SignatureBlock) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer

	for _, sig := range a.GetSignatures() {

		data, err := sig.MarshalBinary()
		if err != nil {
			return nil, fmt.Errorf("Signature failed to Marshal in RCD_1")
		}
		out.Write(data)
	}

	return out.DeepCopyBytes(), nil
}
コード例 #27
0
func (sl *SigList) MarshalBinary() (data []byte, err error) {
	var buf primitives.Buffer

	binary.Write(&buf, binary.BigEndian, uint32(sl.Length))

	for _, individualSig := range sl.List {
		if d, err := individualSig.MarshalBinary(); err != nil {
			return nil, err
		} else {
			buf.Write(d)
		}
	}

	return buf.DeepCopyBytes(), nil
}
コード例 #28
0
ファイル: entry.go プロジェクト: FactomProject/factomd
// MarshalExtIDsBinary marshals the ExtIDs into a []byte containing a series of
// 2 byte size of each ExtID followed by the ExtID.
func (e *Entry) MarshalExtIDsBinary() ([]byte, error) {
	buf := new(primitives.Buffer)

	for _, x := range e.ExtIDs {
		// 2 byte size of the ExtID
		if err := binary.Write(buf, binary.BigEndian, uint16(len(x.Bytes))); err != nil {
			return nil, err
		}

		// ExtID bytes
		buf.Write(x.Bytes)
	}

	return buf.DeepCopyBytes(), nil
}
コード例 #29
0
ファイル: rcd2.go プロジェクト: FactomProject/factomd
func (a RCD_2) MarshalBinary() ([]byte, error) {
	var out primitives.Buffer

	binary.Write(&out, binary.BigEndian, uint8(2))
	binary.Write(&out, binary.BigEndian, uint16(a.N))
	binary.Write(&out, binary.BigEndian, uint16(a.M))
	for i := 0; i < a.M; i++ {
		data, err := a.N_Addresses[i].MarshalBinary()
		if err != nil {
			return nil, err
		}
		out.Write(data)
	}

	return out.DeepCopyBytes(), nil
}
コード例 #30
0
func TestMakeSureBlockCountIsNotDuplicates(t *testing.T) {
	fmt.Println("\n---\nTestMakeSureBlockCountIsNotDuplicates\n---\n")
	block := createTestDirectoryBlock()
	err := block.SetDBEntries([]interfaces.IDBEntry{})
	if err != nil {
		t.Errorf("Error: %v", err)
	}
	min := 1000
	max := -1

	for i := 0; i < 100; i++ {
		//Update the BlockCount in header
		block.GetHeader().SetBlockCount(uint32(len(block.GetDBEntries())))
		//Marshal the block
		marshalled, err := block.MarshalBinary()
		if err != nil {
			t.Errorf("Error: %v", err)
		}
		//Get the byte representation of BlockCount
		var buf primitives.Buffer
		binary.Write(&buf, binary.BigEndian, block.GetHeader().GetBlockCount())
		hex := buf.DeepCopyBytes()

		//How many times does BlockCount appear in the marshalled slice?
		count := bytes.Count(marshalled, hex)
		if count > max {
			max = count
		}
		if count < min {
			min = count
		}

		de := new(DBEntry)
		de.ChainID = primitives.NewZeroHash()
		de.KeyMR = primitives.NewZeroHash()

		err = block.SetDBEntries(append(block.GetDBEntries(), de))
		if err != nil {
			t.Errorf("Error: %v", err)
		}
	}
	t.Logf("Min count - %v, max count - %v", min, max)
	if min != 1 {
		t.Errorf("Invalid number of BlockCount occurances")
	}
}