func (s FactoidSignature) MarshalBinary() ([]byte, error) { var out primitives.Buffer out.Write(s.Signature[:]) return out.DeepCopyBytes(), nil }
func (e *ECBlockBody) String() string { var out primitives.Buffer for _, v := range e.Entries { out.WriteString(v.String()) } return string(out.DeepCopyBytes()) }
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()) }
// 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:] }
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()) }
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 }
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 }
// 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 }
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()) }
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()) }
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 }
// 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 }
// 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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
// 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 }
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 }
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 }
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 }
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()) }
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 }
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 }
// 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 }
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 }
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") } }