Lower matcher (#478)

This commit is contained in:
KirillPamPam
2024-05-20 15:19:17 +04:00
committed by GitHub
parent 55ee0663f2
commit f6090a40ac
2 changed files with 13 additions and 5 deletions

View File

@@ -65,10 +65,18 @@ class Selector {
}.run { }.run {
MultiMatcher(this) MultiMatcher(this)
} }
val sort = selectors.firstOrNull { it.hasHeightSelector() && it.heightSelector.height == -1L } return UpstreamFilter(getSort(selectors), matcher)
?.let { Sort(compareByDescending { it.getHead().getCurrentHeight() }) } }
?: Sort.default
return UpstreamFilter(sort, 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 @JvmStatic