Skip to content

Commit

Permalink
Merge pull request #102
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-dee7 authored Jul 2, 2021
1 parent 1b6d029 commit 9ef0929
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 33 deletions.
2 changes: 1 addition & 1 deletion x/session/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewDecoderStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
cdc.MustUnmarshalBinaryBare(kvB.Value, &activeSessionB)
return fmt.Sprintf("%s\n%s", &activeSessionA, &activeSessionB)

case bytes.Equal(kvA.Key[:1], types.ActiveSessionAtKeyPrefix):
case bytes.Equal(kvA.Key[:1], types.InactiveSessionAtKeyPrefix):
var activeSessionA, activeSessionB protobuf.BoolValue
cdc.MustUnmarshalBinaryBare(kvA.Value, &activeSessionA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &activeSessionB)
Expand Down
175 changes: 175 additions & 0 deletions x/subscription/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/sentinel-official/hub/x/subscription/keeper
// ALIASGEN: github.com/sentinel-official/hub/x/subscription/types
package subscription

import (
"github.com/sentinel-official/hub/x/subscription/keeper"
"github.com/sentinel-official/hub/x/subscription/types"
)

const (
ModuleName = types.ModuleName
QuerierRoute = types.QuerierRoute
DefaultInactiveDuration = types.DefaultInactiveDuration
)

var (
// functions aliases
NewKeeper = keeper.NewKeeper
NewMsgServiceServer = keeper.NewMsgServiceServer
NewQueryServiceServer = keeper.NewQueryServiceServer
RegisterLegacyAminoCodec = types.RegisterLegacyAminoCodec
RegisterInterfaces = types.RegisterInterfaces
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
SubscriptionKey = types.SubscriptionKey
GetSubscriptionForNodeKeyPrefix = types.GetSubscriptionForNodeKeyPrefix
SubscriptionForNodeKey = types.SubscriptionForNodeKey
GetSubscriptionForPlanKeyPrefix = types.GetSubscriptionForPlanKeyPrefix
SubscriptionForPlanKey = types.SubscriptionForPlanKey
GetActiveSubscriptionForAddressKeyPrefix = types.GetActiveSubscriptionForAddressKeyPrefix
ActiveSubscriptionForAddressKey = types.ActiveSubscriptionForAddressKey
GetInactiveSubscriptionForAddressKeyPrefix = types.GetInactiveSubscriptionForAddressKeyPrefix
InactiveSubscriptionForAddressKey = types.InactiveSubscriptionForAddressKey
GetInactiveSubscriptionAtKeyPrefix = types.GetInactiveSubscriptionAtKeyPrefix
InactiveSubscriptionAtKey = types.InactiveSubscriptionAtKey
GetQuotaKeyPrefix = types.GetQuotaKeyPrefix
QuotaKey = types.QuotaKey
IDFromSubscriptionForNodeKey = types.IDFromSubscriptionForNodeKey
IDFromSubscriptionForPlanKey = types.IDFromSubscriptionForPlanKey
IDFromStatusSubscriptionForAddressKey = types.IDFromStatusSubscriptionForAddressKey
IDFromInactiveSubscriptionAtKey = types.IDFromInactiveSubscriptionAtKey
NewMsgSubscribeToNodeRequest = types.NewMsgSubscribeToNodeRequest
NewMsgSubscribeToPlanRequest = types.NewMsgSubscribeToPlanRequest
NewMsgCancelRequest = types.NewMsgCancelRequest
NewMsgAddQuotaRequest = types.NewMsgAddQuotaRequest
NewMsgUpdateQuotaRequest = types.NewMsgUpdateQuotaRequest
NewMsgServiceClient = types.NewMsgServiceClient
RegisterMsgServiceServer = types.RegisterMsgServiceServer
NewParams = types.NewParams
DefaultParams = types.DefaultParams
ParamsKeyTable = types.ParamsKeyTable
NewQuerySubscriptionRequest = types.NewQuerySubscriptionRequest
NewQuerySubscriptionsRequest = types.NewQuerySubscriptionsRequest
NewQuerySubscriptionsForNodeRequest = types.NewQuerySubscriptionsForNodeRequest
NewQuerySubscriptionsForPlanRequest = types.NewQuerySubscriptionsForPlanRequest
NewQuerySubscriptionsForAddressRequest = types.NewQuerySubscriptionsForAddressRequest
NewQueryQuotaRequest = types.NewQueryQuotaRequest
NewQueryQuotasRequest = types.NewQueryQuotasRequest
NewQueryServiceClient = types.NewQueryServiceClient
RegisterQueryServiceServer = types.RegisterQueryServiceServer
RegisterQueryServiceHandlerServer = types.RegisterQueryServiceHandlerServer
RegisterQueryServiceHandlerFromEndpoint = types.RegisterQueryServiceHandlerFromEndpoint
RegisterQueryServiceHandler = types.RegisterQueryServiceHandler
RegisterQueryServiceHandlerClient = types.RegisterQueryServiceHandlerClient

// variable aliases
ModuleCdc = types.ModuleCdc
ErrorMarshal = types.ErrorMarshal
ErrorUnmarshal = types.ErrorUnmarshal
ErrorUnknownMsgType = types.ErrorUnknownMsgType
ErrorUnknownQueryType = types.ErrorUnknownQueryType
ErrorInvalidFieldFrom = types.ErrorInvalidFieldFrom
ErrorPlanDoesNotExist = types.ErrorPlanDoesNotExist
ErrorNodeDoesNotExist = types.ErrorNodeDoesNotExist
ErrorUnauthorized = types.ErrorUnauthorized
ErrorInvalidPlanStatus = types.ErrorInvalidPlanStatus
ErrorPriceDoesNotExist = types.ErrorPriceDoesNotExist
ErrorInvalidNodeStatus = types.ErrorInvalidNodeStatus
ErrorSubscriptionDoesNotExist = types.ErrorSubscriptionDoesNotExist
ErrorInvalidSubscriptionStatus = types.ErrorInvalidSubscriptionStatus
ErrorCanNotSubscribe = types.ErrorCanNotSubscribe
ErrorInvalidQuota = types.ErrorInvalidQuota
ErrorDuplicateQuota = types.ErrorDuplicateQuota
ErrorQuotaDoesNotExist = types.ErrorQuotaDoesNotExist
ErrorCanNotAddQuota = types.ErrorCanNotAddQuota
ErrorInvalidFieldId = types.ErrorInvalidFieldId
ErrorInvalidFieldAddress = types.ErrorInvalidFieldAddress
ErrorInvalidFieldBytes = types.ErrorInvalidFieldBytes
ErrorInvalidFieldDenom = types.ErrorInvalidFieldDenom
ErrorInvalidFieldDeposit = types.ErrorInvalidFieldDeposit
ErrInvalidLengthEvents = types.ErrInvalidLengthEvents
ErrIntOverflowEvents = types.ErrIntOverflowEvents
ErrUnexpectedEndOfGroupEvents = types.ErrUnexpectedEndOfGroupEvents
ErrInvalidLengthGenesis = types.ErrInvalidLengthGenesis
ErrIntOverflowGenesis = types.ErrIntOverflowGenesis
ErrUnexpectedEndOfGroupGenesis = types.ErrUnexpectedEndOfGroupGenesis
ParamsSubspace = types.ParamsSubspace
RouterKey = types.RouterKey
StoreKey = types.StoreKey
EventModuleName = types.EventModuleName
CountKey = types.CountKey
SubscriptionKeyPrefix = types.SubscriptionKeyPrefix
SubscriptionForNodeKeyPrefix = types.SubscriptionForNodeKeyPrefix
SubscriptionForPlanKeyPrefix = types.SubscriptionForPlanKeyPrefix
ActiveSubscriptionForAddressKeyPrefix = types.ActiveSubscriptionForAddressKeyPrefix
InactiveSubscriptionForAddressKeyPrefix = types.InactiveSubscriptionForAddressKeyPrefix
InactiveSubscriptionAtKeyPrefix = types.InactiveSubscriptionAtKeyPrefix
QuotaKeyPrefix = types.QuotaKeyPrefix
ErrInvalidLengthMsg = types.ErrInvalidLengthMsg
ErrIntOverflowMsg = types.ErrIntOverflowMsg
ErrUnexpectedEndOfGroupMsg = types.ErrUnexpectedEndOfGroupMsg
KeyInactiveDuration = types.KeyInactiveDuration
ErrInvalidLengthParams = types.ErrInvalidLengthParams
ErrIntOverflowParams = types.ErrIntOverflowParams
ErrUnexpectedEndOfGroupParams = types.ErrUnexpectedEndOfGroupParams
ErrInvalidLengthQuerier = types.ErrInvalidLengthQuerier
ErrIntOverflowQuerier = types.ErrIntOverflowQuerier
ErrUnexpectedEndOfGroupQuerier = types.ErrUnexpectedEndOfGroupQuerier
ErrInvalidLengthQuota = types.ErrInvalidLengthQuota
ErrIntOverflowQuota = types.ErrIntOverflowQuota
ErrUnexpectedEndOfGroupQuota = types.ErrUnexpectedEndOfGroupQuota
ErrInvalidLengthSubscription = types.ErrInvalidLengthSubscription
ErrIntOverflowSubscription = types.ErrIntOverflowSubscription
ErrUnexpectedEndOfGroupSubscription = types.ErrUnexpectedEndOfGroupSubscription
)

type (
Keeper = keeper.Keeper
EventModule = types.EventModule
EventSetSubscriptionCount = types.EventSetSubscriptionCount
EventSubscribeToNode = types.EventSubscribeToNode
EventSubscribeToPlan = types.EventSubscribeToPlan
EventCancelSubscription = types.EventCancelSubscription
EventAddQuota = types.EventAddQuota
EventUpdateQuota = types.EventUpdateQuota
GenesisSubscriptions = types.GenesisSubscriptions
GenesisSubscription = types.GenesisSubscription
GenesisState = types.GenesisState
MsgSubscribeToNodeRequest = types.MsgSubscribeToNodeRequest
MsgSubscribeToPlanRequest = types.MsgSubscribeToPlanRequest
MsgCancelRequest = types.MsgCancelRequest
MsgAddQuotaRequest = types.MsgAddQuotaRequest
MsgUpdateQuotaRequest = types.MsgUpdateQuotaRequest
MsgSubscribeToNodeResponse = types.MsgSubscribeToNodeResponse
MsgSubscribeToPlanResponse = types.MsgSubscribeToPlanResponse
MsgCancelResponse = types.MsgCancelResponse
MsgAddQuotaResponse = types.MsgAddQuotaResponse
MsgUpdateQuotaResponse = types.MsgUpdateQuotaResponse
MsgServiceClient = types.MsgServiceClient
MsgServiceServer = types.MsgServiceServer
UnimplementedMsgServiceServer = types.UnimplementedMsgServiceServer
Params = types.Params
QuerySubscriptionsRequest = types.QuerySubscriptionsRequest
QuerySubscriptionsForNodeRequest = types.QuerySubscriptionsForNodeRequest
QuerySubscriptionsForPlanRequest = types.QuerySubscriptionsForPlanRequest
QuerySubscriptionsForAddressRequest = types.QuerySubscriptionsForAddressRequest
QuerySubscriptionRequest = types.QuerySubscriptionRequest
QueryQuotaRequest = types.QueryQuotaRequest
QueryQuotasRequest = types.QueryQuotasRequest
QuerySubscriptionsResponse = types.QuerySubscriptionsResponse
QuerySubscriptionsForNodeResponse = types.QuerySubscriptionsForNodeResponse
QuerySubscriptionsForPlanResponse = types.QuerySubscriptionsForPlanResponse
QuerySubscriptionsForAddressResponse = types.QuerySubscriptionsForAddressResponse
QuerySubscriptionResponse = types.QuerySubscriptionResponse
QueryQuotaResponse = types.QueryQuotaResponse
QueryQuotasResponse = types.QueryQuotasResponse
QueryServiceClient = types.QueryServiceClient
QueryServiceServer = types.QueryServiceServer
UnimplementedQueryServiceServer = types.UnimplementedQueryServiceServer
Quotas = types.Quotas
Quota = types.Quota
Subscriptions = types.Subscriptions
Subscription = types.Subscription
)
37 changes: 23 additions & 14 deletions x/subscription/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import (
)

var (
ErrorInvalidField = errors.Register(ModuleName, 101, "invalid field")
ErrorPlanDoesNotExist = errors.Register(ModuleName, 102, "plan does not exist")
ErrorNodeDoesNotExist = errors.Register(ModuleName, 103, "node does not exist")
ErrorUnauthorized = errors.Register(ModuleName, 104, "unauthorized")
ErrorInvalidPlanStatus = errors.Register(ModuleName, 105, "invalid plan status")
ErrorPriceDoesNotExist = errors.Register(ModuleName, 106, "price does not exist")
ErrorInvalidNodeStatus = errors.Register(ModuleName, 107, "invalid node status")
ErrorSubscriptionDoesNotExist = errors.Register(ModuleName, 108, "subscription does not exist")
ErrorInvalidSubscriptionStatus = errors.Register(ModuleName, 109, "invalid subscription status")
ErrorCanNotSubscribe = errors.Register(ModuleName, 110, "can not subscribe")
ErrorInvalidQuota = errors.Register(ModuleName, 111, "invalid quota")
ErrorDuplicateQuota = errors.Register(ModuleName, 112, "duplicate quota")
ErrorQuotaDoesNotExist = errors.Register(ModuleName, 113, "quota does not exist")
ErrorCanNotAddQuota = errors.Register(ModuleName, 114, "can not add quota")
ErrorMarshal = errors.Register(ModuleName, 101, "error occurred while marshalling")
ErrorUnmarshal = errors.Register(ModuleName, 102, "error occurred while unmarshalling")
ErrorUnknownMsgType = errors.Register(ModuleName, 103, "unknown message type")
ErrorUnknownQueryType = errors.Register(ModuleName, 104, "unknown query type")
ErrorInvalidFieldFrom = errors.Register(ModuleName, 105, "invalid value for field from; expected a valid address")
ErrorPlanDoesNotExist = errors.Register(ModuleName, 106, "plan does not exist")
ErrorNodeDoesNotExist = errors.Register(ModuleName, 107, "node does not exist")
ErrorUnauthorized = errors.Register(ModuleName, 108, "unauthorized")
ErrorInvalidPlanStatus = errors.Register(ModuleName, 109, "invalid plan status")
ErrorPriceDoesNotExist = errors.Register(ModuleName, 110, "price does not exist")
ErrorInvalidNodeStatus = errors.Register(ModuleName, 111, "invalid node status")
ErrorSubscriptionDoesNotExist = errors.Register(ModuleName, 112, "subscription does not exist")
ErrorInvalidSubscriptionStatus = errors.Register(ModuleName, 113, "invalid subscription status")
ErrorCanNotSubscribe = errors.Register(ModuleName, 114, "can not subscribe")
ErrorInvalidQuota = errors.Register(ModuleName, 115, "invalid quota")
ErrorDuplicateQuota = errors.Register(ModuleName, 116, "duplicate quota")
ErrorQuotaDoesNotExist = errors.Register(ModuleName, 117, "quota does not exist")
ErrorCanNotAddQuota = errors.Register(ModuleName, 118, "can not add quota")
ErrorInvalidFieldId = errors.Register(ModuleName, 119, "invalid value for field id; expected a value greater than 0")
ErrorInvalidFieldAddress = errors.Register(ModuleName, 120, "invalid value for field address; expected a valid address")
ErrorInvalidFieldBytes = errors.Register(ModuleName, 121, "invalid value for field bytes; expected a positive integer value")
ErrorInvalidFieldDenom = errors.Register(ModuleName, 122, "invalid value for field denom; expected a valid denom")
ErrorInvalidFieldDeposit = errors.Register(ModuleName, 123, "invalid value for field deposit; expected a positive integer value")
)
36 changes: 18 additions & 18 deletions x/subscription/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"

hubtypes "github.com/sentinel-official/hub/types"
)
Expand Down Expand Up @@ -36,17 +35,17 @@ func (m *MsgSubscribeToNodeRequest) Type() string {

func (m *MsgSubscribeToNodeRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "from")
return ErrorInvalidFieldFrom
}

// Address should be valid
if _, err := hubtypes.NodeAddressFromBech32(m.Address); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "address")
return ErrorInvalidFieldAddress
}

// Deposit should be valid and positive
if !m.Deposit.IsValid() || !m.Deposit.IsPositive() {
return errors.Wrapf(ErrorInvalidField, "%s", "deposit")
return ErrorInvalidFieldDeposit
}

return nil
Expand Down Expand Up @@ -83,17 +82,18 @@ func (m *MsgSubscribeToPlanRequest) Type() string {

func (m *MsgSubscribeToPlanRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "from")
return ErrorInvalidFieldFrom
}

// Id shouldn't be zero
if m.Id == 0 {
return errors.Wrapf(ErrorInvalidField, "%s", "id")
return ErrorInvalidFieldId
}

// Denom should be valid
if err := sdk.ValidateDenom(m.Denom); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "denom")
err := sdk.ValidateDenom(m.Denom)
if err != nil {
return ErrorInvalidFieldDenom
}

return nil
Expand Down Expand Up @@ -129,12 +129,12 @@ func (m *MsgCancelRequest) Type() string {

func (m *MsgCancelRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "from")
return ErrorInvalidFieldFrom
}

// Id shouldn't be zero
if m.Id == 0 {
return errors.Wrapf(ErrorInvalidField, "%s", "id")
return ErrorInvalidFieldId
}

return nil
Expand Down Expand Up @@ -172,22 +172,22 @@ func (m *MsgAddQuotaRequest) Type() string {

func (m *MsgAddQuotaRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "from")
return ErrorInvalidFieldFrom
}

// Id shouldn't be zero
if m.Id == 0 {
return errors.Wrapf(ErrorInvalidField, "%s", "id")
return ErrorInvalidFieldId
}

// Address should be valid
if _, err := sdk.AccAddressFromBech32(m.Address); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "address")
return ErrorInvalidFieldAddress
}

// Bytes should be positive
if !m.Bytes.IsPositive() {
return errors.Wrapf(ErrorInvalidField, "%s", "bytes")
return ErrorInvalidFieldBytes
}

return nil
Expand Down Expand Up @@ -225,22 +225,22 @@ func (m *MsgUpdateQuotaRequest) Type() string {

func (m *MsgUpdateQuotaRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "from")
return ErrorInvalidFieldFrom
}

// Id shouldn't be zero
if m.Id == 0 {
return errors.Wrapf(ErrorInvalidField, "%s", "id")
return ErrorInvalidFieldId
}

// Address shouldn be valid
if _, err := sdk.AccAddressFromBech32(m.Address); err != nil {
return errors.Wrapf(ErrorInvalidField, "%s", "address")
return ErrorInvalidFieldAddress
}

// Bytes should be positive
if !m.Bytes.IsPositive() {
return errors.Wrapf(ErrorInvalidField, "%s", "bytes")
return ErrorInvalidFieldBytes
}

return nil
Expand Down
Loading

0 comments on commit 9ef0929

Please sign in to comment.