forked from dymensionxyz/dymension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc_request.go
64 lines (52 loc) · 1.6 KB
/
irc_request.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
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/furyaxyz/furya/x/irc/types"
)
// SetIRCRequest set a specific ircRequest in the store from its index
func (k Keeper) SetIRCRequest(ctx sdk.Context, ircRequest types.IRCRequest) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.IRCRequestKeyPrefix))
b := k.cdc.MustMarshal(&ircRequest)
store.Set(types.IRCRequestKey(
ircRequest.ReqId,
), b)
}
// GetIRCRequest returns a ircRequest from its index
func (k Keeper) GetIRCRequest(
ctx sdk.Context,
reqId uint64,
) (val types.IRCRequest, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.IRCRequestKeyPrefix))
b := store.Get(types.IRCRequestKey(
reqId,
))
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// RemoveIRCRequest removes a ircRequest from the store
func (k Keeper) RemoveIRCRequest(
ctx sdk.Context,
reqId uint64,
) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.IRCRequestKeyPrefix))
store.Delete(types.IRCRequestKey(
reqId,
))
}
// GetAllIRCRequest returns all ircRequest
func (k Keeper) GetAllIRCRequest(ctx sdk.Context) (list []types.IRCRequest) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.IRCRequestKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
// nolint: errcheck
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var val types.IRCRequest
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}