Handle account-based validator exit correctly.

This commit is contained in:
Jim McDonald
2023-02-16 13:20:11 +00:00
parent d5acd2f842
commit 5dcdf9c11f
2 changed files with 30 additions and 1 deletions

View File

@@ -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"),

View File

@@ -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 {