Skip to content

Commit 5ff9cd1

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 c5d9d1d commit 5ff9cd1

2 files changed

Lines changed: 52 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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"github.com/lightninglabs/loop/looprpc"
7+
"github.com/urfave/cli/v3"
8+
)
9+
10+
var recoverCommand = &cli.Command{
11+
Name: "recover",
12+
Usage: "restore static address and L402 state from a local backup file",
13+
Description: "Restores the local static-address state and L402 token " +
14+
"from an encrypted backup file. If --backup_file is omitted, " +
15+
"loopd will use the most recent immutable network-specific " +
16+
"L402 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 the most recent immutable L402 " +
22+
"backup file path",
23+
},
24+
},
25+
Action: runRecover,
26+
}
27+
28+
func runRecover(ctx context.Context, cmd *cli.Command) error {
29+
if cmd.NArg() > 0 {
30+
return showCommandHelp(ctx, cmd)
31+
}
32+
33+
client, cleanup, err := getClient(cmd)
34+
if err != nil {
35+
return err
36+
}
37+
defer cleanup()
38+
39+
resp, err := client.Recover(
40+
ctx, &looprpc.RecoverRequest{
41+
BackupFile: cmd.String("backup_file"),
42+
},
43+
)
44+
if err != nil {
45+
return err
46+
}
47+
48+
printRespJSON(resp)
49+
return nil
50+
}

0 commit comments

Comments
 (0)