-
Notifications
You must be signed in to change notification settings - Fork 204
/
lsm_token_deposit.go
80 lines (65 loc) · 2.84 KB
/
lsm_token_deposit.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
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/Stride-Labs/stride/v16/x/records/types"
)
func (k Keeper) SetLSMTokenDeposit(ctx sdk.Context, deposit types.LSMTokenDeposit) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LSMTokenDepositKey))
depositKey := types.GetLSMTokenDepositKey(deposit.ChainId, deposit.Denom)
depositData := k.Cdc.MustMarshal(&deposit)
store.Set(depositKey, depositData)
}
func (k Keeper) RemoveLSMTokenDeposit(ctx sdk.Context, chainId, denom string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LSMTokenDepositKey))
depositKey := types.GetLSMTokenDepositKey(chainId, denom)
store.Delete(depositKey)
}
func (k Keeper) GetLSMTokenDeposit(ctx sdk.Context, chainId, denom string) (deposit types.LSMTokenDeposit, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LSMTokenDepositKey))
depositKey := types.GetLSMTokenDepositKey(chainId, denom)
depositData := store.Get(depositKey)
if len(depositData) == 0 {
return deposit, false
}
k.Cdc.MustUnmarshal(depositData, &deposit)
return deposit, true
}
func (k Keeper) GetAllLSMTokenDeposit(ctx sdk.Context) []types.LSMTokenDeposit {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LSMTokenDepositKey))
iterator := store.Iterator(nil, nil)
allLSMTokenDeposits := []types.LSMTokenDeposit{}
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var deposit types.LSMTokenDeposit
k.Cdc.MustUnmarshal(iterator.Value(), &deposit)
allLSMTokenDeposits = append(allLSMTokenDeposits, deposit)
}
return allLSMTokenDeposits
}
func (k Keeper) UpdateLSMTokenDepositStatus(ctx sdk.Context, deposit types.LSMTokenDeposit, status types.LSMTokenDeposit_Status) {
deposit.Status = status
k.SetLSMTokenDeposit(ctx, deposit)
}
func (k Keeper) GetLSMDepositsForHostZone(ctx sdk.Context, chainId string) []types.LSMTokenDeposit {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.LSMTokenDepositKey))
iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefix(chainId))
hostZoneLSMTokenDeposits := []types.LSMTokenDeposit{}
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var deposit types.LSMTokenDeposit
k.Cdc.MustUnmarshal(iterator.Value(), &deposit)
hostZoneLSMTokenDeposits = append(hostZoneLSMTokenDeposits, deposit)
}
return hostZoneLSMTokenDeposits
}
func (k Keeper) GetLSMDepositsForHostZoneWithStatus(ctx sdk.Context, chainId string, status types.LSMTokenDeposit_Status) []types.LSMTokenDeposit {
filtered := []types.LSMTokenDeposit{}
hostZoneLSMTokenDeposits := k.GetLSMDepositsForHostZone(ctx, chainId)
for _, deposit := range hostZoneLSMTokenDeposits {
if deposit.Status == status {
filtered = append(filtered, deposit)
}
}
return filtered
}