Exemple #1
0
 def get(self, *args, **kwargs):
     result = []
     for address in Address.objects.filter(
             owner=self.request.user
     ):  # Could have this in custom object manager
         logging.info(f'{address.address} {address.crypto}')
         result.append(
             BlockchainClient.address_balance(crypto=address.crypto,
                                              address=address.address))
     return Response(data=result)
Exemple #2
0
 def test_eth_should_parse_address_balance_into_common_format(self, mock):
     mock.return_value = StubResponse({
         "0xaa62dc6cd0123d5bb1e080e61f5fe508b7c8744e": {
             "balance": "5838070680000000000",
             "nonce": 5
         }
     })
     hash = '0xaa62dc6cd0123d5bb1e080e61f5fe508b7c8744e'
     result = BlockchainClient.address_balance('eth', hash)
     mock.assert_called_once_with(
         f'https://api.blockchain.info/eth/account/{hash}/balance')
     expected = {
         'address': hash,
         'crypto': 'eth',
         'balance': 5838070680000000000
     }
     self.assertDictEqual(result, expected)
Exemple #3
0
 def test_btc_should_parse_address_balance_into_common_format(self, mock):
     mock.return_value = StubResponse({
         "address": "bc1q8c0wvzxjfeuzr6xhp7xyxjxjh8r0dsc5ph224d",
         "confirmed": 0,
         "unconfirmed": 0,
         "utxo": 0,
         "txs": 4,
         "received": 562685
     })
     hash = 'bc1q8c0wvzxjfeuzr6xhp7xyxjxjh8r0dsc5ph224d'
     result = BlockchainClient.address_balance('btc', hash)
     mock.assert_called_once_with(
         f'https://api.blockchain.info/haskoin-store/btc/address/{hash}/balance'
     )
     expected = {
         'address': 'bc1q8c0wvzxjfeuzr6xhp7xyxjxjh8r0dsc5ph224d',
         'crypto': 'btc',
         'balance': 0
     }
     self.assertDictEqual(result, expected)
Exemple #4
0
 def test_bch_should_parse_address_balance_into_common_format(self, mock):
     mock.return_value = StubResponse({
         "address":
         "bitcoincash:qzh0095g66csxg04ms7zhcrg2tludgt3duksgjndts",
         "confirmed": 452481,
         "unconfirmed": 0,
         "utxo": 4,
         "txs": 333,
         "received": 87276583
     })
     hash = 'qzh0095g66csxg04ms7zhcrg2tludgt3duksgjndts'
     result = BlockchainClient.address_balance('bch', hash)
     mock.assert_called_once_with(
         f'https://api.blockchain.info/haskoin-store/bch/address/{hash}/balance'
     )
     expected = {
         'address':
         'bitcoincash:qzh0095g66csxg04ms7zhcrg2tludgt3duksgjndts',
         'crypto': 'bch',
         'balance': 452481
     }
     self.assertDictEqual(result, expected)