Skip to content

Instantly share code, notes, and snippets.

@xwh16
Created April 10, 2018 02:49
Show Gist options
  • Save xwh16/9cc27ad596af471064182730b6d245c1 to your computer and use it in GitHub Desktop.
Save xwh16/9cc27ad596af471064182730b6d245c1 to your computer and use it in GitHub Desktop.
code snippet to test ethereum filters
pragma solidity ^0.4.0;
contract Cui6 {
event signal(uint indexed num);
function testSignal() public {
for (uint i=0; i<10; i++) {
signal(i);
}
}
}
import web3
from eth_abi import encode_single
from eth_utils import keccak
w3 = web3.Web3(web3.HTTPProvider("http://127.0.0.1:7545"))
getABI = lambda num: '0x'+encode_single('uint', num).hex()
topic = [getABI(num) for num in range(0, 50)]
filter = w3.eth.filter({"fromBlock":0, "toBlock":'latest', "topics":["0x"+keccak(b"signal(uint256)").hex(),topic]})
filter.get_all_entries()
while True:
import time
print(filter.get_new_entries())
time.sleep(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment