Beispiel #1
0
 def get_unspent(cls, address):
     r = requests.get(cls.MAIN_UNSPENT_API.format(address),
                      timeout=DEFAULT_TIMEOUT)
     if r.status_code != 200:  # pragma: no cover
         raise ConnectionError
     return [
         Unspent(currency_to_satoshi(tx['amount'],
                                     'btc'), tx['confirmations'],
                 tx['scriptPubKey'], tx['txid'], tx['vout'])
         for tx in r.json()
     ]
Beispiel #2
0
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_UNSPENT_API.format(address) + '?limit=1000',
                      timeout=DEFAULT_TIMEOUT)
     if r.status_code != 200:  # pragma: no cover
         raise ConnectionError
     return [
         Unspent(currency_to_satoshi(tx['value'],
                                     'btc'), tx['confirmations'],
                 tx['script_pub_key']['hex'], tx['txid'], tx['n'])
         for tx in r.json()['unspent']
     ]
Beispiel #3
0
 def _get_unspent(cls, network, address):
     url = "{endpoint}/{address}".format(
         endpoint=cls.MAIN_TRANSACTIONS_UNSPENT, address=address)
     r = requests.get(url, timeout=DEFAULT_TIMEOUT)
     if r.status_code != 200:
         raise ConnectionError
     return [
         Unspent(currency_to_satoshi(tx['value'],
                                     'ltc'), tx['confirmations'],
                 tx['script_hex'], tx['txid'], tx['output_no'])
         for tx in r.json()['data']["txs"]
     ]
Beispiel #4
0
 def _get_unspent(cls, network, address, token):
     loop = True
     data = []
     offset = 0
     while loop:
         url = "{endpoint}/{address}?pageSize=50&offset={offset}".format(
             endpoint=cls.MAIN_TRANSACTIONS, address=address, offset=offset)
         r = requests.get(url,
                          timeout=DEFAULT_TIMEOUT,
                          headers={'x-api-key': token})
         if r.status_code == 200:
             if len(r.json()) == 0:
                 loop = False
             else:
                 for i in r.json():
                     data.append(i)
         else:
             raise ConnectionError
         offset = 50
     final = []
     indexes = [0, 1]
     for i in data:
         for j in indexes:
             url = "{endpoint}/{hash}/{index}".format(
                 endpoint=cls.MAIN_TRANSACTIONS_UNSPENT,
                 hash=i['hash'],
                 index=j)
             r = requests.get(url,
                              timeout=DEFAULT_TIMEOUT,
                              headers={'x-api-key': token})
             if r.status_code == 200 and r.json()['address'] == address:
                 final.append(
                     Unspent(
                         currency_to_satoshi(r.json()['value'], 'satoshi'),
                         10,
                         r.json()['script'],
                         r.json()['hash'],
                         r.json()['index']))
     return final