Skip to content

Commit

Permalink
chore(cmd): rename operator command (#428)
Browse files Browse the repository at this point in the history
According to the changes of #358, rename the command for set/unset
operator.

issue: none
  • Loading branch information
0xHansLee authored Dec 13, 2024
1 parent 288928a commit 9a698e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions client/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func bindValidatorCreateFlags(cmd *cobra.Command, cfg *createValidatorConfig) {
cmd.Flags().StringVar(&cfg.Moniker, "moniker", "", "Custom moniker name for this node")
}

func bindAddOperatorFlags(cmd *cobra.Command, cfg *operatorConfig) {
func bindSetOperatorFlags(cmd *cobra.Command, cfg *operatorConfig) {
bindValidatorBaseFlags(cmd, &cfg.baseConfig)
cmd.Flags().StringVar(&cfg.Operator, "operator", "", "Adds an operator to your delegator")
cmd.Flags().StringVar(&cfg.Operator, "operator", "", "Sets an operator to your delegator")
}

func bindRemoveOperatorFlags(cmd *cobra.Command, cfg *operatorConfig) {
func bindUnsetOperatorFlags(cmd *cobra.Command, cfg *operatorConfig) {
bindValidatorBaseFlags(cmd, &cfg.baseConfig)
cmd.Flags().StringVar(&cfg.Operator, "operator", "", "Removes an operator from your delegator")
cmd.Flags().StringVar(&cfg.Operator, "operator", "", "Unsets an operator from your delegator")
}

func bindSetWithdrawalAddressFlags(cmd *cobra.Command, cfg *withdrawalConfig) {
Expand Down
44 changes: 22 additions & 22 deletions client/cmd/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func newValidatorCmds() *cobra.Command {
newValidatorStakeOnBehalfCmd(),
newValidatorUnstakeCmd(),
newValidatorUnstakeOnBehalfCmd(),
newValidatorAddOperatorCmd(),
newValidatorRemoveOperatorCmd(),
newValidatorSetOperatorCmd(),
newValidatorUnsetOperatorCmd(),
newValidatorSetWithdrawalAddressCmd(),
newValidatorUnjailCmd(),
newValidatorUnjailOnBehalfCmd(),
Expand Down Expand Up @@ -177,44 +177,44 @@ func newValidatorCreateCmd() *cobra.Command {
return cmd
}

func newValidatorAddOperatorCmd() *cobra.Command {
func newValidatorSetOperatorCmd() *cobra.Command {
var cfg operatorConfig

cmd := &cobra.Command{
Use: "add-operator",
Short: "Add a new operator to your delegator",
Use: "set-operator",
Short: "set an operator to your delegator",
Args: cobra.NoArgs,
PreRunE: func(_ *cobra.Command, _ []string) error {
return initializeBaseConfig(&cfg.baseConfig)
},
RunE: runValidatorCommand(
validateOperatorFlags,
func(ctx context.Context) error { return addOperator(ctx, cfg) },
func(ctx context.Context) error { return setOperator(ctx, cfg) },
),
}

bindAddOperatorFlags(cmd, &cfg)
bindSetOperatorFlags(cmd, &cfg)

return cmd
}

func newValidatorRemoveOperatorCmd() *cobra.Command {
func newValidatorUnsetOperatorCmd() *cobra.Command {
var cfg operatorConfig

cmd := &cobra.Command{
Use: "remove-operator",
Short: "Removes an existing operator from your delegator",
Use: "unset-operator",
Short: "Unsets an existing operator from your delegator",
Args: cobra.NoArgs,
PreRunE: func(_ *cobra.Command, _ []string) error {
return initializeBaseConfig(&cfg.baseConfig)
},
RunE: runValidatorCommand(
validateOperatorFlags,
func(ctx context.Context) error { return removeOperator(ctx, cfg) },
func(ctx context.Context) error { return unsetOperator(ctx, cfg) },
),
}

bindRemoveOperatorFlags(cmd, &cfg)
bindUnsetOperatorFlags(cmd, &cfg)

return cmd
}
Expand Down Expand Up @@ -507,7 +507,7 @@ func setWithdrawalAddress(ctx context.Context, cfg withdrawalConfig) error {
return nil
}

func addOperator(ctx context.Context, cfg operatorConfig) error {
func setOperator(ctx context.Context, cfg operatorConfig) error {
uncompressedPubKey, err := uncompressPrivateKey(cfg.PrivateKey)
if err != nil {
return err
Expand All @@ -520,19 +520,19 @@ func addOperator(ctx context.Context, cfg operatorConfig) error {
return err
}

fmt.Printf("Fee for adding operator: %s wei\n", fee.String())
fmt.Printf("Fee for setting operator: %s wei\n", fee.String())

_, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "addOperator", fee, uncompressedPubKey, operatorAddress)
_, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "setOperator", fee, uncompressedPubKey, operatorAddress)
if err != nil {
return err
}

fmt.Println("Operator added successfully!")
fmt.Println("Operator set successfully!")

return nil
}

func removeOperator(ctx context.Context, cfg operatorConfig) error {
func unsetOperator(ctx context.Context, cfg operatorConfig) error {
uncompressedPubKey, err := uncompressPrivateKey(cfg.PrivateKey)
if err != nil {
return err
Expand All @@ -545,18 +545,18 @@ func removeOperator(ctx context.Context, cfg operatorConfig) error {
return err
}

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

_, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "removeOperator", removeOperatorFee, uncompressedPubKey, operatorAddress)
_, err = prepareAndExecuteTransaction(ctx, &cfg.baseConfig, "unsetOperator", unsetOperatorFee, uncompressedPubKey, operatorAddress)
if err != nil {
return err
}

fmt.Println("Operator removed successfully!")
fmt.Println("Operator unset successfully!")

return nil
}
Expand Down

0 comments on commit 9a698e0

Please sign in to comment.