def handle(self, *args, **options): w3 = get_web3() chain = Chain.make(chain_id=int(w3.net.version)) EthereumToken.ETH(chain=chain) erc20_token_addresses = [ to_checksum_address(t) for t in TRACKED_TOKENS if t != EthereumToken.NULL_ADDRESS ] for token_address in erc20_token_addresses: logger.info(f"Checking token {token_address}...") try: token_data = get_token_information(w3=w3, address=token_address) EthereumToken.make(address=token_address, chain=chain, **token_data) except OverflowError: logger.error( f"{token_address} is not a valid address or not ERC20-compliant" ) except Exception as exc: logger.exception( f"Failed to load token data for {token_address}", exc_info=exc)
def process_events(token_network: TokenNetwork, event_filter): w3 = get_web3() try: for event in event_filter.get_all_entries(): logger.info( f"Processing event {event.event} at {event.transactionHash.hex()}" ) block = get_block_by_hash(w3, event.blockHash) tx = get_transaction_by_hash(w3, event.transactionHash, block) if not tx: logger.warning( f"Transaction {event.transactionHash} could not be synced") channel = _get_channel_from_event(token_network, event) if channel: token_network.events.get_or_create(channel=channel, transaction=tx, name=event.event) else: logger.warning( f"Failed to find channel related to event {event}") except TimeoutError: logger.error(f"Timed-out while getting events for {token_network}") except Exception as exc: logger.error(f"Failed to get events for {token_network}: {exc}")
def handle(self, *args, **options): w3 = get_web3() chain_id = int(w3.net.version) txs = options["transactions"] already_recorded = Transaction.objects.filter( hash__in=txs).values_list("hash", flat=True) if already_recorded: logger.info( f"Transactions {', '.join(already_recorded)} already recorded") to_record = set(txs) - set(already_recorded) for tx_hash in to_record: try: tx_data = w3.eth.getTransaction(tx_hash) tx_receipt = w3.eth.getTransactionReceipt(tx_hash) block_data = w3.eth.getBlock(tx_data.blockHash) block = Block.make(block_data, chain_id) Transaction.make(tx_data, tx_receipt, block) except binascii.Error: logger.info(f"{tx_hash} is not a valid transaction hash") except TransactionNotFound: logger.info(f"{tx_hash} not found")
def handle(self, *args, **options): w3 = get_web3() loop = asyncio.get_event_loop() try: loop.run_until_complete(download_all_chain(w3)) finally: loop.close()
def handle(self, *args, **options): w3 = get_web3() loop = asyncio.get_event_loop() add_shutdown_handlers(loop) try: asyncio.gather(*(download_all_account_transactions(w3), )) loop.run_forever() finally: loop.close()
def handle(self, *args, **options): w3 = get_web3() while True: for raiden in models.Raiden.objects.all(): client = RaidenClient(raiden) try: sync_token_networks(client, w3) sync_channels(client) sync_payments(client) except RaidenConnectionError as exc: logger.warn(str(exc)) time.sleep(5) except Exception as exc: logger.exception(exc) time.sleep(3)
def sync_token_network_events(): w3 = get_web3() for token_network in TokenNetwork.objects.all(): token_network_contract = token_network.get_contract(w3=w3) event_blocks = Block.objects.filter( transaction__tokennetworkchannelevent__channel__token_network= token_network) from_block = Block.get_latest_block_number(event_blocks) + 1 logger.info( f"Fetching {token_network.token} events since block {from_block}") channel_open_filter = token_network_contract.events.ChannelOpened.createFilter( fromBlock=from_block) channel_closed_filter = token_network_contract.events.ChannelClosed.createFilter( fromBlock=from_block) process_events(token_network, channel_open_filter) process_events(token_network, channel_closed_filter)
def setUp(self): self.checkout = CheckoutFactory() self.token = self.checkout.currency self.w3 = get_web3() self.block_filter = Mock()