-
Notifications
You must be signed in to change notification settings - Fork 0
/
keeper.go
74 lines (64 loc) · 2.12 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
package keeper
import (
"fmt"
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
ibctmtypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types"
"github.com/ingenuity-build/quicksilver/x/claimsmanager/types"
"github.com/tendermint/tendermint/libs/log"
)
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
IBCKeeper ibckeeper.Keeper
}
// NewKeeper returns a new instance of participationrewards Keeper.
// This function will panic on failure.
func NewKeeper(
cdc codec.Codec,
key storetypes.StoreKey,
ibcKeeper ibckeeper.Keeper,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: key,
IBCKeeper: ibcKeeper,
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k Keeper) StoreSelfConsensusState(ctx sdk.Context, key string) error {
var height ibcclienttypes.Height
if strings.Contains(ctx.ChainID(), "-") {
revisionNum, err := strconv.ParseUint(strings.Split(ctx.ChainID(), "-")[1], 10, 64)
if err != nil {
k.Logger(ctx).Error("Error getting revision number for client ")
return err
}
height = ibcclienttypes.Height{
RevisionNumber: revisionNum,
RevisionHeight: uint64(ctx.BlockHeight() - 1),
}
} else {
// ONLY FOR TESTING - ibctesting module chains donot follow standard [chainname]-[num] structure
height = ibcclienttypes.Height{
RevisionNumber: 0, // revision number for testchain1 is 0 (because parseChainId splits on '-')
RevisionHeight: uint64(ctx.BlockHeight() - 1),
}
}
selfConsState, err := k.IBCKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
if err != nil {
k.Logger(ctx).Error("Error getting self consensus state of previous height")
return err
}
state := selfConsState.(*ibctmtypes.ConsensusState)
k.SetSelfConsensusState(ctx, key, state)
return nil
}