Created
April 10, 2018 02:49
-
-
Save xwh16/9cc27ad596af471064182730b6d245c1 to your computer and use it in GitHub Desktop.
code snippet to test ethereum filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract Cui6 { | |
event signal(uint indexed num); | |
function testSignal() public { | |
for (uint i=0; i<10; i++) { | |
signal(i); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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