problem: doesn't parse block selector specified as object EIP-1898
rel: #81
This commit is contained in:
@@ -61,24 +61,37 @@ class EthereumCallSelector {
|
|||||||
log.debug("Tag is not specified. Ignoring")
|
log.debug("Tag is not specified. Ignoring")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
// integer block number, or the string "latest", "earliest" or "pending"
|
// integer block number, a string "latest", "earliest" or "pending", or an object with block reference
|
||||||
val minHeight = when (val tag = list[pos].toString()) {
|
val minHeight: Long? = when (val tag = list[pos].toString()) {
|
||||||
"latest" -> head.getCurrentHeight() ?: 0
|
"latest" -> head.getCurrentHeight()
|
||||||
// for earliest it doesn't nothing, we expect to have 0 block
|
// for earliest it doesn't nothing, we expect to have 0 block
|
||||||
"earliest" -> 0L
|
"earliest" -> 0L
|
||||||
else -> if (tag.startsWith("0x")) {
|
else -> if (tag.startsWith("0x")) {
|
||||||
|
try {
|
||||||
|
HexQuantity.from(tag).value.toLong()
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
log.debug("Invalid tag: $tag. ${t.javaClass}: ${t.message}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else if (tag.startsWith("{") && list[pos] is Map<*, *>) {
|
||||||
|
// see https://eips.ethereum.org/EIPS/eip-1898
|
||||||
|
val obj = list[pos] as Map<*, *>
|
||||||
|
if (obj.containsKey("blockNumber")) {
|
||||||
try {
|
try {
|
||||||
HexQuantity.from(tag).value.toLong()
|
HexQuantity.from(obj["blockNumber"].toString()).value.toLong()
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
log.debug("Invalid tag: $tag. ${t.javaClass}: ${t.message}")
|
log.warn("Invalid blockNumber: $tag")
|
||||||
0L
|
null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("Invalid tag: $tag")
|
null
|
||||||
0L
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("Invalid tag: $tag")
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return if (minHeight > 0) {
|
return if (minHeight != null && minHeight >= 0) {
|
||||||
Selector.HeightMatcher(minHeight)
|
Selector.HeightMatcher(minHeight)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -78,4 +78,12 @@ class EthereumCallSelectorSpec extends Specification {
|
|||||||
act == null
|
act == null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "Get height matcher with EIP-1898"() {
|
||||||
|
setup:
|
||||||
|
def head = Stub(Head)
|
||||||
|
when:
|
||||||
|
def act = callSelector.getMatcher("eth_call", '["0x0000", {"blockNumber": "0x100"}]', head)
|
||||||
|
then:
|
||||||
|
act == new Selector.HeightMatcher(0x100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user