func (h *BlockHeader) MarshalBinary() ([]byte, error) { buf := new(bytes.Buffer) buf.Write(helpers.FitBytesInto(h.Origin, NETWORK_KEY_SIZE)) binary.Write(buf, binary.LittleEndian, h.Timestamp) buf.Write(helpers.FitBytesInto(h.PrevBlock, 32)) buf.Write(helpers.FitBytesInto(h.MerkelRoot, 32)) binary.Write(buf, binary.LittleEndian, h.Nonce) return buf.Bytes(), nil }
func (th *TransactionHeader) MarshalBinary() ([]byte, error) { buf := new(bytes.Buffer) buf.Write(helpers.FitBytesInto(th.From, NETWORK_KEY_SIZE)) buf.Write(helpers.FitBytesInto(th.To, NETWORK_KEY_SIZE)) binary.Write(buf, binary.LittleEndian, th.Timestamp) buf.Write(helpers.FitBytesInto(th.PayloadHash, 32)) binary.Write(buf, binary.LittleEndian, th.PayloadLength) binary.Write(buf, binary.LittleEndian, th.Nonce) return buf.Bytes(), nil }
func (t *Transaction) MarshalBinary() ([]byte, error) { headerBytes, _ := t.Header.MarshalBinary() if len(headerBytes) != TRANSACTION_HEADER_SIZE { return nil, errors.New("Header marshalling error") } return append(append(headerBytes, helpers.FitBytesInto(t.Signature, NETWORK_KEY_SIZE)...), t.Payload...), nil }
func (b *Block) MarshalBinary() ([]byte, error) { bhb, err := b.BlockHeader.MarshalBinary() if err != nil { return nil, err } sig := helpers.FitBytesInto(b.Signature, NETWORK_KEY_SIZE) tsb, err := b.TransactionSlice.MarshalBinary() if err != nil { return nil, err } return append(append(bhb, sig...), tsb...), nil }