/
redelegation_txs.go
66 lines (54 loc) · 2.13 KB
/
redelegation_txs.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
package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
)
func (k *Keeper) SetRedelegationTx(ctx sdk.Context, redelegationTx *types.RedelegateTx) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
bytes := k.cdc.MustMarshal(redelegationTx)
store.Set(types.GetRedelegationTxStoreKey(redelegationTx.ChainId, redelegationTx.IbcSequenceId), bytes)
}
func (k *Keeper) GetRedelegationTx(ctx sdk.Context, chainID, ibcSequenceID string) (*types.RedelegateTx, bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
bz := store.Get(types.GetRedelegationTxStoreKey(chainID, ibcSequenceID))
if bz == nil {
return nil, false
}
var redelegationtx types.RedelegateTx
k.cdc.MustUnmarshal(bz, &redelegationtx)
return &redelegationtx, true
}
func (k *Keeper) GetAllRedelegationTx(ctx sdk.Context) []*types.RedelegateTx {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
iterator := sdk.KVStorePrefixIterator(store, nil)
defer iterator.Close()
txs := make([]*types.RedelegateTx, 0)
for ; iterator.Valid(); iterator.Next() {
redelegateTx := types.RedelegateTx{}
k.cdc.MustUnmarshal(iterator.Value(), &redelegateTx)
txs = append(txs, &redelegateTx)
}
return txs
}
func (k *Keeper) FilterRedelegationTx(
ctx sdk.Context,
filter func(d types.RedelegateTx) bool,
) []*types.RedelegateTx {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
iterator := sdk.KVStorePrefixIterator(store, nil)
defer iterator.Close()
redelegationTxs := make([]*types.RedelegateTx, 0)
for ; iterator.Valid(); iterator.Next() {
deposit := types.RedelegateTx{}
k.cdc.MustUnmarshal(iterator.Value(), &deposit)
if filter(deposit) {
redelegationTxs = append(redelegationTxs, &deposit)
}
}
return redelegationTxs
}
func (k *Keeper) DeleteRedelegationTx(ctx sdk.Context, chainID, ibcSequenceID string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.RedelegationTxKey)
store.Delete(types.GetRedelegationTxStoreKey(chainID, ibcSequenceID))
}