示例#1
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)
示例#2
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)
示例#3
0
    def print_history(self):
        messages = []

        for tx_hash, tx_type, 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 = "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]
                delta = (80 - 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))
                messages.append(msg)
                self.print_list(messages[::-1],
                                format_str % (_("Date"), 'DIP2',
                                              _("Description"), _("Amount"),
                                              _("Balance")))
            else:
                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")
                msg = format_str % (time_str, label,
                                    format_satoshis(value, whitespaces=True),
                                    format_satoshis(balance, whitespaces=True))
                messages.append(msg)
                self.print_list(messages[::-1],
                                format_str % (_("Date"),
                                              _("Description"), _("Amount"),
                                              _("Balance")))
示例#4
0
 def test_format_satoshis(self):
     result = format_satoshis(1234)
     expected = "0.00001234"
     self.assertEqual(expected, result)
示例#5
0
 def test_format_satoshis_diff_negative(self):
     result = format_satoshis(-1234, is_diff=True)
     expected = "-0.00001234"
     self.assertEqual(expected, result)
示例#6
0
 def test_format_fee(self):
     result = format_satoshis(1700/1000, 0, 0)
     expected = "1.7"
     self.assertEqual(expected, result)
示例#7
0
 def format_amount(self, x, is_diff=False, whitespaces=False):
     return format_satoshis(x,
                            0,
                            self.decimal_point(),
                            is_diff=is_diff,
                            whitespaces=whitespaces)