def _update(self): if self._credstick: self._wei_balance = self._w3.eth.getBalance(self._credstick.addressStr()) # Trying to catch a wily web3.py bug. # Sometimes when using the websockets middleware, # strange responses start coming back. if self._wei_balance.__class__ != int: logging.debug("w3.eth.getBalance returned something other than an int! = {}".format(self._wei_balance)) self._erc20_balances = Erc20.balances(self, self.credstick.address) if self._network == '1': try: self._ens_domain = self.ens.name(self._credstick.addressStr()) self._eth_usd = self.w3.fromWei(self._sai_pip.eth_price(), 'ether') except BadFunctionCallOutput: self._ens_domain = 'Unknown' else: self._ens_domain = 'Unknown' self._best_block = str(self._w3.eth.blockNumber) self._syncing = self._w3.eth.syncing if self._syncing not in (None, False): self._blocks_behind = self._syncing['highestBlock'] - self._syncing['currentBlock'] else: self._blocks_behind = None
def _update(self): w3 = self.w3_getter() # semaphore only allows one thread to wait on update self.update_sem.acquire(blocking=False) with self.update_lock: if self.credstick: self._wei_balance = w3.eth.getBalance( self.credstick.addressStr()) self.erc20_balances = Erc20.balances(self, self.credstick.address) if self.network == '1': try: self.ens = ENS.fromWeb3(_w3) self._ens_domain = self.ens.name( self.credstick.addressStr()) self.eth_price = w3.fromWei(self._sai_pip.eth_price(), 'ether') except BadFunctionCallOutput: self._ens_domain = 'Unknown' else: self._ens_domain = 'Unknown' #self.best_block = str(self.w3.eth.blockNumber) self.best_block = str(w3.eth.blockNumber) self.syncing_hash = w3.eth.syncing if self.syncing_hash not in (None, False): self.blocks_behind = self.syncing_hash[ 'highestBlock'] - self.syncing_hash['currentBlock'] else: self.blocks_behind = None self.update_sem.release()