hydrachain/nc_utils.py
def wait_next_block_factory(app, timeout=None):
    """Creates a `wait_next_block` function, that
    will wait `timeout` seconds (`None` = indefinitely)
    for a new block to appear.

    :param app: the app-instance the function should work for
    :param timeout: timeout in seconds
    """

    chain = app.services.chain

    # setup new block callbacks and events
    new_block_evt = gevent.event.Event()

    def _on_new_block(app):
        log.DEV('new block mined')
        new_block_evt.set()
    chain.on_new_head_cbs.append(_on_new_block)

    def wait_next_block():
        bn = chain.chain.head.number
        chain.consensus_manager.log('waiting for new block', block=bn)
        new_block_evt.wait(timeout)
        new_block_evt.clear()
        if chain.chain.head.number > bn:
            chain.consensus_manager.log('new block event', block=chain.chain.head.number)
        elif chain.chain.head.number == bn:
            chain.consensus_manager.log('wait_next_block timed out', block=bn)

    return wait_next_block
def wait_next_block_factory(app, timeout=None):
    """Creates a `wait_next_block` function, that
    will wait `timeout` seconds (`None` = indefinitely)
    for a new block to appear.

    :param app: the app-instance the function should work for
    :param timeout: timeout in seconds
    """

    chain = app.services.chain

    # setup new block callbacks and events
    new_block_evt = gevent.event.Event()

    def _on_new_block(app):
        log.DEV('new block mined')
        new_block_evt.set()
    chain.on_new_head_cbs.append(_on_new_block)

    def wait_next_block():
        bn = chain.chain.head.number
        chain.consensus_manager.log('waiting for new block', block=bn)
        new_block_evt.wait(timeout)
        new_block_evt.clear()
        if chain.chain.head.number > bn:
            chain.consensus_manager.log('new block event', block=chain.chain.head.number)
        elif chain.chain.head.number == bn:
            chain.consensus_manager.log('wait_next_block timed out', block=bn)

    return wait_next_block
Creates a `wait_next_block` function, that
    will wait `timeout` seconds (`None` = indefinitely)
    for a new block to appear.

    :param app: the app-instance the function should work for
    :param timeout: timeout in seconds