Skip to content

Commit a544054

Browse files
authored
Merge pull request #841 from sputn1ck/better_ntfn_stream_l402
Notifications: Improve L402 handling
2 parents 15ee978 + 7ca5dc8 commit a544054

12 files changed

+829
-580
lines changed

cmd/loop/l402.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,31 @@ func listAuth(ctx *cli.Context) error {
7373
printJSON(tokens)
7474
return nil
7575
}
76+
77+
var fetchL402Command = cli.Command{
78+
Name: "fetchl402",
79+
Usage: "fetches a new L402 authentication token from the server",
80+
Description: "Fetches a new L402 authentication token from the server. " +
81+
"This token is required to listen to notifications from the server, " +
82+
"such as reservation notifications. If a L402 is already present in " +
83+
"the store, this command is a no-op.",
84+
Action: fetchL402,
85+
}
86+
87+
func fetchL402(ctx *cli.Context) error {
88+
client, cleanup, err := getClient(ctx)
89+
if err != nil {
90+
return err
91+
}
92+
defer cleanup()
93+
94+
res, err := client.FetchL402Token(
95+
context.Background(), &looprpc.FetchL402TokenRequest{},
96+
)
97+
if err != nil {
98+
return err
99+
}
100+
101+
printRespJSON(res)
102+
return nil
103+
}

cmd/loop/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func main() {
144144
}
145145
app.Commands = []cli.Command{
146146
loopOutCommand, loopInCommand, termsCommand,
147-
monitorCommand, quoteCommand, listAuthCommand,
147+
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
148148
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
149149
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
150150
getInfoCommand, abandonSwapCommand, reservationsCommands,

loopd/daemon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
504504

505505
// Start the notification manager.
506506
notificationCfg := &notifications.Config{
507-
Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn),
508-
FetchL402: swapClient.Server.FetchL402,
507+
Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn),
508+
CurrentToken: swapClient.L402Store.CurrentToken,
509509
}
510510
notificationManager := notifications.NewManager(notificationCfg)
511511

loopd/perms/perms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ var RequiredPermissions = map[string][]bakery.Op{
7777
Entity: "auth",
7878
Action: "read",
7979
}},
80+
"/looprpc.SwapClient/FetchL402Token": {{
81+
Entity: "auth",
82+
Action: "write",
83+
}},
8084
"/looprpc.SwapClient/SuggestSwaps": {{
8185
Entity: "suggestions",
8286
Action: "read",

loopd/swapclient_server.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,21 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
991991
return s.GetL402Tokens(ctx, req)
992992
}
993993

994+
// FetchL402Token fetches a L402 Token from the server. This is required to
995+
// listen for server notifications such as reservations. If a token is already
996+
// in the local L402, nothing will happen.
997+
func (s *swapClientServer) FetchL402Token(ctx context.Context,
998+
_ *looprpc.FetchL402TokenRequest) (*looprpc.FetchL402TokenResponse,
999+
error) {
1000+
1001+
err := s.impl.Server.FetchL402(ctx)
1002+
if err != nil {
1003+
return nil, err
1004+
}
1005+
1006+
return &looprpc.FetchL402TokenResponse{}, nil
1007+
}
1008+
9941009
// GetInfo returns basic information about the loop daemon and details to swaps
9951010
// from the swap store.
9961011
func (s *swapClientServer) GetInfo(ctx context.Context,

0 commit comments

Comments
 (0)