problem: returns processed json for block with tx, instead of original json
rel: #45
This commit is contained in:
@@ -205,7 +205,7 @@ class TrackEthereumTx(
|
||||
return Mono.empty()
|
||||
}
|
||||
return upstream.getReader()
|
||||
.blocksByHash().read(tx.status.blockHash)
|
||||
.blocksByHashParsed().read(tx.status.blockHash)
|
||||
.map { block ->
|
||||
setBlockDetails(tx, block)
|
||||
}.doOnError { t ->
|
||||
|
||||
@@ -71,54 +71,37 @@ open class EthereumReader(
|
||||
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 blockHashToId = Function<BlockHash, BlockId> { hash -> BlockId.from(hash) }
|
||||
|
||||
private val txHashToId = Function<TransactionId, TxId> { hash -> TxId.from(hash) }
|
||||
private val idToTxHash = Function<TxId, TransactionId> { id -> TransactionId.from(id.value) }
|
||||
|
||||
fun blocksByHash(): Reader<BlockHash, BlockJson<TransactionRefJson>> {
|
||||
return TransformingReader(
|
||||
CompoundReader(
|
||||
RekeyingReader(blockHashToId, caches.getBlocksByHash()),
|
||||
directReader.blockReader
|
||||
),
|
||||
extractBlock
|
||||
)
|
||||
}
|
||||
|
||||
fun blocksById(): Reader<BlockId, BlockJson<TransactionRefJson>> {
|
||||
return TransformingReader(
|
||||
CompoundReader(
|
||||
caches.getBlocksByHash(),
|
||||
RekeyingReader(idToBlockHash, directReader.blockReader)
|
||||
),
|
||||
extractBlock
|
||||
)
|
||||
}
|
||||
|
||||
fun blocksByHashAsCont(): Reader<BlockHash, BlockContainer> {
|
||||
return CompoundReader(
|
||||
RekeyingReader(blockHashToId, caches.getBlocksByHash()),
|
||||
directReader.blockReader
|
||||
)
|
||||
}
|
||||
|
||||
fun blocksByHashParsed(): Reader<BlockHash, BlockJson<TransactionRefJson>> {
|
||||
return TransformingReader(
|
||||
blocksByHash(),
|
||||
blockAsContainer
|
||||
blocksByHashAsCont(),
|
||||
extractBlock
|
||||
)
|
||||
}
|
||||
|
||||
fun blocksByIdParsed(): Reader<BlockId, BlockJson<TransactionRefJson>> {
|
||||
return TransformingReader(
|
||||
blocksByIdAsCont(),
|
||||
extractBlock
|
||||
)
|
||||
}
|
||||
|
||||
open fun blocksByIdAsCont(): Reader<BlockId, BlockContainer> {
|
||||
return TransformingReader(
|
||||
blocksById(),
|
||||
blockAsContainer
|
||||
return CompoundReader(
|
||||
caches.getBlocksByHash(),
|
||||
RekeyingReader(idToBlockHash, directReader.blockReader)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class EthereumReaderSpec extends Specification {
|
||||
def reader = new EthereumReader(Stub(Multistream), caches, calls)
|
||||
|
||||
when:
|
||||
def act = reader.blocksById().read(blockId).block()
|
||||
def act = reader.blocksByIdParsed().read(blockId).block()
|
||||
|
||||
then:
|
||||
act == blockJson
|
||||
@@ -92,7 +92,7 @@ class EthereumReaderSpec extends Specification {
|
||||
def reader = new EthereumReader(upstream, caches, calls)
|
||||
|
||||
when:
|
||||
def act = reader.blocksById().read(blockId).block()
|
||||
def act = reader.blocksByIdParsed().read(blockId).block()
|
||||
|
||||
then:
|
||||
act == blockJson
|
||||
@@ -113,7 +113,7 @@ class EthereumReaderSpec extends Specification {
|
||||
def reader = new EthereumReader(upstream, caches, calls)
|
||||
|
||||
when:
|
||||
def act = reader.blocksById().read(blockId).block()
|
||||
def act = reader.blocksByIdParsed().read(blockId).block()
|
||||
|
||||
then:
|
||||
act == blockJson
|
||||
@@ -130,7 +130,7 @@ class EthereumReaderSpec extends Specification {
|
||||
def reader = new EthereumReader(Stub(Multistream), caches, calls)
|
||||
|
||||
when:
|
||||
def act = reader.blocksByHash().read(blockJson.hash).block()
|
||||
def act = reader.blocksByHashParsed().read(blockJson.hash).block()
|
||||
|
||||
then:
|
||||
act == blockJson
|
||||
@@ -150,7 +150,7 @@ class EthereumReaderSpec extends Specification {
|
||||
def reader = new EthereumReader(upstream, caches, calls)
|
||||
|
||||
when:
|
||||
def act = reader.blocksByHash().read(blockJson.hash).block()
|
||||
def act = reader.blocksByHashParsed().read(blockJson.hash).block()
|
||||
|
||||
then:
|
||||
act == blockJson
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
"0xe589a39acea3091b584b650158d08b159aa07e97b8e8cddb8f81cb606e13382e"
|
||||
],
|
||||
"transactionsRoot": "0xc90078e2af52aef81815cb2a71c22ebd781dd658dd953d9df57f7769a0b2fe51",
|
||||
"uncles": []
|
||||
"uncles": [],
|
||||
"testFoo": "bar"
|
||||
}
|
||||
@@ -48,4 +48,26 @@ class StandardCallsSpec extends Specification {
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user