Skip to content

Commit 8c05226

Browse files
anvacaruehildenb
authored andcommitted
Implement RPC filter methods (#452)
* web3.md : wip filters * web3.md: wip eth_newBlockFilter * web3.md: added eth_newBlockFilter and eth_uninstallFilter * added tests for eth_newBlockFilter and eth_uninstallFilter * wip * web3: formatting, error messages * web3.md: add owise case for eth_uninstallFilter
1 parent d938b30 commit 8c05226

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

tests/web3/eth_newBlockFilter.in.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":1},
2+
{"jsonrpc":"2.0", "method":"eth_newBlockFilter", "params":[], "id":2},
3+
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x0"], "id":3},
4+
{"jsonrpc":"2.0", "method":"eth_uninstallFilter", "params":["0x1"], "id":4}]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"jsonrpc":"2.0","id":1,"result":"0x0"},{"jsonrpc":"2.0","id":2,"result":"0x1"},{"jsonrpc":"2.0","id":3,"result":"true"},{"jsonrpc":"2.0","id":4,"result":"true"}]

web3.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ module WEB3
1616
<chainID> $CHAINID:Int </chainID>
1717
</blockchain>
1818
<accountKeys> .Map </accountKeys>
19+
<nextFilterSlot> 0 </nextFilterSlot>
20+
<filters>
21+
<filter multiplicity="*" type="Map">
22+
<filterID> 0 </filterID>
23+
<fromBlock> 0 </fromBlock>
24+
<toBlock> 0 </toBlock>
25+
<address> 0 </address>
26+
<topics> .List </topics>
27+
</filter>
28+
</filters>
1929
<snapshots> .List </snapshots>
2030
<web3socket> $SOCK:Int </web3socket>
2131
<web3shutdownable> $SHUTDOWNABLE:Bool </web3shutdownable>
@@ -177,6 +187,10 @@ module WEB3
177187
<method> "evm_revert" </method>
178188
rule <k> #runRPCCall => #evm_increaseTime ... </k>
179189
<method> "evm_increaseTime" </method>
190+
rule <k> #runRPCCall => #eth_newBlockFilter ... </k>
191+
<method> "eth_newBlockFilter" </method>
192+
rule <k> #runRPCCall => #eth_uninstallFilter ... </k>
193+
<method> "eth_uninstallFilter" </method>
180194
181195
rule <k> #runRPCCall => #sendResponse( "error": {"code": -32601, "message": "Method not found"} ) ... </k> [owise]
182196
@@ -308,5 +322,41 @@ module WEB3
308322
rule <k> #evm_increaseTime => #sendResponse( "result" : Int2String(TS +Int DATA ) ) ... </k>
309323
<params> [ DATA:Int, .JSONList ] </params>
310324
<timestamp> ( TS:Int => ( TS +Int DATA ) ) </timestamp>
325+
326+
syntax KItem ::= "#eth_newBlockFilter"
327+
// --------------------------------------
328+
rule <k> #eth_newBlockFilter => #sendResponse ( "result": #unparseQuantity( FILTID )) ... </k>
329+
<filters>
330+
( .Bag
331+
=> <filter>
332+
<filterID> FILTID </filterID>
333+
<fromBlock> BLOCKNUM </fromBlock>
334+
...
335+
</filter>
336+
)
337+
...
338+
</filters>
339+
<number> BLOCKNUM </number>
340+
<nextFilterSlot> ( FILTID:Int => FILTID +Int 1 ) </nextFilterSlot>
341+
342+
syntax KItem ::= "#eth_uninstallFilter"
343+
// ---------------------------------------
344+
rule <k> #eth_uninstallFilter ... </k>
345+
<params> [ (DATA => #parseHexWord(DATA)), .JSONList ] </params>
346+
347+
rule <k> #eth_uninstallFilter => #sendResponse ( "result": "true" ) ... </k>
348+
<params> [ FILTID, .JSONList ] </params>
349+
<filters>
350+
( <filter>
351+
<filterID> FILTID </filterID>
352+
...
353+
</filter>
354+
=> .Bag
355+
)
356+
...
357+
</filters>
358+
359+
rule <k> #eth_uninstallFilter => #sendResponse ( "result": false ) ... </k> [owise]
360+
311361
endmodule
312362
```

0 commit comments

Comments
 (0)