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

nit: Use nil pointer pattern to check for interface compliance. #3439

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
)

var _ porttypes.Middleware = &IBCMiddleware{}
var _ porttypes.Middleware = (*IBCMiddleware)(nil)

// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
// ICA controller keeper and the underlying application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to revert the changes on types implementing interfaces using value receivers if it generally gives the impression (unsure) they must be used as pointers.


// InterchainAccount implements the Query/InterchainAccount gRPC method
func (k Keeper) InterchainAccount(goCtx context.Context, req *types.QueryInterchainAccountRequest) (*types.QueryInterchainAccountResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
)

var _ types.MsgServer = msgServer{}
var _ types.MsgServer = (*msgServer)(nil)

type msgServer struct {
*Keeper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
)

var _ sdk.Msg = &MsgRegisterInterchainAccount{}
var _ sdk.Msg = (*MsgRegisterInterchainAccount)(nil)

// NewMsgRegisterInterchainAccount creates a new instance of MsgRegisterInterchainAccount
func NewMsgRegisterInterchainAccount(connectionID, owner, version string) *MsgRegisterInterchainAccount {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)

// Params implements the Query/Params gRPC method
func (q Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)

_ porttypes.IBCModule = host.IBCModule{}
_ porttypes.IBCModule = (*host.IBCModule)(nil)
)

// AppModuleBasic is the IBC interchain accounts AppModuleBasic
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

var _ porttypes.Middleware = &IBCMiddleware{}
var _ porttypes.Middleware = (*IBCMiddleware)(nil)

// IBCMiddleware implements the ICS26 callbacks for the fee middleware given the
// fee keeper and the underlying application.
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)

// IncentivizedPackets implements the Query/IncentivizedPackets gRPC method
func (k Keeper) IncentivizedPackets(goCtx context.Context, req *types.QueryIncentivizedPacketsRequest) (*types.QueryIncentivizedPacketsResponse, error) {
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
// Middleware must implement types.ChannelKeeper and types.PortKeeper expected interfaces
// so that it can wrap IBC channel and port logic for underlying application.
var (
_ types.ChannelKeeper = Keeper{}
_ types.PortKeeper = Keeper{}
_ types.ChannelKeeper = (*Keeper)(nil)
_ types.PortKeeper = (*Keeper)(nil)
)

// Keeper defines the IBC fungible transfer keeper
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

var _ types.MsgServer = Keeper{}
var _ types.MsgServer = (*Keeper)(nil)

// RegisterPayee defines a rpc handler method for MsgRegisterPayee
// RegisterPayee is called by the relayer on each channelEnd and allows them to set an optional
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
)

// AppModuleBasic is the 29-fee AppModuleBasic
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)

// DenomTrace implements the Query/DenomTrace gRPC method
func (q Keeper) DenomTrace(c context.Context, req *types.QueryDenomTraceRequest) (*types.QueryDenomTraceResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)

var _ types.MsgServer = Keeper{}
var _ types.MsgServer = (*Keeper)(nil)

// Transfer defines an rpc handler method for MsgTransfer.
func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ porttypes.IBCModule = IBCModule{}
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ porttypes.IBCModule = (*IBCModule)(nil)
)

// AppModuleBasic is the IBC Transfer AppModuleBasic
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (t Traces) Validate() error {
return nil
}

var _ sort.Interface = Traces{}
var _ sort.Interface = (*Traces)(nil)

// Len implements sort.Interface for Traces
func (t Traces) Len() int { return len(t) }
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const gasCostPerIteration = uint64(10)

var _ authz.Authorization = &TransferAuthorization{}
var _ authz.Authorization = (*TransferAuthorization)(nil)

// NewTransferAuthorization creates a new TransferAuthorization object.
func NewTransferAuthorization(allocations ...Allocation) *TransferAuthorization {
Expand Down
9 changes: 4 additions & 5 deletions modules/capability/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
)

var (
_ module.BeginBlockAppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
_ module.BeginBlockAppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ appmodule.AppModule = (*AppModule)(nil)
)

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -100,8 +101,6 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, sealKeeper bool) AppMod
}
}

var _ appmodule.AppModule = AppModule{}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)

// ClientState implements the Query/ClientState gRPC method
func (q Keeper) ClientState(c context.Context, req *types.QueryClientStateRequest) (*types.QueryClientStateResponse, error) {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/migrations/v7/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

// Interface implementation checks.
var (
_, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{}
_, _ codectypes.UnpackInterfacesMessage = (*ClientState)(nil), (*ConsensusState)(nil)
_ exported.ClientState = (*ClientState)(nil)
_ exported.ConsensusState = &ConsensusState{}
_ exported.ConsensusState = (*ConsensusState)(nil)
)

// RegisterInterfaces registers the solomachine v2 ClientState and ConsensusState types in the interface registry.
Expand Down
6 changes: 3 additions & 3 deletions modules/core/02-client/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
)

var (
_ codectypes.UnpackInterfacesMessage = IdentifiedClientState{}
_ codectypes.UnpackInterfacesMessage = ConsensusStateWithHeight{}
_ codectypes.UnpackInterfacesMessage = (*IdentifiedClientState)(nil)
_ codectypes.UnpackInterfacesMessage = (*ConsensusStateWithHeight)(nil)
)

// NewIdentifiedClientState creates a new IdentifiedClientState instance
Expand All @@ -42,7 +42,7 @@ func (ics IdentifiedClientState) UnpackInterfaces(unpacker codectypes.AnyUnpacke
return unpacker.UnpackAny(ics.ClientState, new(exported.ClientState))
}

var _ sort.Interface = IdentifiedClientStates{}
var _ sort.Interface = (*IdentifiedClientStates)(nil)

// IdentifiedClientStates defines a slice of ClientConsensusStates that supports the sort interface
type IdentifiedClientStates []IdentifiedClientState
Expand Down
14 changes: 6 additions & 8 deletions modules/core/02-client/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
)

var (
_ codectypes.UnpackInterfacesMessage = IdentifiedClientState{}
_ codectypes.UnpackInterfacesMessage = ClientsConsensusStates{}
_ codectypes.UnpackInterfacesMessage = ClientConsensusStates{}
_ codectypes.UnpackInterfacesMessage = GenesisState{}
)
_ codectypes.UnpackInterfacesMessage = (*IdentifiedClientState)(nil)
_ codectypes.UnpackInterfacesMessage = (*ClientsConsensusStates)(nil)
_ codectypes.UnpackInterfacesMessage = (*ClientConsensusStates)(nil)
_ codectypes.UnpackInterfacesMessage = (*GenesisState)(nil)

var (
_ sort.Interface = ClientsConsensusStates{}
_ exported.GenesisMetadata = GenesisMetadata{}
_ sort.Interface = (*ClientsConsensusStates)(nil)
_ exported.GenesisMetadata = (*GenesisMetadata)(nil)
)

// ClientsConsensusStates defines a slice of ClientConsensusStates that supports the sort interface
Expand Down
16 changes: 8 additions & 8 deletions modules/core/02-client/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
)

var (
_ sdk.Msg = &MsgCreateClient{}
_ sdk.Msg = &MsgUpdateClient{}
_ sdk.Msg = &MsgSubmitMisbehaviour{}
_ sdk.Msg = &MsgUpgradeClient{}
_ sdk.Msg = (*MsgCreateClient)(nil)
_ sdk.Msg = (*MsgUpdateClient)(nil)
_ sdk.Msg = (*MsgSubmitMisbehaviour)(nil)
_ sdk.Msg = (*MsgUpgradeClient)(nil)

_ codectypes.UnpackInterfacesMessage = MsgCreateClient{}
_ codectypes.UnpackInterfacesMessage = MsgUpdateClient{}
_ codectypes.UnpackInterfacesMessage = MsgSubmitMisbehaviour{}
_ codectypes.UnpackInterfacesMessage = MsgUpgradeClient{}
_ codectypes.UnpackInterfacesMessage = (*MsgCreateClient)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgUpdateClient)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgSubmitMisbehaviour)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgUpgradeClient)(nil)
)

// NewMsgCreateClient creates a new MsgCreateClient instance
Expand Down
6 changes: 3 additions & 3 deletions modules/core/02-client/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const (
)

var (
_ govtypes.Content = &ClientUpdateProposal{}
_ govtypes.Content = &UpgradeProposal{}
_ codectypes.UnpackInterfacesMessage = &UpgradeProposal{}
_ govtypes.Content = (*ClientUpdateProposal)(nil)
_ govtypes.Content = (*UpgradeProposal)(nil)
_ codectypes.UnpackInterfacesMessage = (*UpgradeProposal)(nil)
)

func init() {
Expand Down
8 changes: 4 additions & 4 deletions modules/core/02-client/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

var (
_ codectypes.UnpackInterfacesMessage = QueryClientStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryClientStatesResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConsensusStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConsensusStatesResponse{}
_ codectypes.UnpackInterfacesMessage = (*QueryClientStateResponse)(nil)
_ codectypes.UnpackInterfacesMessage = (*QueryClientStatesResponse)(nil)
_ codectypes.UnpackInterfacesMessage = (*QueryConsensusStateResponse)(nil)
_ codectypes.UnpackInterfacesMessage = (*QueryConsensusStatesResponse)(nil)
)

// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
Expand Down
2 changes: 1 addition & 1 deletion modules/core/03-connection/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
)

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = (*Keeper)(nil)

// Connection implements the Query/Connection gRPC method
func (q Keeper) Connection(c context.Context, req *types.QueryConnectionRequest) (*types.QueryConnectionResponse, error) {
Expand Down
12 changes: 6 additions & 6 deletions modules/core/03-connection/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
)

var (
_ sdk.Msg = &MsgConnectionOpenInit{}
_ sdk.Msg = &MsgConnectionOpenConfirm{}
_ sdk.Msg = &MsgConnectionOpenAck{}
_ sdk.Msg = &MsgConnectionOpenTry{}
_ sdk.Msg = (*MsgConnectionOpenInit)(nil)
_ sdk.Msg = (*MsgConnectionOpenConfirm)(nil)
_ sdk.Msg = (*MsgConnectionOpenAck)(nil)
_ sdk.Msg = (*MsgConnectionOpenTry)(nil)

_ codectypes.UnpackInterfacesMessage = MsgConnectionOpenTry{}
_ codectypes.UnpackInterfacesMessage = MsgConnectionOpenAck{}
_ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenTry)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgConnectionOpenAck)(nil)
)

// NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance. It sets the
Expand Down
4 changes: 2 additions & 2 deletions modules/core/03-connection/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

var (
_ codectypes.UnpackInterfacesMessage = QueryConnectionClientStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConnectionConsensusStateResponse{}
_ codectypes.UnpackInterfacesMessage = (*QueryConnectionClientStateResponse)(nil)
_ codectypes.UnpackInterfacesMessage = (*QueryConnectionConsensusStateResponse)(nil)
)

// NewQueryConnectionResponse creates a new QueryConnectionResponse instance
Expand Down
2 changes: 1 addition & 1 deletion modules/core/03-connection/types/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
}
)

var _ exported.Version = &Version{}
var _ exported.Version = (*Version)(nil)

// NewVersion returns a new instance of Version.
func NewVersion(identifier string, features []string) *Version {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

var _ porttypes.ICS4Wrapper = Keeper{}
var _ porttypes.ICS4Wrapper = (*Keeper)(nil)

// Keeper defines the IBC channel keeper
type Keeper struct {
Expand Down
Loading