Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def fiat_to_bch(amount, fiat='usd'):
    satoshi = currency_to_satoshi_cached(amount, fiat)
    return satoshi_to_currency_cached(satoshi, 'bch')
Ejemplo n.º 4
0
def bch_to_fiat(amount, fiat='usd'):
    satoshi = currency_to_satoshi_cached(amount, 'bch')
    return satoshi_to_currency_cached(satoshi, fiat)
Ejemplo n.º 5
0
def bch_to_fiat(amount, currency):
    amount = amount * (10**8)
    conversion = satoshi_to_currency_cached(amount, currency)
    return conversion