def issue_credreq():

    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "agent has no active connections"
        })

    role = os.getenv("ROLE")

    if role == "bank":
        logging.debug("MAJOR STAGE: ISSUING PAYMENT CRED")
        trans.send_payment_cred_offer(config.agent_data.current_connection,
                                      config.agent_data.creddef_id)

    elif role == "vendor":
        logging.debug("MAJOR STAGE 4: ISSUEING PACKAGE CRED")
        trans.send_package_cred_offer(
            config.agent_data.current_connection,
            config.agent_data.creddefs["package_cred"])

    elif role == "shipper":
        logging.debug("MAJOR STAGE 4: ISSUEING PACKAGE CRED")
        trans.send_package_receipt_cred_offer(
            config.agent_data.current_connection, config.agent_data.creddef_id,
            config.agent_data.get_package_no())

    return make_response({"code": "success", "role": role}, 200)
def prop_cred():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    ##propose payment credential
    if config.role == "user":
        logging.debug("proposing payment agreement credential")
        ##todo implement input through web

        if not config.agent_data.product_id:
            product_id = trans.gen_product_id()
        else:
            product_id = config.agent_data.product_id

        trans.send_payment_agreement_proposal(product_id)

        return make_response({"code": "received"})

    return make_response({
        "code": "failure",
        "reason": "Error in proposing agreement"
    })
def approve_purchase():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })
    if config.role != "vendor":
        make_response({"code": "not avialable for this agent"}, 400)
    trans.approve_payment_agreement()
    return make_response({"code": "received"})
示例#4
0
def prop_prove_ownership():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    logging.debug("proposing proof of package ownership")
    ownership_creddef = trans.get_creddefid("package_cred")
    trans.propose_proof_of_ownership(config.agent_data.current_connection,
                                     ownership_creddef)
    return make_response({"code": "received"})
示例#5
0
def prop_agree_proof():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    logging.debug("proposing proof of purchase agreement")
    agreement_creddef = trans.get_creddefid("payment_agreement")
    trans.propose_proof_of_payment_agreement(
        config.agent_data.current_connection, agreement_creddef)
    return make_response({"code": "received"})
def received_package():

    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })
    if config.role != "shipper":
        make_response({"code": "not avialable for this agent"}, 500)

    creddef_id = config.agent_data.creddefs["received_package"]
    trans.send_package_receipt_cred_offer(config.agent_data.current_connection,
                                          creddef_id)

    return make_response({"code": "received"})
def req_purchase():

    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    if config.role != "user":
        make_response({"code": "not avialable for this agent"}, 500)

    ##todo implement input through web
    product_id = trans.gen_product_id()
    trans.send_payment_agreement_proposal(product_id)
    return make_response({"code": "received"})
示例#8
0
def issue_proof_req():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    logging.debug("Has active connection :)")
    role = os.getenv("ROLE")
    if role == "vendor":
        trans.request_proof_of_payment()

    elif role == "shipper":
        trans.request_proof_of_ownership()

    return make_response({"code": "success"})
示例#9
0
def request_item():

    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "agent has no active connections"
        })

    data = request.data.decode("utf-8")
    print(data)
    print(type(data))

    product = data.split("=")[1].strip()

    if len(product) > 3:
        print("Purchase request for product : ", product)
        config.agent_data.update_product_id(product)
        trans.send_payment_agreement_proposal(product)

    return make_response({"code": "success"})
示例#10
0
def prop_proof():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    ##propose proof of payment
    if config.role == "user":
        logging.debug("proposing proof of payment")
        payment_creddef = trans.get_payment_creddefid()
        if not payment_creddef:
            return make_response({"code": "Do not have correct credential"})

        trans.propose_proof_of_payment(config.agent_data.current_connection,
                                       payment_creddef)

        return make_response({"code": "received"})
    else:
        return make_response({"code": "failed"}, 400)
示例#11
0
def ready_for_dispatch():
    if not ob.hasActiveConnection():
        return make_response({
            "code": "failure",
            "reason": "no active connections"
        })

    ##propose proof of payment
    if config.role != "vendor":
        return make_response(
            {"code": "action unavailable for this demo agent"}, 500)

    logging.debug("proposing proof of package status")
    dispatch_creddef = trans.get_creddefid("received_package")
    if not dispatch_creddef:
        return make_response({"code": "Do not have correct credential"})

    trans.propose_proof_of_dispatch(config.agent_data.current_connection,
                                    dispatch_creddef)

    return make_response({"code": "received"})