problem: returns processed json for block with tx, instead of original json

rel: #45
This commit is contained in:
Igor Artamonov
2020-11-30 19:40:56 -05:00
parent e09b7a4eee
commit cfd73119f6
5 changed files with 49 additions and 43 deletions

View File

@@ -205,7 +205,7 @@ class TrackEthereumTx(
return Mono.empty() return Mono.empty()
} }
return upstream.getReader() return upstream.getReader()
.blocksByHash().read(tx.status.blockHash) .blocksByHashParsed().read(tx.status.blockHash)
.map { block -> .map { block ->
setBlockDetails(tx, block) setBlockDetails(tx, block)
}.doOnError { t -> }.doOnError { t ->

View File

@@ -71,54 +71,37 @@ open class EthereumReader(
tx.json ?: ByteArray(0) tx.json ?: ByteArray(0)
} }
val jsonToRaw = Function<Any, ByteArray> { json ->
objectMapper.writeValueAsBytes(json)
}
val blockAsContainer = Function<BlockJson<*>, BlockContainer> { block ->
BlockContainer.from(block.withoutTransactionDetails())
}
val txAsContainer = Function<TransactionJson, TxContainer> { tx ->
TxContainer.from(tx)
}
private val idToBlockHash = Function<BlockId, BlockHash> { id -> BlockHash.from(id.value) } private val idToBlockHash = Function<BlockId, BlockHash> { id -> BlockHash.from(id.value) }
private val blockHashToId = Function<BlockHash, BlockId> { hash -> BlockId.from(hash) } private val blockHashToId = Function<BlockHash, BlockId> { hash -> BlockId.from(hash) }
private val txHashToId = Function<TransactionId, TxId> { hash -> TxId.from(hash) } private val txHashToId = Function<TransactionId, TxId> { hash -> TxId.from(hash) }
private val idToTxHash = Function<TxId, TransactionId> { id -> TransactionId.from(id.value) } private val idToTxHash = Function<TxId, TransactionId> { id -> TransactionId.from(id.value) }
fun blocksByHash(): Reader<BlockHash, BlockJson<TransactionRefJson>> { fun blocksByHashAsCont(): Reader<BlockHash, BlockContainer> {
return TransformingReader( return CompoundReader(
CompoundReader(
RekeyingReader(blockHashToId, caches.getBlocksByHash()), RekeyingReader(blockHashToId, caches.getBlocksByHash()),
directReader.blockReader directReader.blockReader
), )
}
fun blocksByHashParsed(): Reader<BlockHash, BlockJson<TransactionRefJson>> {
return TransformingReader(
blocksByHashAsCont(),
extractBlock extractBlock
) )
} }
fun blocksById(): Reader<BlockId, BlockJson<TransactionRefJson>> { fun blocksByIdParsed(): Reader<BlockId, BlockJson<TransactionRefJson>> {
return TransformingReader( return TransformingReader(
CompoundReader( blocksByIdAsCont(),
caches.getBlocksByHash(),
RekeyingReader(idToBlockHash, directReader.blockReader)
),
extractBlock extractBlock
) )
} }
fun blocksByHashAsCont(): Reader<BlockHash, BlockContainer> {
return TransformingReader(
blocksByHash(),
blockAsContainer
)
}
open fun blocksByIdAsCont(): Reader<BlockId, BlockContainer> { open fun blocksByIdAsCont(): Reader<BlockId, BlockContainer> {
return TransformingReader( return CompoundReader(
blocksById(), caches.getBlocksByHash(),
blockAsContainer RekeyingReader(idToBlockHash, directReader.blockReader)
) )
} }

View File

@@ -71,7 +71,7 @@ class EthereumReaderSpec extends Specification {
def reader = new EthereumReader(Stub(Multistream), caches, calls) def reader = new EthereumReader(Stub(Multistream), caches, calls)
when: when:
def act = reader.blocksById().read(blockId).block() def act = reader.blocksByIdParsed().read(blockId).block()
then: then:
act == blockJson act == blockJson
@@ -92,7 +92,7 @@ class EthereumReaderSpec extends Specification {
def reader = new EthereumReader(upstream, caches, calls) def reader = new EthereumReader(upstream, caches, calls)
when: when:
def act = reader.blocksById().read(blockId).block() def act = reader.blocksByIdParsed().read(blockId).block()
then: then:
act == blockJson act == blockJson
@@ -113,7 +113,7 @@ class EthereumReaderSpec extends Specification {
def reader = new EthereumReader(upstream, caches, calls) def reader = new EthereumReader(upstream, caches, calls)
when: when:
def act = reader.blocksById().read(blockId).block() def act = reader.blocksByIdParsed().read(blockId).block()
then: then:
act == blockJson act == blockJson
@@ -130,7 +130,7 @@ class EthereumReaderSpec extends Specification {
def reader = new EthereumReader(Stub(Multistream), caches, calls) def reader = new EthereumReader(Stub(Multistream), caches, calls)
when: when:
def act = reader.blocksByHash().read(blockJson.hash).block() def act = reader.blocksByHashParsed().read(blockJson.hash).block()
then: then:
act == blockJson act == blockJson
@@ -150,7 +150,7 @@ class EthereumReaderSpec extends Specification {
def reader = new EthereumReader(upstream, caches, calls) def reader = new EthereumReader(upstream, caches, calls)
when: when:
def act = reader.blocksByHash().read(blockJson.hash).block() def act = reader.blocksByHashParsed().read(blockJson.hash).block()
then: then:
act == blockJson act == blockJson

View File

@@ -21,5 +21,6 @@
"0xe589a39acea3091b584b650158d08b159aa07e97b8e8cddb8f81cb606e13382e" "0xe589a39acea3091b584b650158d08b159aa07e97b8e8cddb8f81cb606e13382e"
], ],
"transactionsRoot": "0xc90078e2af52aef81815cb2a71c22ebd781dd658dd953d9df57f7769a0b2fe51", "transactionsRoot": "0xc90078e2af52aef81815cb2a71c22ebd781dd658dd953d9df57f7769a0b2fe51",
"uncles": [] "uncles": [],
"testFoo": "bar"
} }

View File

@@ -48,4 +48,26 @@ class StandardCallsSpec extends Specification {
} }
act.error == null act.error == null
} }
def "returns original block json"() {
when:
def act = client.execute("eth_getBlockByNumber", ["0x100001", false])
then:
act.result != null
with(act.result) {
testFoo == "bar"
}
act.error == null
}
def "returns original block json with tx"() {
when:
def act = client.execute("eth_getBlockByNumber", ["0x100001", true])
then:
act.result != null
with(act.result) {
testFoo == "bar"
}
act.error == null
}
} }