mirror of
https://github.com/wealdtech/ethdo.git
synced 2026-01-09 14:07:56 -05:00
Handle account-based validator exit correctly.
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user