Esempio n. 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
}
Esempio n. 2
0
func (a RCD_2) CustomMarshalText() ([]byte, error) {
	var out primitives.Buffer

	primitives.WriteNumber8(&out, uint8(2)) // Type 2 Authorization
	out.WriteString("\n n: ")
	primitives.WriteNumber16(&out, uint16(a.N))
	out.WriteString(" m: ")
	primitives.WriteNumber16(&out, uint16(a.M))
	out.WriteString("\n")
	for i := 0; i < a.M; i++ {
		out.WriteString("  m: ")
		out.WriteString(hex.EncodeToString(a.N_Addresses[i].Bytes()))
		out.WriteString("\n")
	}

	return out.DeepCopyBytes(), nil
}