• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13408822928

19 Feb 2025 08:59AM UTC coverage: 41.123% (-17.7%) from 58.794%
13408822928

Pull #9521

github

web-flow
Merge d2f397b3c into 0e8786348
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

92496 of 224923 relevant lines covered (41.12%)

18825.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lntypes/channel_party.go
1
package lntypes
2

3
import "fmt"
4

5
// ChannelParty is a type used to have an unambiguous description of which node
6
// is being referred to. This eliminates the need to describe as "local" or
7
// "remote" using bool.
8
type ChannelParty uint8
9

10
const (
11
        // Local is a ChannelParty constructor that is used to refer to the
12
        // node that is running.
13
        Local ChannelParty = iota
14

15
        // Remote is a ChannelParty constructor that is used to refer to the
16
        // node on the other end of the peer connection.
17
        Remote
18
)
19

20
// String provides a string representation of ChannelParty (useful for logging).
21
func (p ChannelParty) String() string {
×
22
        switch p {
×
23
        case Local:
×
24
                return "Local"
×
25
        case Remote:
×
26
                return "Remote"
×
27
        default:
×
28
                panic(fmt.Sprintf("invalid ChannelParty value: %d", p))
×
29
        }
30
}
31

32
// CounterParty inverts the role of the ChannelParty.
33
func (p ChannelParty) CounterParty() ChannelParty {
×
34
        switch p {
×
35
        case Local:
×
36
                return Remote
×
37
        case Remote:
×
38
                return Local
×
39
        default:
×
40
                panic(fmt.Sprintf("invalid ChannelParty value: %v", p))
×
41
        }
42
}
43

44
// IsLocal returns true if the ChannelParty is Local.
45
func (p ChannelParty) IsLocal() bool {
×
46
        return p == Local
×
47
}
×
48

49
// IsRemote returns true if the ChannelParty is Remote.
50
func (p ChannelParty) IsRemote() bool {
×
51
        return p == Remote
×
52
}
×
53

54
// Dual represents a structure when we are tracking the same parameter for both
55
// the Local and Remote parties.
56
type Dual[A any] struct {
57
        // Local is the value tracked for the Local ChannelParty.
58
        Local A
59

60
        // Remote is the value tracked for the Remote ChannelParty.
61
        Remote A
62
}
63

64
// GetForParty gives Dual an access method that takes a ChannelParty as an
65
// argument. It is included for ergonomics in cases where the ChannelParty is
66
// in a variable and which party determines how we want to access the Dual.
67
func (d *Dual[A]) GetForParty(p ChannelParty) A {
×
68
        switch p {
×
69
        case Local:
×
70
                return d.Local
×
71
        case Remote:
×
72
                return d.Remote
×
73
        default:
×
74
                panic(fmt.Sprintf(
×
75
                        "switch default triggered in ForParty: %v", p,
×
76
                ))
×
77
        }
78
}
79

80
// SetForParty sets the value in the Dual for the given ChannelParty. This
81
// returns a copy of the original value.
82
func (d *Dual[A]) SetForParty(p ChannelParty, value A) {
×
83
        switch p {
×
84
        case Local:
×
85
                d.Local = value
×
86
        case Remote:
×
87
                d.Remote = value
×
88
        default:
×
89
                panic(fmt.Sprintf(
×
90
                        "switch default triggered in ForParty: %v", p,
×
91
                ))
×
92
        }
93
}
94

95
// ModifyForParty applies the function argument to the given ChannelParty field
96
// and returns a new copy of the Dual.
97
func (d *Dual[A]) ModifyForParty(p ChannelParty, f func(A) A) A {
×
98
        switch p {
×
99
        case Local:
×
100
                d.Local = f(d.Local)
×
101
                return d.Local
×
102
        case Remote:
×
103
                d.Remote = f(d.Remote)
×
104
                return d.Remote
×
105
        default:
×
106
                panic(fmt.Sprintf(
×
107
                        "switch default triggered in ForParty: %v", p,
×
108
                ))
×
109
        }
110
}
111

112
// MapDual applies the function argument to both the Local and Remote fields of
113
// the Dual[A] and returns a Dual[B] with that function applied.
114
func MapDual[A, B any](d Dual[A], f func(A) B) Dual[B] {
×
115
        return Dual[B]{
×
116
                Local:  f(d.Local),
×
117
                Remote: f(d.Remote),
×
118
        }
×
119
}
×
120

121
var BothParties []ChannelParty = []ChannelParty{Local, Remote}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc