-
Notifications
You must be signed in to change notification settings - Fork 205
/
subscription.go
40 lines (32 loc) · 1.19 KB
/
subscription.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package types
import (
"strings"
sdkerrors "cosmossdk.io/errors"
)
const (
MAX_SUBSCRIPTION_DURATION = 12 // max duration of subscription in months
)
// ValidateSubscription validates a subscription object fields
func (sub Subscription) ValidateSubscription() error {
// PlanIndex may not be blank
if len(strings.TrimSpace(sub.PlanIndex)) == 0 {
return sdkerrors.Wrap(ErrBlankParameter, "subscription plan cannot be blank")
}
// Creator may not be blank
if len(strings.TrimSpace(sub.Creator)) == 0 {
return sdkerrors.Wrap(ErrBlankParameter, "subscription creator cannot be blank")
}
// Consumer may not be blank
if len(strings.TrimSpace(sub.Consumer)) == 0 {
return sdkerrors.Wrap(ErrInvalidParameter, "subscription consumer cannot be blank")
}
// DurationBought must be between 1 and MAX_SUBSCRIPTION_DURATION
if sub.DurationBought > MAX_SUBSCRIPTION_DURATION {
return sdkerrors.Wrap(ErrInvalidParameter, "subscription duration (bought) is out of range")
}
// DurationLeft must be between 1 and MAX_SUBSCRIPTION_DURATION+1
if sub.DurationLeft > MAX_SUBSCRIPTION_DURATION+1 {
return sdkerrors.Wrap(ErrInvalidParameter, "subscription duration (left) is out of range")
}
return nil
}