forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htlc_settleaccept.go
71 lines (59 loc) · 1.4 KB
/
htlc_settleaccept.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
package lnwire
import (
"fmt"
"io"
)
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
type HTLCSettleAccept struct {
// We can use a different data type for this if necessary...
ChannelID uint64
// ID of this request
HTLCKey HTLCKey
}
func (c *HTLCSettleAccept) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// HTLCKey(8)
err := readElements(r,
&c.ChannelID,
&c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
// Creates a new HTLCSettleAccept
func NewHTLCSettleAccept() *HTLCSettleAccept {
return &HTLCSettleAccept{}
}
// Serializes the item from the HTLCSettleAccept struct
// Writes the data to w
func (c *HTLCSettleAccept) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
func (c *HTLCSettleAccept) Command() uint32 {
return CmdHTLCSettleAccept
}
func (c *HTLCSettleAccept) MaxPayloadLength(uint32) uint32 {
// 16
return 16
}
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *HTLCSettleAccept) Validate() error {
// We're good!
return nil
}
func (c *HTLCSettleAccept) String() string {
return fmt.Sprintf("\n--- Begin HTLCSettleAccept ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
fmt.Sprintf("--- End HTLCSettleAccept ---\n")
}