def balance_as(self, currency): """Returns your balance as a formatted string in a particular currency. :param currency: One of the :ref:`supported currencies`. :type currency: ``str`` :rtype: ``str`` """ return satoshi_to_currency_cached(self.balance, currency)
def get_transaction_details(id): transaction = NetworkAPI.get_transaction(id) is_sent = key.address in list( map(lambda txin: txin.address, transaction.inputs)) address = None amount = None if is_sent: address = list(map(lambda txout: txout.address, transaction.outputs))[0] amount = '{:f}'.format(transaction.outputs[0].amount + transaction.amount_fee) else: address = list(map(lambda txin: txin.address, transaction.inputs))[0] amount = '{:f}'.format( next(txout.amount for txout in transaction.outputs if txout.address == key.address)) amount = satoshi_to_currency_cached(int(amount), 'bch') tx = { 'id': transaction.txid, 'inputs': list(map(lambda txin: '{:f}'.format(txin.amount), transaction.inputs)), 'outputs': list( map(lambda txout: '{:f}'.format(txout.amount), transaction.outputs)), 'is_sent': is_sent, 'address': address, 'amount': amount } jsontx = json.dumps(tx) return jsontx
def fiat_to_bch(amount, fiat='usd'): satoshi = currency_to_satoshi_cached(amount, fiat) return satoshi_to_currency_cached(satoshi, 'bch')
def bch_to_fiat(amount, fiat='usd'): satoshi = currency_to_satoshi_cached(amount, 'bch') return satoshi_to_currency_cached(satoshi, fiat)
def bch_to_fiat(amount, currency): amount = amount * (10**8) conversion = satoshi_to_currency_cached(amount, currency) return conversion