forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtlc_timeoutrequest.go
100 lines (86 loc) · 2.77 KB
/
htlc_timeoutrequest.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
package lnwire
import (
"fmt"
"io"
"github.com/roasbeef/btcd/wire"
)
// HTLCTimeoutRequest is sent by Alice to Bob in order to timeout a previously
// added HTLC. Upon receipt of an HTLCTimeoutRequest the HTLC should be removed
// from the next commitment transaction, with the HTLCTimeoutRequest propgated
// backwards in the route to fully clear the HTLC.
type HTLCTimeoutRequest struct {
// ChannelPoint is the particular active channel that this HTLCTimeoutRequest
// is binded to.
ChannelPoint *wire.OutPoint
// HTLCKey references which HTLC on the remote node's commitment
// transaction has timed out.
HTLCKey HTLCKey
}
// Decode deserializes a serialized HTLCTimeoutRequest message stored in the passed
// io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) Decode(r io.Reader, pver uint32) error {
// ChannelPoint(8)
// HTLCKey(8)
err := readElements(r,
&c.ChannelPoint,
&c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
// NewHTLCTimeoutRequest creates a new HTLCTimeoutRequest message.
func NewHTLCTimeoutRequest() *HTLCTimeoutRequest {
return &HTLCTimeoutRequest{}
}
// A compile time check to ensure HTLCTimeoutRequest implements the lnwire.Message
// interface.
var _ Message = (*HTLCTimeoutRequest)(nil)
// Encode serializes the target HTLCTimeoutRequest into the passed io.Writer observing
// the protocol version specified.
//
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelPoint,
c.HTLCKey,
)
if err != nil {
return err
}
return nil
}
// Command returns the integer uniquely identifying this message type on the
// wire.
//
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) Command() uint32 {
return CmdHTLCTimeoutRequest
}
// MaxPayloadLength returns the maximum allowed payload size for a HTLCTimeoutRequest
// complete message observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) MaxPayloadLength(uint32) uint32 {
// 36 + 8
return 44
}
// Validate performs any necessary sanity checks to ensure all fields present
// on the HTLCTimeoutRequest are valid.
//
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) Validate() error {
// We're good!
return nil
}
// String returns the string representation of the target HTLCTimeoutRequest. //
// This is part of the lnwire.Message interface.
func (c *HTLCTimeoutRequest) String() string {
return fmt.Sprintf("\n--- Begin HTLCTimeoutRequest ---\n") +
fmt.Sprintf("ChannelPoint:\t%d\n", c.ChannelPoint) +
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
fmt.Sprintf("--- End HTLCTimeoutRequest ---\n")
}