lnwire: add a case for a slice of signatures to readElement/writeElement

This commit modifies the readElement and writeElement functions to add
the capability of reading/writing a slice of btcec.Signature. This new
case is required for the upcoming commit which will modify the
CommitSig message to include a field which houses signatures of reach
HTLC on the commitment transaction.
This commit is contained in:
Olaoluwa Osuntokun 2017-07-28 16:26:06 -07:00
parent 7f36b70a4a
commit be67bd46cd
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -87,6 +87,19 @@ func writeElement(w io.Writer, element interface{}) error {
if _, err := w.Write(b[:]); err != nil {
return err
}
case []*btcec.Signature:
var b [2]byte
numSigs := uint16(len(e))
binary.BigEndian.PutUint16(b[:], numSigs)
if _, err := w.Write(b[:]); err != nil {
return err
}
for _, sig := range e {
if err := writeElement(w, sig); err != nil {
return err
}
}
case *btcec.Signature:
var b [64]byte
err := serializeSigToWire(&b, e)
@ -359,6 +372,25 @@ func readElement(r io.Reader, element interface{}) error {
*e = f
case *[]*btcec.Signature:
var l [2]byte
if _, err := io.ReadFull(r, l[:]); err != nil {
return err
}
numSigs := binary.BigEndian.Uint16(l[:])
var sigs []*btcec.Signature
if numSigs > 0 {
sigs = make([]*btcec.Signature, numSigs)
for i := 0; i < int(numSigs); i++ {
if err := readElement(r, &sigs[i]); err != nil {
return err
}
}
}
*e = sigs
case **btcec.Signature:
var b [64]byte
if _, err := io.ReadFull(r, b[:]); err != nil {