lnwire: add missing cases in [read/write]Element
Add cases to encode/decode wire.OutPoint, and a final line to properly write out signatures fully.
This commit is contained in:
parent
61994bc294
commit
9978d889b7
@ -200,6 +200,10 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
if sliceLength > MaxSliceLength {
|
if sliceLength > MaxSliceLength {
|
||||||
return fmt.Errorf("Slice length too long!")
|
return fmt.Errorf("Slice length too long!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := wire.WriteVarBytes(w, 0, e); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case PkScript:
|
case PkScript:
|
||||||
// Make sure it's P2PKH or P2SH size or less.
|
// Make sure it's P2PKH or P2SH size or less.
|
||||||
scriptLength := len(e)
|
scriptLength := len(e)
|
||||||
@ -252,6 +256,21 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
if _, err := w.Write(idx[:]); err != nil {
|
if _, err := w.Write(idx[:]); err != nil {
|
||||||
return err
|
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
|
// TODO(roasbeef): *MsgTx
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown type in writeElement: %T", e)
|
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[:])
|
(*e).PreviousOutPoint.Index = binary.BigEndian.Uint32(idxBytes[:])
|
||||||
return nil
|
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:
|
default:
|
||||||
return fmt.Errorf("Unknown type in readElement: %T", e)
|
return fmt.Errorf("Unknown type in readElement: %T", e)
|
||||||
}
|
}
|
||||||
|
@ -173,9 +173,7 @@ func discardInput(r io.Reader, n uint32) {
|
|||||||
|
|
||||||
// WriteMessage writes a lightning Message to w including the necessary header
|
// WriteMessage writes a lightning Message to w including the necessary header
|
||||||
// information and returns the number of bytes written.
|
// information and returns the number of bytes written.
|
||||||
func WriteMessage(w io.Writer, msg Message, pver uint32,
|
func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet) (int, error) {
|
||||||
btcnet wire.BitcoinNet) (int, error) {
|
|
||||||
|
|
||||||
totalBytes := 0
|
totalBytes := 0
|
||||||
|
|
||||||
cmd := msg.Command()
|
cmd := msg.Command()
|
||||||
|
Loading…
Reference in New Issue
Block a user