def issue(app_config, certificate_batch_handler, transaction_handler):
    unsigned_certs_dir = app_config.unsigned_certificates_dir
    signed_certs_dir = app_config.signed_certificates_dir
    blockchain_certificates_dir = app_config.blockchain_certificates_dir
    work_dir = app_config.work_dir

    certificates_metadata = helpers.prepare_issuance_batch(unsigned_certs_dir, signed_certs_dir,
                                                           blockchain_certificates_dir, work_dir)
    num_certificates = len(certificates_metadata)
    if num_certificates < 1:
        logging.warning('No certificates to process')
        return None

    logging.info('Processing %d certificates under work path=%s', num_certificates, work_dir)
    certificate_batch_handler.set_certificates_in_batch(certificates_metadata)

    transaction_handler.ensure_balance()

    issuer = Issuer(
        certificate_batch_handler=certificate_batch_handler,
        transaction_handler=transaction_handler,
        max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.bitcoin_chain)

    helpers.copy_output(certificates_metadata)

    logging.info('Your Blockchain Certificates are in %s', blockchain_certificates_dir)
    return tx_id
def issue(app_config, certificate_batch_handler, transaction_handler):
    unsigned_certs_dir = app_config.unsigned_certificates_dir
    signed_certs_dir = app_config.signed_certificates_dir
    blockchain_certificates_dir = app_config.blockchain_certificates_dir
    work_dir = app_config.work_dir

    certificates_metadata = helpers.prepare_issuance_batch(
        unsigned_certs_dir, signed_certs_dir, blockchain_certificates_dir,
        work_dir)
    num_certificates = len(certificates_metadata)
    if num_certificates < 1:
        logging.warning('No certificates to process')
        return None

    logging.info('Processing %d certificates under work path=%s',
                 num_certificates, work_dir)
    certificate_batch_handler.set_certificates_in_batch(certificates_metadata)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.bitcoin_chain)

    helpers.copy_output(certificates_metadata)

    logging.info('Your Blockchain Certificates are in %s',
                 blockchain_certificates_dir)
    return tx_id
Пример #3
0
def issue(app_config, certificate_batch_handler, transaction_handler):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.chain)

    certificate_batch_handler.post_batch_actions(app_config)
    return tx_id
Пример #4
0
def issue(app_config, certificate_batch_handler, transaction_handler):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.chain)
    """"Este metodo copia del workingDir al blockchainCertDir"""
    #certificate_batch_handler.post_batch_actions(app_config)
    return tx_id
Пример #5
0
    def post(self):
        json_data = request.get_json(force=True)
        # get recipient from the json_data
        fields = {}
        fields["identity"] = json_data['email']
        fields["name"] = json_data['name']
        recipient = Recipient(fields)

        # get the template from db
        template_col = DAO().get_collection('certificate_template')
        template = template_col.find_one({}, {"_id": 0})

        # get deep copy of the template as cert
        cert = deepcopy(template)

        # get the config
        config = Config().get()

        # call instantiate_assertion and instantiate_recipient
        uid = str(uuid.uuid4())
        issued_on = helpers.create_iso8601_tz()
        instantiate_assertion(cert, uid, issued_on)
        instantiate_recipient(cert, recipient,
                              config.additional_per_recipient_fields,
                              config.hash_emails)

        # get the config
        config = Config().get()

        # post it to blockchain
        # first instantiate handlers
        chain = config.chain
        if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten:
            from cert_issuer.blockchain_handlers import ethereum
            certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers(
                config, False)
        else:
            from cert_issuer.blockchain_handlers import bitcoin
            certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers(
                config, False)

        certificate_batch_handler.certificates_to_issue = [cert]
        issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                        transaction_handler=transaction_handler,
                        max_retry=config.max_retry)
        tx_id = issuer.issue(config.chain)

        issued_cert = certificate_batch_handler.certificates_to_issue[0]
        issued_cert_to_insert = deepcopy(issued_cert)
        cert_col = DAO().get_collection("certificates")
        cert_col.insert_one(issued_cert_to_insert)
        return issued_cert
Пример #6
0
def issue(app_config, certificate_batch_handler, transaction_handler):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(
        certificate_batch_handler=certificate_batch_handler,
        transaction_handler=transaction_handler,
        max_retry=app_config.max_retry)
    tx_id = issuer.issue(app_config.chain)

    certificate_batch_handler.post_batch_actions(app_config)
    return tx_id
Пример #7
0
def issue(app_config, certificate_batch_handler, transaction_handler,
          recipient_address, token_uri):
    certificate_batch_handler.pre_batch_actions(app_config)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    (tx_id, token_id) = issuer.issue(app_config.chain, app_config,
                                     recipient_address, token_uri)

    certificate_batch_handler.post_batch_actions(app_config)
    return (tx_id, token_id)
Пример #8
0
def issue(app_config, certificate_batch_handler, transaction_handler,
          recipient_address, uidArray, token_uri):
    # Provide array of uidArrays to generate certificates
    certificate_batch_handler.pre_batch_actions(app_config, uidArray)

    transaction_handler.ensure_balance()

    issuer = Issuer(certificate_batch_handler=certificate_batch_handler,
                    transaction_handler=transaction_handler,
                    max_retry=app_config.max_retry)
    (tx_id, token_id) = issuer.issue(app_config.chain, app_config,
                                     recipient_address, token_uri)

    certificate_batch_handler.post_batch_actions(app_config)
    return (tx_id, token_id)