mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 17:53:30 +02:00
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:
parent
7f36b70a4a
commit
be67bd46cd
@ -87,6 +87,19 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
if _, err := w.Write(b[:]); err != nil {
|
if _, err := w.Write(b[:]); err != nil {
|
||||||
return err
|
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:
|
case *btcec.Signature:
|
||||||
var b [64]byte
|
var b [64]byte
|
||||||
err := serializeSigToWire(&b, e)
|
err := serializeSigToWire(&b, e)
|
||||||
@ -359,6 +372,25 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
|
|
||||||
*e = f
|
*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:
|
case **btcec.Signature:
|
||||||
var b [64]byte
|
var b [64]byte
|
||||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
if _, err := io.ReadFull(r, b[:]); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user