�
R\�h� � �| � d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ ej e
� � Z G d� d� � ZdS )� N)�Web3)�Account)�TransactionNotFoundc �f � e Zd ZdZd� Zd� Zd� Zdd�Zdd
�Zd� Z d� Z
d
� Zd� Zd� Z
dd�Zd� Zd� ZdS )�EthereumClientzEthereum blockchain clientc �. � t j dd� � | _ t t j | j � � � � | _ | j � � � st � d� � d S t � d� � d S )N�ETHEREUM_RPC_URLzhttps://cloudflare-eth.comz%Failed to connect to Ethereum networkzConnected to Ethereum network)
�os�getenv�rpc_urlr �HTTPProvider�w3�is_connected�logger�error�info)�selfs �-/home/runner/workspace/blockchain/ethereum.py�__init__zEthereumClient.__init__
s} � ��y�!3�5Q�R�R����t�(���6�6�7�7��� �w�#�#�%�%� 9��L�L�@�A�A�A�A�A��K�K�7�8�8�8�8�8� c � � | j j � |� � }| j � |d� � }t |� � S # t
$ r8}t � d|� dt |� � � �� � Y d}~dS d}~ww xY w)zGet ETH balance for address�etherzFailed to get balance for z: N�0)r �eth�get_balance�from_wei�str� Exceptionr r )r �address�balance_wei�balance_eth�es r r zEthereumClient.get_balance s� � � ��'�+�1�1�'�:�:�K��'�*�*�;��@�@�K��{�#�#�#��� � � ��L�L�I�g�I�I��Q���I�I�J�J�J��3�3�3�3�3����� ���s �AA �
B
�-B�B
c �� � dddd�gdddd�gdd �dg d
ddd�gdd �g}| j j � ||�
� � }|j � |� � � � � }|j � � � � � � }|d|z z }t |� � S # t $ r5}t �
dt |� � � �� � Y d}~dS d}~ww xY w)zGet ERC20 token balanceT�_ownerr )�name�type� balanceOf�balance�uint256�function)�constant�inputsr% �outputsr&