Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): separate unjail and unjail on behalf cmd #369

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func bindRollbackFlags(cmd *cobra.Command, cfg *config.Config) {

func bindValidatorUnjailFlags(cmd *cobra.Command, cfg *unjailConfig) {
bindValidatorBaseFlags(cmd, &cfg.baseConfig)
}

func bindValidatorUnjailOnBehalfFlags(cmd *cobra.Command, cfg *unjailConfig) {
bindValidatorBaseFlags(cmd, &cfg.baseConfig)
cmd.Flags().StringVar(&cfg.ValidatorPubKey, "validator-pubkey", "", "Validator's hex-encoded compressed 33-byte secp256k1 public key")
}

Expand Down Expand Up @@ -229,6 +233,10 @@ func validateKeyConvertFlags(cmd *cobra.Command) error {
}

func validateValidatorUnjailFlags(cmd *cobra.Command) error {
return validateFlags(cmd, []string{})
}

func validateValidatorUnjailOnBehalfFlags(cmd *cobra.Command) error {
return validateFlags(cmd, []string{"validator-pubkey"})
}

Expand Down
53 changes: 52 additions & 1 deletion client/cmd/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func newValidatorCmds() *cobra.Command {
newValidatorRemoveOperatorCmd(),
newValidatorSetWithdrawalAddressCmd(),
newValidatorUnjailCmd(),
newValidatorUnjailOnBehalfCmd(),
)

return cmd
Expand Down Expand Up @@ -376,6 +377,27 @@ func newValidatorUnjailCmd() *cobra.Command {
return cmd
}

func newValidatorUnjailOnBehalfCmd() *cobra.Command {
var cfg unjailConfig

cmd := &cobra.Command{
Use: "unjail-on-behalf",
Short: "Unjail the validator on behalf of a validator",
Args: cobra.NoArgs,
PreRunE: func(_ *cobra.Command, _ []string) error {
return initializeBaseConfig(&cfg.baseConfig)
},
RunE: runValidatorCommand(
validateValidatorUnjailOnBehalfFlags,
func(ctx context.Context) error { return unjailOnBehalf(ctx, cfg) },
),
}

bindValidatorUnjailOnBehalfFlags(cmd, &cfg)

return cmd
}

func runValidatorCommand(
validate func(cmd *cobra.Command) error,
execute func(ctx context.Context) error,
Expand Down Expand Up @@ -715,6 +737,35 @@ func unstakeOnBehalf(ctx context.Context, cfg unstakeConfig) error {
}

func unjail(ctx context.Context, cfg unjailConfig) error {
uncompressedValidatorPubKeyBytes, err := uncompressPrivateKey(cfg.PrivateKey)
if err != nil {
return errors.Wrap(err, "failed to get uncompressed pub key from private key")
}

result, err := prepareAndReadContract(ctx, &cfg.baseConfig, "fee")
if err != nil {
return err
}

var unjailFee *big.Int
err = cfg.ABI.UnpackIntoInterface(&unjailFee, "fee", result)
if err != nil {
return errors.Wrap(err, "failed to unpack unjailFee")
}

fmt.Printf("Unjail fee: %s\n", unjailFee.String())

_, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "unjail", unjailFee, uncompressedValidatorPubKeyBytes, []byte{})
if err != nil {
return err
}

fmt.Println("Validator successfully unjailed!")

return nil
}

func unjailOnBehalf(ctx context.Context, cfg unjailConfig) error {
validatorPubKeyBytes, err := hex.DecodeString(cfg.ValidatorPubKey)
if err != nil {
return errors.Wrap(err, "failed to decode hex-encoded validator public key")
Expand Down Expand Up @@ -743,7 +794,7 @@ func unjail(ctx context.Context, cfg unjailConfig) error {
return err
}

fmt.Println("Validator successfully unjailed!")
fmt.Println("Validator successfully unjailed on behalf of validator!")

return nil
}
Expand Down
Loading