-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch.go
65 lines (55 loc) · 2.47 KB
/
patch.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
package simapp
import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
clientkeeper "github.com/cosmos/ibc-go/modules/core/02-client/keeper"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
connectionkeeper "github.com/cosmos/ibc-go/modules/core/03-connection/keeper"
connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/modules/core/keeper"
ibctmtypes "github.com/cosmos/ibc-go/modules/light-clients/07-tendermint/types"
mocktypes "github.com/datachainlab/ibc-mock-client/modules/light-clients/xx-mock/types"
"github.com/datachainlab/ibc-trusted-ethereum-client/modules/light-clients/trusted-ethereum/types"
)
func overrideIBCClientKeeper(k ibckeeper.Keeper, cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, sk clienttypes.StakingKeeper) *ibckeeper.Keeper {
clientKeeper := NewClientKeeper(k.ClientKeeper, sk)
k.ConnectionKeeper = connectionkeeper.NewKeeper(cdc, key, paramSpace, clientKeeper)
return &k
}
var _ connectiontypes.ClientKeeper = (*ClientKeeper)(nil)
var _ channeltypes.ClientKeeper = (*ClientKeeper)(nil)
// ClientKeeper override `GetSelfConsensusState` and `ValidateSelfClient` in the keeper of ibc-client
// original method doesn't yet support a consensus state for general client
type ClientKeeper struct {
clientkeeper.Keeper
stakingKeeper clienttypes.StakingKeeper
}
func NewClientKeeper(k clientkeeper.Keeper, sk clienttypes.StakingKeeper) ClientKeeper {
return ClientKeeper{
Keeper: k,
stakingKeeper: sk,
}
}
// Just for e2e where ibc-mock-client is used for verifying a tendermint header.
// Used in combination with https://github.com/datachainlab/yui-relayer/tree/trusted-ethereum-client-e2e
func (k ClientKeeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, bool) {
return &mocktypes.ConsensusState{
Timestamp: uint64(1),
}, true
}
func (k ClientKeeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error {
switch cs := clientState.(type) {
case *ibctmtypes.ClientState:
return k.Keeper.ValidateSelfClient(ctx, cs)
case *types.ClientState:
return nil
case *mocktypes.ClientState:
return nil
default:
return fmt.Errorf("unexpected client state type: %T", cs)
}
}