Skip to content

Commit

Permalink
dcrlncli: Add RescanWallet command
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusd committed Feb 1, 2024
1 parent ae2058f commit 35efe85
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cmd/dcrlncli/cmd_dcrlnd_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"errors"
"io"

"github.com/decred/dcrlnd/lnrpc/walletrpc"
"github.com/urfave/cli"
)

var rescanWalletCommand = cli.Command{
Name: "rescanwallet",
Usage: "Peform an on-chain rescan for wallet funds.",
Description: `
Performs an on-chain rescan for wallet funds.
This does NOT do any changes to LN channels or recovers funds encumbered
by LN channels, this only attempts to find on-chain funds that may have
been missed by dcrwallet.`,
ArgsUsage: "[height]",
Flags: []cli.Flag{
cli.Int64Flag{
Name: "height",
Usage: "The starting height from which to perform rescan",
},
},
Action: actionDecorator(rescanWallet),
}

func rescanWallet(ctx *cli.Context) error {
var (
height int32
err error
)
ctxc := getContext()
client, cleanUp := getWalletClient(ctx)
defer cleanUp()

if ctx.IsSet("height") {
height = int32(ctx.Int64("height"))
}

request := &walletrpc.RescanWalletRequest{
BeginHeight: height,
}

resp, err := client.RescanWallet(ctxc, request)
if err != nil {
return err
}

progress, err := resp.Recv()
for err == nil {
printRespJSON(progress)
progress, err = resp.Recv()
}
if !errors.Is(err, io.EOF) {
return err
}

return nil
}
1 change: 1 addition & 0 deletions cmd/dcrlncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func walletCommands() []cli.Command {
listLeasesCommand,
psbtCommand,
accountsCommand,
rescanWalletCommand,
},
},
}
Expand Down

0 comments on commit 35efe85

Please sign in to comment.