Skip to content

Commit bcf3b89

Browse files
committed
cmd/loop: add recover command for local backups
Expose the new recovery flow through loop-cli with a dedicated recover command that calls loopd over the existing RPC connection and optionally accepts a custom backup file path.
1 parent 3e00592 commit bcf3b89

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

cmd/loop/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ var (
8888
monitorCommand, quoteCommand, listAuthCommand, fetchL402Command,
8989
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
9090
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
91-
getInfoCommand, abandonSwapCommand, reservationsCommands,
91+
getInfoCommand, abandonSwapCommand, recoverCommand,
92+
reservationsCommands,
9293
instantOutCommand, listInstantOutsCommand, stopCommand,
9394
printManCommand, printMarkdownCommand,
9495
}

cmd/loop/recover.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"github.com/urfave/cli/v3"
7+
"google.golang.org/protobuf/types/known/structpb"
8+
"google.golang.org/protobuf/types/known/wrapperspb"
9+
)
10+
11+
var recoverCommand = &cli.Command{
12+
Name: "recover",
13+
Usage: "restore static address and L402 state from a local backup file",
14+
Description: "Restores the local static-address state and L402 token " +
15+
"from an encrypted backup file. If --backup_file is omitted, " +
16+
"loopd will use its default network-specific backup file.",
17+
Flags: []cli.Flag{
18+
&cli.StringFlag{
19+
Name: "backup_file",
20+
Usage: "path to an encrypted backup file; if omitted, " +
21+
"loopd uses its default backup file path",
22+
},
23+
},
24+
Action: runRecover,
25+
}
26+
27+
func runRecover(ctx context.Context, cmd *cli.Command) error {
28+
if cmd.NArg() > 0 {
29+
return showCommandHelp(ctx, cmd)
30+
}
31+
32+
_, conn, cleanup, err := getClientWithConn(cmd)
33+
if err != nil {
34+
return err
35+
}
36+
defer cleanup()
37+
38+
resp := &structpb.Struct{}
39+
err = conn.Invoke(
40+
ctx, "/looprpc.Recovery/Recover",
41+
wrapperspb.String(cmd.String("backup_file")), resp,
42+
)
43+
if err != nil {
44+
return err
45+
}
46+
47+
printJSON(resp.AsMap())
48+
return nil
49+
}

0 commit comments

Comments
 (0)