Replace keeper types with interfaces
This commit is contained in:
@@ -15,10 +15,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
)
|
||||
@@ -60,8 +57,8 @@ type messenger interface {
|
||||
type Keeper struct {
|
||||
storeKey sdk.StoreKey
|
||||
cdc codec.Marshaler
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
accountKeeper types.AccountKeeper
|
||||
bankKeeper types.BankKeeper
|
||||
ChannelKeeper types.ChannelKeeper
|
||||
portKeeper types.PortKeeper
|
||||
capabilityKeeper types.CapabilityKeeper
|
||||
@@ -82,9 +79,9 @@ func NewKeeper(
|
||||
storeKey sdk.StoreKey,
|
||||
paramSpace paramtypes.Subspace,
|
||||
accountKeeper authkeeper.AccountKeeper,
|
||||
bankKeeper bankkeeper.Keeper,
|
||||
stakingKeeper stakingkeeper.Keeper,
|
||||
distKeeper distributionkeeper.Keeper,
|
||||
bankKeeper types.BankKeeper,
|
||||
stakingKeeper types.StakingKeeper,
|
||||
distKeeper types.DistributionKeeper,
|
||||
channelKeeper types.ChannelKeeper,
|
||||
portKeeper types.PortKeeper,
|
||||
capabilityKeeper types.CapabilityKeeper,
|
||||
|
||||
@@ -4,14 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
|
||||
|
||||
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
|
||||
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
@@ -91,7 +89,7 @@ type QueryPlugins struct {
|
||||
Wasm func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error)
|
||||
}
|
||||
|
||||
func DefaultQueryPlugins(bank bankkeeper.ViewKeeper, staking stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper, channelKeeper types.ChannelKeeper, queryRouter GRPCQueryRouter, wasm *Keeper) QueryPlugins {
|
||||
func DefaultQueryPlugins(bank types.BankViewKeeper, staking types.StakingKeeper, distKeeper types.DistributionKeeper, channelKeeper types.ChannelKeeper, queryRouter GRPCQueryRouter, wasm *Keeper) QueryPlugins {
|
||||
return QueryPlugins{
|
||||
Bank: BankQuerier(bank),
|
||||
Custom: NoCustomQuerier,
|
||||
@@ -128,7 +126,7 @@ func (e QueryPlugins) Merge(o *QueryPlugins) QueryPlugins {
|
||||
return e
|
||||
}
|
||||
|
||||
func BankQuerier(bankKeeper bankkeeper.ViewKeeper) func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error) {
|
||||
func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error) {
|
||||
return func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error) {
|
||||
if request.AllBalances != nil {
|
||||
addr, err := sdk.AccAddressFromBech32(request.AllBalances.Address)
|
||||
@@ -176,7 +174,7 @@ func IBCQuerier(wasm *Keeper, channelKeeper types.ChannelKeeper) func(ctx sdk.Co
|
||||
if request.ListChannels != nil {
|
||||
portID := request.ListChannels.PortID
|
||||
var channels wasmvmtypes.IBCEndpoints
|
||||
channelKeeper.IterateChannels(ctx, func(ch types.IdentifiedChannel) bool {
|
||||
channelKeeper.IterateChannels(ctx, func(ch channeltypes.IdentifiedChannel) bool {
|
||||
if portID == "" || portID == ch.PortId {
|
||||
newChan := wasmvmtypes.IBCEndpoint{
|
||||
PortID: ch.PortId,
|
||||
@@ -243,7 +241,7 @@ func StargateQuerier(queryRouter GRPCQueryRouter) func(ctx sdk.Context, request
|
||||
}
|
||||
}
|
||||
|
||||
func StakingQuerier(keeper stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper) func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) {
|
||||
func StakingQuerier(keeper types.StakingKeeper, distKeeper types.DistributionKeeper) func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) {
|
||||
return func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) {
|
||||
if request.BondedDenom != nil {
|
||||
denom := keeper.BondDenom(ctx)
|
||||
@@ -308,7 +306,7 @@ func StakingQuerier(keeper stakingkeeper.Keeper, distKeeper distributionkeeper.K
|
||||
}
|
||||
}
|
||||
|
||||
func sdkToDelegations(ctx sdk.Context, keeper stakingkeeper.Keeper, delegations []stakingtypes.Delegation) (wasmvmtypes.Delegations, error) {
|
||||
func sdkToDelegations(ctx sdk.Context, keeper types.StakingKeeper, delegations []stakingtypes.Delegation) (wasmvmtypes.Delegations, error) {
|
||||
result := make([]wasmvmtypes.Delegation, len(delegations))
|
||||
bondDenom := keeper.BondDenom(ctx)
|
||||
|
||||
@@ -339,7 +337,7 @@ func sdkToDelegations(ctx sdk.Context, keeper stakingkeeper.Keeper, delegations
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func sdkToFullDelegation(ctx sdk.Context, keeper stakingkeeper.Keeper, distKeeper distributionkeeper.Keeper, delegation stakingtypes.Delegation) (*wasmvmtypes.FullDelegation, error) {
|
||||
func sdkToFullDelegation(ctx sdk.Context, keeper types.StakingKeeper, distKeeper types.DistributionKeeper, delegation stakingtypes.Delegation) (*wasmvmtypes.FullDelegation, error) {
|
||||
delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.Wrap(err, "delegator address")
|
||||
@@ -387,7 +385,7 @@ func sdkToFullDelegation(ctx sdk.Context, keeper stakingkeeper.Keeper, distKeepe
|
||||
|
||||
// FIXME: simplify this enormously when
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/7466 is merged
|
||||
func getAccumulatedRewards(ctx sdk.Context, distKeeper distributionkeeper.Keeper, delegation stakingtypes.Delegation) ([]wasmvmtypes.Coin, error) {
|
||||
func getAccumulatedRewards(ctx sdk.Context, distKeeper types.DistributionKeeper, delegation stakingtypes.Delegation) ([]wasmvmtypes.Coin, error) {
|
||||
// Try to get *delegator* reward info!
|
||||
params := distributiontypes.QueryDelegationRewardsRequest{
|
||||
DelegatorAddress: delegation.DelegatorAddress,
|
||||
|
||||
90
x/wasm/internal/types/expected_keepers.go
Normal file
90
x/wasm/internal/types/expected_keepers.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
|
||||
ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// BankKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper
|
||||
type BankViewKeeper interface {
|
||||
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
||||
}
|
||||
|
||||
// BankKeeper defines a subset of methods implemented by the cosmos-sdk bank keeper
|
||||
type BankKeeper interface {
|
||||
BankViewKeeper
|
||||
SendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
|
||||
BlockedAddr(addr sdk.AccAddress) bool
|
||||
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
|
||||
}
|
||||
|
||||
// AccountKeeper defines a subset of methods implemented by the cosmos-sdk account keeper
|
||||
type AccountKeeper interface {
|
||||
// Return a new account with the next account number and the specified address. Does not save the new account to the store.
|
||||
NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
|
||||
// Retrieve an account from the store.
|
||||
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
|
||||
// Set an account in the store.
|
||||
SetAccount(ctx sdk.Context, acc authtypes.AccountI)
|
||||
}
|
||||
|
||||
// DistributionKeeper defines a subset of methods implemented by the cosmos-sdk distribution keeper
|
||||
type DistributionKeeper interface {
|
||||
DelegationRewards(c context.Context, req *types.QueryDelegationRewardsRequest) (*types.QueryDelegationRewardsResponse, error)
|
||||
}
|
||||
|
||||
// StakingKeeper defines a subset of methods implemented by the cosmos-sdk staking keeper
|
||||
type StakingKeeper interface {
|
||||
// BondDenom - Bondable coin denomination
|
||||
BondDenom(ctx sdk.Context) (res string)
|
||||
// GetValidator get a single validator
|
||||
GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool)
|
||||
// GetBondedValidatorsByPower get the current group of bonded validators sorted by power-rank
|
||||
GetBondedValidatorsByPower(ctx sdk.Context) []stakingtypes.Validator
|
||||
// GetAllDelegatorDelegations return all delegations for a delegator
|
||||
GetAllDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress) []stakingtypes.Delegation
|
||||
// GetDelegation return a specific delegation
|
||||
GetDelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation stakingtypes.Delegation, found bool)
|
||||
// HasReceivingRedelegation check if validator is receiving a redelegation
|
||||
HasReceivingRedelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool
|
||||
}
|
||||
|
||||
// ChannelKeeper defines the expected IBC channel keeper
|
||||
type ChannelKeeper interface {
|
||||
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool)
|
||||
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
|
||||
SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error
|
||||
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error
|
||||
GetAllChannels(ctx sdk.Context) (channels []channeltypes.IdentifiedChannel)
|
||||
IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool)
|
||||
}
|
||||
|
||||
// ClientKeeper defines the expected IBC client keeper
|
||||
type ClientKeeper interface {
|
||||
GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool)
|
||||
}
|
||||
|
||||
// ConnectionKeeper defines the expected IBC connection keeper
|
||||
type ConnectionKeeper interface {
|
||||
GetConnection(ctx sdk.Context, connectionID string) (connection connectiontypes.ConnectionEnd, found bool)
|
||||
}
|
||||
|
||||
// PortKeeper defines the expected IBC port keeper
|
||||
type PortKeeper interface {
|
||||
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
|
||||
}
|
||||
|
||||
type CapabilityKeeper interface {
|
||||
GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool)
|
||||
ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error
|
||||
AuthenticateCapability(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types"
|
||||
ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
|
||||
)
|
||||
|
||||
// Much copied from ibc-transfer in the cosmos-sdk
|
||||
|
||||
// ChannelKeeper defines the expected IBC channel keeper
|
||||
type ChannelKeeper interface {
|
||||
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool)
|
||||
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
|
||||
SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error
|
||||
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error
|
||||
GetAllChannels(ctx sdk.Context) (channels []channeltypes.IdentifiedChannel)
|
||||
IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool)
|
||||
}
|
||||
|
||||
type IdentifiedChannel = channeltypes.IdentifiedChannel
|
||||
|
||||
// ClientKeeper defines the expected IBC client keeper
|
||||
type ClientKeeper interface {
|
||||
GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool)
|
||||
}
|
||||
|
||||
// ConnectionKeeper defines the expected IBC connection keeper
|
||||
type ConnectionKeeper interface {
|
||||
GetConnection(ctx sdk.Context, connectionID string) (connection connectiontypes.ConnectionEnd, found bool)
|
||||
}
|
||||
|
||||
// PortKeeper defines the expected IBC port keeper
|
||||
type PortKeeper interface {
|
||||
BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability
|
||||
}
|
||||
|
||||
type CapabilityKeeper interface {
|
||||
GetCapability(ctx sdk.Context, name string) (*capabilitytypes.Capability, bool)
|
||||
ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error
|
||||
AuthenticateCapability(ctx sdk.Context, capability *capabilitytypes.Capability, name string) bool
|
||||
}
|
||||
Reference in New Issue
Block a user