-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
135 lines (114 loc) · 3.59 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package keepers
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/coinexchain/cet-sdk/modules/comment/internal/types"
)
var (
CommentCountKey = []byte{0x10}
CommentCountKeyEnd = []byte{0x11}
)
type CommentCountKeeper struct {
commentKey sdk.StoreKey
}
func NewCommentCountKeeper(key sdk.StoreKey) *CommentCountKeeper {
return &CommentCountKeeper{
commentKey: key,
}
}
func (keeper *CommentCountKeeper) IncrCommentCount(ctx sdk.Context, denom string) uint64 {
store := ctx.KVStore(keeper.commentKey)
ccKey := append(CommentCountKey, []byte(denom)...)
a := store.Get(ccKey)
count := uint64(0)
if len(a) != 0 {
count = binary.LittleEndian.Uint64(a)
}
lastCount := count
count++
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, count)
store.Set(ccKey, b)
return lastCount
}
func (keeper *CommentCountKeeper) GetAllCommentCount(ctx sdk.Context) map[string]uint64 {
res := make(map[string]uint64)
store := ctx.KVStore(keeper.commentKey)
iter := store.Iterator(CommentCountKey, CommentCountKeyEnd)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
denom := iter.Key()[1:]
a := iter.Value()
count := binary.LittleEndian.Uint64(a[:])
res[string(denom)] = count
}
return res
}
func (keeper *CommentCountKeeper) GetCommentCount(ctx sdk.Context, denom string) uint64 {
store := ctx.KVStore(keeper.commentKey)
ccKey := append(CommentCountKey, []byte(denom)...)
a := store.Get(ccKey)
count := uint64(0)
if len(a) != 0 {
count = binary.LittleEndian.Uint64(a[:])
}
return count
}
func (keeper *CommentCountKeeper) SetCommentCount(ctx sdk.Context, denom string, count uint64) {
store := ctx.KVStore(keeper.commentKey)
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b[:], count)
ccKey := append(CommentCountKey, []byte(denom)...)
store.Set(ccKey, b[:])
}
type Keeper struct {
cck *CommentCountKeeper
bxk types.ExpectedBankxKeeper
axk types.ExpectedAssetStatusKeeper
ak types.ExpectedAccountKeeper
dk types.ExpectedDistributionxKeeper
eventTypeMsgQueue string
}
func NewKeeper(key sdk.StoreKey,
bxk types.ExpectedBankxKeeper,
axk types.ExpectedAssetStatusKeeper,
ak types.ExpectedAccountKeeper,
dk types.ExpectedDistributionxKeeper,
et string) *Keeper {
return &Keeper{
cck: NewCommentCountKeeper(key),
bxk: bxk,
axk: axk,
ak: ak,
dk: dk,
eventTypeMsgQueue: et,
}
}
func (k *Keeper) GetEventTypeMsgQueue() string {
return k.eventTypeMsgQueue
}
func (k *Keeper) SendCoins(ctx sdk.Context, from sdk.AccAddress, to sdk.AccAddress, amt sdk.Coins) sdk.Error {
return k.bxk.SendCoins(ctx, from, to, amt)
}
func (k *Keeper) IsTokenExists(ctx sdk.Context, denom string) bool {
return k.axk.IsTokenExists(ctx, denom)
}
func (k *Keeper) DonateToCommunityPool(ctx sdk.Context, fromAddr sdk.AccAddress, amt sdk.Coins) sdk.Error {
return k.dk.DonateToCommunityPool(ctx, fromAddr, amt)
}
func (k *Keeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) auth.Account {
return k.ak.GetAccount(ctx, addr)
}
func (k *Keeper) IncrCommentCount(ctx sdk.Context, denom string) uint64 {
return k.cck.IncrCommentCount(ctx, denom)
}
func (k *Keeper) GetAllCommentCount(ctx sdk.Context) map[string]uint64 {
return k.cck.GetAllCommentCount(ctx)
}
func (k *Keeper) GetCommentCount(ctx sdk.Context, denom string) uint64 {
return k.cck.GetCommentCount(ctx, denom)
}
func (k *Keeper) SetCommentCount(ctx sdk.Context, denom string, count uint64) {
k.cck.SetCommentCount(ctx, denom, count)
}