def mongo(contractAddress, block):
Block_Address = pymongo.MongoClient(connection_Url).get_database('Holders').Block_Address
if Block_Address.find_one({'contractAddress': contractAddress}) == None:
Block_Address.insert_one({
'contractAddress': contractAddress,
'Block': block
})
@ray.remote
def contract(_block):
web3 = Web3(Web3.WebsocketProvider(infuraURL))
for i in range(len(web3.eth.get_block(_block).transactions)):
address = web3.eth.getTransactionReceipt(web3.eth.get_block(_block).transactions[i].hex()).contractAddress
if address != None:
mongo(address, _block)
if __name__=="__main__":
ray.init(address='auto')
print('''This cluster consists of
{} nodes in total
{} CPU resources in total
'''.format(len(ray.nodes()), ray.cluster_resources()['CPU']))
web3 = Web3(Web3.WebsocketProvider(infura_url))
latestBlock = web3.eth.get_block('latest').number
del web3
del infura_url
ray.get([contract.remote(block) for block in reversed(range(latestBlock))])
I am not able to figure out why code is getting killed and sometime system gets hanged.
Could anyone provide some help