rpc: event websocket subscription (#308)

* rpc: event websocket subscription

* rpc: use tendermint event subscriptions

* new log events

* filter evm transactions

* filter logs

* wip: refactor filters

* remove custom BlockNumber

* wip: refactor rpc

* HeaderByNumber and HeaderByHash

* update Tendermint event system

* update Filter

* update EventSystem

* fix lint issues

* update rpc filters

* upgrade to tendermint v0.33.4

* update filters

* fix unsubscription

* updates wip

* initialize channels

* cleanup go routines

* pass ResultEvent channel on subscription

* error channel

* add block filter changes test

* add eventCh loop

* pass funcs in select go func, block filter working

* cleanup

* lint

* NewFilter and GetFilterChanges working

* eth_getLogs working

* lint

* lint

* cleanup

* remove logs and minor fixes

* changelog

* address @noot comments

* revert BlockNumber removal

Co-authored-by: noot <elizabethjbinks@gmail.com>
This commit is contained in:
Federico Kunze
2020-07-03 11:40:00 -04:00
committed by GitHub
co-authored by noot
parent c8b8f49675
commit 20e9b2ede3
12 changed files with 1304 additions and 334 deletions
+18 -6
View File
@@ -276,6 +276,22 @@ func TestEth_NewBlockFilter(t *testing.T) {
require.NoError(t, err)
}
func TestEth_GetFilterChanges_BlockFilter(t *testing.T) {
rpcRes := call(t, "eth_newBlockFilter", []string{})
var ID hexutil.Bytes
err := json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err)
time.Sleep(5 * time.Second)
changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
var hashes []ethcmn.Hash
err = json.Unmarshal(changesRes.Result, &hashes)
require.NoError(t, err)
require.GreaterOrEqual(t, len(hashes), 1)
}
func TestEth_GetFilterChanges_NoLogs(t *testing.T) {
param := make([]map[string][]string, 1)
param[0] = make(map[string][]string)
@@ -286,6 +302,8 @@ func TestEth_GetFilterChanges_NoLogs(t *testing.T) {
err := json.Unmarshal(rpcRes.Result, &ID)
require.NoError(t, err)
t.Log(ID.String())
changesRes := call(t, "eth_getFilterChanges", []string{ID.String()})
var logs []*ethtypes.Log
@@ -419,7 +437,6 @@ func TestEth_GetTransactionLogs(t *testing.T) {
logs := new([]*ethtypes.Log)
err := json.Unmarshal(rpcRes.Result, logs)
require.NoError(t, err)
require.Equal(t, 1, len(*logs))
}
@@ -434,7 +451,6 @@ func TestEth_GetFilterChanges_NoTopics(t *testing.T) {
param[0] = make(map[string]interface{})
param[0]["topics"] = []string{}
param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest
// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
@@ -526,7 +542,6 @@ func TestEth_GetFilterChanges_Topics_AB(t *testing.T) {
param[0] = make(map[string]interface{})
param[0]["topics"] = []string{helloTopic, worldTopic}
param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest
// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
@@ -557,7 +572,6 @@ func TestEth_GetFilterChanges_Topics_XB(t *testing.T) {
param[0] = make(map[string]interface{})
param[0]["topics"] = []interface{}{nil, worldTopic}
param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = "0x0" // latest
// instantiate new filter
rpcRes = call(t, "eth_newFilter", param)
@@ -600,7 +614,6 @@ func TestEth_GetLogs_Topics_AB(t *testing.T) {
param[0] = make(map[string]interface{})
param[0]["topics"] = []string{helloTopic, worldTopic}
param[0]["fromBlock"] = res.String()
param[0]["toBlock"] = zeroString // latest
hash := deployTestContractWithFunction(t)
waitForReceipt(t, hash)
@@ -637,7 +650,6 @@ func TestEth_PendingTransactionFilter(t *testing.T) {
require.NoError(t, err, string(changesRes.Result))
require.True(t, len(txs) >= 2, "could not get any txs", "changesRes.Result", string(changesRes.Result))
}
func TestBlockBloom(t *testing.T) {