def get_onchain_history(self):
    current_height = self.wallet.get_local_height()
    out = {}
    for chan in self.channels.values():
        item = chan.get_funding_height()
        if (item is None):
            continue
        if (not self.lnwatcher):
            continue
        (funding_txid, funding_height, funding_timestamp) = item
        tx_height = self.lnwatcher.get_tx_height(funding_txid)
        item = {'channel_id': bh2u(chan.channel_id), 'type': 'channel_opening', 'label': (self.wallet.get_label_for_txid(funding_txid) or ((_('Open channel') + ' ') + chan.get_id_for_log())), 'txid': funding_txid, 'amount_msat': chan.balance(LOCAL, ctn=0), 'direction': 'received', 'timestamp': tx_height.timestamp, 'date': timestamp_to_datetime(tx_height.timestamp), 'fee_sat': None, 'fee_msat': None, 'height': tx_height.height, 'confirmations': tx_height.conf}
        out[funding_txid] = item
        item = chan.get_closing_height()
        if (item is None):
            continue
        (closing_txid, closing_height, closing_timestamp) = item
        tx_height = self.lnwatcher.get_tx_height(closing_txid)
        item = {'channel_id': bh2u(chan.channel_id), 'txid': closing_txid, 'label': (self.wallet.get_label_for_txid(closing_txid) or ((_('Close channel') + ' ') + chan.get_id_for_log())), 'type': 'channel_closure', 'amount_msat': (- chan.balance_minus_outgoing_htlcs(LOCAL)), 'direction': 'sent', 'timestamp': tx_height.timestamp, 'date': timestamp_to_datetime(tx_height.timestamp), 'fee_sat': None, 'fee_msat': None, 'height': tx_height.height, 'confirmations': tx_height.conf}
        out[closing_txid] = item
    settled_payments = self.get_payments(status='settled')
    for (payment_hash_hex, swap) in self.swap_manager.swaps.items():
        txid = (swap.spending_txid if swap.is_reverse else swap.funding_txid)
        if (txid is None):
            continue
        payment_hash = bytes.fromhex(payment_hash_hex)
        if (payment_hash in settled_payments):
            plist = settled_payments[payment_hash]
            info = self.get_payment_info(payment_hash)
            (amount_msat, fee_msat, timestamp) = self.get_payment_value(info, plist)
        else:
            amount_msat = 0
        label = ('Reverse swap' if swap.is_reverse else 'Forward swap')
        delta = (current_height - swap.locktime)
        if ((not swap.is_redeemed) and (swap.spending_txid is None) and (delta < 0)):
            label += f' (refundable in {(- delta)} blocks)'
        out[txid] = {'txid': txid, 'group_id': txid, 'amount_msat': 0, 'type': 'swap', 'label': (self.wallet.get_label_for_txid(txid) or label)}
    return out
def get_onchain_history(self):
    current_height = self.wallet.get_local_height()
    out = {}
    for chan in self.channels.values():
        item = chan.get_funding_height()
        if (item is None):
            continue
        if (not self.lnwatcher):
            continue
        (funding_txid, funding_height, funding_timestamp) = item
        tx_height = self.lnwatcher.get_tx_height(funding_txid)
        item = {'channel_id': bh2u(chan.channel_id), 'type': 'channel_opening', 'label': (self.wallet.get_label_for_txid(funding_txid) or ((_('Open channel') + ' ') + chan.get_id_for_log())), 'txid': funding_txid, 'amount_msat': chan.balance(LOCAL, ctn=0), 'direction': 'received', 'timestamp': tx_height.timestamp, 'date': timestamp_to_datetime(tx_height.timestamp), 'fee_sat': None, 'fee_msat': None, 'height': tx_height.height, 'confirmations': tx_height.conf}
        out[funding_txid] = item
        item = chan.get_closing_height()
        if (item is None):
            continue
        (closing_txid, closing_height, closing_timestamp) = item
        tx_height = self.lnwatcher.get_tx_height(closing_txid)
        item = {'channel_id': bh2u(chan.channel_id), 'txid': closing_txid, 'label': (self.wallet.get_label_for_txid(closing_txid) or ((_('Close channel') + ' ') + chan.get_id_for_log())), 'type': 'channel_closure', 'amount_msat': (- chan.balance_minus_outgoing_htlcs(LOCAL)), 'direction': 'sent', 'timestamp': tx_height.timestamp, 'date': timestamp_to_datetime(tx_height.timestamp), 'fee_sat': None, 'fee_msat': None, 'height': tx_height.height, 'confirmations': tx_height.conf}
        out[closing_txid] = item
    settled_payments = self.get_payments(status='settled')
    for (payment_hash_hex, swap) in self.swap_manager.swaps.items():
        txid = (swap.spending_txid if swap.is_reverse else swap.funding_txid)
        if (txid is None):
            continue
        payment_hash = bytes.fromhex(payment_hash_hex)
        if (payment_hash in settled_payments):
            plist = settled_payments[payment_hash]
            info = self.get_payment_info(payment_hash)
            (amount_msat, fee_msat, timestamp) = self.get_payment_value(info, plist)
        else:
            amount_msat = 0
        label = ('Reverse swap' if swap.is_reverse else 'Forward swap')
        delta = (current_height - swap.locktime)
        if ((not swap.is_redeemed) and (swap.spending_txid is None) and (delta < 0)):
            label += f' (refundable in {(- delta)} blocks)'
        out[txid] = {'txid': txid, 'group_id': txid, 'amount_msat': 0, 'type': 'swap', 'label': (self.wallet.get_label_for_txid(txid) or label)}
    return out