Exemplo n.º 1
0
 def history_tab_update(self, tx, entry):
     if not self.config_history():
         return
     tx_hash, conf, value, timestamp, balance = tx
     date = timestamp_to_datetime(timestamp)
     if not date:
         date = timestamp_to_datetime(0)
     for amount in [value, balance]:
         text = self.historical_value_str(self.ccy, amount, date)
         entry.append("%16s" % text)
Exemplo n.º 2
0
 def history_tab_update(self, tx, entry):
     if not self.show_history():
         return
     tx_hash, height, conf, timestamp, value, balance = tx
     if conf <= 0:
         date = timestamp_to_datetime(time.time())
     else:
         date = timestamp_to_datetime(timestamp)
     for amount in [value, balance]:
         text = self.historical_value_str(amount, date)
         entry.append(text)
Exemplo n.º 3
0
 def history_tab_update(self, tx, entry):
     if not self.show_history():
         return
     tx_hash, height, conf, timestamp, value, balance = tx
     if conf <= 0:
         date = timestamp_to_datetime(time.time())
     else:
         date = timestamp_to_datetime(timestamp)
     for amount in [value, balance]:
         text = self.historical_value_str(amount, date)
         entry.append(text)
Exemplo n.º 4
0
 def on_update(self):
     self.wallet = self.parent.wallet
     h = self.wallet.get_history(self.get_domain())
     item = self.currentItem()
     current_tx = item.data(0, Qt.UserRole) if item else None
     self.clear()
     fx = self.parent.fx
     if fx: fx.history_used_spot = False
     for h_item in h:
         tx_hash, height, conf, timestamp, value, balance = h_item
         status, status_str = self.wallet.get_tx_status(
             tx_hash, height, conf, timestamp)
         has_invoice = self.wallet.invoices.paid.get(tx_hash)
         icon = QIcon(":icons/" + TX_ICONS[status])
         v_str = self.parent.format_amount(value, True, whitespaces=True)
         balance_str = self.parent.format_amount(balance, whitespaces=True)
         label = self.wallet.get_label(tx_hash)
         entry = ['', tx_hash, status_str, label, v_str, balance_str]
         fiat_value = None
         if value is not None and fx and fx.show_history():
             date = timestamp_to_datetime(
                 time.time() if conf <= 0 else timestamp)
             fiat_value = self.wallet.get_fiat_value(tx_hash, fx.ccy)
             if not fiat_value:
                 fiat_value = fx.historical_value(value, date)
                 fiat_default = True
             else:
                 fiat_default = False
             value_str = fx.format_fiat(fiat_value)
             entry.append(value_str)
             # fixme: should use is_mine
             if value < 0:
                 ap, lp = self.wallet.capital_gain(tx_hash,
                                                   fx.timestamp_rate,
                                                   fx.ccy)
                 cg = None if lp is None or ap is None else lp - ap
                 entry.append(fx.format_fiat(ap))
                 entry.append(fx.format_fiat(cg))
         item = QTreeWidgetItem(entry)
         item.setIcon(0, icon)
         item.setToolTip(
             0,
             str(conf) + " confirmation" + ("s" if conf != 1 else ""))
         if has_invoice:
             item.setIcon(3, QIcon(":icons/seal"))
         for i in range(len(entry)):
             if i > 3:
                 item.setTextAlignment(i, Qt.AlignRight)
             if i != 2:
                 item.setFont(i, QFont(MONOSPACE_FONT))
         if value and value < 0:
             item.setForeground(3, QBrush(QColor("#BC1E1E")))
             item.setForeground(4, QBrush(QColor("#BC1E1E")))
         if fiat_value and not fiat_default:
             item.setForeground(6, QBrush(QColor("#1E1EFF")))
         if tx_hash:
             item.setData(0, Qt.UserRole, tx_hash)
         self.insertTopLevelItem(0, item)
         if current_tx == tx_hash:
             self.setCurrentItem(item)
Exemplo n.º 5
0
    def parse_history(self, items):
        for item in items:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf > 0:
                try:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = _("error")
            if conf == -1:
                time_str = _('unverified')
                icon = "atlas://gui/kivy/theming/light/close"
            elif conf == 0:
                time_str = _('pending')
                icon = "atlas://gui/kivy/theming/light/unconfirmed"
            elif conf < 6:
                conf = max(1, conf)
                icon = "atlas://gui/kivy/theming/light/clock{}".format(conf)
            else:
                icon = "atlas://gui/kivy/theming/light/confirmed"

            label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
            date = timestamp_to_datetime(timestamp)
            rate = run_hook('history_rate', date)
            if self.app.fiat_unit:
                quote_text = "..." if rate is None else "{0:.3} {1}".format(Decimal(value) / 100000000 * Decimal(rate), self.app.fiat_unit)
            else:
                quote_text = ''
            yield (conf, icon, time_str, label, value, tx_hash, quote_text)
Exemplo n.º 6
0
 def get_card(self, tx_hash, height, conf, timestamp, value, balance):
     status, status_str = self.app.wallet.get_tx_status(
         tx_hash, height, conf, timestamp)
     icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
     label = self.app.wallet.get_label(tx_hash) if tx_hash else _(
         'Pruned transaction outputs')
     date = timestamp_to_datetime(timestamp)
     ri = self.cards.get(tx_hash)
     if ri is None:
         ri = Factory.HistoryItem()
         ri.screen = self
         ri.tx_hash = tx_hash
         self.cards[tx_hash] = ri
     ri.icon = icon
     ri.date = status_str
     ri.message = label
     ri.confirmations = conf
     if value is not None:
         ri.is_mine = value < 0
         if value < 0: value = -value
         ri.amount = self.app.format_amount_and_units(value)
         if self.app.fiat_unit and date:
             ri.quote_text = self.app.fx.historical_value_str(
                 value, date) + ' ' + self.app.fx.ccy
     return ri
Exemplo n.º 7
0
    def parse_history(self, items):
        for item in items:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf > 0:
                try:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = _("error")
            if conf == -1:
                time_str = _('Not Verified')
                icon = "atlas://gui/kivy/theming/light/close"
            elif conf == 0:
                time_str = _('Unconfirmed')
                icon = "atlas://gui/kivy/theming/light/unconfirmed"
            elif conf < 6:
                conf = max(1, conf)
                icon = "atlas://gui/kivy/theming/light/clock{}".format(conf)
            else:
                icon = "atlas://gui/kivy/theming/light/confirmed"

            label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
            date = timestamp_to_datetime(timestamp)
            quote_text = ''
            if self.app.fiat_unit and date:
                rate = run_hook('history_rate', date)
                if rate:
                    s = run_hook('value_str', value, rate)
                    quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
            yield (conf, icon, time_str, label, value, tx_hash, quote_text)
Exemplo n.º 8
0
    def parse_history(self, items):
        for item in items:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf > 0:
                try:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(" ")[:-3]
                except Exception:
                    time_str = _("error")
            if conf == -1:
                time_str = _("unverified")
                icon = "atlas://gui/kivy/theming/light/close"
            elif conf == 0:
                time_str = _("pending")
                icon = "atlas://gui/kivy/theming/light/unconfirmed"
            elif conf < 6:
                conf = max(1, conf)
                icon = "atlas://gui/kivy/theming/light/clock{}".format(conf)
            else:
                icon = "atlas://gui/kivy/theming/light/confirmed"

            label = self.app.wallet.get_label(tx_hash) if tx_hash else _("Pruned transaction outputs")
            date = timestamp_to_datetime(timestamp)
            rate = run_hook("history_rate", date)
            if self.app.fiat_unit:
                s = run_hook("historical_value_str", value, date)
                quote_text = "..." if s is None else s + " " + self.app.fiat_unit
            else:
                quote_text = ""
            yield (conf, icon, time_str, label, value, tx_hash, quote_text)
Exemplo n.º 9
0
 def get_card(self, tx_hash, height, conf, timestamp, value, balance):
     status, status_str = self.app.wallet.get_tx_status(
         tx_hash, height, conf, timestamp)
     icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
     label = self.app.wallet.get_label(tx_hash) if tx_hash else _(
         'Pruned transaction outputs')
     date = timestamp_to_datetime(timestamp)
     ri = self.cards.get(tx_hash)
     if ri is None:
         ri = Factory.HistoryItem()
         ri.screen = self
         ri.tx_hash = tx_hash
         self.cards[tx_hash] = ri
     ri.icon = icon
     ri.date = status_str
     ri.message = label
     ri.value = value or 0
     ri.value_known = value is not None
     ri.confirmations = conf
     if self.app.fiat_unit and date:
         rate = run_hook('history_rate', date)
         if rate:
             s = run_hook('value_str', value, rate)
             ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
     return ri
Exemplo n.º 10
0
    def showTransaction_desc_(self, txraw, desc) -> None:
        tx = Transaction(txraw)
        tx.deserialize()
        tx_hash, status_, label_, can_broadcast, can_bump, amount, fee, height, conf, timestamp, exp_n = wallet(
        ).get_tx_info(tx)
        # print("send: status_",status_,"label_",label_,"amount",amount,"conf",conf)
        size = tx.estimated_size()
        conf = 0 if conf is None else conf
        timestamp = time.time() if timestamp is None else timestamp
        status, status_str = (
            status_, _("Unsigned")
        )  # wallet().get_tx_status(tx_hash, height, conf, timestamp)
        doFX = fx() and fx().is_enabled()
        ccy = fx().get_currency() if doFX else None
        fiat_amount_str = str(self.fiat.text) if doFX else None
        # HistoryEntry = namedtuple("HistoryEntry", "tx tx_hash status_str label v_str balance_str date ts conf status value fiat_amount fiat_balance fiat_amount_str fiat_balance_str ccy status_image")
        entry = HistoryEntry(
            tx, tx_hash, status_str, str(desc), self.amt.text, "",
            timestamp_to_datetime(time.time() if conf <= 0 else timestamp),
            timestamp, conf, status, amount, None, None, fiat_amount_str, None,
            ccy, None)

        def newLabel(l):
            self.descDel.text = l

        self.navigationController.pushViewController_animated_(
            txdetail.CreateTxDetailWithEntry(entry, on_label=newLabel), True)

        # For modal do the following:
        # self.presentViewController_animated_completion_(txdetail.CreateTxDetailWithEntry(entry, on_label = newLabel, asModalNav = True), True, None)
        '''
Exemplo n.º 11
0
    def update_tx_mined_status(self, tx_hash: str, tx_mined_info: TxMinedInfo):

        for key in self.transactions:
            if tx_hash == key.split('_')[0]:
                try:
                    row = self.transactions.pos_from_key(tx_hash)
                    tx_item = self.transactions[tx_hash]
                    self.tx_status_cache[
                        tx_hash] = self.parent.wallet.get_tx_status(
                            tx_hash, tx_mined_info)
                    tx_item.update({
                        'confirmations':
                        tx_mined_info.conf,
                        'timestamp':
                        tx_mined_info.timestamp,
                        'txpos_in_block':
                        tx_mined_info.txpos,
                        'date':
                        timestamp_to_datetime(tx_mined_info.timestamp),
                    })
                    topLeft = self.createIndex(row, 0)
                    bottomRight = self.createIndex(row,
                                                   len(HistoryColumns) - 1)
                    self.dataChanged.emit(topLeft, bottomRight)
                except KeyError:
                    pass
Exemplo n.º 12
0
    def parse_history(self, items):
        for item in items:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf > 0:
                try:
                    time_str = datetime.datetime.fromtimestamp(
                        timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = _("error")
            if conf == -1:
                time_str = _('Not Verified')
                icon = "atlas://gui/kivy/theming/light/close"
            elif conf == 0:
                time_str = _('Unconfirmed')
                icon = "atlas://gui/kivy/theming/light/unconfirmed"
            elif conf < 6:
                conf = max(1, conf)
                icon = "atlas://gui/kivy/theming/light/clock{}".format(conf)
            else:
                icon = "atlas://gui/kivy/theming/light/confirmed"

            label = self.app.wallet.get_label(tx_hash) if tx_hash else _(
                'Pruned transaction outputs')
            date = timestamp_to_datetime(timestamp)
            quote_text = ''
            if self.app.fiat_unit and date:
                rate = run_hook('history_rate', date)
                if rate:
                    s = run_hook('value_str', value, rate)
                    quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
            yield (conf, icon, time_str, label, value, tx_hash, quote_text)
Exemplo n.º 13
0
 def update_tx_mined_status(self, tx_hash: str, tx_mined_info: TxMinedInfo):
     try:
         row = self.transactions.pos_from_key(tx_hash)
         tx_item = self.transactions[tx_hash]
     except KeyError:
         return
     self.tx_status_cache[tx_hash] = self.parent.wallet.get_tx_status(tx_hash, tx_mined_info)
     tx_item.update({
         'confirmations':  tx_mined_info.conf,
         'timestamp':      tx_mined_info.timestamp,
         'txpos_in_block': tx_mined_info.txpos,
         'date':           timestamp_to_datetime(tx_mined_info.timestamp),
     })
     topLeft = self.createIndex(row, 0)
     bottomRight = self.createIndex(row, len(HistoryColumns) - 1)
     self.dataChanged.emit(topLeft, bottomRight)
 def on_update(self):
     self.wallet = self.parent.wallet
     h = self.wallet.get_history(self.get_domain())
     item = self.currentItem()
     current_tx = item.data(0, Qt.UserRole).toString() if item else None
     self.clear()
     fx = self.parent.fx
     if fx: fx.history_used_spot = False
     for h_item in h:
         tx_hash, height, conf, timestamp, value, balance = h_item
         status, status_str = self.wallet.get_tx_status(
             tx_hash, height, conf, timestamp)
         has_invoice = self.wallet.invoices.paid.get(tx_hash)
         icon = QIcon(":icons/" + TX_ICONS[status])
         v_str = self.parent.format_amount(value, True, whitespaces=True)
         balance_str = self.parent.format_amount(balance, whitespaces=True)
         label = self.wallet.get_label(tx_hash)
         entry = ['', tx_hash, status_str, label, v_str, balance_str]
         if fx and fx.show_history():
             date = timestamp_to_datetime(
                 time.time() if conf <= 0 else timestamp)
             for amount in [value, balance]:
                 text = fx.historical_value_str(amount, date)
                 entry.append(text)
         item = QTreeWidgetItem(entry)
         item.setIcon(0, icon)
         item.setToolTip(
             0,
             str(conf) + " confirmation" + ("s" if conf != 1 else ""))
         if has_invoice:
             item.setIcon(3, QIcon(":icons/seal"))
         for i in range(len(entry)):
             if i > 3:
                 item.setTextAlignment(i, Qt.AlignRight)
             if i != 2:
                 item.setFont(i, QFont(MONOSPACE_FONT))
                 item.setTextAlignment(i, Qt.AlignVCenter)
         if value < 0:
             item.setForeground(3, QBrush(QColor("#BC1E1E")))
             item.setForeground(4, QBrush(QColor("#BC1E1E")))
         if tx_hash:
             item.setData(0, Qt.UserRole, tx_hash)
         self.insertTopLevelItem(0, item)
         if current_tx == tx_hash:
             self.setCurrentItem(item)
Exemplo n.º 15
0
 def upgrade_timestamps_block(self, wallet, network):
     local_height = network.get_local_height()
     txid_pending = set([f.txid for f in self.proofs_storage_file.incomplete_proofs if f.status == "pending"])
     for txid in txid_pending:
         try:
             tx_height, timestamp, _ = wallet.verified_tx[txid]
             is_upgradable = (local_height - tx_height >= default_blocks_until_confirmed)
         except KeyError:
             is_upgradable = False
         if is_upgradable:  # txid -> block
             t = proof_from_txid_to_block(txid, tx_height, network)
             for f in self.proofs_storage_file.incomplete_proofs:
                 tf = roll_timestamp(f.detached_timestamp.timestamp)
                 if tf.msg == t.msg:
                     tf.merge(t)
                     f.status = "complete"
                     f.block = tx_height
                     f.date = timestamp_to_datetime(timestamp).strftime("%-d %B %Y")
                     f.write_ots()
                     # f.detached_timestamp = None
     self.update_storage()
Exemplo n.º 16
0
def CreateTxDetailWithTx(tx: Transaction,
                         on_label=None,
                         on_appear=None,
                         asModalNav=False) -> ObjCInstance:
    parent = gui.ElectrumGui.gui
    wallet = parent.wallet
    import time

    tx_hash, status_, label_, can_broadcast, can_bump, amount, fee, height, conf, timestamp, exp_n = wallet.get_tx_info(
        tx)
    size = tx.estimated_size()
    status_str = ""
    status = status_
    img = None
    if conf is not None:
        if tx_hash is not None and height is not None and timestamp is not None:
            status, status_str = wallet.get_tx_status(tx_hash, height, conf,
                                                      timestamp)
            if status is not None and status >= 0 and status < len(
                    StatusImages):
                img = StatusImages[status]
    else:
        conf = 0
    timestamp = time.time() if timestamp is None else timestamp
    doFX = False  # fx() and fx().is_enabled()
    ccy = None  # fx().get_currency() if doFX else None
    fiat_amount_str = None  # str(self.fiat.text) if doFX else None
    # HistoryEntry = namedtuple("HistoryEntry", "extra_data tx_hash status_str label v_str balance_str date ts conf status value fiat_amount fiat_balance fiat_amount_str fiat_balance_str ccy status_image")
    entry = HistoryEntry(
        tx, tx_hash, status_str, label_,
        parent.format_amount(amount) if amount is not None else
        _("Transaction unrelated to your wallet"), "",
        timestamp_to_datetime(time.time() if conf <= 0 else timestamp),
        timestamp, conf, status, amount, None, None, fiat_amount_str, None,
        ccy, img)

    return CreateTxDetailWithEntry(entry,
                                   on_label=on_label,
                                   on_appear=on_appear,
                                   asModalNav=asModalNav)
Exemplo n.º 17
0
 def on_update(self):
     self.wallet = self.parent.wallet
     h = self.wallet.get_history(self.get_domain())
     item = self.currentItem()
     current_tx = item.data(0, Qt.UserRole) if item else None
     self.clear()
     fx = self.parent.fx
     if fx: fx.history_used_spot = False
     for h_item in h:
         tx_hash, height, conf, timestamp, value, balance = h_item
         status, status_str = self.wallet.get_tx_status(tx_hash, height, conf, timestamp)
         has_invoice = self.wallet.invoices.paid.get(tx_hash)
         icon = QIcon(":icons/" + TX_ICONS[status])
         v_str = self.parent.format_amount(value, True, whitespaces=True)
         balance_str = self.parent.format_amount(balance, whitespaces=True)
         label = self.wallet.get_label(tx_hash)
         entry = ['', tx_hash, status_str, label, v_str, balance_str]
         if fx and fx.show_history():
             date = timestamp_to_datetime(time.time() if conf <= 0 else timestamp)
             for amount in [value, balance]:
                 text = fx.historical_value_str(amount, date)
                 entry.append(text)
         item = QTreeWidgetItem(entry)
         item.setIcon(0, icon)
         item.setToolTip(0, str(conf) + " confirmation" + ("s" if conf != 1 else ""))
         if has_invoice:
             item.setIcon(3, QIcon(":icons/seal"))
         for i in range(len(entry)):
             if i>3:
                 item.setTextAlignment(i, Qt.AlignRight)
             if i!=2:
                 item.setFont(i, QFont(MONOSPACE_FONT))
         if value and value < 0:
             item.setForeground(3, QBrush(QColor("#BC1E1E")))
             item.setForeground(4, QBrush(QColor("#BC1E1E")))
         if tx_hash:
             item.setData(0, Qt.UserRole, tx_hash)
         self.insertTopLevelItem(0, item)
         if current_tx == tx_hash:
             self.setCurrentItem(item)
Exemplo n.º 18
0
 def get_card(self, tx_hash, height, conf, timestamp, value, balance):
     status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
     icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
     label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
     date = timestamp_to_datetime(timestamp)
     ri = self.cards.get(tx_hash)
     if ri is None:
         ri = Factory.HistoryItem()
         ri.screen = self
         ri.tx_hash = tx_hash
         self.cards[tx_hash] = ri
     ri.icon = icon
     ri.date = status_str
     ri.message = label
     ri.confirmations = conf
     if value is not None:
         ri.is_mine = value < 0
         if value < 0: value = - value
         ri.amount = self.app.format_amount_and_units(value)
         if self.app.fiat_unit and date:
             ri.quote_text = self.app.fx.historical_value_str(value, date) + ' ' + self.app.fx.ccy
     return ri
Exemplo n.º 19
0
 def get_card(self, tx_hash, height, conf, timestamp, value, balance):
     status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
     icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
     label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
     date = timestamp_to_datetime(timestamp)
     ri = self.cards.get(tx_hash)
     if ri is None:
         ri = Factory.HistoryItem()
         ri.screen = self
         ri.tx_hash = tx_hash
         self.cards[tx_hash] = ri
     ri.icon = icon
     ri.date = status_str
     ri.message = label
     ri.value = value or 0
     ri.value_known = value is not None
     ri.confirmations = conf
     if self.app.fiat_unit and date:
         rate = run_hook('history_rate', date)
         if rate:
             s = run_hook('value_str', value, rate)
             ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
     return ri
Exemplo n.º 20
0
    def tableView_cellForRowAtIndexPath_(self, tv, indexPath):
        # todo: - allow for label editing (popup menu?)
        identifier = "TxDetailInOutCell"
        cell = tv.dequeueReusableCellWithIdentifier_(identifier)
        parent = gui.ElectrumGui.gui
        wallet = parent.wallet

        def format_amount(amt):
            return parent.format_amount(amt, whitespaces=False)

        def fx():
            return parent.daemon.fx if parent.daemon and parent.daemon.fx and parent.daemon.fx.show_history(
            ) else None

        base_unit = parent.base_unit()

        try:
            tx = utils.nspy_get(self)

            isInput = None
            x = None
            if tv.tag == self.tagin:
                isInput = True
                x = tx.inputs()[indexPath.row]
            elif tv.tag == self.tagout:
                isInput = False
                x = tx.get_outputs()[indexPath.row]
            else:
                raise ValueError(
                    "tv tag %d is neither input (%d) or output (%d) tag!" %
                    (int(tv.tag), int(self.tagin), int(self.tagout)))

            cell.address.text = ""
            cell.addressType.text = ""
            cell.detail.text = ""

            addr = None

            if isInput:
                if x['type'] == 'coinbase':
                    cell.addressType.text = "coinbase"
                    cell.address.text = "coinbase"
                else:
                    prevout_hash = x.get('prevout_hash')
                    prevout_n = x.get('prevout_n')
                    mytxt = ""
                    mytxt += prevout_hash[0:8] + '...'
                    mytxt += prevout_hash[-8:] + (":%-4d " % prevout_n)
                    addr = x['address']
                    if addr is None:
                        addr_text = _('unknown')
                    else:
                        addr_text = addr
                    cell.address.text = addr_text
                    if x.get('value') is not None:
                        v_in = x['value']
                        mytxt += format_amount(v_in) + ' ' + base_unit
                        if fx():
                            mytxt += ' (' + fx().historical_value_str(
                                v_in, timestamp_to_datetime(
                                    self.ts)) + " " + fx().get_currency() + ')'
                    cell.detail.text = mytxt.strip()
            else:
                addr, v = x
                cell.address.text = addr
                if v is not None:
                    cell.detail.text = (format_amount(v) + " " + base_unit + (
                        (' (' + fx().historical_value_str(
                            v, timestamp_to_datetime(self.ts)) + " " +
                         fx().get_currency() + ')') if fx() else '')).strip()

            typ = ''
            if is_address(addr):
                if wallet.is_mine(addr):
                    if wallet.is_change(addr):
                        typ = _("My Change Address")
                    else:
                        typ = _("My Receiving Address")
                else:
                    typ = _("External Address")
                    contact = contacts.Find(addr)
                    if contact:
                        typ += ', ' + _('Contact') + ": " + contact.name
            cell.addressType.text = typ
            cell.accessoryType = UITableViewCellAccessoryNone  # UITableViewCellAccessoryDisclosureIndicator#UITableViewCellAccessoryDetailDisclosureButton#UITableViewCellAccessoryDetailButton #
        except Exception as e:
            print("exception in %s: %s" % (__class__.name, str(e)))
            cell.addressType.text = ""
            cell.address.text = "Not found"
            cell.detail.text = ""
            cell.accessoryType = UITableViewCellAccessoryNone
        return cell
Exemplo n.º 21
0
def get_history(domain: list = None,
                statusImagesOverride: list = None,
                forceNoFX: bool = False) -> list:
    """ For a given set of addresses (or None for all addresses), builds a list of
        HistoryEntry """
    sImages = StatusImages if not statusImagesOverride or len(
        statusImagesOverride) < len(StatusImages) else statusImagesOverride
    parent = gui.ElectrumGui.gui
    wallet = parent.wallet
    daemon = parent.daemon
    if wallet is None or daemon is None:
        utils.NSLog(
            "get_history: wallet and/or daemon was None, returning early")
        return list()
    h = wallet.get_history(domain)
    fx = daemon.fx if daemon.fx and daemon.fx.show_history() else None
    history = list()
    ccy = ''
    for h_item in h:
        # ('261c045fb9aa3153af8132c58c8c448416dfffa124cad7b4f7c6a14a0950097d', TxMinedStatus(height=1286635, conf=127601, timestamp=1519732666, header_hash='00000000000002f19a40364b4441b38a6dd7d1643a419b92251281ba03112954'), 130000000, 130000000)
        tx_hash, mined_status, value, balance = h_item
        status, status_str = wallet.get_tx_status(tx_hash, mined_status)
        has_invoice = wallet.invoices.paid.get(tx_hash)
        v_str = parent.format_amount(value, True, whitespaces=True)
        balance_str = parent.format_amount(balance, whitespaces=True)
        label = wallet.get_label(tx_hash)
        date = timestamp_to_datetime(
            time.time() if mined_status.conf <= 0 else mined_status.timestamp)
        ts = mined_status.timestamp if mined_status.conf > 0 else time.time()
        fiat_amount = 0
        fiat_balance = 0
        fiat_amount_str = ''
        fiat_balance_str = ''
        if fx: fx.history_used_spot = False
        if not forceNoFX and fx:
            if not ccy:
                ccy = fx.get_currency()
            try:
                hdate = timestamp_to_datetime(time.time(
                ) if mined_status.conf <= 0 else mined_status.timestamp)
                hamount = fx.historical_value(value, hdate)
                htext = fx.historical_value_str(value,
                                                hdate) if hamount else ''
                fiat_amount = hamount if hamount else fiat_amount
                fiat_amount_str = htext if htext else fiat_amount_str
                hamount = fx.historical_value(balance, hdate) if balance else 0
                htext = fx.historical_value_str(balance,
                                                hdate) if hamount else ''
                fiat_balance = hamount if hamount else fiat_balance
                fiat_balance_str = htext if htext else fiat_balance_str
            except:
                utils.NSLog(
                    "Exception in get_history computing fiat amounts!\n%s",
                    str(sys.exc_info()[1]))
                # import traceback
                # traceback.print_exc(file=sys.stderr)
                fiat_amount = fiat_balance = 0
                fiat_amount_str = fiat_balance_str = ''
        if status >= 0 and status < len(sImages):
            img = sImages[status]
        else:
            img = None
        tx = wallet.transactions.get(tx_hash, None)
        if tx is not None: tx.deserialize()
        entry = HistoryEntry(tx, tx_hash, status_str, label, v_str,
                             balance_str, date, ts, mined_status.conf, status,
                             value, fiat_amount, fiat_balance, fiat_amount_str,
                             fiat_balance_str, ccy, img)
        history.append(entry)  # appending is O(1)
    history.reverse()  # finally, reverse the order to keep most recent first
    return history
Exemplo n.º 22
0
 def get_history_rate(self, btc_balance, timestamp):
     date = timestamp_to_datetime(timestamp)
     return run_hook('historical_value_str', btc_balance, date)
 def on_update(self):
     self.wallet = self.parent.wallet
     fx = self.parent.fx
     r = self.wallet.get_full_history(domain=self.get_domain(),
                                      from_timestamp=self.start_timestamp,
                                      to_timestamp=self.end_timestamp,
                                      fx=fx)
     self.transactions = r['transactions']
     self.summary = r['summary']
     if not self.years and self.start_timestamp is None and self.end_timestamp is None:
         start_date = self.summary.get('start_date')
         end_date = self.summary.get('end_date')
         if start_date and end_date:
             self.years = [
                 str(i) for i in range(start_date.year, end_date.year + 1)
             ]
             self.period_combo.insertItems(1, self.years)
     item = self.currentItem()
     current_tx = item.data(0, Qt.UserRole) if item else None
     self.clear()
     if fx: fx.history_used_spot = False
     for tx_item in self.transactions:
         tx_hash = tx_item['txid']
         height = tx_item['height']
         conf = tx_item['confirmations']
         timestamp = tx_item['timestamp']
         value = tx_item['value'].value
         balance = tx_item['balance'].value
         label = tx_item['label']
         status, status_str = self.wallet.get_tx_status(
             tx_hash, height, conf, timestamp)
         has_invoice = self.wallet.invoices.paid.get(tx_hash)
         icon = QIcon(":icons/" + TX_ICONS[status])
         v_str = self.parent.format_amount(value, True, whitespaces=True)
         balance_str = self.parent.format_amount(balance, whitespaces=True)
         entry = ['', tx_hash, status_str, label, v_str, balance_str]
         fiat_value = None
         if value is not None and fx and fx.show_history():
             date = timestamp_to_datetime(
                 time.time() if conf <= 0 else timestamp)
             fiat_value = tx_item['fiat_value'].value
             value_str = fx.format_fiat(fiat_value)
             entry.append(value_str)
             # fixme: should use is_mine
             if value < 0:
                 entry.append(
                     fx.format_fiat(tx_item['acquisition_price'].value))
                 entry.append(fx.format_fiat(tx_item['capital_gain'].value))
         item = QTreeWidgetItem(entry)
         item.setIcon(0, icon)
         item.setToolTip(
             0,
             str(conf) + " confirmation" + ("s" if conf != 1 else ""))
         if has_invoice:
             item.setIcon(3, QIcon(":icons/seal"))
         for i in range(len(entry)):
             if i > 3:
                 item.setTextAlignment(i, Qt.AlignRight)
             if i != 2:
                 item.setFont(i, QFont(MONOSPACE_FONT))
         if value and value < 0:
             item.setForeground(3, QBrush(QColor("#BC1E1E")))
             item.setForeground(4, QBrush(QColor("#BC1E1E")))
         if fiat_value and not tx_item['fiat_default']:
             item.setForeground(6, QBrush(QColor("#1E1EFF")))
         if tx_hash:
             item.setData(0, Qt.UserRole, tx_hash)
         self.insertTopLevelItem(0, item)
         if current_tx == tx_hash:
             self.setCurrentItem(item)
Exemplo n.º 24
0
 def timestamp_rate(self, timestamp):
     from electrum.util import timestamp_to_datetime
     date = timestamp_to_datetime(timestamp)
     return self.history_rate(date)
Exemplo n.º 25
0
    def on_update(self):
        self.wallet = self.parent.wallet
        h = self.wallet.get_history(self.get_domain(),
                                    from_timestamp=self.start_timestamp,
                                    to_timestamp=self.end_timestamp)
        if not self.years and h:
            if timestamp_to_datetime(h[0][3]):
                start_date = timestamp_to_datetime(h[0][3]).date()
            else:
                start_date = datetime.date.today()
            if timestamp_to_datetime(h[-1][3]):
                end_date = timestamp_to_datetime(h[-1][3]).date()
            else:
                end_date = datetime.date.today()

            self.years = [
                str(i) for i in range(start_date.year, end_date.year + 1)
            ]
            self.period_combo.insertItems(1, self.years)

        item = self.currentItem()
        current_tx = item.data(0, Qt.UserRole) if item else None
        self.clear()
        fx = self.parent.fx
        if fx: fx.history_used_spot = False
        blue_brush = QBrush(QColor("#1E1EFF"))
        red_brush = QBrush(QColor("#BC1E1E"))
        monospace_font = QFont(MONOSPACE_FONT)
        for h_item in h:
            tx_hash, tx_mined_status, delta, balance = h_item
            status, status_str = self.wallet.get_tx_status(
                tx_hash, tx_mined_status)
            conf = tx_mined_status.conf

            has_invoice = self.wallet.invoices.paid.get(tx_hash)
            icon = read_QIcon(TX_ICONS[status])
            v_str = self.parent.format_amount(delta, True, whitespaces=True)
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            label = self.wallet.get_label(tx_hash)
            if delta and 0 < delta < 4 * 10**7 and label == _('stake mined'):
                label = _('contract gas change')
            entry = ['', tx_hash, status_str, label, v_str, balance_str]
            if fx and fx.show_history():
                date = timestamp_to_datetime(
                    time.time() if conf <= 0 else tx_mined_status.timestamp)
                for amount in [delta, balance]:
                    text = fx.historical_value_str(amount, date)
                    entry.append(text)
            item = QTreeWidgetItem(entry)
            item.setIcon(0, icon)
            item.setToolTip(
                0,
                str(conf) + " confirmation" + ("s" if conf != 1 else ""))
            if has_invoice:
                item.setIcon(3, read_QIcon("seal"))
            for i in range(len(entry)):
                if i > 3:
                    item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter)
                if i != 2:
                    item.setFont(i, monospace_font)
            if delta and delta < 0:
                item.setForeground(3, red_brush)
                item.setForeground(4, red_brush)
            if tx_hash:
                item.setData(0, Qt.UserRole, tx_hash)
            self.insertTopLevelItem(0, item)
            if current_tx == tx_hash:
                self.setCurrentItem(item)
Exemplo n.º 26
0
 def timestamp_rate(self, timestamp):
     from electrum.util import timestamp_to_datetime
     date = timestamp_to_datetime(timestamp)
     return self.history_rate(date)
Exemplo n.º 27
0
 def get_history_rate(self, btc_balance, timestamp):
     date = timestamp_to_datetime(timestamp)
     return run_hook('historical_value_str', btc_balance, date)