forked from Fairblock/fairyring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Fairblock#142 from Fairblock/feat/add-deregister
Add deregister msg & tests
- Loading branch information
Showing
12 changed files
with
623 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/Fairblock/fairyring/x/keyshare/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdDeRegisterValidator() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "deregister-validator", | ||
Short: "Deregister a validator for being eligible to send keyshares", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgDeRegisterValidator( | ||
clientCtx.GetFromAddress().String(), | ||
) | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"github.com/Fairblock/fairyring/x/keyshare/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// DeRegisterValidator remove a validator in the validator set | ||
func (k msgServer) DeRegisterValidator(goCtx context.Context, msg *types.MsgDeRegisterValidator) (*types.MsgDeRegisterValidatorResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
_, found := k.GetValidatorSet(ctx, msg.Creator) | ||
|
||
if !found { | ||
return nil, types.ErrValidatorNotRegistered.Wrap(msg.Creator) | ||
} | ||
|
||
for _, v := range k.GetAllAuthorizedAddress(ctx) { | ||
if v.AuthorizedBy == msg.Creator { | ||
k.RemoveAuthorizedAddress(ctx, v.Target) | ||
k.DecreaseAuthorizedCount(ctx, msg.Creator) | ||
break | ||
} | ||
} | ||
|
||
k.RemoveValidatorSet(ctx, msg.Creator) | ||
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent(types.DeRegisteredValidatorEventType, | ||
sdk.NewAttribute(types.DeRegisteredValidatorEventCreator, msg.Creator), | ||
), | ||
) | ||
|
||
return &types.MsgDeRegisterValidatorResponse{ | ||
Creator: msg.Creator, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package types | ||
|
||
import ( | ||
sdkerrors "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
cosmoserror "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const TypeMsgDeRegisterValidator = "deregister_validator" | ||
|
||
var _ sdk.Msg = &MsgRegisterValidator{} | ||
|
||
func NewMsgDeRegisterValidator(creator string) *MsgDeRegisterValidator { | ||
return &MsgDeRegisterValidator{ | ||
Creator: creator, | ||
} | ||
} | ||
|
||
func (msg *MsgDeRegisterValidator) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgDeRegisterValidator) Type() string { | ||
return TypeMsgDeRegisterValidator | ||
} | ||
|
||
func (msg *MsgDeRegisterValidator) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgDeRegisterValidator) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgDeRegisterValidator) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
return sdkerrors.Wrapf(cosmoserror.ErrInvalidAddress, "invalid creator address (%s)", err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.