diff --git a/proto/composable/keyrotation/tx.proto b/proto/composable/keyrotation/tx.proto index f8a93940a..0fd9217af 100644 --- a/proto/composable/keyrotation/tx.proto +++ b/proto/composable/keyrotation/tx.proto @@ -5,15 +5,21 @@ import "cosmos/msg/v1/msg.proto"; import "amino/amino.proto"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; +import "google/protobuf/any.proto"; option go_package = "x/keyrotation/types"; -// Msg defines the x/mint Msg service. +// Msg defines the x/keyrotation Msg service. service Msg { option (cosmos.msg.v1.service) = true; + // CreateValidator defines a method for creating a new validator. + rpc RotateConsPubKey(MsgRotateConsPubKey) returns (MsgRotateConsPubKeyResponse); } message MsgRotateConsPubKey { - string val_address = 1; - + string validator_address = 1; + google.protobuf.Any pubkey = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; +} + +message MsgRotateConsPubKeyResponse { } \ No newline at end of file diff --git a/x/keyrotation/keeper/abci.go b/x/keyrotation/keeper/abci.go index 43df2c021..65cc444e4 100644 --- a/x/keyrotation/keeper/abci.go +++ b/x/keyrotation/keeper/abci.go @@ -6,5 +6,5 @@ import ( ) func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { - + return nil } diff --git a/x/keyrotation/keeper/msg_server.go b/x/keyrotation/keeper/msg_server.go new file mode 100644 index 000000000..b5b425ec9 --- /dev/null +++ b/x/keyrotation/keeper/msg_server.go @@ -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 +} diff --git a/x/keyrotation/types/codec.go b/x/keyrotation/types/codec.go index 4e8baaf9e..63cd1b44a 100644 --- a/x/keyrotation/types/codec.go +++ b/x/keyrotation/types/codec.go @@ -2,8 +2,10 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" @@ -13,9 +15,17 @@ import ( // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the // provided LegacyAmino codec. These types are used for Amino JSON serialization -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgRotateConsPubKey{}, "composable/MsgAddRateLimit") +} -func RegisterInterfaces(registry codectypes.InterfaceRegistry) {} +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgRotateConsPubKey{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} var ( amino = codec.NewLegacyAmino() diff --git a/x/keyrotation/types/expected_keepers.go b/x/keyrotation/types/expected_keepers.go index 94e8b8524..4116d6da1 100644 --- a/x/keyrotation/types/expected_keepers.go +++ b/x/keyrotation/types/expected_keepers.go @@ -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) } diff --git a/x/keyrotation/types/keys.go b/x/keyrotation/types/keys.go index f195c7fac..44720477b 100644 --- a/x/keyrotation/types/keys.go +++ b/x/keyrotation/types/keys.go @@ -5,4 +5,6 @@ const ( // QuerierRoute defines the module's query routing key QuerierRoute = ModuleName + + RouterKey = ModuleName ) diff --git a/x/keyrotation/types/msgs.go b/x/keyrotation/types/msgs.go new file mode 100644 index 000000000..fb2c33716 --- /dev/null +++ b/x/keyrotation/types/msgs.go @@ -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) +} diff --git a/x/keyrotation/types/tx.pb.go b/x/keyrotation/types/tx.pb.go index 65ec026b6..74146503d 100644 --- a/x/keyrotation/types/tx.pb.go +++ b/x/keyrotation/types/tx.pb.go @@ -7,13 +7,18 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -27,22 +32,125 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type MsgRotateConsPubKey struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + Pubkey *types.Any `protobuf:"bytes,2,opt,name=pubkey,proto3" json:"pubkey,omitempty"` +} + +func (m *MsgRotateConsPubKey) Reset() { *m = MsgRotateConsPubKey{} } +func (m *MsgRotateConsPubKey) String() string { return proto.CompactTextString(m) } +func (*MsgRotateConsPubKey) ProtoMessage() {} +func (*MsgRotateConsPubKey) Descriptor() ([]byte, []int) { + return fileDescriptor_13955a0614b66d67, []int{0} +} +func (m *MsgRotateConsPubKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRotateConsPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRotateConsPubKey.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRotateConsPubKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRotateConsPubKey.Merge(m, src) +} +func (m *MsgRotateConsPubKey) XXX_Size() int { + return m.Size() +} +func (m *MsgRotateConsPubKey) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRotateConsPubKey.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRotateConsPubKey proto.InternalMessageInfo + +func (m *MsgRotateConsPubKey) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +func (m *MsgRotateConsPubKey) GetPubkey() *types.Any { + if m != nil { + return m.Pubkey + } + return nil +} + +type MsgRotateConsPubKeyResponse struct { +} + +func (m *MsgRotateConsPubKeyResponse) Reset() { *m = MsgRotateConsPubKeyResponse{} } +func (m *MsgRotateConsPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRotateConsPubKeyResponse) ProtoMessage() {} +func (*MsgRotateConsPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_13955a0614b66d67, []int{1} +} +func (m *MsgRotateConsPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRotateConsPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRotateConsPubKeyResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRotateConsPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRotateConsPubKeyResponse.Merge(m, src) +} +func (m *MsgRotateConsPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRotateConsPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRotateConsPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRotateConsPubKeyResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgRotateConsPubKey)(nil), "composable.keyrotation.v1beta1.MsgRotateConsPubKey") + proto.RegisterType((*MsgRotateConsPubKeyResponse)(nil), "composable.keyrotation.v1beta1.MsgRotateConsPubKeyResponse") +} + func init() { proto.RegisterFile("composable/keyrotation/tx.proto", fileDescriptor_13955a0614b66d67) } var fileDescriptor_13955a0614b66d67 = []byte{ - // 180 bytes of a gzipped FileDescriptorProto + // 340 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0xcf, 0x2d, 0xc8, 0x2f, 0x4e, 0x4c, 0xca, 0x49, 0xd5, 0xcf, 0x4e, 0xad, 0x2c, 0xca, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0xd3, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x43, 0x28, 0xd0, 0x43, 0x52, 0xa0, 0x57, 0x66, 0x98, 0x94, 0x5a, 0x92, 0x68, 0x28, 0x25, 0x9e, 0x9c, 0x5f, 0x9c, 0x9b, 0x5f, 0xac, 0x9f, 0x5b, 0x9c, 0xae, 0x5f, 0x66, 0x08, 0xa2, 0x20, 0x1a, 0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x54, 0x48, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, - 0x07, 0xb1, 0xa0, 0xa2, 0x92, 0x10, 0x13, 0xe2, 0x21, 0x12, 0x10, 0x0e, 0x44, 0xca, 0x88, 0x87, - 0x8b, 0xd9, 0xb7, 0x38, 0x5d, 0x8a, 0xb5, 0xe1, 0xf9, 0x06, 0x2d, 0x46, 0x27, 0xdd, 0x13, 0x8f, - 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, - 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x12, 0xae, 0x40, 0x75, 0x7c, 0x65, 0x41, 0x6a, - 0x71, 0x12, 0x1b, 0xd8, 0x0c, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x10, 0x62, 0x12, - 0xe3, 0x00, 0x00, 0x00, + 0x07, 0xb1, 0xa0, 0xa2, 0x92, 0x10, 0x13, 0xe2, 0x21, 0x12, 0x10, 0x0e, 0x4c, 0x2a, 0x3d, 0x3f, + 0x3f, 0x3d, 0x27, 0x55, 0x1f, 0xcc, 0x4b, 0x2a, 0x4d, 0xd3, 0x4f, 0xcc, 0xab, 0x84, 0x48, 0x29, + 0x75, 0x31, 0x72, 0x09, 0xfb, 0x16, 0xa7, 0x07, 0x81, 0xdc, 0x93, 0xea, 0x9c, 0x9f, 0x57, 0x1c, + 0x50, 0x9a, 0xe4, 0x9d, 0x5a, 0x29, 0xa4, 0xcd, 0x25, 0x58, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, + 0x92, 0x5f, 0x14, 0x9f, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, + 0x19, 0x24, 0x00, 0x97, 0x70, 0x84, 0x88, 0x0b, 0xb9, 0x71, 0xb1, 0x15, 0x94, 0x26, 0x65, 0xa7, + 0x56, 0x4a, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x1b, 0x89, 0xe8, 0x41, 0x2c, 0xd4, 0x83, 0x59, 0xa8, + 0xe7, 0x98, 0x57, 0xe9, 0x24, 0x71, 0x6a, 0x8b, 0xae, 0x08, 0xd4, 0x5d, 0xc9, 0x45, 0x95, 0x05, + 0x25, 0xf9, 0x7a, 0x10, 0xcb, 0x82, 0xa0, 0xba, 0x95, 0x64, 0xb9, 0xa4, 0xb1, 0xb8, 0x25, 0x28, + 0xb5, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0xd5, 0x68, 0x32, 0x23, 0x17, 0xb3, 0x6f, 0x71, 0xba, 0x50, + 0x0b, 0x23, 0x97, 0x00, 0x86, 0x83, 0x8d, 0xf5, 0xf0, 0x87, 0xb0, 0x1e, 0x16, 0x93, 0xa5, 0xac, + 0xc9, 0xd0, 0x04, 0x73, 0x8e, 0x14, 0x6b, 0xc3, 0xf3, 0x0d, 0x5a, 0x8c, 0x4e, 0xba, 0x27, 0x1e, + 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, + 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x25, 0x5c, 0x81, 0x9a, 0x16, 0x2a, 0x0b, 0x52, + 0x8b, 0x93, 0xd8, 0xc0, 0x61, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x8c, 0xce, 0x08, + 0x32, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -57,6 +165,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // CreateValidator defines a method for creating a new validator. + RotateConsPubKey(ctx context.Context, in *MsgRotateConsPubKey, opts ...grpc.CallOption) (*MsgRotateConsPubKeyResponse, error) } type msgClient struct { @@ -67,22 +177,421 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) RotateConsPubKey(ctx context.Context, in *MsgRotateConsPubKey, opts ...grpc.CallOption) (*MsgRotateConsPubKeyResponse, error) { + out := new(MsgRotateConsPubKeyResponse) + err := c.cc.Invoke(ctx, "/composable.keyrotation.v1beta1.Msg/RotateConsPubKey", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { + // CreateValidator defines a method for creating a new validator. + RotateConsPubKey(context.Context, *MsgRotateConsPubKey) (*MsgRotateConsPubKeyResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) RotateConsPubKey(ctx context.Context, req *MsgRotateConsPubKey) (*MsgRotateConsPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RotateConsPubKey not implemented") +} + func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_RotateConsPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRotateConsPubKey) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RotateConsPubKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/composable.keyrotation.v1beta1.Msg/RotateConsPubKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RotateConsPubKey(ctx, req.(*MsgRotateConsPubKey)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "composable.keyrotation.v1beta1.Msg", HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "composable/keyrotation/tx.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "RotateConsPubKey", + Handler: _Msg_RotateConsPubKey_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "composable/keyrotation/tx.proto", +} + +func (m *MsgRotateConsPubKey) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRotateConsPubKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRotateConsPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pubkey != nil { + { + size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } + +func (m *MsgRotateConsPubKeyResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRotateConsPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRotateConsPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgRotateConsPubKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Pubkey != nil { + l = m.Pubkey.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRotateConsPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgRotateConsPubKey) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRotateConsPubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRotateConsPubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pubkey == nil { + m.Pubkey = &types.Any{} + } + if err := m.Pubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRotateConsPubKeyResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRotateConsPubKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRotateConsPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +)