Beispiel #1
0
// Marshal to text.  Largely a debugging thing.
func (t *Transaction) CustomMarshalText() (text []byte, err error) {
	data, err := t.MarshalBinary()
	if err != nil {
		return nil, err
	}
	var out primitives.Buffer
	out.WriteString(fmt.Sprintf("Transaction (size %d):\n", len(data)))
	out.WriteString("                 Version: ")
	primitives.WriteNumber64(&out, uint64(t.GetVersion()))
	out.WriteString("\n          MilliTimestamp: ")
	primitives.WriteNumber64(&out, uint64(t.MilliTimestamp))
	ts := time.Unix(0, int64(t.MilliTimestamp*1000000))
	out.WriteString(ts.UTC().Format(" Jan 2, 2006 at 15:04:05 (MST)"))
	out.WriteString("\n                # Inputs: ")
	primitives.WriteNumber16(&out, uint16(len(t.Inputs)))
	out.WriteString("\n               # Outputs: ")
	primitives.WriteNumber16(&out, uint16(len(t.Outputs)))
	out.WriteString("\n   # EntryCredit Outputs: ")
	primitives.WriteNumber16(&out, uint16(len(t.OutECs)))
	out.WriteString("\n")
	for _, address := range t.Inputs {
		text, _ := address.CustomMarshalText()
		out.Write(text)
	}
	for _, address := range t.Outputs {
		text, _ := address.CustomMarshalText()
		out.Write(text)
	}
	for _, ecaddress := range t.OutECs {
		text, _ := ecaddress.CustomMarshalText()
		out.Write(text)
	}
	for i, rcd := range t.RCDs {
		text, err = rcd.CustomMarshalText()
		if err != nil {
			return nil, err
		}
		out.Write(text)

		for len(t.SigBlocks) <= i {
			t.SigBlocks = append(t.SigBlocks, new(SignatureBlock))
		}
		text, err := t.SigBlocks[i].CustomMarshalText()
		if err != nil {
			return nil, err
		}
		out.Write(text)
	}

	return out.DeepCopyBytes(), nil
}
Beispiel #2
0
// Marshal to text.  Largely a debugging thing.
func (b FBlock) CustomMarshalText() (text []byte, err error) {
	var out bytes.Buffer

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

	out.WriteString("Transaction Block\n")
	out.WriteString("  ChainID:       ")
	out.WriteString(hex.EncodeToString(constants.FACTOID_CHAINID))
	if b.BodyMR == nil {
		b.BodyMR = new(primitives.Hash)
	}
	out.WriteString("\n  BodyMR:        ")
	out.WriteString(b.BodyMR.String())
	if b.PrevKeyMR == nil {
		b.PrevKeyMR = new(primitives.Hash)
	}
	out.WriteString("\n  PrevKeyMR:     ")
	out.WriteString(b.PrevKeyMR.String())
	if b.PrevLedgerKeyMR == nil {
		b.PrevLedgerKeyMR = new(primitives.Hash)
	}
	out.WriteString("\n  PrevLedgerKeyMR:  ")
	out.WriteString(b.PrevLedgerKeyMR.String())
	out.WriteString("\n  ExchRate:      ")
	primitives.WriteNumber64(&out, b.ExchRate)
	out.WriteString("\n  DBHeight:      ")
	primitives.WriteNumber32(&out, b.DBHeight)
	out.WriteString("\n  Period Marks:  ")
	for _, mark := range b.endOfPeriod {
		out.WriteString(fmt.Sprintf("%d ", mark))
	}
	out.WriteString("\n  #Transactions: ")
	primitives.WriteNumber32(&out, uint32(len(b.Transactions)))
	transdata, err := b.MarshalTrans()
	if err != nil {
		return out.Bytes(), err
	}
	out.WriteString("\n  Body Size:     ")
	primitives.WriteNumber32(&out, uint32(len(transdata)))
	out.WriteString("\n\n")
	markPeriod := 0

	for i, trans := range b.Transactions {

		for markPeriod < 10 && i == b.endOfPeriod[markPeriod] {
			out.WriteString(fmt.Sprintf("\n   End of Minute %d\n\n", markPeriod+1))
			markPeriod++
		}

		txt, err := trans.CustomMarshalText()
		if err != nil {
			return out.Bytes(), err
		}
		out.Write(txt)
	}
	return out.Bytes(), nil
}