Exemple #1
0
def create_diploma_transaction():
    """
    Method that gives a diploma to a student. It gets the asset name of the university currency and sends a unit
    of that asset to the multisignature student+university. Then it creates a multisignature transfer from the
    multisignature student+university to university+high authority and signs it. It also adds the cnp(student id)+hash
    as metadata and adds the diploma to the database.

    Args:
        multisig_address (str): the multisignature of student+university.
        stud_cnp (str): the id of the student.
        diploma_hash (str): the hash of the diploma.
        diploma_name (str): the name of the diploma.

    Returns:
        (html): the university page.
        (dict): response variable that contains the students, diplomas and the hexblob of the
        transaction that the student must sign.
    """
    response = dict()

    multisig_address = request.args.get("multisig_address")
    stud_cnp = request.args.get("stud_cnp")
    diploma_hash = request.args.get("diploma_hash")
    diploma_name = request.args.get("diploma_name")

    asset_name = MultichainCLI.get_asset_name()

    error = MultichainCLI.send_asset(multisig_address, asset_name)

    print("Student cnp: {}".format(stud_cnp))

    if not error:
        time.sleep(0.5)

        asset_dest_addr = MultichainCLI.get_destination_addr_asset(asset_name)

        hexblob, errors = MultichainCLI.create_raw_trans(multisig_address, asset_dest_addr, asset_name, stud_cnp + diploma_hash)

        if errors:
            response["create_hexblob"] = "Multisignature with the high authority was not created. Please create the " \
                                         "multisignature before issuing any diploma."
        else:
            response["create_hexblob"] = "Hexblob: {}".format(hexblob["hex"])

            diploma = Diploma(hash=diploma_hash, name=diploma_name, student_cnp=stud_cnp)
            db.session.add(diploma)
            db.session.commit()

    students = Student.query.all()
    response["students"] = students_schema.dump(students).data
    diplomas = Diploma.query.all()
    response["diplomas"] = diplomas_schema.dump(diplomas).data

    return render_template("university.html", response=response)
Exemple #2
0
def revoke_diploma_transaction():
    """
        Method that revokes a diploma from a student. It creates a multisignature transfer from the multisignature
        between univ+high authority to the burn address.

        Args:
            stud_cnp (str): the id of the student.
            diploma_hash (str): the hash of the diploma.

        Returns:
            (html): the university page.
            (dict): response variable that contains the students, diplomas and the hexblob of the
            transaction that the high authority must sign.
        """

    response = dict()

    stud_cnp = request.args.get("stud_cnp")

    diploma_hash = request.args.get("diploma_hash")

    asset_name = MultichainCLI.get_asset_name()
    asset_dest_addr = MultichainCLI.get_destination_addr_asset(asset_name)

    burn_address = MultichainCLI.get_burn_address()

    hexblob, _ = MultichainCLI.create_raw_trans(asset_dest_addr, burn_address, asset_name, stud_cnp + diploma_hash)

    response["revoke_hexblob"] = "Hexblob: {}".format(hexblob["hex"])

    db.session.execute("delete from diploma where hash = '{}'".format(diploma_hash))
    db.session.commit()

    students = Student.query.all()
    response["students"] = students_schema.dump(students).data
    diplomas = Diploma.query.all()
    response["diplomas"] = diplomas_schema.dump(diplomas).data

    return render_template("university.html", response=response)