Ejemplo n.º 1
0
// Marshal to text.  Largely a debugging thing.
func (b FBlock) CustomMarshalText() (text []byte, err error) {
	var out primitives.Buffer

	out.WriteString("Transaction Block\n")
	out.WriteString("  ChainID:       ")
	out.WriteString(hex.EncodeToString(constants.FACTOID_CHAINID))
	keyMR := b.GetKeyMR()
	out.WriteString("\n  KeyMR (NM):    ")
	out.WriteString(keyMR.String())

	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:      ")
	out.WriteString(fmt.Sprintf("%d.%08d fct, %d factoshis", b.ExchRate/100000000, b.ExchRate%100000000, b.ExchRate))
	out.WriteString(fmt.Sprintf("\n  DBHeight:      %v", 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 nil, 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 nil, err
		}
		out.Write(txt)
	}
	return out.DeepCopyBytes(), nil
}
Ejemplo n.º 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
}