diff --git a/aioetherscan/__init__.py b/aioetherscan/__init__.py new file mode 100644 index 0000000..6ea21d0 --- /dev/null +++ b/aioetherscan/__init__.py @@ -0,0 +1,4 @@ +# coding:utf-8 +from .aioetherscan import * + +name = 'aioetherscan' diff --git a/etherscan/etherscan.py b/aioetherscan/aioetherscan.py similarity index 81% rename from etherscan/etherscan.py rename to aioetherscan/aioetherscan.py index 643baed..3dac38d 100644 --- a/etherscan/etherscan.py +++ b/aioetherscan/aioetherscan.py @@ -45,22 +45,22 @@ def __init__( @property def _cache_type_factory(self): - payload = { + data = { 'cache_name': self._cache_name, 'expire_after': self._cache_expire_after } if self._cache_backend == 'CacheBackend': - return aiohttp_client_cache.CacheBackend(**payload) + return aiohttp_client_cache.CacheBackend(**data) elif self._cache_backend == 'DynamoDBBackend': - return aiohttp_client_cache.DynamoDBBackend(**payload) + return aiohttp_client_cache.DynamoDBBackend(**data) elif self._cache_backend == 'FileBackend': - return aiohttp_client_cache.FileBackend(**payload) + return aiohttp_client_cache.FileBackend(**data) elif self._cache_backend == 'MongoDBBackend': - return aiohttp_client_cache.MongoDBBackend(**payload) + return aiohttp_client_cache.MongoDBBackend(**data) elif self._cache_backend == 'RedisBackend': - return aiohttp_client_cache.RedisBackend(**payload) + return aiohttp_client_cache.RedisBackend(**data) elif self._cache_backend == 'SQLiteBackend': - return aiohttp_client_cache.SQLiteBackend(**payload) + return aiohttp_client_cache.SQLiteBackend(**data) else: return aiohttp_client_cache.CacheBackend(self._cache_name or 'demo_cache') @@ -70,11 +70,10 @@ def session(self): self._session = aiohttp_client_cache.CachedSession( cache=self._cache_type_factory ) - self._session.headers.update( { - 'User-agent': 'etherscan - python wrapper ' - 'around etherscan.io (github.com/neoctobers/etherscan)' + 'User-agent': 'aioetherscan - python wrapper ' + 'around etherscan.io (github.com/viacheslav-sabadash/aioetherscan)' } ) @@ -137,28 +136,29 @@ async def get_eth_price(self): 'ethusd_timestamp': int(r['ethbtc_timestamp']), } - def get_eth_supply(self): + async def get_eth_supply(self): self._params['module'] = 'stats' self._params['action'] = 'ethsupply' - return int(self.__req()) + return int(await self.__req()) - def get_eth_balance(self, address: str): + async def get_eth_balance(self, address: str): """Get ETH balance by address.""" self._params['module'] = 'account' self._params['action'] = 'balance' self._params['address'] = address - return int(self.__req()) + return int(await self.__req()) - def get_eth_balances(self, addresses: list): + async def get_eth_balances(self, addresses: list): """Get ETH balances by addresses list.""" self._params['module'] = 'account' self._params['action'] = 'balancemulti' self._params['address'] = ','.join(addresses) balances = {} - for row in self.__req(): + rs = await self.__req() + for row in rs: balances[row['account']] = int(row['balance']) return balances @@ -190,15 +190,16 @@ def __transaction(self, source: dict): 'block_hash': self.__str(source['blockHash']), } - def get_transactions_by_address(self, - address: str, - type: str = 'normal', - start_block: int = 0, - end_block: int = 999999999, - page: int = 1, - limit: int = 1000, - sort: str = 'asc', - ): + async def get_transactions_by_address( + self, + address: str, + type: str = 'normal', + start_block: int = 0, + end_block: int = 999999999, + page: int = 1, + limit: int = 1000, + sort: str = 'asc', + ): """Get transactions by address.""" self._params['module'] = 'account' @@ -216,7 +217,7 @@ def get_transactions_by_address(self, self._params['offset'] = limit self._params['sort'] = sort - rs = self.__req() + rs = await self.__req() transactions = [] for t in rs: @@ -252,15 +253,16 @@ def __token_transaction(self, source: dict): 'block_hash': self.__str(source['blockHash']), } - def get_token_transactions(self, - contract_address: str = None, - address: str = None, - start_block: int = 0, - end_block: int = 999999999, - page: int = 1, - limit: int = 1000, - sort: str = 'asc', - ): + async def get_token_transactions( + self, + contract_address: str = None, + address: str = None, + start_block: int = 0, + end_block: int = 999999999, + page: int = 1, + limit: int = 1000, + sort: str = 'asc', + ): """Get ERC20 token transactions by contract address.""" if contract_address is None and address is None: raise EtherscanIoException('Param `contract_address` and `address` cannot be None at the same time.') @@ -280,7 +282,7 @@ def get_token_transactions(self, self._params['offset'] = limit self._params['sort'] = sort - rs = self.__req() + rs = await self.__req() token_transactions = [] for t in rs: @@ -288,22 +290,22 @@ def get_token_transactions(self, return token_transactions - def get_gas_price(self): + async def get_gas_price(self): """Get gas price.""" self._params['action'] = 'eth_gasPrice' - return int(self.__proxy_req(), 16) + return int(await self.__proxy_req(), 16) - def get_block_number(self): + async def get_block_number(self): """Get latest block number.""" self._params['action'] = 'eth_blockNumber' - return int(self.__proxy_req(), 16) + return int(await self.__proxy_req(), 16) - def get_block_by_number(self, block_number): + async def get_block_by_number(self, block_number): """Get block by number.""" self._params['action'] = 'eth_getBlockByNumber' self._params['tag'] = hex(block_number) self._params['boolean'] = True - return self.__proxy_req() + return await self.__proxy_req() diff --git a/etherscan/errors.py b/aioetherscan/errors.py similarity index 100% rename from etherscan/errors.py rename to aioetherscan/errors.py diff --git a/docs/conf.py b/docs/conf.py index fe09354..aa70d8a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,9 +23,9 @@ # -- Project information ----------------------------------------------------- -project = 'etherscan' -copyright = '2018, neoctobers' -author = 'neoctobers' +project = 'aioetherscan' +copyright = '2021, neoctobers' +author = 'neoctobers, viacheslav-sabadash' # The short X.Y version version = '' @@ -106,7 +106,7 @@ # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = 'etherscandoc' +htmlhelp_basename = 'aioetherscandoc' # -- Options for LaTeX output ------------------------------------------------ @@ -133,8 +133,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'etherscan.tex', 'etherscan Documentation', - 'neoctobers', 'manual'), + (master_doc, 'aioetherscan.tex', 'aioetherscan Documentation', + 'viacheslav-sabadash', 'manual'), ] @@ -143,7 +143,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'etherscan', 'etherscan Documentation', + (master_doc, 'aioetherscan', 'aioetherscan Documentation', [author], 1) ] @@ -154,8 +154,8 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'etherscan', 'etherscan Documentation', - author, 'etherscan', 'One line description of project.', + (master_doc, 'aioetherscan', 'aioetherscan Documentation', + author, 'aioetherscan', 'One line description of project.', 'Miscellaneous'), ] diff --git a/etherscan/__init__.py b/etherscan/__init__.py deleted file mode 100644 index 0989267..0000000 --- a/etherscan/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# coding:utf-8 -from .etherscan import * - -name = 'etherscan'