Skip to content

Commit

Permalink
chore: move nil checks to top of methods in 08-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Mar 26, 2024
1 parent 0e8ba03 commit ef6c625
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions modules/light-clients/08-wasm/types/consensus_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func NewWasmConsensusHost(cdc codec.BinaryCodec, delegate clienttypes.ConsensusH

// GetSelfConsensusState implements the 02-client types.ConsensusHost interface.
func (w *WasmConsensusHost) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) {
if w.cdc == nil {
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm consensus host codec is nil")
}

if w.delegate == nil {
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm delegate consensus host is nil")
}

consensusState, err := w.delegate.GetSelfConsensusState(ctx, height)
if err != nil {
return nil, err
Expand All @@ -48,17 +56,17 @@ func (w *WasmConsensusHost) GetSelfConsensusState(ctx sdk.Context, height export

// ValidateSelfClient implements the 02-client types.ConsensusHost interface.
func (w *WasmConsensusHost) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error {
wasmClientState, ok := clientState.(*ClientState)
if !ok {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client must be a wasm client, expected: %T, got: %T", ClientState{}, wasmClientState)
if w.cdc == nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm consensus host codec is nil")
}

if w == nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm consensus host is nil")
if w.delegate == nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm delegate consensus host is nil")
}

if w.cdc == nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "wasm consensus host cdc is nil")
wasmClientState, ok := clientState.(*ClientState)
if !ok {
return errorsmod.Wrapf(clienttypes.ErrInvalidClient, "client must be a wasm client, expected: %T, got: %T", ClientState{}, wasmClientState)
}

if wasmClientState.Data == nil {
Expand Down

0 comments on commit ef6c625

Please sign in to comment.