github.com/decred/dcrlnd@v0.7.6/cmd/dcrlncli/cmd_dcrlnd_commands.go (about) 1 package main 2 3 import ( 4 "errors" 5 "io" 6 7 "github.com/decred/dcrlnd/lnrpc/walletrpc" 8 "github.com/urfave/cli" 9 ) 10 11 var rescanWalletCommand = cli.Command{ 12 Name: "rescanwallet", 13 Usage: "Peform an on-chain rescan for wallet funds.", 14 Description: ` 15 Performs an on-chain rescan for wallet funds. 16 17 This does NOT do any changes to LN channels or recovers funds encumbered 18 by LN channels, this only attempts to find on-chain funds that may have 19 been missed by dcrwallet.`, 20 ArgsUsage: "[height]", 21 Flags: []cli.Flag{ 22 cli.Int64Flag{ 23 Name: "height", 24 Usage: "The starting height from which to perform rescan", 25 }, 26 }, 27 Action: actionDecorator(rescanWallet), 28 } 29 30 func rescanWallet(ctx *cli.Context) error { 31 var ( 32 height int32 33 err error 34 ) 35 ctxc := getContext() 36 client, cleanUp := getWalletClient(ctx) 37 defer cleanUp() 38 39 if ctx.IsSet("height") { 40 height = int32(ctx.Int64("height")) 41 } 42 43 request := &walletrpc.RescanWalletRequest{ 44 BeginHeight: height, 45 } 46 47 resp, err := client.RescanWallet(ctxc, request) 48 if err != nil { 49 return err 50 } 51 52 progress, err := resp.Recv() 53 for err == nil { 54 printRespJSON(progress) 55 progress, err = resp.Recv() 56 } 57 if !errors.Is(err, io.EOF) { 58 return err 59 } 60 61 return nil 62 }