Example #1
0
def get_eos_cost(request):
    eos_url = 'https://%s' % (str(NETWORKS['EOS_MAINNET']['host']))
    command1 = [
        'cleos', '-u', eos_url, 'get', 'table', 'eosio', 'eosio', 'rammarket'
    ]
    result = implement_cleos_command(command1)
    ram = result['rows'][0]
    ram_price = float(ram['quote']['balance'].split()[0]) / float(
        ram['base']['balance'].split()[0]) * 1024
    print('get ram price', flush=True)
    ram = request.query_params['buy_ram_kbytes']
    net = request.query_params['stake_net_value']
    cpu = request.query_params['stake_cpu_value']
    eos_cost = round(
        (float(ram) * ram_price + float(net) + float(cpu)) * 2 + 0.3, 0)
    print('eos cost', eos_cost, flush=True)

    return JsonResponse({
        'EOS':
        str(eos_cost),
        'EOSISH':
        str(int(eos_cost) * convert('EOS', 'EOSISH')['EOSISH']),
        'ETH':
        str(round(int(eos_cost) * convert('EOS', 'ETH')['ETH'], 2)),
        'WISH':
        str(int(eos_cost) * convert('EOS', 'WISH')['WISH']),
        'BTC':
        str(int(eos_cost) * convert('EOS', 'BTC')['BTC'])
    })
Example #2
0
def freeze_payments(amount, network):
    if network == 'EOS_MAINNET':
        #if currency in ('EOS', 'EOSISH'):
        value = amount * 0.15 * NET_DECIMALS['EOSISH'] / NET_DECIMALS['ETH']
        value *= convert('WISH', 'EOSISH')['EOSISH']
        #value = float(':.4f'.format(value)
        FreezeBalance.objects.select_for_update().filter(id=1).update(
            eosish=F('eosish') + value)
        print('FREEZE', value, 'EOSISH', flush=True)
    elif network == 'TRON_MAINNET':
        #elif currency in ('TRON', 'TRONISH'):
        value = amount * 0.10 * NET_DECIMALS['TRX'] / NET_DECIMALS['ETH']
        value *= convert('WISH', 'TRONISH')['TRONISH']
        FreezeBalance.objects.select_for_update().filter(id=1).update(
            tronish=F('tronish') + int(value))
        wish_value = amount * 0.10
        FreezeBalance.objects.select_for_update().filter(id=1).update(
            wish=F('wish') + wish_value)
        print('FREEZE', int(value), 'TRONISH', flush=True)
        print('FREEZE', wish_value, 'WISH', flush=True)
    #elif currency in ('BNB', 'BWISH'):
    else:
        value = amount * 0.10
        FreezeBalance.objects.select_for_update().filter(id=1).update(
            wish=F('wish') + value)
        print('FREEZE', value, 'BWISH', flush=True)
Example #3
0
def get_authio_cost(request):
    usdt_cost = str(450 * NET_DECIMALS['USDT'])
    eth_cost = str(
        int(usdt_cost) * convert('USDT', 'ETH')['ETH'] / NET_DECIMALS['USDT'] *
        NET_DECIMALS['ETH'])
    wish_cost = str(
        int(usdt_cost) * convert('USDT', 'WISH')['WISH'] /
        NET_DECIMALS['USDT'] * NET_DECIMALS['WISH'])
    btc_cost = str(
        int(usdt_cost) * convert('USDT', 'BTC')['BTC'] / NET_DECIMALS['USDT'] *
        NET_DECIMALS['BTC'])
    return JsonResponse({
        'USDT': usdt_cost,
        'ETH': eth_cost,
        'WISH': wish_cost,
        'BTC': btc_cost
    })
Example #4
0
 def calc_cost(kwargs, network):
     if NETWORKS[network.name]['is_free']:
         return 0
     eos_cost = ContractDetailsEOSAccount.calc_cost_eos(
         kwargs, network) / NET_DECIMALS['EOS']
     cost = eos_cost * convert('EOS', 'ETH')['ETH']
     print('convert eos cost', cost, flush=True)
     return round(cost, 2) * NET_DECIMALS['USDT']
Example #5
0
def profile_view(request):
    if request.user.is_anonymous:
        print('anonymous', flush=True)
        raise PermissionDenied()
    site_name = request.META['HTTP_HOST']
    if site_name.startswith('cn'):
        site_name = site_name[2:]
    if site_name.startswith('local'):
        print('cut local')
        site_name = site_name[5:]
    site = SubSite.objects.get(site_name=site_name)
    user_balance = UserSiteBalance.objects.get(subsite=site, user=request.user)

    if request.user.email:
        user_name = request.user.email
    elif request.user.first_name or request.user.last_name:
        user_name = '{} {}'.format(request.user.first_name,
                                   request.user.last_name)
    else:
        user_name = request.user.username

    answer = {
        'username':
        user_name,
        'contracts':
        Contract.objects.filter(user=request.user).count(),
        'balance':
        str(user_balance.balance),
        'internal_address':
        user_balance.eth_address,
        'internal_btc_address':
        user_balance.btc_address,
        'use_totp':
        request.user.profile.use_totp,
        'is_social':
        request.user.profile.is_social,
        'id':
        request.user.id,
        'lang':
        request.user.profile.lang,
        'memo':
        user_balance.memo,
        'eos_address':
        'mywishcoming',
        'bnb_address':
        'tbnb1pxwzr62lhdn27mpkdauuf7r4f56mkgmn2zznkc',
        'tron_address':
        hex2tronwif(user_balance.tron_address)
        if user_balance.tron_address else '',
        'usdt_balance':
        str(
            int(
                int(user_balance.balance) / 10**18 *
                convert('WISH', 'USDT')['USDT'] * 10**6))
    }
    return Response(answer)
Example #6
0
def get_cost_all_contracts(request):
    answer = {}
    contract_details_types = Contract.get_all_details_model()
    for i in contract_details_types:
        answer[i] = {
            'USDT':
            str(contract_details_types[i]['model'].min_cost() /
                NET_DECIMALS['USDT']),
            'WISH':
            str(
                int(contract_details_types[i]['model'].min_cost() /
                    NET_DECIMALS['USDT']) * convert('USDT', 'WISH')['WISH'])
        }
    return JsonResponse(answer)
Example #7
0
def get_eos_airdrop_cost(request):
    eos_url = 'https://%s' % (str(NETWORKS['EOS_MAINNET']['host']))
    command1 = [
        'cleos', '-u', eos_url, 'get', 'table', 'eosio', 'eosio', 'rammarket'
    ]
    result = implement_cleos_command(command1)
    ram = result['rows'][0]
    ram_price = float(ram['quote']['balance'].split()[0]) / float(
        ram['base']['balance'].split()[0])
    count = float(request.query_params['address_count'])
    eos_cost = round(250 + ram_price * 240 * count * 1.2, 4)

    return JsonResponse({
        'EOS':
        str(eos_cost),
        'EOSISH':
        str(int(eos_cost) * convert('EOS', 'EOSISH')['EOSISH']),
        'ETH':
        str(round(int(eos_cost) * convert('EOS', 'ETH')['ETH'], 2)),
        'WISH':
        str(int(eos_cost) * convert('EOS', 'WISH')['WISH']),
        'BTC':
        str(int(eos_cost) * convert('EOS', 'BTC')['BTC'])
    })
Example #8
0
def get_cost_all_contracts(request):
    answer = {}
    contract_details_types = Contract.get_all_details_model()
    for i in contract_details_types:
        answer[i] = {
            'USDT':
            str(contract_details_types[i]['model'].min_cost() /
                NET_DECIMALS['USDT']),
            'WISH':
            str(
                int(contract_details_types[i]['model'].min_cost() /
                    NET_DECIMALS['USDT']) * convert('USDT', 'WISH')['WISH'])
        }
        # if i in [10, 11, 12, 13, 14]:
        #     # print(host, EOSISH_URL, flush=True)
        #     answer[i] = contract_details_types[i]['model'].min_cost_eos() / 10 ** 4
        # elif i in [15, 16, 17, 18]:
        #     # eth_cost = contract_details_types[i]['model'].min_cost() / NET_DECIMALS['ETH']
        #     # print('price', i, 'eth_cost', eth_cost, flush=True)
        #     # answer[i] = (eth_cost * convert('ETH', 'TRX')['TRX'])
        #     answer[i] = contract_details_types[i]['model'].min_cost_tron() / NET_DECIMALS['TRX']
        # else:
        #     answer[i] = contract_details_types[i]['model'].min_cost() / NET_DECIMALS['ETH']
    return JsonResponse(answer)
Example #9
0
def create_payment(uid, tx, currency, amount, site_id):
    amount = float(amount)
    if amount == 0.0:
        return
    print('create payment')
    if SubSite.objects.get(id=site_id).site_name == MY_WISH_URL:
        if currency == 'WISH-1EF':
            currency = 'WISH'
            amount = amount * 10**10
        value = amount if currency == 'WISH' else to_wish(currency, amount)
        if currency == 'BTC':
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['BTC']
        if currency in ['TRON', 'TRX', 'TRONISH']:
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['TRX']
        if currency in ['EOS', 'EOSISH']:
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['EOS']
        if currency == 'USDT':
            value = value * NET_DECIMALS['ETH'] / NET_DECIMALS['USDT']
    elif SubSite.objects.get(id=site_id).site_name == TRON_URL:
        value = amount if currency in (
            'TRONISH',
            'TRX') else amount * float(convert(
                currency,
                'TRX')['TRX']) / NET_DECIMALS[currency] * NET_DECIMALS['TRON']
    elif SubSite.objects.get(id=site_id).site_name == SWAPS_URL:
        value = amount if currency == 'USDT' else amount * float(
            convert(currency, 'USDT')
            ['USDT']) / NET_DECIMALS[currency] * NET_DECIMALS['USDT']
    else:
        amount = calculate_decimals(currency, amount)
        value = amount if currency == 'EOSISH' else amount * convert(
            currency, 'EOSISH')['EOSISH'] * NET_DECIMALS['EOSISH']
        amount = add_decimals(currency, amount)
    user = User.objects.get(id=uid)
    if amount < 0.0:
        if site_id == 4:
            try:
                negative_payment(user, -value, site_id)
            except:
                print('-5% payment', flush=True)
                value = value * 0.95
                negative_payment(user, -value, site_id)
        else:
            negative_payment(user, -value, site_id)
    else:
        positive_payment(user, value, site_id, currency, amount)
    site = SubSite.objects.get(id=site_id)
    InternalPayment(user_id=uid,
                    delta=value,
                    tx_hash=tx,
                    original_currency=currency,
                    original_delta=str(amount),
                    site=site).save()
    print('PAYMENT: Created')
    print(
        'PAYMENT: Received {amount} {curr} from user {email}, id {user_id} with TXID: {txid} at site: {sitename}'
        .format(amount=value,
                curr=currency,
                email=user,
                user_id=uid,
                txid=tx,
                sitename=site_id))
Example #10
0
def profile_view(request):
    site_name = request.META['HTTP_HOST']
    print('site is', site_name, flush=True)
    if request.user.is_anonymous:
        print('anonymous', flush=True)
        raise PermissionDenied()
    if site_name.startswith('cn'):
        site_name = site_name[2:]
    if site_name.startswith('local'):
        print('cut local')
        site_name = site_name[5:]
    if site_name.startswith('trondev'):
        site_name = site_name.replace('trondev', 'dev')
    if site_name == WAVES_URL:
        site_name = MY_WISH_URL
    if site_name == RUBIC_EXC_URL:
        site_name = SWAPS_URL
    site = SubSite.objects.get(site_name=site_name)
    user_balance = UserSiteBalance.objects.get(subsite=site, user=request.user)

    if request.user.email:
        user_name = request.user.email
    elif request.user.first_name or request.user.last_name:
        user_name = '{} {}'.format(request.user.first_name,
                                   request.user.last_name)
    else:
        user_name = request.user.username

    swaps_notifications = None
    swaps_notification_email = None
    swaps_notification_telegram_name = None
    swaps_notification_type = None

    swaps_notification_set = request.user.swapsnotificationdefaults_set.all()
    if swaps_notification_set:
        swaps_notification_set = swaps_notification_set.first()
        swaps_notification_email = swaps_notification_set.email
        swaps_notification_telegram_name = swaps_notification_set.telegram_name
        swaps_notification_type = swaps_notification_set.notification

    swaps_notifications = {
        'email': swaps_notification_email,
        'telegram_name': swaps_notification_telegram_name,
        'notification': swaps_notification_type
    }

    answer = {
        'username':
        user_name,
        'contracts':
        Contract.objects.filter(user=request.user).count(),
        'balance':
        str(user_balance.balance),
        'internal_address':
        user_balance.eth_address,
        'internal_btc_address':
        user_balance.btc_address,
        'use_totp':
        request.user.profile.use_totp,
        'is_social':
        request.user.profile.is_social,
        'id':
        request.user.id,
        'lang':
        request.user.profile.lang,
        'memo':
        user_balance.memo,
        'eos_address':
        'mywishcoming',
        'bnb_address':
        BINANCE_PAYMENT_ADDRESS,
        'tron_address':
        hex2tronwif(user_balance.tron_address)
        if user_balance.tron_address else '',
        'usdt_balance':
        str(
            int(
                int(user_balance.balance) / 10**18 *
                convert('WISH', 'USDT')['USDT'] * 10**6)),
        'is_swaps_admin':
        request.user.profile.is_swaps_admin,
        'swaps_notifications':
        swaps_notifications
    }
    return Response(answer)
Example #11
0
def exc_rate(request):
    return Response(
        convert(request.query_params.get('fsym'),
                request.query_params.get('tsyms')))
Example #12
0
def eth2rub(request):
    return Response(convert('ETH', 'RUB'))