def get_lightning_history(self):
    out = {}
    for (payment_hash, plist) in self.get_payments(status='settled').items():
        if (len(plist) == 0):
            continue
        key = payment_hash.hex()
        info = self.get_payment_info(payment_hash)
        (amount_msat, fee_msat, timestamp) = self.get_payment_value(info, plist)
        if (info is not None):
            label = self.wallet.get_label(key)
            direction = (('sent' if (info.direction == SENT) else 'received') if (len(plist) == 1) else 'self-payment')
        else:
            direction = 'forwarding'
            label = _('Forwarding')
        preimage = self.get_preimage(payment_hash).hex()
        item = {'type': 'payment', 'label': label, 'timestamp': (timestamp or 0), 'date': timestamp_to_datetime(timestamp), 'direction': direction, 'amount_msat': amount_msat, 'fee_msat': fee_msat, 'payment_hash': key, 'preimage': preimage}
        swap = self.swap_manager.get_swap(payment_hash)
        if swap:
            if swap.is_reverse:
                item['group_id'] = swap.spending_txid
                item['group_label'] = (('Reverse swap' + ' ') + self.config.format_amount_and_units(swap.lightning_amount))
            else:
                item['group_id'] = swap.funding_txid
                item['group_label'] = (('Forward swap' + ' ') + self.config.format_amount_and_units(swap.onchain_amount))
        out[payment_hash] = item
    return out
def get_lightning_history(self):
    out = {}
    for (payment_hash, plist) in self.get_payments(status='settled').items():
        if (len(plist) == 0):
            continue
        key = payment_hash.hex()
        info = self.get_payment_info(payment_hash)
        (amount_msat, fee_msat, timestamp) = self.get_payment_value(info, plist)
        if (info is not None):
            label = self.wallet.get_label(key)
            direction = (('sent' if (info.direction == SENT) else 'received') if (len(plist) == 1) else 'self-payment')
        else:
            direction = 'forwarding'
            label = _('Forwarding')
        preimage = self.get_preimage(payment_hash).hex()
        item = {'type': 'payment', 'label': label, 'timestamp': (timestamp or 0), 'date': timestamp_to_datetime(timestamp), 'direction': direction, 'amount_msat': amount_msat, 'fee_msat': fee_msat, 'payment_hash': key, 'preimage': preimage}
        swap = self.swap_manager.get_swap(payment_hash)
        if swap:
            if swap.is_reverse:
                item['group_id'] = swap.spending_txid
                item['group_label'] = (('Reverse swap' + ' ') + self.config.format_amount_and_units(swap.lightning_amount))
            else:
                item['group_id'] = swap.funding_txid
                item['group_label'] = (('Forward swap' + ' ') + self.config.format_amount_and_units(swap.onchain_amount))
        out[payment_hash] = item
    return out