From 5dcdf9c11f1ab46728f45b2d2bb299ca7ffb6872 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Thu, 16 Feb 2023 13:20:11 +0000 Subject: [PATCH] Handle account-based validator exit correctly. --- cmd/validator/exit/command.go | 2 ++ cmd/validator/exit/process.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/validator/exit/command.go b/cmd/validator/exit/command.go index dfb2deb..75d4897 100644 --- a/cmd/validator/exit/command.go +++ b/cmd/validator/exit/command.go @@ -34,6 +34,7 @@ type command struct { json bool // Input. + account string passphrases []string mnemonic string path string @@ -72,6 +73,7 @@ func newCommand(_ context.Context) (*command, error) { connection: viper.GetString("connection"), allowInsecureConnections: viper.GetBool("allow-insecure-connections"), prepareOffline: viper.GetBool("prepare-offline"), + account: viper.GetString("account"), passphrases: util.GetPassphrases(), mnemonic: viper.GetString("mnemonic"), path: viper.GetString("path"), diff --git a/cmd/validator/exit/process.go b/cmd/validator/exit/process.go index deab8d1..3c3abc0 100644 --- a/cmd/validator/exit/process.go +++ b/cmd/validator/exit/process.go @@ -88,7 +88,7 @@ func (c *command) process(ctx context.Context) error { } func (c *command) obtainOperation(ctx context.Context) error { - if (c.mnemonic == "" || c.path == "") && c.privateKey == "" && c.validator == "" { + if c.account == "" && (c.mnemonic == "" || c.path == "") && c.privateKey == "" && c.validator == "" { // No input information; fetch the operation from a file. err := c.obtainOperationFromFileOrInput(ctx) if err == nil { @@ -114,6 +114,10 @@ func (c *command) obtainOperation(ctx context.Context) error { } } + if c.account != "" { + return c.generateOperationFromAccountOnly(ctx) + } + if c.privateKey != "" { return c.generateOperationFromPrivateKey(ctx) } @@ -194,6 +198,29 @@ func (c *command) generateOperationFromMnemonicAndValidator(ctx context.Context) return nil } +func (c *command) generateOperationFromAccountOnly(ctx context.Context) error { + validatorAccount, err := util.ParseAccount(ctx, c.account, c.passphrases, true) + if err != nil { + return err + } + + validatorPubKey, err := util.BestPublicKey(validatorAccount) + if err != nil { + return err + } + + validatorInfo, err := c.chainInfo.FetchValidatorInfo(ctx, fmt.Sprintf("%#x", validatorPubKey.Marshal())) + if err != nil { + return err + } + + if err := c.generateOperationFromAccount(ctx, validatorInfo, validatorAccount, c.chainInfo.Epoch); err != nil { + return err + } + + return nil +} + func (c *command) generateOperationFromPrivateKey(ctx context.Context) error { validatorAccount, err := util.ParseAccount(ctx, c.privateKey, nil, true) if err != nil {