Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Filtering for eth_getLogs #120

Merged
merged 3 commits into from
Oct 8, 2019
Merged

Filtering for eth_getLogs #120

merged 3 commits into from
Oct 8, 2019

Conversation

dutterbutter
Copy link

@dutterbutter dutterbutter commented Oct 6, 2019

Changes made in this PR:

  • Added PublicFilterAPI
  • Added Logs query in querier.go
  • Added filterLogs, UnmarshalJSON funcs from go-ethereum
  • Added helper funcs

To Test:

make install 
rm -rf ~/.emint*
emintd init moniker --chain-id 3
emintcli config chain-id 3
emintcli config output json
emintcli config indent true
emintcli config trust-node true
emintcli keys add dustin
testpass
testpass
emintcli emintkeys add dustineth
testpass
testpass
emintd add-genesis-account $(emintcli keys show dustin -a) 1000photon,100000000stake
emintd add-genesis-account $(emintcli emintkeys show dustineth -a) 100000000photon,100000000stake
emintd gentx --name dustin
testpass
emintd collect-gentxs
emintd validate-genesis
emintd start --pruning=nothing --rpc.unsafe --log_level "main:info,state:info,mempool:i

Start server with unlocked key to send tx:

emintcli rest-server --laddr "tcp://localhost:8545" --unlock-key dustineth

Deploy Contract and Emit Events:

While ethermint node is running:

git clone git@github.com:ChainSafe/ethermint-scripts.git
cd web3
node test_contract.js

Get logs with a range of blocks

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock":"0x7", "toBlock: "0x9"}],"id":6}' -H "Content-Type: application/json" http://localhost:8545/rpc

Get logs with address criteria (this can also take an array of addresses)

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"address":"<contract_address"}],"id":6}' -H "Content-Type: application/json" http://localhost:8545/rpc

Remaining todos for logs:

  • Need to set blockHash in Prepare func prior to log entry (will also then enable filtering by blockHash
  • Subscribing to event logs
  • Using the bloom filter to optimize log querying
  • additional filter rpc calls

* addded PublicFilterAPI
* added filter logs func to filter based on params
* added Unmarshal func from go-ethereum
@dutterbutter dutterbutter changed the title Filtering for eth_getLogs Filtering for eth_getLogs Oct 6, 2019
rpc/filter_api.go Outdated Show resolved Hide resolved
end = criteria.ToBlock.Int64()
}
to := big.NewInt(end)
results := e.getLogs()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be beneficial to include the range filter on the type you created to abstract this logic so you aren't doing it duplicate times?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate on what you mean from the above?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just replicating the e.getLogs and filterLogs calls, can't the filter just be generated in this if/ else then call these equivalently outside of it for consistency?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need some clarity here.... e.getLogs is the actual call to retrieve the logs whereas filterLogs does the filtering. We want to keep this functionality separate when we introduce bloom filters so that we only call filterLogs on the logs that may meet the filter criteria which will be indicated by the bloom filter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be more specific, I just mean having the functionality to create a range filter like you do with NewBlockFilter() then get logs and filter them below this conditional (let me know what you think of this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem I have is that you are handling block filters and range filters asymmetrically, which is somewhat hard to follow. Also small thing with this is that it adds a linting issue with returning both in the coniditonal (that doesn't matter as much)

rpc/filter_api.go Outdated Show resolved Hide resolved
rpc/filters.go Show resolved Hide resolved
Copy link

@austinabell austinabell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

@dutterbutter dutterbutter merged commit a61f3b8 into development Oct 8, 2019
@dutterbutter dutterbutter deleted the dustin/filtered-logs branch October 8, 2019 03:32
@amerameen amerameen mentioned this pull request Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants