コード例 #1
0
    def print_history(self):
        messages = []

        def_dip2 = not self.wallet.psman.unsupported
        show_dip2 = self.config.get('show_dip2_tx_type', def_dip2)
        if show_dip2:
            width = [20, 18, 22, 14, 14]
            wdelta = (80 - sum(width) - 5) // 3
            format_str = ("%" + "%d" % width[0] + "s" +
                          "%" + "%d" % width[1] + "s" +
                          "%" + "%d" % (width[2] + wdelta) + "s" +
                          "%" + "%d" % (width[3] + wdelta) + "s" +
                          "%" + "%d" % (width[4] + wdelta) + "s")
        else:
            width = [20, 40, 14, 14]
            wdelta = (80 - sum(width) - 4) // 3
            format_str = ("%" + "%d" % width[0] + "s" +
                          "%" + "%d" % (width[1] + wdelta) + "s" +
                          "%" + "%d" % (width[2] + wdelta) + "s" +
                          "%" + "%d" % (width[3] + wdelta) + "s")
        for hist_item in reversed(self.wallet.get_history(config=self.config)):
            if hist_item.tx_mined_status.conf:
                timestamp = hist_item.tx_mined_status.timestamp
                try:
                    dttm = datetime.fromtimestamp(timestamp)
                    time_str = dttm.isoformat(' ')[:-3]
                except Exception:
                    time_str = "unknown"
            elif hist_item.islock:
                dttm = datetime.fromtimestamp(hist_item.islock)
                time_str = dttm.isoformat(' ')[:-3]
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label_for_txid(hist_item.txid)
            if show_dip2:
                tx_type = hist_item.tx_type
                tx_type_name = SPEC_TX_NAMES.get(tx_type, str(tx_type))
                msg = format_str % (time_str, tx_type_name, label,
                                    format_satoshis(hist_item.delta, whitespaces=True),
                                    format_satoshis(hist_item.balance, whitespaces=True))
            else:
                msg = format_str % (time_str, label,
                                    format_satoshis(hist_item.delta, whitespaces=True),
                                    format_satoshis(hist_item.balance, whitespaces=True))
            messages.append(msg)
        if show_dip2:
            self.print_list(messages[::-1],
                            format_str % (_("Date"), 'Type',
                                          _("Description"), _("Amount"),
                                          _("Balance")))
        else:
            self.print_list(messages[::-1],
                            format_str % (_("Date"),
                                          _("Description"), _("Amount"),
                                          _("Balance")))
コード例 #2
0
ファイル: text.py プロジェクト: firoorg/electrum-firo
    def update_history(self):
        self.history = []
        self.txid = []
        for hist_item in self.wallet.get_history(config=self.config):
            if hist_item.tx_mined_status.conf:
                timestamp = hist_item.tx_mined_status.timestamp
                try:
                    dttm = datetime.fromtimestamp(timestamp)
                    time_str = dttm.isoformat(' ')[:-3]
                except Exception:
                    time_str = "------"
            elif hist_item.islock:
                dttm = datetime.fromtimestamp(hist_item.islock)
                time_str = dttm.isoformat(' ')[:-3]
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label_for_txid(hist_item.txid)
            self.txid.insert(0, hist_item.txid)
            if self.show_dip2:
                if len(label) > 22:
                    label = label[0:19] + '...'
                tx_type = hist_item.tx_type
                tx_type_name = SPEC_TX_NAMES.get(tx_type, str(tx_type))
                width = [20, 18, 22, 14, 14]
                delta = (self.maxx - sum(width) - 5) // 3
                format_str = ("%" + "%d" % width[0] + "s" + "%" +
                              "%d" % width[1] + "s" + "%" + "%d" %
                              (width[2] + delta) + "s" + "%" + "%d" %
                              (width[3] + delta) + "s" + "%" + "%d" %
                              (width[4] + delta) + "s")
                msg = format_str % (
                    time_str, tx_type_name, label,
                    format_satoshis(hist_item.delta, whitespaces=True),
                    format_satoshis(hist_item.balance, whitespaces=True))
                self.history.append(msg)
            else:
                if len(label) > 40:
                    label = label[0:37] + '...'
                width = [20, 40, 14, 14]
                delta = (self.maxx - sum(width) - 4) // 3
                format_str = ("%" + "%d" % width[0] + "s" + "%" + "%d" %
                              (width[1] + delta) + "s" + "%" + "%d" %
                              (width[2] + delta) + "s" + "%" + "%d" %
                              (width[3] + delta) + "s")
                msg = format_str % (
                    time_str, label,
                    format_satoshis(hist_item.delta, whitespaces=True),
                    format_satoshis(hist_item.balance, whitespaces=True))
                self.history.append(msg)
コード例 #3
0
 def test_format_satoshis_diff_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234, is_diff=True))
コード例 #4
0
 def test_format_satoshis_diff_positive(self):
     self.assertEqual("+0.00001234",
                      format_satoshis(1234, is_diff=True))
コード例 #5
0
 def test_format_satoshis_whitespaces_negative(self):
     self.assertEqual("    -0.0001234 ",
                      format_satoshis(-12340, whitespaces=True))
     self.assertEqual("    -0.00001234",
                      format_satoshis(-1234, whitespaces=True))
コード例 #6
0
 def test_format_satoshis_whitespaces(self):
     self.assertEqual("     0.0001234 ",
                      format_satoshis(12340, whitespaces=True))
     self.assertEqual("     0.00001234",
                      format_satoshis(1234, whitespaces=True))
コード例 #7
0
 def test_format_satoshis_decimal(self):
     self.assertEqual("0.00001234", format_satoshis(Decimal(1234)))
コード例 #8
0
 def test_format_satoshis_to_mbtc(self):
     self.assertEqual("0.01234", format_satoshis(1234, decimal_point=5))
コード例 #9
0
 def test_format_satoshis_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234))
コード例 #10
0
 def test_format_satoshis(self):
     self.assertEqual("0.00001234", format_satoshis(1234))