def add_token(request, token, token_name): if token is None or token == "": return JsonResponse( { 'status': 'false', 'reason': 'token not specified' }, status=400) if token_name is None or token_name == "": return JsonResponse({ 'status': 'false', 'reason': 'token_name wrong' }, status=400) etherscan_api_url = "https://api.etherscan.io/api?module=stats&action=tokensupply&contractaddress={}&apikey=B4IFQIJ88Z36UYYRUHVRPTZ46HZ2S3FCCV".format( token) r = requests.get(etherscan_api_url) json_result = r.json() if json_result['result'] == "0": return JsonResponse( { 'status': 'false', 'reason': 'token not found on etherscan' }, status=400) error = False try: dummy = Token.objects.get(contract_address=token) error = True except ObjectDoesNotExist: token_obj = Token(coin_name=token_name, contract_address=token) token_obj.status = "fetching_all_data" token_obj.save() get_all_transaction_data_for_a_token(token_name, token) if error: return JsonResponse({ "status": "false", 'reason': 'token already exists' }) else: return JsonResponse({"status": "okay"})
def generate(request, poll_name): amount = request.GET.get('amount', None) poll = Poll.objects.get(url=poll_name) context = { 'poll': poll, 'generate': True } if amount is not None: tokens = [ Token.generate(poll) for _ in range(int(amount)) ] context['tokens'] = tokens return render( request, 'polls/token/gen.html', context )
def generate_user_token(request, poll_name): poll = Poll.objects.get(url=poll_name) try: t = Token.objects.get( poll=poll, user=request.user ) return render_to_response( 'polls/error/has_token.html', { 'token': t } ) except Token.DoesNotExist: token = Token.generate( poll=poll, user=request.user ) return render( request, 'polls/token/overview.html', {'tokens': [token]} )