Example #1
0
    def post(self, request):
        data = JSONParser().parse(request)
        username = data.get('username')
        password = data.get('password')
        email = data.get('email')

        try:

            if username and password and email:
                user = User.objects.create_user(username=username,
                                                email=email,
                                                password=password)
                if user:
                    user_dict = {}
                    user_dict['username'] = username
                    user = str(user_dict)
                    user = user.replace('\'', '\"')
                    #Util.sendMessage(message=user,listner=WalletListener(Util.get_stomp_connection()),destination= '/queue/wallet')
                    Util.sendMessage(message=user, destination='wallet')

                else:
                    raise ValidationError(
                        get_env_var('exception.business.user.create'))

            else:
                raise ValidationError(
                    get_env_var('exception.validation.user.create'))
            return JsonResponse(data=data, safe=False, status=201)
        except Exception as e:
            track = traceback.format_exc()
            print(track)
            print("error" + str(e))
            raise e
Example #2
0
    def post(self,request):

        print('Started ' + self.__class__.__name__ + ' get method')
        try:
            data = JSONParser().parse(request)
            network = data.get('network')
            hex = data.get('hex')

            txn_data = {}
            txn_data['wallet_id'] = data.get('wallet_id')
            txn_data['type'] = data.get('txn_type')
            txn_data['destination'] = data.get('address_id')
            txn_data['destination_amount'] = data.get('amount')
            txn_data['message'] = data.get('message')
            txn_data['includes_fee'] = data.get('includes_fee')

            print(' txn with data' + str(data))

            if network and hex:

                if network == 'bitcoin':
                    txn_data['network'] = 'btc'
                    resp = btc_srv.sendrawtransaction(hex)
                    txn_data['network'] = 'ltc'
                elif network == 'litecoin':
                    resp = ltc_srv.sendrawtransaction(hex)
                print('\nreceived for sendrawtransaction  resp', resp.status_code, 'response %s' %(resp.text))
                
                if resp.status_code != 200:
                    Util.sendMessage(message=hex,destination='/queue/txn.failure')
                    raise ServiceException(get_env_var('exception.business.send.serviceexception'))
                else:

                    if resp.text:
                        print('saving in txn')
                        response_dict = json.loads(resp.text)
                        txn_data['txn_id'] = response_dict['result']
                        print('saving in txn with data' + str(txn_data))
                        Util.sendMessage(message=txn_data, destination='/queue/txn')
                        serializer = TxnSerializer(data=txn_data)
                        if serializer.is_valid():
                            serializer.save()
                        else:
                            return JsonResponse(serializer.errors, status=400)
                        return JsonResponse(serializer.data, status=201, safe=False)
                    else:
                        raise ServiceException(get_env_var('exception.business.send.serviceexception'))
            else:
                raise ValidationError(get_env_var('exception.validation.send.no_network_or_no_hex'))

        except Exception as e:
            track = traceback.format_exc()
            logger.exception(track)
            print("error" + str(track))
            raise e;
Example #3
0
    def post(self, request):
        try:
            print('Started ' + self.__class__.__name__ + ' post method ')
            data = JSONParser().parse(request)
            username = data.get('username')
            print('Wallet creation for username='******'network') == 'bitcoin':
                    w = wallet_create_or_open(data.get('wallet_name'),
                                              network='bitcoin',
                                              username=data.get('username'),
                                              account_id=user.user_id,
                                              db_uri=db_uri)
                elif data.get('network') == 'litecoin':
                    w = wallet_create_or_open(data['wallet_name'],
                                              network='litecoin',
                                              username=data.get('username'),
                                              account_id=user.user_id,
                                              db_uri=db_uri)

                w.utxos_update()
                w.info(detail=3)
                print('wallet ', w)
                print('w.get_key()', w.get_key())
                print('w.get_key().address ', w.get_key().address)
                return JsonResponse(serializer.data, status=201)
            else:
                response_dict = {
                    'status': 'error',
                    # the format of error message determined by you base exception class
                    'msg': serializer.errors
                }
                return JsonResponse(response_dict, status=400)

        except Exception as e:
            track = traceback.format_exc()
            print(track)
            print("error" + str(e))
            raise e
Example #4
0
    def get(self, request, account_id, wallet_id):
        try:
            logger.debug('Started ', self.__class__.__name__, ' get method')
            amount = request.GET.get('amount')
            qr = request.GET.get('qr')
            print(
                'Started ', self.__class__.__name__,
                ' wallet_id=%s,  account_id=%s, qr=%s, amount=%s ' %
                (str(wallet_id), str(account_id), bool(qr), str(amount)))
            if account_id and wallet_id:
                addressimpl = AddressImpl()
                address = addressimpl.getNewAddress(account_id, wallet_id)
                if address:
                    response_dict = {
                        'address_id': address.address_id,
                        'status': 'success'
                    }
                    if qr:
                        text = address.network_name + ':' + address.address_id + ' amoount:' + str(
                            amount)
                        output = Util.generate_qr(text)
                        print('received for  response generate_qr %s' %
                              (output))
                        image = QRSerializer(output).data
                        response_dict['file_type'] = image['file_type']
                        response_dict['image_base64'] = image['image_base64']

                return JsonResponse(response_dict, safe=False)
            else:
                raise ValidationError(
                    get_env_var(
                        'exception.validation.address.no_account_or_no_wallet')
                )
        except AuthenticationError as e:
            raise e
        except Exception as e:
            raise e
Example #5
0
    def post(self, request):
        try:

            data = JSONParser().parse(request)
            print('username ', data['username'])
            user = Util.get_user(data['username'])
            serializer = WalletSerializer(data=data)
            if serializer.is_valid():
                print('username ', data['username'])
                if data['type'] == 'BTC':
                    w = wallet_create_or_open(data['wallet_name'],
                                              network='bitcoin',
                                              username=data['username'],
                                              account_id=user.user_id,
                                              db_uri=db_uri)
                    w.utxos_update()
                    w.info(detail=3)
                elif data['type'] == 'LTC':
                    w = wallet_create_or_open(data['wallet_name'],
                                              network='litecoin',
                                              username=data['username'],
                                              account_id=user.user_id,
                                              db_uri=db_uri)
                    w.utxos_update()
                    w.info(detail=3)
                print('wallet ', w)
                print('w.get_key()', w.get_key())
                print('w.get_key().address ', w.get_key().address)
                return JsonResponse(serializer.data, status=201)
        except Exception as e:
            track = traceback.format_exc()
            print(track)
            print("error" + str(e))
            raise e
            return HttpResponse(status=404)
        return JsonResponse(serializer.errors, status=400)
Example #6
0
    def post(self, request):
        """
        Retrieve, update or delete a code snippet.
        """
        print("enter sign and send")
        try:
            data = JSONParser().parse(request)
            wallet_id = data.get('wallet_id')
            username = data.get('username')
            hex = data.get('hex')
            coin_type = data.get('type')

            txn_data = {}
            txn_data['username'] = data.get('username')
            txn_data['type'] = data.get('txn_type')
            txn_data['status'] = data.get('status')
            txn_data['source'] = data.get('source')
            txn_data['source_amount'] = data.get('source_amount')
            txn_data['source_currency'] = data.get('source_currency')
            txn_data['destination'] = data.get('destination')
            txn_data['destination_amount'] = data.get('destination_amount')
            txn_data['destination_currency'] = data.get('destination_currency')
            txn_data['message'] = data.get('message')
            txn_data['includes_fee'] = data.get('includes_fee')

            print(' txn with data' + str(data))

            if username and coin_type and hex:
                print(username + "username")
                service_url = get_env_var(
                    'service.url') + '/key/?wallet_id=' + str(
                        wallet_id) + '&type=' + coin_type
                print(service_url + "service_url")
                resp = requests.get(service_url, auth=service_auth)
                if resp.status_code != 200:
                    print('address response', resp.text)
                    raise ServiceException(
                        get_env_var(
                            'exception.business.sign.serviceexception'))
                else:
                    print('address response', resp.text)
                    response_list = json.loads(resp.text)
                    sign_dict_str = self.sign_txn(hex, response_list)
                    print('sign request ' + sign_dict_str)
                    url = get_url(coin_type, "signtxn")
                    # url = 'https://66f49c90-24e2-4d2b-891d-5746233c8ae7.mock.pstmn.io/sign'
                    if coin_type == 'BTC':
                        resp = requests.post(url,
                                             auth=btc_auth,
                                             data=sign_dict_str)
                    elif coin_type == 'LTC':
                        resp = requests.post(url,
                                             auth=ltc_auth,
                                             data=sign_dict_str)

                    print(resp.status_code)
                    if resp.status_code != 200:
                        print('sign response ' + resp.text)
                        raise ServiceException(
                            get_env_var(
                                'exception.business.sign.serviceexception'))
                    else:
                        print('sign response ' + resp.text)
                        send_dict = json.loads(resp.text)
                        send_dict_str = self.send_txn(hex, send_dict)
                        url = get_url(coin_type, 'sendtxn')

                        # url = 'https://66f49c90-24e2-4d2b-891d-5746233c8ae7.mock.pstmn.io/send'
                        if coin_type == 'BTC':
                            resp = requests.post(url,
                                                 auth=btc_auth,
                                                 data=send_dict_str)
                        elif coin_type == 'LTC':
                            resp = requests.post(url,
                                                 auth=ltc_auth,
                                                 data=send_dict_str)

                        print(resp.status_code)
                        if resp.status_code != 200:
                            print('send error response ' + resp.text +
                                  ' with status code' + str(resp.status_code))
                            Util.sendMessage('send', '/queue/test')
                            raise ServiceException(
                                get_env_var(
                                    'exception.business.send.serviceexception')
                            )
                        else:
                            print('send suucess response ' + resp.text +
                                  ' with status code' + str(resp.status_code))
                            Util.sendMessage('send', '/queue/test')
                            if resp.text:
                                print('saving in txn')
                                txn_data['txn_id'] = resp.text
                                serializer = TxnSerializer(data=txn_data)
                                if serializer.is_valid():
                                    serializer.save()
                                else:
                                    print('data invalid')
                                    return JsonResponse(serializer.errors,
                                                        status=400)
                                return JsonResponse(serializer.data,
                                                    status=201,
                                                    safe=False)
                            else:
                                raise ServiceException(
                                    get_env_var(
                                        'exception.business.send.serviceexception'
                                    ))

            else:
                raise ValidationError(
                    get_env_var(
                        'exception.validation.sign.no_user_or_no_coin_type_or_no_hex'
                    ))
        except Exception as e:
            track = traceback.format_exc()
            print(track)
            print("error" + str(e))
            raise e