diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 960bb153..14eed9d8 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -69,13 +69,27 @@ func printRespJSON(resp proto.Message) { func actionDecorator(f func(*cli.Context) error) func(*cli.Context) error { return func(c *cli.Context) error { if err := f(c); err != nil { + s, ok := status.FromError(err) + + // If it's a command for the UnlockerService (like + // 'create' or 'unlock') but the wallet is already + // unlocked, then these methods aren't recognized any + // more because this service is shut down after + // successful unlock. That's why the code + // 'Unimplemented' means something different for these + // two commands. + if s.Code() == codes.Unimplemented && + (c.Command.Name == "create" || + c.Command.Name == "unlock") { + return fmt.Errorf("Wallet is already unlocked") + } + // lnd might be active, but not possible to contact // using RPC if the wallet is encrypted. If we get // error code Unimplemented, it means that lnd is // running, but the RPC server is not active yet (only // WalletUnlocker server active) and most likely this // is because of an encrypted wallet. - s, ok := status.FromError(err) if ok && s.Code() == codes.Unimplemented { return fmt.Errorf("Wallet is encrypted. " + "Please unlock using 'lncli unlock', " +