Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow localhost client type. #560

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions x/liquidstakeibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibclocalhosttypes "github.com/cosmos/ibc-go/v7/modules/light-clients/09-localhost"

"github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
)
Expand Down Expand Up @@ -119,7 +121,7 @@ func (k *Keeper) SendProtocolFee(ctx sdk.Context, protocolFee sdk.Coins, moduleA
}

// GetClientState retrieves the client state given a connection id
func (k *Keeper) GetClientState(ctx sdk.Context, connectionID string) (*ibctmtypes.ClientState, error) {
func (k *Keeper) GetClientState(ctx sdk.Context, connectionID string) (exported.ClientState, error) {
conn, found := k.ibcKeeper.ConnectionKeeper.GetConnection(ctx, connectionID)
if !found {
return nil, fmt.Errorf("invalid connection id, \"%s\" not found", connectionID)
Expand All @@ -130,32 +132,7 @@ func (k *Keeper) GetClientState(ctx sdk.Context, connectionID string) (*ibctmtyp
return nil, fmt.Errorf("client id \"%s\" not found for connection \"%s\"", conn.ClientId, connectionID)
}

client, ok := clientState.(*ibctmtypes.ClientState)
if !ok {
return nil, fmt.Errorf("invalid client state for connection \"%s\"", connectionID)
}

return client, nil
}

// GetLatestConsensusState retrieves the last tendermint consensus state
func (k *Keeper) GetLatestConsensusState(ctx sdk.Context, connectionID string) (*ibctmtypes.ConsensusState, error) {
conn, found := k.ibcKeeper.ConnectionKeeper.GetConnection(ctx, connectionID)
if !found {
return nil, fmt.Errorf("invalid connection id, \"%s\" not found", connectionID)
}

consensusState, found := k.ibcKeeper.ClientKeeper.GetLatestClientConsensusState(ctx, conn.ClientId)
if !found {
return nil, fmt.Errorf("client id \"%s\" not found for connection \"%s\"", conn.ClientId, connectionID)
}

state, ok := consensusState.(*ibctmtypes.ConsensusState)
if !ok {
return nil, fmt.Errorf("invalid consensus state for connection \"%s\"", connectionID)
}

return state, nil
return clientState, nil
}

// GetChainID gets the id of the host chain given a connection id
Expand All @@ -165,7 +142,14 @@ func (k *Keeper) GetChainID(ctx sdk.Context, connectionID string) (string, error
return "", fmt.Errorf("client state not found for connection \"%s\": \"%s\"", connectionID, err.Error())
}

return clientState.ChainId, nil
switch clientType := clientState.(type) {
case *ibctmtypes.ClientState:
return clientType.ChainId, nil
case *ibclocalhosttypes.ClientState:
return ctx.ChainID(), nil
default:
return "", fmt.Errorf("unexpected type of client, cannot determine chain-id: clientType: %s, connectionid: %s", clientState.ClientType(), connectionID)
}
}

// GetPortID constructs a port id given the port owner
Expand Down
2 changes: 0 additions & 2 deletions x/lscosmos/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/cosmos/gogoproto/proto"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
epochstypes "github.com/persistenceOne/persistence-sdk/v2/x/epochs/types"

liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"
Expand Down Expand Up @@ -104,7 +103,6 @@ type LiquidStakeIBCKeeper interface {
SetValidatorUnbonding(ctx sdk.Context, vu *liquidstakeibctypes.ValidatorUnbonding)
SetUserUnbonding(ctx sdk.Context, ub *liquidstakeibctypes.UserUnbonding)
SetDeposit(ctx sdk.Context, deposit *liquidstakeibctypes.Deposit)
GetLatestConsensusState(ctx sdk.Context, connectionID string) (*ibctmtypes.ConsensusState, error)
GetHostChain(ctx sdk.Context, chainID string) (*liquidstakeibctypes.HostChain, bool)
GenerateAndExecuteICATx(ctx sdk.Context, connectionID string, ownerID string, messages []proto.Message) (string, error)
SetParams(ctx sdk.Context, params liquidstakeibctypes.Params)
Expand Down
Loading