Пример #1
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    network, node = get_network_node(args)
    block = chain.get_block(network, node, args.block_hash)

    if block:
        print(json.dumps(block, indent=4))
    else:
        print("Chain query returned null - is the block hash correct ?")
Пример #2
0
def _process_block(ctx: _Context):
    """Processes a finalised block.
    
    """
    # Escape if block not found.
    try:
        ctx.on_chain_block = chain.get_block(ctx.network, ctx.node,
                                             ctx.block_hash)
    except Exception as err:
        log_event(EventType.CHAIN_QUERY_BLOCK_NOT_FOUND, None, ctx.block_hash)
        return

    # Escape if block empty.
    if not ctx.deploy_hashes and not ctx.transfer_hashes:
        log_event(EventType.CHAIN_ADDED_BLOCK_EMPTY, None, ctx.block_hash)
        return

    # Set stats.
    ctx.block = factory.create_block_statistics_on_addition(
        block_hash=ctx.block_hash,
        block_hash_parent=ctx.on_chain_block['header']['parent_hash'],
        chain_name=ctx.network.chain_name,
        era_id=ctx.on_chain_block['header']['era_id'],
        deploy_cost_total=None,
        deploy_count=len(ctx.deploy_hashes) + len(ctx.transfer_hashes),
        deploy_gas_price_avg=None,
        height=ctx.on_chain_block['header']['height'],
        is_switch_block=ctx.on_chain_block['header']['era_end'] is not None,
        network=ctx.network.name,
        proposer=ctx.on_chain_block['header']['proposer'],
        size_bytes=None,
        state_root_hash=ctx.on_chain_block['header']['state_root_hash'],
        status=BlockStatus.FINALIZED.name,
        timestamp=datetime.strptime(ctx.on_chain_block['header']['timestamp'],
                                    "%Y-%m-%dT%H:%M:%S.%fZ"),
    )

    # Emit event.
    log_event(EventType.CHAIN_ADDED_BLOCK, f"{ctx.block_hash}", ctx.block)

    # Process associated deploys + transfers.
    _process_block_deploys(ctx)
Пример #3
0
def main(args):
    """Entry point.

    :param args: Parsed CLI arguments.

    """
    if args.node:
        network, node = get_network_node(args)
        nodeset = [node]
    else:
        network, nodeset = get_network_nodeset(args)

    for node in nodeset:
        try:
            block = chain.get_block(network, node)
        except:
            utils.log(f"ERA::HEIGHT @ {node.address_rpc} = N/A")
        else:
            utils.log(
                f"ERA:HEIGHT @ {node.address_rpc} = {block['header']['era_id']}:{block['header']['height']}"
            )
Пример #4
0
def main(args):
    """Entry point.

    :param args: Parsed CLI arguments.

    """
    if args.node:
        network, node = get_network_node(args)
        nodeset = [node]
    else:
        network, nodeset = get_network_nodeset(args)

    for node in nodeset:
        block = chain.get_block(network, node)
        try:
            era_id = block['header']['era_id']
        except:
            era_id = "N/A"
        try:
            height = block['header']['height']
        except:
            height = "N/A"
        utils.log(f"ERA::HEIGHT @ {node.address_rpc} = {era_id}::{height}")