Esempio n. 1
0
def _txlist_summary(txlist):
    txns = sorted(txlist['transactions'], key=lambda tx: tx['created_at_ts'])
    balance = collections.defaultdict(int)
    lines = []
    for tx in txns:
        confs = confs_str(tx['block_height'])
        fee_rate = tx['fee'] / tx['transaction_vsize']
        if tx['type'] == 'outgoing':
            # Currently only supports txs which are all one-way
            tx['satoshi'] = {asset: -tx['satoshi'][asset] for asset in tx['satoshi']}
        for asset, amount in tx['satoshi'].items():
            balance[asset] += amount
            ts = tx['created_at_ts']
            created_at = datetime.fromtimestamp(ts // 1000000, tz=timezone.utc).replace(tzinfo=None)
            lines.append(f"{tx['txhash']} {created_at} ({confs}) {amount:+} "\
                f"{balance[asset]} {asset} fee={tx['fee']}@{fee_rate:.2f}")
    return '\n'.join(lines)
Esempio n. 2
0
def format_utxo(utxo):
    confs = confs_str(utxo['block_height'])
    s = f"{utxo['satoshi']}"
    s += f" {utxo['txhash']}:{utxo['pt_idx']} {utxo['address_type']} {confs} {utxo['address']}"
    return s