Click Components#

The core click components are built to provide required functionality to the Click library which is used for creating commands.

BlockChainParamType#

A click param type to validate and transform the input name for a blockchain and provide a blockcrawler.core.entities.BlockChain value.

Example:

@click.argument("BLOCKCHAIN", type=BlockChainParamType())

HexIntParamType#

A click param type to validate and transform the input hex or int and provide a blockcrawler.core.types.HexInt value.

Example:

@click.argument("HEX_INT", type=HexIntParamType())

AddressParamType#

A click param type to validate and transform the input hex for a blockchain address and provide a blockcrawler.core.entities.Address value.

Example:

@click.argument("ADDRESS", type=AddressParamType())

HexBytesParamType#

A click param type to validate and transform the input hex and provide a hexbytes.HexBytes value.

Example:

@click.argument("HEX_BYTES", type=HexBytesParamType())

Complete Simple Example#

import click
from hexbytes import HexBytes

from blockcrawler.core.click import (
    BlockChainParamType,
    HexIntParamType,
    AddressParamType,
    HexBytesParamType,
)
from blockcrawler.core.entities import BlockChain
from blockcrawler.core.types import HexInt, Address


@click.command()
@click.argument("BLOCKCHAIN", type=BlockChainParamType())
@click.argument("HEX_INT", type=HexIntParamType())
@click.argument("ADDRESS", type=AddressParamType())
@click.argument("HEX_BYTES", type=HexBytesParamType())
def run(blockchain: BlockChain, hex_int: HexInt, address: Address, hex_bytes: HexBytes):
    print("blockchain:", blockchain)
    print("hex_int:", hex_int)
    print("address:", address)
    print("hex_bytes:", hex_bytes)


if __name__ == "__main__":
    run()

Executing the above example will result in something similar to the following being displayed in the console:

blockchain: BlockChain.ETHEREUM_MAINNET
hex_int: 0x1
address: 0x7581871e1c11f85ec7f02382632b8574fad11b22
hex_bytes: b’}x00x15Ux97&x13xbfxd9x14x86x12U/6x05xa1&~xdexe3xe0\xee`x91xd1x19]x93x01E’

Download the example and try it yourself.