diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlobDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlobDetector.kt index 6e83959d..96b502c8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlobDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlobDetector.kt @@ -55,12 +55,16 @@ class BeaconChainLowerBoundBlobDetector( private fun parseHeadersResponse(data: ByteArray): ChainResponse { val node = Global.objectMapper.readValue(data) - if (node.get("code") != null && node.get("message") != null && node.get("code").textValue() == "404") { - return ChainResponse(null, ChainCallError(node.get("code").asInt(), node.get("message").asText(), node.get("message").asText())) + val codeNode = node.get("code") + val messageNode = node.get("message") + val is404 = codeNode != null && (codeNode.asInt() == 404 || codeNode.asText() == "404") + if (is404 && messageNode != null) { + return ChainResponse(null, ChainCallError(404, messageNode.asText(), messageNode.asText())) } - if (node.get("data").toString() == "[]") { + val dataNode = node.get("data") + if (dataNode == null || dataNode.isNull || (dataNode.isArray && dataNode.size() == 0)) { return ChainResponse(null, ChainCallError(404, notFoundError)) } - return ChainResponse(node.get("data").toString().toByteArray(), null) + return ChainResponse(dataNode.toString().toByteArray(), null) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlockDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlockDetector.kt index d44f2c5c..d3840773 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlockDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundBlockDetector.kt @@ -57,8 +57,11 @@ class BeaconChainLowerBoundBlockDetector( private fun parseHeadersResponse(data: ByteArray): ChainResponse { val node = Global.objectMapper.readValue(data) - if (node.get("code") != null && node.get("message") != null && node.get("code").textValue() == "404") { - return ChainResponse(null, ChainCallError(node.get("code").asInt(), node.get("message").asText(), node.get("message").asText())) + val codeNode = node.get("code") + val messageNode = node.get("message") + val is404 = codeNode != null && (codeNode.asInt() == 404 || codeNode.asText() == "404") + if (is404 && messageNode != null) { + return ChainResponse(null, ChainCallError(404, messageNode.asText(), messageNode.asText())) } if (node.get("data")?.get("message")?.get("slot") != null) { return ChainResponse(node.get("data").toString().toByteArray(), null) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundEpochDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundEpochDetector.kt index 4be97020..bd2fa2f1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundEpochDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundEpochDetector.kt @@ -80,10 +80,12 @@ class BeaconChainLowerBoundEpochDetector( private fun parseHeadersResponse(data: ByteArray): ChainResponse { val node = Global.objectMapper.readValue(data) - if (node.get("code") != null && node.get("message") != null && node.get("code").textValue() == "404") { - return ChainResponse(null, ChainCallError(node.get("code").asInt(), node.get("message").asText(), node.get("message").asText())) + val codeNode = node.get("code") + val messageNode = node.get("message") + val is404 = codeNode != null && (codeNode.asInt() == 404 || codeNode.asText() == "404") + if (is404 && messageNode != null) { + return ChainResponse(null, ChainCallError(404, messageNode.asText(), messageNode.asText())) } - val jsonData = node.get("data") if (jsonData != null) { val str = jsonData.toString() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundStateDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundStateDetector.kt index e84fdca5..d68b1c1f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundStateDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/beaconchain/BeaconChainLowerBoundStateDetector.kt @@ -54,10 +54,12 @@ class BeaconChainLowerBoundStateDetector( private fun parseHeadersResponse(data: ByteArray): ChainResponse { val node = Global.objectMapper.readValue(data) - if (node.get("code") != null && node.get("message") != null && node.get("code").textValue() == "404") { - return ChainResponse(null, ChainCallError(node.get("code").asInt(), node.get("message").asText(), node.get("message").asText())) + val codeNode = node.get("code") + val messageNode = node.get("message") + val is404 = codeNode != null && (codeNode.asInt() == 404 || codeNode.asText() == "404") + if (is404 && messageNode != null) { + return ChainResponse(null, ChainCallError(404, messageNode.asText(), messageNode.asText())) } - val jsonData = node.get("data") if (jsonData != null) { val str = jsonData.toString() diff --git a/src/test/kotlin/io/emeraldpay/dshackle/upstream/generic/GenericRpcHeadTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/upstream/generic/GenericRpcHeadTest.kt index 22511100..2bb09721 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/upstream/generic/GenericRpcHeadTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/upstream/generic/GenericRpcHeadTest.kt @@ -133,7 +133,7 @@ class GenericRpcHeadTest { "id", BlockValidator.ALWAYS_VALID, upstream, - Schedulers.boundedElastic(), + Schedulers.immediate(), EthereumChainSpecific, Duration.ofSeconds(5), )