def generate_addresses(request, times): for i in range(0, times): a = Address() idx = random.randint(0, 1) a.address_type = ['B', 'S'][idx] a.first_name = random_text('t', 15) a.last_name = random_text('t', 15) a.address = random_text('t', 50) a.zipcode = random_text('n', 5) a.country = random_text('t', 10) a.city = random_text('t', 10) a.save() return HttpResponse(f'{times} Addresses generated !')
def create_withdraw_address(request, order_pk): error_message = 'Error creating address: %s' order = Order.objects.get(pk=order_pk) if not order.user.profile.is_verified and not order.exchange: pm = order.payment_preference.payment_method if pm.required_verification_buy or order.user.profile.anonymous_login: resp = { 'status': 'ERR', 'msg': 'You need to be a verified user to set withdrawal ' 'address for order with payment method \'{}\'' ''.format(pm.name) } return JsonResponse(resp, safe=False) address = request.POST.get('value') addr = Address() addr.type = Address.WITHDRAW addr.user = request.user addr.address = address if order.order_type == Order.BUY: currency = order.pair.base else: currency = order.pair.quote addr.currency = currency try: if currency.code == 'BTC': validate_btc(addr.address) elif currency.code == 'LTC': validate_ltc(addr.address) elif currency.code == 'ETH': validate_eth(addr.address) else: validate_address(addr.address) addr.save() resp = {'status': 'OK', 'pk': addr.pk, 'target': addr.currency.code} except ValidationError: resp = {'status': 'ERR', 'msg': 'The supplied address is invalid.'} except Exception as e: msg = error_message % (e) resp = {'status': 'ERR', 'msg': msg} return JsonResponse(resp, safe=False)
def create_withdraw_address(request): error_message = 'Error creating address: %s' address = request.POST.get('value') addr = Address() addr.type = Address.WITHDRAW addr.user = request.user addr.address = address try: validate_bc(addr.address) addr.save() resp = {'status': 'OK', 'pk': addr.pk} except ValidationError: resp = {'status': 'ERR', 'msg': 'The supplied address is invalid.'} except Exception as e: msg = error_message % (e) resp = {'status': 'ERR', 'msg': msg} return JsonResponse(resp, safe=False)