forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_funding_signcomplete.go
108 lines (93 loc) · 3.14 KB
/
single_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package lnwire
import (
"fmt"
"io"
"github.com/roasbeef/btcd/btcec"
)
// SingleFundingSignComplete is the message Bob sends to Alice which delivers
// a signature for Alice's version of the commitment transaction. After thie
// message is received and processed by Alice, she is free to broadcast the
// funding transaction.
type SingleFundingSignComplete struct {
// ChannelID serves to uniquely identify the future channel created by
// the initiated single funder workflow.
ChannelID uint64
// CommitSignature is Bobs's signature for Alice's version of the
// commitment transaction.
CommitSignature *btcec.Signature
}
// NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete
// message.
func NewSingleFundingSignComplete(chanID uint64,
sig *btcec.Signature) *SingleFundingSignComplete {
return &SingleFundingSignComplete{
ChannelID: chanID,
CommitSignature: sig,
}
}
// Decode deserializes the serialized SingleFundingSignComplete stored in the
// passed io.Reader into the target SingleFundingComplete using the
// deserialization rules defined by the passed protocol version.
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error {
// ChannelID (8)
// CommitmentSignature (73)
err := readElements(r,
&c.ChannelID,
&c.CommitSignature)
if err != nil {
return err
}
return nil
}
// Encode serializes the target SingleFundingSignComplete into the passed
// io.Writer implementation. Serialization will observe the rules defined by
// the passed protocol version.
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.CommitSignature)
if err != nil {
return err
}
return nil
}
// Command returns the uint32 code which uniquely identifies this message as a
// SingleFundingSignComplete on the wire.
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) Command() uint32 {
return CmdSingleFundingSignComplete
}
// MaxPayloadLength returns the maximum allowed payload length for a
// SingleFundingComplete. This is calculated by summing the max length of all
// the fields within a SingleFundingResponse. The final breakdown
// is: 8 + 73 = 81
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32 {
return 81
}
// Validate examines each populated field within the SingleFundingComplete for
// field sanity.
//
// This is part of the lnwire.Message interface.
func (s *SingleFundingSignComplete) Validate() error {
if s.CommitSignature == nil {
return fmt.Errorf("commitment signature must be non-nil")
}
// We're good!
return nil
}
// String returns the string representation of the SingleFundingSignComplete.
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingSignComplete) String() string {
return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
fmt.Sprintf("CommitSignature\t\t%s\n", c.CommitSignature) +
fmt.Sprintf("--- End FundingSignComplete ---\n")
}