Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cmd/loop/l402.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,31 @@ func listAuth(ctx *cli.Context) error {
printJSON(tokens)
return nil
}

var fetchL402Command = cli.Command{
Name: "fetchl402",
Usage: "fetches a new L402 authentication token from the server",
Description: "Fetches a new L402 authentication token from the server. " +
"This token is required to listen to notifications from the server, " +
"such as reservation notifications. If a L402 is already present in " +
"the store, this command is a no-op.",
Action: fetchL402,
}

func fetchL402(ctx *cli.Context) error {
client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()

res, err := client.FetchL402Token(
context.Background(), &looprpc.FetchL402TokenRequest{},
)
if err != nil {
return err
}

printRespJSON(res)
return nil
}
2 changes: 1 addition & 1 deletion cmd/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func main() {
}
app.Commands = []cli.Command{
loopOutCommand, loopInCommand, termsCommand,
monitorCommand, quoteCommand, listAuthCommand,
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
Expand Down
4 changes: 2 additions & 2 deletions loopd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ func (d *Daemon) initialize(withMacaroonService bool) error {

// Start the notification manager.
notificationCfg := &notifications.Config{
Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn),
FetchL402: swapClient.Server.FetchL402,
Client: loop_swaprpc.NewSwapServerClient(swapClient.Conn),
CurrentToken: swapClient.L402Store.CurrentToken,
}
notificationManager := notifications.NewManager(notificationCfg)

Expand Down
4 changes: 4 additions & 0 deletions loopd/perms/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ var RequiredPermissions = map[string][]bakery.Op{
Entity: "auth",
Action: "read",
}},
"/looprpc.SwapClient/FetchL402Token": {{
Entity: "auth",
Action: "write",
}},
"/looprpc.SwapClient/SuggestSwaps": {{
Entity: "suggestions",
Action: "read",
Expand Down
15 changes: 15 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,21 @@ func (s *swapClientServer) GetLsatTokens(ctx context.Context,
return s.GetL402Tokens(ctx, req)
}

// FetchL402Token fetches a L402 Token from the server. This is required to
// listen for server notifications such as reservations. If a token is already
// in the local L402, nothing will happen.
func (s *swapClientServer) FetchL402Token(ctx context.Context,
_ *looprpc.FetchL402TokenRequest) (*looprpc.FetchL402TokenResponse,
error) {

err := s.impl.Server.FetchL402(ctx)
if err != nil {
return nil, err
}

return &looprpc.FetchL402TokenResponse{}, nil
}

// GetInfo returns basic information about the loop daemon and details to swaps
// from the swap store.
func (s *swapClientServer) GetInfo(ctx context.Context,
Expand Down
Loading
Loading