-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
663 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ import ( | |
) | ||
|
||
func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/notional-labs/composable/v6/x/keyrotation/types" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
// NewMsgServerImpl returns an implementation of the MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper Keeper) types.MsgServer { | ||
return &msgServer{ | ||
Keeper: keeper, | ||
} | ||
} | ||
|
||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
func (k Keeper) RotateConsPubKey(goCtx context.Context, msg *types.MsgRotateConsPubKey) (*types.MsgRotateConsPubKeyResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// check to see if the validator not exist | ||
if _, found := k.sk.GetValidator(ctx, valAddr); !found { | ||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "validator not exists") | ||
} | ||
|
||
return &types.MsgRotateConsPubKeyResponse{}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
package types | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// StakingKeeper expected staking keeper | ||
type StakingKeeper interface { | ||
// iterate through validators by operator address, execute func for each validator | ||
IterateValidators(sdk.Context, | ||
func(index int64, validator stakingtypes.ValidatorI) (stop bool)) | ||
|
||
Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI // get a particular validator by operator address | ||
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address | ||
|
||
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction | ||
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) math.Int | ||
SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.Infraction) math.Int | ||
Jail(sdk.Context, sdk.ConsAddress) // jail a validator | ||
Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator | ||
|
||
// Delegation allows for getting a particular delegation for a given validator | ||
// and delegator outside the scope of the staking module. | ||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingtypes.DelegationI | ||
GetAllValidators(ctx sdk.Context) (validators []stakingtypes.Validator) | ||
|
||
// MaxValidators returns the maximum amount of bonded validators | ||
MaxValidators(sdk.Context) uint32 | ||
|
||
// IsValidatorJailed returns if the validator is jailed. | ||
IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool | ||
GetValidator(sdk.Context, sdk.ValAddress) (stakingtypes.Validator, bool) | ||
} |
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ const ( | |
|
||
// QuerierRoute defines the module's query routing key | ||
QuerierRoute = ModuleName | ||
|
||
RouterKey = ModuleName | ||
) |
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,78 @@ | ||
package types | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const ( | ||
TypeMsgRotateConsPubKey = "rotate_cons_pubkey" | ||
) | ||
|
||
var ( | ||
_ sdk.Msg = &MsgRotateConsPubKey{} | ||
) | ||
|
||
func NewMsgRotateConsPubKey( | ||
valAddr sdk.ValAddress, | ||
pubKey cryptotypes.PubKey, | ||
) (*MsgRotateConsPubKey, error) { | ||
var pkAny *codectypes.Any | ||
if pubKey != nil { | ||
var err error | ||
if pkAny, err = codectypes.NewAnyWithValue(pubKey); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return &MsgRotateConsPubKey{ | ||
ValidatorAddress: valAddr.String(), | ||
Pubkey: pkAny, | ||
}, nil | ||
} | ||
|
||
// Route implements the sdk.Msg interface. | ||
func (msg MsgRotateConsPubKey) Route() string { return RouterKey } | ||
|
||
// Type implements the sdk.Msg interface. | ||
func (msg MsgRotateConsPubKey) Type() string { return TypeMsgRotateConsPubKey } | ||
|
||
// GetSigners implements the sdk.Msg interface. It returns the address(es) that | ||
// must sign over msg.GetSignBytes(). | ||
// If the validator address is not same as delegator's, then the validator must | ||
// sign the msg as well. | ||
func (msg MsgRotateConsPubKey) GetSigners() []sdk.AccAddress { | ||
valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) | ||
|
||
valAccAddr := sdk.AccAddress(valAddr) | ||
|
||
return []sdk.AccAddress{valAccAddr} | ||
} | ||
|
||
// GetSignBytes returns the message bytes to sign over. | ||
func (msg MsgRotateConsPubKey) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(&msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
// ValidateBasic implements the sdk.Msg interface. | ||
func (msg MsgRotateConsPubKey) ValidateBasic() error { | ||
_, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) | ||
if err != nil { | ||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) | ||
} | ||
|
||
if msg.Pubkey == nil { | ||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "empty pubkey") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces | ||
func (msg MsgRotateConsPubKey) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { | ||
var pubKey cryptotypes.PubKey | ||
return unpacker.UnpackAny(msg.Pubkey, &pubKey) | ||
} |
Oops, something went wrong.