from flask import request, Response
from messaging.ReconnectingMessageManager import ReconnectingMessageManager
import json

message_sender = ReconnectingMessageManager.getInstance()
message_sender.create_message_destination('inhub', 'direct')

def receive():
    body = request.json
    
    if isBlockchainTraceValid(body):
        message = {'type': 'blockchain-transaction', 'retries': 0, 'content': body}
        message_sender.send_message('inhub', 'trace-retrieval', json.dumps(message))
        return Response(status=201)
        
    return Response('ApplicationType is missing', status=400)

def isBlockchainTraceValid(trace) -> bool:
    # different for every use case, no global schema
    return 'ApplicationType' in trace 
