diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index d62d9a43..67e4629c 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -200,6 +200,10 @@ func writeElement(w io.Writer, element interface{}) error { if sliceLength > MaxSliceLength { return fmt.Errorf("Slice length too long!") } + + if err := wire.WriteVarBytes(w, 0, e); err != nil { + return err + } case PkScript: // Make sure it's P2PKH or P2SH size or less. scriptLength := len(e) @@ -252,6 +256,21 @@ func writeElement(w io.Writer, element interface{}) error { if _, err := w.Write(idx[:]); err != nil { return err } + case wire.OutPoint: + // TODO(roasbeef): consolidate with above + // First write out the previous txid. + var h [32]byte + copy(h[:], e.Hash[:]) + if _, err := w.Write(h[:]); err != nil { + return err + } + + // Then the exact index of this output. + var idx [4]byte + binary.BigEndian.PutUint32(idx[:], e.Index) + if _, err := w.Write(idx[:]); err != nil { + return err + } // TODO(roasbeef): *MsgTx default: return fmt.Errorf("Unknown type in writeElement: %T", e) @@ -478,6 +497,25 @@ func readElement(r io.Reader, element interface{}) error { } (*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:]) return nil + case *wire.OutPoint: + // TODO(roasbeef): consolidate with above + var h [32]byte + if _, err = io.ReadFull(r, h[:]); err != nil { + return err + } + hash, err := wire.NewShaHash(h[:]) + if err != nil { + return err + } + (*e).Hash = *hash + + // Index + var idxBytes [4]byte + _, err = io.ReadFull(r, idxBytes[:]) + if err != nil { + return err + } + (*e).Index = binary.BigEndian.Uint32(idxBytes[:]) default: return fmt.Errorf("Unknown type in readElement: %T", e) } diff --git a/lnwire/message.go b/lnwire/message.go index 026a7901..340db2f2 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -173,9 +173,7 @@ func discardInput(r io.Reader, n uint32) { // WriteMessage writes a lightning Message to w including the necessary header // information and returns the number of bytes written. -func WriteMessage(w io.Writer, msg Message, pver uint32, - btcnet wire.BitcoinNet) (int, error) { - +func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet) (int, error) { totalBytes := 0 cmd := msg.Command()