second-state/smart-contract-search-engine

Allow for destructed contracts

tpmccallum opened this issue · 3 comments

Show only the last known state of a contract, which has since been destructed.
Display a flag which shows that the contract has been destructed.

We will also need to write a separate process for updating the "yes"/"no" values in the "requiresUpdating" field.

The harvest.py maintains a list of contract addresses (which have ABIs and can therefore have their state updated in real-time). When run in the -m state mode the harvest.py file can compare the list of fresh contract addresses (which have ABIs) with the previous round's cached list. If a new contract has been added since the last round then the harvest.py file creates only one new web3 contract instance (as apposed to starting all over and creating all new web3 contract instances). Here is the code.

 
origListOfAddresses = []
for originalItem in originalListOfAddressesAndAbi:
    if originalItem['contractAddress'] not in origListOfAddresses:
        origListOfAddresses.append(originalItem['contractAddress'])
self.fetchContractAddressesWithAbis()
for newItem in self.esAbiAddresses:
    if newItem['contractAddress'] not in origListOfAddresses:
        print("Found a new contract " + newItem['contractAddress'] + ", creating a new web3 instance")
        self.fetchContractInstances(newItem['abiSha3'], newItem['contractAddress'])

If a contract is destructed it will still show up the self.esAbiAddresses (which is updated every block). All we need to do to stop the state updating is to add an additional condition to the function that populates the self.esAbiAddresses. The current function is called fetchContractAddressesWithAbis it produces the following query which we will need to modify slightly; to account for the requiresUpdating field.

{'query': {'bool': {'must_not': [{'exists': {'field': 'byteSha3'}}], 'should': [{'wildcard': {'abiSha3': '0x*'}}]}}, '_source': ['contractAddress', 'abiSha3']}

Obviously another separate process with awareness of the contract's destruction will still be required to set the requiresUpdating field in the first place.