2015-12-30 16:38:57 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-05-23 23:54:34 +03:00
|
|
|
"io"
|
|
|
|
|
2016-05-15 17:17:44 +03:00
|
|
|
"github.com/roasbeef/btcd/btcec"
|
|
|
|
"github.com/roasbeef/btcd/wire"
|
2015-12-30 16:38:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type FundingSignComplete struct {
|
|
|
|
ReservationID uint64
|
|
|
|
|
|
|
|
TxID *wire.ShaHash
|
2015-12-31 11:25:00 +03:00
|
|
|
FundingTXSigs []*btcec.Signature
|
2015-12-30 16:38:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ReservationID (8)
|
|
|
|
// TxID (32)
|
|
|
|
// 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.TxID,
|
|
|
|
&c.FundingTXSigs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Creates a new FundingSignComplete
|
2015-12-30 16:38:57 +03:00
|
|
|
func NewFundingSignComplete() *FundingSignComplete {
|
|
|
|
return &FundingSignComplete{}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Serializes the item from the FundingSignComplete struct
|
|
|
|
// Writes the data to w
|
2015-12-30 16:38:57 +03:00
|
|
|
func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
2015-12-31 10:34:40 +03:00
|
|
|
err := writeElements(w,
|
2015-12-30 16:38:57 +03:00
|
|
|
c.ReservationID,
|
|
|
|
c.TxID,
|
|
|
|
c.FundingTXSigs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignComplete) Command() uint32 {
|
|
|
|
return CmdFundingSignComplete
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
2016-01-17 04:14:35 +03:00
|
|
|
// 8 (base size) + 32 + (73maxSigSize*127maxInputs)
|
2015-12-30 16:38:57 +03:00
|
|
|
return 9311
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
2015-12-30 16:38:57 +03:00
|
|
|
func (c *FundingSignComplete) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2015-12-30 16:38:57 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FundingSignComplete) 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
|
|
|
|
2015-12-30 16:38:57 +03:00
|
|
|
return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
|
|
|
|
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
|
|
|
fmt.Sprintf("TxID\t\t%s\n", c.TxID.String()) +
|
|
|
|
fmt.Sprintf("FundingTxSigs:") +
|
|
|
|
sigs +
|
|
|
|
fmt.Sprintf("--- End FundingSignComplete ---\n")
|
|
|
|
}
|