problem: zero bytes when requesting block with tx

This commit is contained in:
Igor Artamonov
2020-08-17 22:32:21 -04:00
parent 340e665f08
commit 8be97df9b5
2 changed files with 48 additions and 2 deletions

View File

@@ -81,7 +81,7 @@ class EthereumFullBlocksReader(
} else {
joinWithTransactions(blockSplit.t1, blockSplit.t2, Flux.fromIterable(transactionsData).map { it.json!! })
.reduce(ByteBuffer.allocate(block.json.size * 4), accumulate)
.map { it.flip().array() }
.map(this@EthereumFullBlocksReader::extractContent)
.map { json ->
BlockContainer(block.height, block.hash, block.difficulty, block.timestamp,
true,
@@ -95,6 +95,13 @@ class EthereumFullBlocksReader(
}
}
fun extractContent(it: ByteBuffer): ByteArray {
val pos = it.position()
val result = ByteArray(pos)
it.flip().get(result, 0, pos)
return result
}
fun splitByTransactions(json: ByteArray): Tuple2<ByteArray, ByteArray> {
//TODO find a lib that implements Knuth-Morris-Pratt Pattern Matching Algorithm for byte arrays
// and reimplement without making a string copy from bytes