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: JSONEncoder

Custom encoder to parse Web3 responses. By default Web3 returns responses as AttributeDict with binary values. Web3JsonEncoder thansforms it into the 0x... hex format.

default(o: Any) Union[Dict[Any, Any], HexStr]

Convert Web3 response to dict

web3cat.fetcher.utils.json_response(response: AttributeDict) str

Convert AttributeDict to 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.ContractFunction call

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