Esempio n. 1
0
    def get(self, request):

        print('Started ' + self.__class__.__name__ + ' get method')
        try:
            network = request.GET.get('network')
            wallet_id = request.GET.get('wallet_id')
            withsum = request.GET.get('withsum')
            withsum = bool(withsum)
            print('Started ', self.__class__.__name__, '  wallet_id=%s, withsum=%s, network=%s ' % (str(wallet_id),
                                                                                             bool(str(withsum)),network))
            address_list = []
            if  wallet_id and network :
                wallet = HDWallet(wallet_id, db_uri=db_uri)
                wallet_address_list = wallet.addresslist()
                print('Wallet=%s, with unspent value=%s' %(wallet_id,str(wallet.balance())))

                address_list = '|'.join([str(a) for a in wallet_address_list])
                block_service_url = get_env_var(
                    'blockchain.service.url') + '/multiaddr?active=' + address_list
                print('service_url for get balance', block_service_url)
                resp = requests.get(block_service_url)
                print('\nreceived for blcokchain multiaddr resp', resp.status_code)
                address_list = json.loads(resp.text)
                address_list =  self.getunspent(wallet_address_list,address_list,withsum)
                return JsonResponse(address_list, safe=False)
            else:
                raise ValidationError(get_env_var('exception.validation.unspent.no_wallet_or_no_network'))
        except ServiceException as e:
            track = traceback.format_exc()
            print(track)
            raise ServiceException(e)
        except Exception as e:
            track = traceback.format_exc()
            print(track)
            raise ServiceException(get_env_var('exception.business.unspent.serviceexception'))
Esempio n. 2
0
    def get(self, request, wallet_id):
        """
        Retrieve, update or delete a code snippet.
        """
        try:
            print('enter txn')
            txn = Txn.txn_list_wallet(db_uri=db_uri, wallet_id=wallet_id)

            print('Started ' + self.__class__.__name__ + ' get method')

            network = request.GET.get('network')

            print('Started ', self.__class__.__name__,
                  '  wallet_id=%s, network=%s ' % (str(wallet_id), network))
            address_list = []
            if wallet_id and network:
                wallet = HDWallet(wallet_id, db_uri=db_uri)
                wallet_address_list = wallet.addresslist()
                if network == 'bitcoin':
                    address_list = '|'.join(
                        [str(a) for a in wallet_address_list])
                    block_service_url = get_env_var(
                        'blockchain.service.url'
                    ) + '/multiaddr?active=' + address_list
                    print('service_url for get balance', block_service_url)
                    resp = requests.get(block_service_url)
                    print('\nreceived for blcokchain multiaddr resp',
                          resp.status_code)
                    address_list = json.loads(resp.text)
                    address_list = self.getBitcoinTxn(address_list)
                    return JsonResponse(address_list, safe=False)
                elif network == 'litecoin':
                    address_list = ';'.join(
                        [str(a) for a in wallet_address_list])
                    blockcypher_service_url = get_env_var(
                        'blockcypher.service.url'
                    ) + '/v1/ltc/main/addrs/' + address_list + '/full?token=' + get_env_var(
                        'blockcypher.service.token')
                    print('service_url for unspent balance',
                          blockcypher_service_url)
                    resp = requests.get(blockcypher_service_url)
                    print('\nreceived for blockcypher balance resp',
                          resp.status_code)
                    address_list = json.loads(resp.text)
                    address_list = self.getLitecoinTxn(address_list)
                    print('address_list----------', address_list)
                    return JsonResponse(address_list, safe=False)
            else:
                raise ValidationError(
                    get_env_var(
                        'exception.validation.txn.no_wallet_or_no_network'))
        except WalletError as e:
            track = traceback.format_exc()
            print(track)
            raise e
        except ServiceException as e:
            track = traceback.format_exc()
            print(track)
            raise ServiceException(e)
        except Exception as e:
            track = traceback.format_exc()
            print(track)
            raise ServiceException(
                get_env_var('exception.business.txn.serviceexception'))

            return JsonResponse(txn, safe=False)

        except Txn.DoesNotExist:
            return HttpResponse(status=404)