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