Merge pull request #35 from p2p-org/support_eth_uninstallFilter

Added support of eth_uninstallFilter
This commit is contained in:
MaxFomenkov
2022-11-14 14:30:11 +03:00
committed by GitHub
4 changed files with 42 additions and 3 deletions

View File

@@ -255,7 +255,10 @@ open class NativeCall(
} }
private fun getRequestDecorator(method: String): RequestDecorator = private fun getRequestDecorator(method: String): RequestDecorator =
if (method == "eth_getFilterChanges") GetFilterUpdatesDecorator() else NoneRequestDecorator() if (method == "eth_getFilterChanges" || method == "eth_uninstallFilter")
GetFilterUpdatesDecorator()
else
NoneRequestDecorator()
private fun getResultDecorator(method: String): ResultDecorator = private fun getResultDecorator(method: String): ResultDecorator =
if (CreateFilterDecorator.createFilterMethods.contains(method)) CreateFilterDecorator() else NoneResultDecorator() if (CreateFilterDecorator.createFilterMethods.contains(method)) CreateFilterDecorator() else NoneResultDecorator()
@@ -378,7 +381,11 @@ open class NativeCall(
companion object { companion object {
const val quoteCode = '"'.code.toByte() const val quoteCode = '"'.code.toByte()
val createFilterMethods = listOf("eth_getFilterChanges", "eth_newFilter", "eth_newBlockFilter") val createFilterMethods = listOf(
"eth_newFilter",
"eth_newBlockFilter",
"eth_newPendingTransactionFilter"
)
} }
override fun processResult(result: QuorumRpcReader.Result): ByteArray { override fun processResult(result: QuorumRpcReader.Result): ByteArray {
val bytes = result.value val bytes = result.value

View File

@@ -75,6 +75,7 @@ class DefaultEthereumMethods(
"eth_newFilter", "eth_newFilter",
"eth_newBlockFilter", "eth_newBlockFilter",
"eth_newPendingTransactionFilter", "eth_newPendingTransactionFilter",
"eth_uninstallFilter"
) )
private val allowedMethods = anyResponseMethods + firstValueMethods + specialMethods + headVerifiedMethods + filterMethods private val allowedMethods = anyResponseMethods + firstValueMethods + specialMethods + headVerifiedMethods + filterMethods

View File

@@ -57,7 +57,7 @@ class EthereumCallSelector(
return blockTagSelector(params, 1, head) return blockTagSelector(params, 1, head)
} else if (method == "eth_getStorageAt") { } else if (method == "eth_getStorageAt") {
return blockTagSelector(params, 2, head) return blockTagSelector(params, 2, head)
} else if (method == "eth_getFilterChanges") { } else if (method == "eth_getFilterChanges" || method == "eth_uninstallFilter") {
return sameUpstreamMatcher(params) return sameUpstreamMatcher(params)
} }
return Mono.empty() return Mono.empty()

View File

@@ -457,6 +457,37 @@ class NativeCallSpec extends Specification {
act.requestDecorator instanceof NativeCall.GetFilterUpdatesDecorator act.requestDecorator instanceof NativeCall.GetFilterUpdatesDecorator
} }
def "Prepare call adds decorator for eth_uninstallFilter"() {
setup:
def methods = new ManagedCallMethods(
new DefaultEthereumMethods(Chain.ETHEREUM),
["eth_uninstallFilter"] as Set, [] as Set
)
methods.setQuorum("eth_uninstallFilter", "always")
def multistream = new MultistreamHolderMock.EthereumMultistreamMock(Chain.ETHEREUM, TestingCommons.upstream())
multistream.customMethods = methods
multistream.customHead = Mock(Head)
def multistreamHolder = Mock(MultistreamHolder) {
_ * it.observeChains() >> Flux.empty()
}
def nativeCall = nativeCall(multistreamHolder)
def req = BlockchainOuterClass.NativeCallRequest.newBuilder()
.setChain(Common.ChainRef.CHAIN_ETHEREUM)
.addItems(
BlockchainOuterClass.NativeCallItem.newBuilder()
.setId(1)
.setMethod("eth_uninstallFilter")
)
.build()
when:
def act = nativeCall.prepareCall(req, multistream)
.collectList().block(Duration.ofSeconds(1)).first()
then:
act instanceof NativeCall.ValidCallContext
act.requestDecorator instanceof NativeCall.GetFilterUpdatesDecorator
}
def "Parse empty params"() { def "Parse empty params"() {
setup: setup:
def nativeCall = nativeCall() def nativeCall = nativeCall()