Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add slot to solana chain head #351

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emerald-grpc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import io.emeraldpay.etherjar.rpc.json.TransactionRefJson
import java.math.BigInteger
import java.time.Instant

class BlockContainer(
class BlockContainer @JvmOverloads constructor(
val height: Long,
val hash: BlockId,
val difficulty: BigInteger,
Expand All @@ -39,6 +39,7 @@ class BlockContainer(
val transactions: List<TxId> = emptyList(),
val nodeRating: Int = 0,
val upstreamId: String = "",
val slot: Long = 0,
) : SourceContainer(json, parsed) {
val enriched: Boolean = transactions.isNotEmpty()

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class StreamHead(
return BlockchainOuterClass.ChainHead.newBuilder()
.setChainValue(chain.id)
.setHeight(block.height)
.setSlot(block.slot)
.setTimestamp(block.timestamp.toEpochMilli())
.setWeight(ByteString.copyFrom(block.difficulty.toByteArray()))
.setBlockId(block.hash.toHex())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object SolanaChainSpecific : AbstractChainSpecific() {
).map {
val raw = it.getResult()
val block = Global.objectMapper.readValue(it.getResult(), SolanaBlock::class.java)
makeBlock(raw, block, upstreamId)
makeBlock(raw, block, upstreamId, response.max())
}.onErrorResume {
log.debug("error during getting last solana block - ${it.message}")
Mono.empty()
Expand All @@ -77,10 +77,10 @@ object SolanaChainSpecific : AbstractChainSpecific() {

override fun parseHeader(data: ByteArray, upstreamId: String): BlockContainer {
val res = Global.objectMapper.readValue(data, SolanaWrapper::class.java)
return makeBlock(data, res.value.block, upstreamId)
return makeBlock(data, res.value.block, upstreamId, res.context.slot)
}

private fun makeBlock(raw: ByteArray, block: SolanaBlock, upstreamId: String): BlockContainer {
private fun makeBlock(raw: ByteArray, block: SolanaBlock, upstreamId: String, slot: Long): BlockContainer {
return BlockContainer(
height = block.height,
hash = BlockId.fromBase64(block.hash),
Expand All @@ -92,6 +92,7 @@ object SolanaChainSpecific : AbstractChainSpecific() {
transactions = emptyList(),
upstreamId = upstreamId,
parentHash = BlockId.fromBase64(block.parent),
slot = slot,
)
}

Expand Down
Loading