Skip to content

Commit

Permalink
deduplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Apr 23, 2021
1 parent 317bb64 commit 30758d0
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions modules/light-clients/07-tendermint/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,8 @@ func GetNextConsensusState(clientStore sdk.KVStore, cdc codec.BinaryMarshaler, h
}

csKey := iterator.Value()
bz := clientStore.Get(csKey)
if bz == nil {
return nil, false
}

consensusStateI, err := clienttypes.UnmarshalConsensusState(cdc, bz)
if err != nil {
return nil, false
}

consensusState, ok := consensusStateI.(*ConsensusState)
if !ok {
return nil, false
}

return consensusState, true
return getTmConsensusState(clientStore, cdc, csKey)
}

// GetPreviousConsensusState returns the highest consensus state that is lower than the given height.
Expand All @@ -229,7 +215,13 @@ func GetPreviousConsensusState(clientStore sdk.KVStore, cdc codec.BinaryMarshale
}

csKey := iterator.Value()
bz := clientStore.Get(csKey)

return getTmConsensusState(clientStore, cdc, csKey)
}

// Helper function for GetNextConsensusState and GetPreviousConsensusState
func getTmConsensusState(clientStore sdk.KVStore, cdc codec.BinaryMarshaler, key []byte) (*ConsensusState, bool) {
bz := clientStore.Get(key)
if bz == nil {
return nil, false
}
Expand All @@ -243,8 +235,6 @@ func GetPreviousConsensusState(clientStore sdk.KVStore, cdc codec.BinaryMarshale
if !ok {
return nil, false
}

return consensusState, true
}

func bigEndianHeightBytes(height exported.Height) []byte {
Expand Down

0 comments on commit 30758d0

Please sign in to comment.