コード例 #1
0
def listener():
    """ Listener for Sawtooth State changes
    """
    try:
        database = Database()
        subscriber = Subscriber(VALIDATOR)
        database.connect()
        subscriber.add_handler(get_delta_handler(database))
        known_blocks = database.get_last_known_blocks()
        subscriber.start(known_blocks)
        LOGGER.info("Listening for Sawtooth state changes")

    except Exception as err:  # pylint: disable=broad-except
        LOGGER.exception("Outbound listener %s exception", type(err).__name__)
        LOGGER.exception(err)

    finally:
        try:
            database.disconnect()
        except UnboundLocalError:
            pass
        try:
            subscriber.stop()
        except UnboundLocalError:
            pass
コード例 #2
0
def main():
    try:
        opts = parse_args(sys.argv[1:])
        init_logger(opts.verbose)

        LOGGER.info("Starting Ledger Sync...")

        database = Database(opts.db_host, opts.db_port, opts.db_name)
        database.connect()

        subscriber = Subscriber(opts.validator)
        subscriber.add_handler(get_delta_handler(database))
        known_blocks = get_last_known_blocks(database)
        subscriber.start(known_blocks)

    except KeyboardInterrupt:
        sys.exit(0)

    except Exception as err:  # pylint: disable=broad-except
        LOGGER.exception(err)
        sys.exit(1)

    finally:
        try:
            subscriber.stop()
        except UnboundLocalError:
            pass

        try:
            database.disconnect()
        except UnboundLocalError:
            pass

        LOGGER.info("Ledger Sync shut down successfully")