Height matcher to proxy (#340)
This commit is contained in:
Submodule emerald-grpc updated: e6153279a5...e6fcfa6f81
@@ -285,9 +285,12 @@ open class NativeCall(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val requestMatcher = requestItem.selectorsList
|
||||||
|
.takeIf { it.isNotEmpty() }
|
||||||
|
?.run { Mono.just(Selector.convertToMatcher(this, upstream.getHead())) }
|
||||||
// for ethereum the actual block needed for the call may be specified in the call parameters
|
// for ethereum the actual block needed for the call may be specified in the call parameters
|
||||||
val callSpecificMatcher: Mono<Selector.Matcher> =
|
val callSpecificMatcher: Mono<Selector.Matcher> =
|
||||||
upstream.callSelector?.getMatcher(method, params, upstream.getHead(), passthrough) ?: Mono.empty()
|
requestMatcher ?: upstream.callSelector?.getMatcher(method, params, upstream.getHead(), passthrough) ?: Mono.empty()
|
||||||
return callSpecificMatcher.defaultIfEmpty(Selector.empty).map { csm ->
|
return callSpecificMatcher.defaultIfEmpty(Selector.empty).map { csm ->
|
||||||
val matcher = Selector.Builder()
|
val matcher = Selector.Builder()
|
||||||
.withMatcher(csm)
|
.withMatcher(csm)
|
||||||
|
|||||||
@@ -39,6 +39,26 @@ class Selector {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
val anyLabel = AnyLabelMatcher()
|
val anyLabel = AnyLabelMatcher()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun convertToMatcher(selectors: List<BlockchainOuterClass.Selector>, head: Head): Matcher {
|
||||||
|
return selectors
|
||||||
|
.map {
|
||||||
|
when {
|
||||||
|
it.hasHeightSelector() -> {
|
||||||
|
val height = if (it.heightSelector.height == -1L) head.getCurrentHeight() else it.heightSelector.height
|
||||||
|
if (height == null) {
|
||||||
|
empty
|
||||||
|
} else {
|
||||||
|
HeightMatcher(height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> empty
|
||||||
|
}
|
||||||
|
}.run {
|
||||||
|
MultiMatcher(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun convertToMatcher(req: BlockchainOuterClass.Selector?): LabelSelectorMatcher {
|
fun convertToMatcher(req: BlockchainOuterClass.Selector?): LabelSelectorMatcher {
|
||||||
return when {
|
return when {
|
||||||
|
|||||||
@@ -32,11 +32,37 @@ class SelectorSpec extends Specification {
|
|||||||
private BlockchainOuterClass.Selector selectLabel2Selector = BlockchainOuterClass.Selector.newBuilder()
|
private BlockchainOuterClass.Selector selectLabel2Selector = BlockchainOuterClass.Selector.newBuilder()
|
||||||
.setLabelSelector(selectLabel2).build()
|
.setLabelSelector(selectLabel2).build()
|
||||||
|
|
||||||
def "Convert nothing"() {
|
def "Convert height selector"() {
|
||||||
|
setup:
|
||||||
|
def heightSelector = BlockchainOuterClass.Selector.newBuilder()
|
||||||
|
.setHeightSelector(
|
||||||
|
BlockchainOuterClass.HeightSelector.newBuilder()
|
||||||
|
.setHeight(10000)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
when:
|
when:
|
||||||
def act = Selector.convertToMatcher(null)
|
def act = Selector.convertToMatcher(List.of(heightSelector), Stub(Head))
|
||||||
then:
|
then:
|
||||||
act.class == Selector.AnyLabelMatcher
|
act == new Selector.MultiMatcher(List.of(new Selector.HeightMatcher(10000)))
|
||||||
|
}
|
||||||
|
|
||||||
|
def "Convert height selector with latest"() {
|
||||||
|
setup:
|
||||||
|
def head = Mock(Head) {
|
||||||
|
1 * getCurrentHeight() >> 15000
|
||||||
|
}
|
||||||
|
def heightSelector = BlockchainOuterClass.Selector.newBuilder()
|
||||||
|
.setHeightSelector(
|
||||||
|
BlockchainOuterClass.HeightSelector.newBuilder()
|
||||||
|
.setHeight(-1)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
when:
|
||||||
|
def act = Selector.convertToMatcher(List.of(heightSelector), head)
|
||||||
|
then:
|
||||||
|
act == new Selector.MultiMatcher(List.of(new Selector.HeightMatcher(15000)))
|
||||||
}
|
}
|
||||||
|
|
||||||
def "Convert LABEL match"() {
|
def "Convert LABEL match"() {
|
||||||
|
|||||||
Reference in New Issue
Block a user