solana stable poll (#344)
This commit is contained in:
@@ -17,6 +17,7 @@ import io.emeraldpay.dshackle.upstream.generic.AbstractChainSpecific
|
|||||||
import io.emeraldpay.dshackle.upstream.generic.GenericEgressSubscription
|
import io.emeraldpay.dshackle.upstream.generic.GenericEgressSubscription
|
||||||
import io.emeraldpay.dshackle.upstream.generic.GenericIngressSubscription
|
import io.emeraldpay.dshackle.upstream.generic.GenericIngressSubscription
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
import reactor.core.publisher.Mono
|
import reactor.core.publisher.Mono
|
||||||
import reactor.core.scheduler.Scheduler
|
import reactor.core.scheduler.Scheduler
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
@@ -24,25 +25,45 @@ import java.time.Instant
|
|||||||
|
|
||||||
object SolanaChainSpecific : AbstractChainSpecific() {
|
object SolanaChainSpecific : AbstractChainSpecific() {
|
||||||
|
|
||||||
|
private val log = LoggerFactory.getLogger(SolanaChainSpecific::class.java)
|
||||||
|
|
||||||
override fun getLatestBlock(api: JsonRpcReader, upstreamId: String): Mono<BlockContainer> {
|
override fun getLatestBlock(api: JsonRpcReader, upstreamId: String): Mono<BlockContainer> {
|
||||||
return api.read(JsonRpcRequest("getLatestBlockhash", listOf())).flatMap {
|
return api.read(JsonRpcRequest("getSlot", listOf())).flatMap {
|
||||||
val response = Global.objectMapper.readValue(it.getResult(), SolanaLatest::class.java)
|
val slot = it.getResultAsProcessedString().toLong()
|
||||||
api.read(
|
api.read(
|
||||||
JsonRpcRequest(
|
JsonRpcRequest(
|
||||||
"getBlock",
|
"getBlocks",
|
||||||
listOf(
|
listOf(
|
||||||
response.context.slot,
|
slot - 10,
|
||||||
mapOf(
|
slot,
|
||||||
"showRewards" to false,
|
|
||||||
"transactionDetails" to "none",
|
|
||||||
"maxSupportedTransactionVersion" to 0,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).map {
|
).flatMap {
|
||||||
val raw = it.getResult()
|
val response = Global.objectMapper.readValue(it.getResult(), LongArray::class.java)
|
||||||
val block = Global.objectMapper.readValue(it.getResult(), SolanaBlock::class.java)
|
if (response == null || response.isEmpty()) {
|
||||||
makeBlock(raw, block, upstreamId)
|
Mono.empty()
|
||||||
|
} else {
|
||||||
|
api.read(
|
||||||
|
JsonRpcRequest(
|
||||||
|
"getBlock",
|
||||||
|
listOf(
|
||||||
|
response.max(),
|
||||||
|
mapOf(
|
||||||
|
"showRewards" to false,
|
||||||
|
"transactionDetails" to "none",
|
||||||
|
"maxSupportedTransactionVersion" to 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).map {
|
||||||
|
val raw = it.getResult()
|
||||||
|
val block = Global.objectMapper.readValue(it.getResult(), SolanaBlock::class.java)
|
||||||
|
makeBlock(raw, block, upstreamId)
|
||||||
|
}.onErrorResume {
|
||||||
|
log.debug("error during getting last solana block - ${it.message}")
|
||||||
|
Mono.empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,11 +118,6 @@ object SolanaChainSpecific : AbstractChainSpecific() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
data class SolanaLatest(
|
|
||||||
@JsonProperty("context") var context: SolanaContext,
|
|
||||||
)
|
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
data class SolanaWrapper(
|
data class SolanaWrapper(
|
||||||
@JsonProperty("context") var context: SolanaContext,
|
@JsonProperty("context") var context: SolanaContext,
|
||||||
|
|||||||
Reference in New Issue
Block a user