Skip to content

Commit d4abbe5

Browse files
committed
Fix macaroon permissions and rename WtClientClient
WtClientClient renamed to WatchtowerClientClient in order to make macaroon permission code play nice. Change macaroon permission code to allow for Services with "Client" in the name.
1 parent 0f74c4b commit d4abbe5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

macaroon_recipes.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
"signrpc": (*SignerClient)(nil),
2222
"verrpc": (*VersionerClient)(nil),
2323
"walletrpc": (*WalletKitClient)(nil),
24-
"wtclientrpc": (*WtClientClient)(nil),
24+
"wtclientrpc": (*WatchtowerClientClient)(nil),
2525
}
2626

2727
// renames is a map of renamed RPC method names. The key is the name as
@@ -55,6 +55,15 @@ var (
5555
}
5656
)
5757

58+
func replaceRight(s, old, new string) string {
59+
i := strings.LastIndex(s, old)
60+
if i == -1 {
61+
return s
62+
}
63+
64+
return s[:i] + new + s[i+len(old):]
65+
}
66+
5867
// MacaroonRecipe returns a list of macaroon permissions that is required to use
5968
// the full feature set of the given list of RPC package names.
6069
func MacaroonRecipe(c LightningClient, packages []string) ([]MacaroonPermission,
@@ -78,7 +87,7 @@ func MacaroonRecipe(c LightningClient, packages []string) ([]MacaroonPermission,
7887
// From the pointer type we can find out the interface, its name
7988
// and what methods it declares.
8089
ifaceType := reflect.TypeOf(ifacePtr).Elem()
81-
serverName := strings.ReplaceAll(ifaceType.Name(), "Client", "")
90+
serverName := replaceRight(ifaceType.Name(), "Client", "")
8291
for i := range ifaceType.NumMethod() {
8392
// The methods in lndclient might be called slightly
8493
// differently. Rename according to our rename mapping

wtclient_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"google.golang.org/grpc"
99
)
1010

11-
type WtClientClient interface {
11+
type WatchtowerClientClient interface {
1212
ServiceClient[wtclientrpc.WatchtowerClientClient]
1313

1414
AddTower(ctx context.Context, pubkey []byte, address string) error
@@ -51,7 +51,7 @@ type wtClientClient struct {
5151

5252
// A compile time check to ensure that wtClientClient implements the
5353
// WtclientClient interface.
54-
var _ WtClientClient = (*wtClientClient)(nil)
54+
var _ WatchtowerClientClient = (*wtClientClient)(nil)
5555

5656
func newWtClientClient(conn grpc.ClientConnInterface,
5757
wtClientMac serializedMacaroon, timeout time.Duration) *wtClientClient {

0 commit comments

Comments
 (0)