Пример #1
0
def deploy(request):
    contract = Contract.objects.get(id=request.data.get('id'))
    contract_details = contract.get_details()
    contract_details.predeploy_validate()

    if contract.user != request.user or contract.state not in (
            'CREATED', 'WAITING_FOR_PAYMENT'):
        raise PermissionDenied

    cost = contract.cost
    currency = 'USDT'
    site_id = 1
    network = contract.network.name
    promo_str = request.data.get('promo', None)
    if promo_str:
        promo_str = promo_str.upper()
    promo_str = check_error_promocode(
        promo_str, contract.contract_type) if promo_str else None
    cost = check_promocode(promo_str, request.user, cost, contract,
                           contract_details)
    create_payment(request.user.id, '', currency, -cost, site_id, network)
    if promo_str:
        promo_object = Promo.objects.get(promo_str=promo_str.upper())
        User2Promo(user=request.user,
                   promo=promo_object,
                   contract_id=contract.id).save()
    contract.state = 'WAITING_FOR_DEPLOYMENT'
    contract.save()
    queue = NETWORKS[contract.network.name]['queue']
    send_in_queue(contract.id, 'launch', queue)
    return Response('ok')
Пример #2
0
def cancel(request):
    contract = Contract.objects.get(id=request.data.get('id'))
    if contract.user != request.user or contract.state not in (
            'ACTIVE', 'EXPIRED') or contract.contract_type not in (0, 1, 18):
        raise PermissionDenied()
    queue = NETWORKS[contract.network.name]['queue']
    send_in_queue(contract.id, 'cancel', queue)
    return Response('ok')
Пример #3
0
def deploy(request):
    host = request.META['HTTP_HOST']
    contract = Contract.objects.get(id=request.data.get('id'))
    contract_details = contract.get_details()
    contract_details.predeploy_validate()

    if contract.user != request.user or contract.state not in (
            'CREATED', 'WAITING_FOR_PAYMENT'):
        raise PermissionDenied

    cost = contract.cost
    currency = 'USDT'
    site_id = 1

    # if host == EOSISH_URL:
    #     kwargs = ContractSerializer().get_details_serializer(
    #         contract.contract_type
    #     )().to_representation(contract_details)
    #     cost = contract_details.calc_cost_eos(kwargs, contract.network)
    #     currency = 'EOS'
    #     site_id = 2
    # elif host == MY_WISH_URL:
    #     cost = contract.cost
    #     currency = 'ETH'
    #     site_id = 1
    # else:
    #     kwargs = ContractSerializer().get_details_serializer(
    #         contract.contract_type
    #     )().to_representation(contract_details)
    #     cost = contract_details.calc_cost_tron(kwargs, contract.network)
    #     # cost = eth_cost * convert('ETH', 'TRX')['TRX'] * 10 ** 6
    #     currency = 'TRX'
    #     site_id = 3
    promo_str = request.data.get('promo', None)
    if promo_str:
        promo_str = promo_str.upper()
    promo_str = check_error_promocode(
        promo_str, contract.contract_type) if promo_str else None
    cost = check_promocode(promo_str, request.user, cost, contract,
                           contract_details)
    create_payment(request.user.id, '', currency, -cost, site_id)
    if promo_str:
        promo_object = Promo.objects.get(promo_str=promo_str.upper())
        User2Promo(user=request.user,
                   promo=promo_object,
                   contract_id=contract.id).save()
    contract.state = 'WAITING_FOR_DEPLOYMENT'
    contract.save()
    queue = NETWORKS[contract.network.name]['queue']
    send_in_queue(contract.id, 'launch', queue)
    return Response('ok')
Пример #4
0
def i_am_alive(request):
    contract = Contract.objects.get(id=request.data.get('id'))
    if contract.user != request.user or contract.state != 'ACTIVE' or contract.contract_type not in (
            0, 1, 18):
        raise PermissionDenied
    details = contract.get_details()
    if details.last_press_imalive:
        delta = timezone.now() - details.last_press_imalive
        if delta.days < 1:
            raise PermissionDenied(3000)
    queue = NETWORKS[contract.network.name]['queue']
    send_in_queue(contract.id, 'confirm_alive', queue)
    details.last_press_imalive = timezone.now()
    details.save()
    return Response('ok')