-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
56 lines (48 loc) · 1.69 KB
/
keeper.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package keeper
import (
"strings"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
iidkeeper "github.com/furya-official/fury-blockchain/x/iid/keeper"
"github.com/furya-official/fury-blockchain/x/payments/types"
)
type Keeper struct {
cdc codec.BinaryCodec
storeKey sdk.StoreKey
paramSpace paramtypes.Subspace
bankKeeper bankkeeper.Keeper
IidKeeper iidkeeper.Keeper
ReservedIdPrefixes []string
}
func NewKeeper(cdc codec.BinaryCodec, storeKey sdk.StoreKey, bankKeeper bankkeeper.Keeper,
iidKeeper iidkeeper.Keeper, reservedIdPrefixes []string) Keeper {
return Keeper{
cdc: cdc,
storeKey: storeKey,
bankKeeper: bankKeeper,
IidKeeper: iidKeeper,
ReservedIdPrefixes: reservedIdPrefixes,
}
}
// idReserved checks if the id (from a template, contract, or subscription)
// is using a reserved prefix (i.e. should not be used). The prefixPrefix
// indicates whether we are referring to a template, contract, or subscription.
func (k Keeper) idReserved(id string, prefixPrefix string) bool {
for _, prefix := range k.ReservedIdPrefixes {
if strings.HasPrefix(id, prefixPrefix+prefix) {
return true
}
}
return false
}
func (k Keeper) PaymentTemplateIdReserved(id string) bool {
return k.idReserved(id, types.PaymentTemplateIdPrefix)
}
func (k Keeper) PaymentContractIdReserved(id string) bool {
return k.idReserved(id, types.PaymentContractIdPrefix)
}
func (k Keeper) SubscriptionIdReserved(id string) bool {
return k.idReserved(id, types.SubscriptionIdPrefix)
}