def check_if_valid(trans : Transaction) -> bool:
    if trans.prove_signature() is False:
        # Singature wrong
        return False

    if test_inside_open_transactions(trans) or test_inside_current_block(trans):
        # Trans sender got a Trans already in open state
        return False

    if test_generel_formal(trans) is False:
        return False
    if test_trans_id(trans) is False:
        return False

    if trans.op_name == "account_creation":
        if test_account_creation(trans).result() is False:
            return False
    elif trans.op_name == "account_setting":
        if test_account_setting(trans).result() is False:
            return False
    elif trans.op_name == "transfer":
        if test_transfer(trans).result() is False:
            return False
    elif trans.op_name == "set_friend":
        if test_set_friend(trans).result() is False:
            return False
    else:
        return False

    return True

    
예제 #2
0
def post_transaction():
    if not "sender" in request.json or not "op" in request.json:
        return jsonify({
            "status": "error",
            "info": "no sender/operation is given"
        }), 400
    if not "data" in request.json or not "signature" in request.json:
        return jsonify({
            "status": "error",
            "info": "no data/signature is given"
        }), 400
    if not "id" in request.json or not "timestamp" in request.json:
        return jsonify({
            "status": "error",
            "info": "no id/timestamp is given"
        }), 400

    sender = request.json["sender"]
    data = request.json["data"]
    timestamp = request.json["timestamp"]
    id = request.json["id"]
    op_name = request.json["op"]
    signature = request.json["signature"]
    trans = Transaction(sender,
                        id,
                        op_name,
                        data,
                        signature,
                        timestamp=timestamp)

    if trans.prove_signature() is False:
        return jsonify({"status": "error", "info": "Signature is wrong"}), 400

    if check_if_valid(trans) is False:
        return jsonify({
            "status": "error",
            "info": "Transaction is invalid"
        }), 400

    statics.OPEN_TRANSACTIONS.append(trans)
    return jsonify({"status": "ok"}), 200