def _send_error_message(self, error_message): self.write_message( json.dumps({ "type": "error-message", "text": error_message })) log.error(error_message)
def find_keystore_file_path(cls, address, keystore_path): try: files = os.listdir(keystore_path) except OSError as ex: msg = "Unable to list the specified directory" log.error("OsError", msg=msg, path=keystore_path, ex=ex) return for f in files: full_path = keystore_path.joinpath(f) if full_path.is_file(): try: file_content = full_path.read_text() data = json.loads(file_content) if not isinstance(data, dict) or "address" not in data: # we expect a dict in specific format. # Anything else is not a keyfile raise KeyError(f"Invalid keystore file {full_path}") address_from_file = to_checksum_address( to_canonical_address(data["address"])) if address_from_file == address: return Path(full_path) except OSError as ex: msg = "Can not read account file (errno=%s)" % ex.errno log.warning(msg, path=full_path, ex=ex) except (json.JSONDecodeError, KeyError, UnicodeDecodeError) as ex: # Invalid file - skip if f.startswith("UTC--"): # Should be a valid account file - warn user msg = "Invalid account file" if isinstance(ex, json.decoder.JSONDecodeError): msg = "The account file is not valid JSON format" log.warning(msg, path=full_path, ex=ex)
def post(self, configuration_file_name): configuration_file = RaidenConfigurationFile.get_by_filename( configuration_file_name) account = configuration_file.account try_unlock(account) w3 = make_web3_provider( configuration_file.ethereum_client_rpc_endpoint, account) ex_currency_amt = json_decode(self.request.body) exchange = Exchange.get_by_name(ex_currency_amt["exchange"])(w3=w3) currency = Erc20Token.find_by_ticker(ex_currency_amt["currency"], configuration_file.network) token_amount = TokenAmount(ex_currency_amt["target_amount"], currency) try: exchange_costs = exchange.calculate_transaction_costs( token_amount, account) total_cost = exchange_costs["total"] self.render_json({ "exchange": exchange.name, "currency": currency.ticker, "target_amount": ex_currency_amt["target_amount"], "as_wei": total_cost.as_wei, "formatted": total_cost.formatted, "utc_seconds": int(time.time()), }) except ExchangeError as ex: log.error("There was an error preparing the exchange", exc_info=ex) self.set_status( status_code=409, reason=str(ex), )