def main(app_config): chain = app_config.chain if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten or chain == Chain.ethereum_goerli: from cert_issuer.blockchain_handlers import ethereum certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers( app_config) else: from cert_issuer.blockchain_handlers import bitcoin certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers( app_config) return issue(app_config, certificate_batch_handler, transaction_handler)
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
def main(app_config): chain = app_config.chain if chain == Chain.ethereum_mainnet or chain == Chain.ethereum_ropsten: if app_config.issuing_method == "smart_contract": from cert_issuer.blockchain_handlers import ethereum_sc certificate_batch_handler, transaction_handler, connector = ethereum_sc.instantiate_blockchain_handlers( app_config) if app_config.revoke is True: return revoke_certificates(app_config, transaction_handler) else: from cert_issuer.blockchain_handlers import ethereum certificate_batch_handler, transaction_handler, connector = ethereum.instantiate_blockchain_handlers( app_config) else: from cert_issuer.blockchain_handlers import bitcoin certificate_batch_handler, transaction_handler, connector = bitcoin.instantiate_blockchain_handlers( app_config) return issue(app_config, certificate_batch_handler, transaction_handler)