forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htlc_addaccept.go
71 lines (59 loc) · 1.29 KB
/
htlc_addaccept.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"
)
// HTLCAddAccept ...
type HTLCAddAccept struct {
ChannelID uint64
HTLCKey HTLCKey
}
// Decode ...
func (c *HTLCAddAccept) 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
}
// NewHTLCAddAccept creates a new HTLCAddAccept
func NewHTLCAddAccept() *HTLCAddAccept {
return &HTLCAddAccept{}
}
// Encode serializes the item from the HTLCAddAccept struct
// Writes the data to w
func (c *HTLCAddAccept) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
// Command ...
func (c *HTLCAddAccept) Command() uint32 {
return CmdHTLCAddAccept
}
// MaxPayloadLength ...
func (c *HTLCAddAccept) MaxPayloadLength(uint32) uint32 {
// 16 base size
return 16
}
// Validate makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *HTLCAddAccept) Validate() error {
// We're good!
return nil
}
func (c *HTLCAddAccept) String() string {
return fmt.Sprintf("\n--- Begin HTLCAddAccept ---\n") +
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
fmt.Sprintf("HTLCKey:\t\t%d\n", c.HTLCKey) +
fmt.Sprintf("--- End HTLCAddAccept ---\n")
}