コード例 #1
0
    def get_unspent_testnet(cls, address):
        endpoint = cls.TEST_UNSPENT_API + "&limit=100"

        unspents = []

        r = requests.get(endpoint.format(address), timeout=DEFAULT_TIMEOUT)
        if r.status_code != 200:  # pragma: no cover
            raise ConnectionError

        response = r.json()

        while len(response) > 0:
            unspents.extend(
                Unspent(
                    currency_to_satoshi(tx['value'], 'satoshi'),
                    tx['confirmations'],
                    tx['script'],
                    tx['mintTxid'],
                    tx['mintIndex'],
                )
                for tx in response
            )
            response = requests.get(
                endpoint.format(address) + "&since={}".format(response[-1]['_id']), timeout=DEFAULT_TIMEOUT
            ).json()

        return unspents
コード例 #2
0
ファイル: services.py プロジェクト: shekkbuilder/bit
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_UNSPENT_API + address,
                      timeout=DEFAULT_TIMEOUT)
     return [
         Unspent(currency_to_satoshi(tx['amount'], 'btc'),
                 tx['confirmations'], tx['script'], tx['tx'], tx['n'])
         for tx in r.json()['data']['unspent']
     ]
コード例 #3
0
ファイル: services.py プロジェクト: shekkbuilder/bit
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_UNSPENT_API.format(address),
                      timeout=DEFAULT_TIMEOUT)
     return [
         Unspent(currency_to_satoshi(tx['amount'],
                                     'btc'), tx['confirmations'],
                 tx['scriptPubKey'], tx['txid'], tx['vout'])
         for tx in r.json()
     ]
コード例 #4
0
ファイル: services.py プロジェクト: shekkbuilder/bit
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_UNSPENT_API.format(address) + '?limit=1000',
                      timeout=DEFAULT_TIMEOUT)
     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']
     ]
コード例 #5
0
 def get_balance_testnet(cls, address: str) -> int:
     r = requests.get(cls.TEST_BALANCE_API.format(address),
                      timeout=DEFAULT_TIMEOUT)
     if r.status_code != 200:  # pragma: no cover
         raise ConnectionError
     try:
         return currency_to_satoshi(r.json() / 10**8, "ppc")
     except:
         return 0
コード例 #6
0
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_UNSPENT_API + 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['script'], tx['tx'], tx['n'])
         for tx in r.json()['data']['unspent']
     ]
コード例 #7
0
    def get_unspent_testnet(cls, address):
        txs_per_page = 1000
        payload = {'limit': str(txs_per_page)}
        r = requests.get(cls.TEST_UNSPENT_API.format(address), params=payload, timeout=DEFAULT_TIMEOUT)
        if r.status_code != 200:  # pragma: no cover
            raise ConnectionError

        response = r.json()

        unspents = []
        next_link = None

        if 'unspent' in response:
            unspents.extend(
                Unspent(
                    currency_to_satoshi(tx['value'], 'btc'),
                    tx['confirmations'],
                    tx['script_pub_key']['hex'],
                    tx['txid'],
                    tx['n'],
                )
                for tx in response['unspent']
            )
            next_link = response['paging']['next_link']

        while next_link:
            r = requests.get(next_link, params=payload, timeout=DEFAULT_TIMEOUT)
            if r.status_code != 200:  # pragma: no cover
                raise ConnectionError
            response = r.json()
            unspents.extend(
                Unspent(
                    currency_to_satoshi(tx['value'], 'btc'),
                    tx['confirmations'],
                    tx['script_pub_key']['hex'],
                    tx['txid'],
                    tx['n'],
                )
                for tx in response['unspent']
            )
            next_link = response['paging']['next_link']

        return unspents
コード例 #8
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()
     ]
コード例 #9
0
 def get_unspent(cls, address):
     r = requests.get(cls.MAIN_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']
     ]
コード例 #10
0
 def get_unspent(self, address):
     r = self.listunspent(0, 9999999, [address])
     return [
         Unspent(
             currency_to_satoshi(tx["amount"], "btc"),
             tx["confirmations"],
             tx["scriptPubKey"],
             tx["txid"],
             tx["vout"],
         ) for tx in r
     ]
コード例 #11
0
 def get_unspent_testnet(cls, address):
     r = requests.get(cls.TEST_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()
     ]
コード例 #12
0
ファイル: services.py プロジェクト: shawngustaw/lit
 def _get_unspent(cls, network, address):
     url = "{endpoint}{network}/{address}".format(
         endpoint=cls.MAIN_TRANSACTIONS_UNSPENT,
         network=network,
         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"]
     ]
コード例 #13
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"]
     ]
コード例 #14
0
    def get_unspent(cls, address: str) -> list:

        r = requests.get(cls.MAIN_UNSPENT_API.format(address),
                         timeout=DEFAULT_TIMEOUT)
        if r.status_code != 200:  # pragma: no cover
            raise ConnectionError

        try:
            return [
                Unspent(  # divide by 10**8 because explorer handles the decimals wrong (extra 2 zeros)
                    currency_to_satoshi(tx["value"] / 10**8, "ppc"),
                    1,  # presume 1 confirmation
                    tx["script"],
                    tx["tx_hash"],
                    tx["tx_ouput_n"],
                ) for tx in r.json()['unspent_outputs']
            ]
        except KeyError:
            return []
コード例 #15
0
 def get_balance_testnet(cls, address):
     r = requests.get(cls.TEST_BALANCE_API + address,
                      timeout=DEFAULT_TIMEOUT)
     if r.status_code != 200:  # pragma: no cover
         raise ConnectionError
     return currency_to_satoshi(r.json()['data']['balance'], 'btc')
コード例 #16
0
ファイル: services.py プロジェクト: shekkbuilder/bit
 def get_balance_testnet(cls, address):
     r = requests.get(cls.TEST_BALANCE_API + address,
                      timeout=DEFAULT_TIMEOUT)
     return currency_to_satoshi(r.json()['data']['balance'], 'btc')