def get_unspent(cls, address): r = requests.get(cls.MAIN_UNSPENT_API.format(address), timeout=DEFAULT_TIMEOUT) r.raise_for_status() # pragma: no cover return [ Unspent(currency_to_satoshi(tx['amount'], 'bch'), tx['confirmations'], tx['scriptPubKey'], tx['txid'], tx['vout']) for tx in r.json() ]
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'], 'bch'), tx['confirmations'], tx['scriptPubKey'], tx['txid'], tx['vout']) for tx in r.json() ]
def get_unspent(cls, address): address = address.replace('bitcoincash:', '') r = requests.get(cls.MAIN_UNSPENT_API.format(address), timeout=DEFAULT_TIMEOUT) r.raise_for_status() # pragma: no cover return [ Unspent(currency_to_satoshi(tx['value'], 'satoshi'), tx['confirmations'], tx['script'], tx['mintTxid'], tx['mintIndex']) for tx in r.json() ]
def get_unspent(cls, address, network): API = cls.network_endpoint(network) + cls.UNSPENT_PATH r = requests.get(API.format(address), timeout=DEFAULT_TIMEOUT) r.raise_for_status() return [ Unspent( currency_to_satoshi(tx["amount"], "bch"), tx["confirmations"], r.json()["scriptPubKey"], tx["txid"], tx["vout"], ) for tx in r.json()["utxos"] ]
def get_unspent(cls, address): # As of 2018-05-16, cashexplorer.bitcoin.com only supports legacy addresses. address = cashaddress.to_legacy_address(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'], 'bch'), tx['confirmations'], tx['scriptPubKey'], tx['txid'], tx['vout']) for tx in r.json() ]
def get_unspent(cls, address): if not cls.NEW_ADDRESS_SUPPORTED: address = cashaddress.to_legacy_address(address) r = requests.get((cls.MAIN_ENDPOINT+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'], 'bch'), tx['confirmations'], tx['scriptPubKey'], tx['txid'], tx['vout']) for tx in r.json() ]
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 unspents = [] for tx in r.json(): # In weird conditions, the API will send back unspents without a scriptPubKey. if 'scriptPubKey' in tx: unspents.append( Unspent(currency_to_satoshi(tx['amount'], 'bch'), tx['confirmations'], tx['scriptPubKey'], tx['txid'], tx['vout'])) else: logging.warning('Unspent without scriptPubKey.') return unspents
def get_unspent_testnet(cls, address): address = address.replace('bchtest:', '') r = requests.get(cls.TEST_UNSPENT_API.format(address), timeout=DEFAULT_TIMEOUT) r.raise_for_status() # pragma: no cover unspents = [] for tx in r.json(): # In weird conditions, the API will send back unspents # without a scriptPubKey. if 'script' in tx: unspents.append( Unspent(currency_to_satoshi(tx['value'], 'satoshi'), tx['confirmations'], tx['script'], tx['mintTxid'], tx['mintIndex'])) else: logging.warning('Unspent without scriptPubKey.') return unspents
def get_unspent(cls, address, network): address = cls.remove_prefix(address) API = cls.network_endpoint(network) + cls.UNSPENT_API r = requests.get(API.format(address), timeout=DEFAULT_TIMEOUT) r.raise_for_status() unspents = [] for tx in r.json(): # In weird conditions, the API will send back unspents # without a scriptPubKey. if "script" in tx: unspents.append( Unspent( currency_to_satoshi(tx["value"], "satoshi"), tx["confirmations"], tx["script"], tx["mintTxid"], tx["mintIndex"], )) else: logging.warning("Unspent without scriptPubKey.") return unspents
def to_satoshi(coins): return currency_to_satoshi(coins, 'bch')
def from_bits(coins): return currency_to_satoshi(coins, 'mbch')