2015-12-30 16:38:57 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/btcec"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FundingSignAccept struct {
|
|
|
|
ReservationID uint64
|
|
|
|
|
|
|
|
CommitSig *btcec.Signature //Requester's Commitment
|
2015-12-31 11:25:00 +03:00
|
|
|
FundingTXSigs []*btcec.Signature
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignAccept) Decode(r io.Reader, pver uint32) error {
|
2015-12-31 11:41:55 +03:00
|
|
|
//ReservationID (8)
|
|
|
|
//CommitSig (73)
|
2015-12-30 16:38:57 +03:00
|
|
|
// First byte length then sig
|
|
|
|
//FundingTXSigs
|
|
|
|
// First byte is number of FundingTxSigs
|
|
|
|
// Sorted list of the requester's input signatures
|
|
|
|
// (originally provided in the Funding Request)
|
2015-12-31 10:34:40 +03:00
|
|
|
err := readElements(r,
|
2015-12-30 16:38:57 +03:00
|
|
|
&c.ReservationID,
|
|
|
|
&c.CommitSig,
|
|
|
|
&c.FundingTXSigs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//Creates a new FundingSignAccept
|
|
|
|
func NewFundingSignAccept() *FundingSignAccept {
|
|
|
|
return &FundingSignAccept{}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Serializes the item from the FundingSignAccept struct
|
|
|
|
//Writes the data to w
|
|
|
|
func (c *FundingSignAccept) Encode(w io.Writer, pver uint32) error {
|
2015-12-31 11:41:55 +03:00
|
|
|
//ReservationID
|
2015-12-30 16:38:57 +03:00
|
|
|
//CommitSig
|
|
|
|
//FundingTxSigs
|
2015-12-31 10:34:40 +03:00
|
|
|
err := writeElements(w,
|
2015-12-30 16:38:57 +03:00
|
|
|
c.ReservationID,
|
|
|
|
c.CommitSig,
|
|
|
|
c.FundingTXSigs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignAccept) Command() uint32 {
|
|
|
|
return CmdFundingSignAccept
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignAccept) MaxPayloadLength(uint32) uint32 {
|
|
|
|
//8 (base size) + 73 + (73maxSigSize*127maxInputs)
|
|
|
|
return 9352
|
|
|
|
}
|
|
|
|
|
|
|
|
//Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
|
|
|
func (c *FundingSignAccept) Validate() error {
|
|
|
|
//We're good!
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignAccept) String() string {
|
|
|
|
var sigs string
|
2015-12-31 11:25:00 +03:00
|
|
|
for i, in := range c.FundingTXSigs {
|
2015-12-30 16:38:57 +03:00
|
|
|
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
2015-12-31 11:25:00 +03:00
|
|
|
if in != nil {
|
2015-12-31 09:28:14 +03:00
|
|
|
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
|
|
|
}
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|
2015-12-31 10:34:40 +03:00
|
|
|
|
|
|
|
var serializedSig []byte
|
|
|
|
if &c.CommitSig != nil && c.CommitSig.R != nil {
|
|
|
|
serializedSig = c.CommitSig.Serialize()
|
|
|
|
}
|
|
|
|
|
2015-12-30 16:38:57 +03:00
|
|
|
return fmt.Sprintf("\n--- Begin FundingSignAccept ---\n") +
|
|
|
|
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
2015-12-31 10:34:40 +03:00
|
|
|
fmt.Sprintf("CommitSig\t\t%x\n", serializedSig) +
|
2015-12-30 16:38:57 +03:00
|
|
|
fmt.Sprintf("FundingTxSigs:") +
|
|
|
|
sigs +
|
|
|
|
fmt.Sprintf("--- End FundingSignAccept ---\n")
|
|
|
|
}
|