Skip to content

Commit

Permalink
Lower matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Кирилл committed May 17, 2024
1 parent 55ee066 commit e98eb84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion emerald-grpc
16 changes: 12 additions & 4 deletions src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ class Selector {
}.run {
MultiMatcher(this)
}
val sort = selectors.firstOrNull { it.hasHeightSelector() && it.heightSelector.height == -1L }
?.let { Sort(compareByDescending { it.getHead().getCurrentHeight() }) }
?: Sort.default
return UpstreamFilter(sort, matcher)
return UpstreamFilter(getSort(selectors), matcher)
}

private fun getSort(selectors: List<BlockchainOuterClass.Selector>): Sort {
selectors.forEach { selector ->
if (selector.hasHeightSelector() && selector.heightSelector.height == -1L) {
return Sort(compareByDescending { it.getHead().getCurrentHeight() })
} else if (selector.hasLowerHeightSelector() && selector.lowerHeightSelector.height == 0L) {
return Sort(compareBy(nullsLast()) { it.getHead().getCurrentHeight() })
}
}
return Sort.default
}

@JvmStatic
Expand Down

0 comments on commit e98eb84

Please sign in to comment.