fetcher.utils
Utility functions.
- class web3cat.fetcher.utils.Web3JsonEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
JSONEncoderCustom encoder to parse Web3 responses. By default Web3 returns responses as
AttributeDictwith binary values.Web3JsonEncoderthansforms it into the0x...hex format.
- web3cat.fetcher.utils.json_response(response: AttributeDict) str
Convert
AttributeDictto standard json string- Parameters:
response –
a Web3 response
- Returns:
json string
- web3cat.fetcher.utils.short_address(address: str) str
Converts ethereum address to short version (for display purposes only).
- Parameters:
address – Ethereum address to shorten
- Returns:
Short version of the address.
Examples
print(short_address("0x6B175474E89094C44Da98b954EedeAC495271d0F")) # 0x6B17...1d0F
- web3cat.fetcher.utils.calldata(call: ContractFunction) str
Hex calldata for
web3.contract.ContractFunctioncall- Parameters:
call – A web3 call
- Returns:
Hex data (starting with 0x, lowercase)
- web3cat.fetcher.utils.print_progress(iteration: int, total: int, prefix: str = '', suffix: str = '', decimals: int = 1, bar_length: int = 20) int
Call in a loop to create terminal progress bar.
- Parameters:
iteration – current iteration
total – total iterations
prefix – prefix string
suffix – suffix string
decimals – positive number of decimals in percent complete
bar_length – character length of bar