Exemplo n.º 1
0
    def print_history(self):
        width = [20, 40, 14, 14]
        delta = (80 - 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"
        messages = []

        for tx_hash, tx_mined_status, delta, balance in self.wallet.get_history(
        ):
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    time_str = datetime.datetime.fromtimestamp(
                        timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "unknown"
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            messages.append(
                format_str %
                (time_str, label, format_satoshis(delta, whitespaces=True),
                 format_satoshis(balance, whitespaces=True)))

        self.print_list(
            messages[::-1], format_str %
            (_("Date"), _("Description"), _("Amount"), _("Balance")))
Exemplo n.º 2
0
    def update_history(self):
        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"

        b = 0
        self.history = []
        for tx_hash, tx_mined_status, value, balance in self.wallet.get_history(
        ):
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    time_str = datetime.datetime.fromtimestamp(
                        timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "------"
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            if len(label) > 40:
                label = label[0:37] + '...'
            self.history.append(
                format_str %
                (time_str, label, format_satoshis(value, whitespaces=True),
                 format_satoshis(balance, whitespaces=True)))
Exemplo n.º 3
0
    def test_format_satoshis_whitespaces_negative(self):
        result = format_satoshis(-12340, whitespaces=True)
        expected = "    -0.0001234 "
        self.assertEqual(expected, result)

        result = format_satoshis(-1234, whitespaces=True)
        expected = "    -0.00001234"
        self.assertEqual(expected, result)
Exemplo n.º 4
0
    def test_format_fee_precision(self):
        result = format_satoshis(1666 / 1000, 0, 0, precision=6)
        expected = "1.666"
        self.assertEqual(expected, result)

        result = format_satoshis(1666 / 1000, 0, 0, precision=1)
        expected = "1.7"
        self.assertEqual(expected, result)
Exemplo n.º 5
0
    def print_history(self):
        messages = []

        hist_list = reversed(self.wallet.get_history(config=self.config))
        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 (tx_hash, tx_type, tx_mined_status, delta, balance,
             islock, group_txid, group_data) in hist_list:
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    dttm = datetime.fromtimestamp(timestamp)
                    time_str = dttm.isoformat(' ')[:-3]
                except Exception:
                    time_str = "unknown"
            elif islock:
                dttm = datetime.fromtimestamp(islock)
                time_str = dttm.isoformat(' ')[:-3]
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            if show_dip2:
                tx_type_name = SPEC_TX_NAMES.get(tx_type, str(tx_type))
                msg = format_str % (time_str, tx_type_name, label,
                                    format_satoshis(delta, whitespaces=True),
                                    format_satoshis(balance, whitespaces=True))
                messages.append(msg)
            else:
                msg = format_str % (time_str, label,
                                    format_satoshis(delta, whitespaces=True),
                                    format_satoshis(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")))
Exemplo n.º 6
0
    def update_history(self):
        b = 0
        self.history = []
        hist_list = self.wallet.get_history(config=self.config)
        for (tx_hash, tx_type, tx_mined_status, value, balance,
             islock) in hist_list:
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    dttm = datetime.fromtimestamp(timestamp)
                    time_str = dttm.isoformat(' ')[:-3]
                except Exception:
                    time_str = "------"
            elif islock:
                dttm = datetime.fromtimestamp(islock)
                time_str = dttm.isoformat(' ')[:-3]
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            if self.show_dip2:
                if len(label) > 22:
                    label = label[0:19] + '...'
                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(value, whitespaces=True),
                                    format_satoshis(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(value, whitespaces=True),
                                    format_satoshis(balance, whitespaces=True))
                self.history.append(msg)
Exemplo n.º 7
0
    def print_history(self):
        messages = []

        for tx_hash, tx_type, tx_mined_status, delta, balance in reversed(
                self.wallet.get_history()):
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    time_str = datetime.datetime.fromtimestamp(
                        timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "unknown"
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            if self.config.get('show_dip2_tx_type', False):
                tx_type_name = SPEC_TX_NAMES.get(tx_type, str(tx_type))
                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")
                msg = format_str % (time_str, tx_type_name, label,
                                    format_satoshis(delta, whitespaces=True),
                                    format_satoshis(balance, whitespaces=True))
                messages.append(msg)
                self.print_list(
                    messages[::-1],
                    format_str % (_("Date"), 'DIP2', _("Description"),
                                  _("Amount"), _("Balance")))
            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")
                msg = format_str % (time_str, label,
                                    format_satoshis(delta, whitespaces=True),
                                    format_satoshis(balance, whitespaces=True))
                messages.append(msg)
                self.print_list(
                    messages[::-1], format_str %
                    (_("Date"), _("Description"), _("Amount"), _("Balance")))
Exemplo n.º 8
0
 def test_format_satoshis(self):
     self.assertEqual("0.00001234", format_satoshis(1234))
Exemplo n.º 9
0
 def test_format_satoshis_diff_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234, is_diff=True))
Exemplo n.º 10
0
 def test_format_satoshis_diff_positive(self):
     self.assertEqual("+0.00001234", format_satoshis(1234, is_diff=True))
Exemplo n.º 11
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))
Exemplo n.º 12
0
 def test_format_satoshis_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234))
Exemplo n.º 13
0
 def test_format_satoshis(self):
     result = format_satoshis(1234)
     expected = "0.00001234"
     self.assertEqual(expected, result)
Exemplo n.º 14
0
 def test_format_satoshis_diff_negative(self):
     result = format_satoshis(-1234, is_diff=True)
     expected = "-0.00001234"
     self.assertEqual(expected, result)
Exemplo n.º 15
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))
Exemplo n.º 16
0
 def format_amount(self, x, is_diff=False, whitespaces=False):
     return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces)
Exemplo n.º 17
0
 def test_format_fee(self):
     result = format_satoshis(1700 / 1000, 0, 0)
     expected = "1.7"
     self.assertEqual(expected, result)