def main()

in pyqldbsamples/validate_qldb_hash_chain.py [0:0]


def main(ledger_name=Constants.LEDGER_NAME):
    """
     Validate the hash chain of a QLDB ledger by stepping through its S3 export.

     This code accepts an exportID as an argument, if exportID is passed the code
     will use that or request QLDB to generate a new export to perform QLDB hash
     chain validation.
     """
    s3_client = client('s3')
    try:
        if len(argv) == 2:
            export_id = argv[1]
            logger.info('Validating qldb hash chain for ExportId: {}.'.format(export_id))

        else:
            logger.info('Requesting qldb to create an export.')
            export_id = create_journal_export()

        journal_export = describe_journal_export(ledger_name, export_id).get('ExportDescription')
        journal_blocks = read_export(journal_export, s3_client)
        verify(journal_blocks)
    except Exception as e:
        logger.exception('Unable to perform hash chain verification.')
        raise e