forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funding_signcomplete.go
84 lines (71 loc) · 1.85 KB
/
funding_signcomplete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package lnwire
import (
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/wire"
"io"
)
type FundingSignComplete struct {
ReservationID uint64
TxID *wire.ShaHash
FundingTXSigs []*btcec.Signature
}
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
// 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)
err := readElements(r,
&c.ReservationID,
&c.TxID,
&c.FundingTXSigs)
if err != nil {
return err
}
return nil
}
// Creates a new FundingSignComplete
func NewFundingSignComplete() *FundingSignComplete {
return &FundingSignComplete{}
}
// Serializes the item from the FundingSignComplete struct
// Writes the data to w
func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
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 {
// 8 (base size) + 32 + (73maxSigSize*127maxInputs)
return 9311
}
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *FundingSignComplete) Validate() error {
// We're good!
return nil
}
func (c *FundingSignComplete) String() string {
var sigs string
for i, in := range c.FundingTXSigs {
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
if in != nil {
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
}
}
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")
}