In case disabled enrichment and native subscription without proxy we should have fallback enrichment of blocks (#159)
This commit is contained in:
@@ -17,8 +17,13 @@
|
|||||||
package io.emeraldpay.dshackle.data
|
package io.emeraldpay.dshackle.data
|
||||||
|
|
||||||
import io.emeraldpay.dshackle.Global
|
import io.emeraldpay.dshackle.Global
|
||||||
|
import io.emeraldpay.etherjar.domain.Address
|
||||||
|
import io.emeraldpay.etherjar.domain.BlockHash
|
||||||
|
import io.emeraldpay.etherjar.domain.Bloom
|
||||||
|
import io.emeraldpay.etherjar.domain.Wei
|
||||||
import io.emeraldpay.etherjar.rpc.json.BlockJson
|
import io.emeraldpay.etherjar.rpc.json.BlockJson
|
||||||
import io.emeraldpay.etherjar.rpc.json.TransactionJson
|
import io.emeraldpay.etherjar.rpc.json.TransactionJson
|
||||||
|
import io.emeraldpay.etherjar.rpc.json.TransactionRefJson
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
@@ -99,4 +104,25 @@ class BlockContainer(
|
|||||||
result = 31 * result + hash.hashCode()
|
result = 31 * result + hash.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toBlock(): BlockJson<*> {
|
||||||
|
return if (parsed != null) {
|
||||||
|
parsed as BlockJson<TransactionRefJson>
|
||||||
|
} else if (json != null) {
|
||||||
|
Global.objectMapper.readValue(json, BlockJson::class.java)
|
||||||
|
} else {
|
||||||
|
BlockJson<TransactionRefJson>().also {
|
||||||
|
it.number = height
|
||||||
|
it.hash = BlockHash.from(hash.value)
|
||||||
|
it.parentHash = BlockHash.empty()
|
||||||
|
it.timestamp = timestamp
|
||||||
|
it.difficulty = difficulty
|
||||||
|
it.gasLimit = 0
|
||||||
|
it.gasUsed = 0
|
||||||
|
it.logsBloom = Bloom.empty()
|
||||||
|
it.miner = Address.empty()
|
||||||
|
it.baseFeePerGas = Wei.ZERO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.emeraldpay.dshackle.upstream.ethereum.subscribe
|
package io.emeraldpay.dshackle.upstream.ethereum.subscribe
|
||||||
|
|
||||||
import io.emeraldpay.dshackle.Global
|
|
||||||
import io.emeraldpay.dshackle.data.BlockContainer
|
|
||||||
import io.emeraldpay.dshackle.upstream.Head
|
import io.emeraldpay.dshackle.upstream.Head
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.NewHeadMessage
|
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.NewHeadMessage
|
||||||
import io.emeraldpay.etherjar.rpc.json.BlockJson
|
|
||||||
import io.emeraldpay.etherjar.rpc.json.TransactionRefJson
|
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import reactor.core.publisher.Flux
|
import reactor.core.publisher.Flux
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,16 +28,10 @@ class ProduceNewHeads(
|
|||||||
val head: Head
|
val head: Head
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val log = LoggerFactory.getLogger(ProduceNewHeads::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val objectMapper = Global.objectMapper
|
|
||||||
|
|
||||||
fun start(): Flux<NewHeadMessage> {
|
fun start(): Flux<NewHeadMessage> {
|
||||||
return head.getFlux()
|
return head.getFlux()
|
||||||
.map {
|
.map {
|
||||||
val block = extractBlock(it)
|
val block = it.toBlock()
|
||||||
NewHeadMessage(
|
NewHeadMessage(
|
||||||
block.number,
|
block.number,
|
||||||
block.hash,
|
block.hash,
|
||||||
@@ -58,11 +47,4 @@ class ProduceNewHeads(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractBlock(blockContainer: BlockContainer): BlockJson<out TransactionRefJson> =
|
|
||||||
if (blockContainer.parsed != null) {
|
|
||||||
blockContainer.parsed as BlockJson<TransactionRefJson>
|
|
||||||
} else {
|
|
||||||
objectMapper.readValue(blockContainer.json, BlockJson::class.java)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user