Пример #1
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 = []
        self.txid = []
        for hist_item in self.wallet.get_history():
            if hist_item.tx_mined_status.conf:
                timestamp = hist_item.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_for_txid(hist_item.txid)
            self.txid.insert(0, hist_item.txid)
            if len(label) > 40:
                label = label[0:37] + '...'
            self.history.append(
                format_str %
                (time_str, label,
                 format_satoshis(hist_item.delta, whitespaces=True),
                 format_satoshis(hist_item.balance, whitespaces=True)))
Пример #2
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 hist_item in reversed(self.wallet.get_history()):
            if hist_item.tx_mined_status.conf:
                timestamp = hist_item.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_for_txid(hist_item.txid)
            messages.append(
                format_str %
                (time_str, label, format_satoshis(delta, whitespaces=True),
                 format_satoshis(hist_item.balance, whitespaces=True)))

        self.print_list(
            messages[::-1], format_str %
            (_("Date"), _("Description"), _("Amount"), _("Balance")))
Пример #3
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))
     self.assertEqual(
         "     0.45831275",
         format_satoshis(Decimal("45831275."), whitespaces=True))
     self.assertEqual(
         "     0.45831275   ",
         format_satoshis(Decimal("45831275."),
                         whitespaces=True,
                         precision=3))
     self.assertEqual(
         "     0.458312757  ",
         format_satoshis(Decimal("45831275.7"),
                         whitespaces=True,
                         precision=3))
     self.assertEqual(
         "     0.45831275748",
         format_satoshis(Decimal("45831275.748"),
                         whitespaces=True,
                         precision=3))
Пример #4
0
 def test_format_satoshis_decimal(self):
     self.assertEqual("0.00001234", format_satoshis(Decimal(1234)))
Пример #5
0
    def test_format_satoshis_msat_resolution(self):
        self.assertEqual("45831276.",
                         format_satoshis(Decimal("45831276"), decimal_point=0))
        self.assertEqual(
            "45831276.",
            format_satoshis(Decimal("45831275.748"), decimal_point=0))
        self.assertEqual(
            "45831275.75",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=0,
                            precision=2))
        self.assertEqual(
            "45831275.748",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=0,
                            precision=3))

        self.assertEqual("458312.76",
                         format_satoshis(Decimal("45831276"), decimal_point=2))
        self.assertEqual(
            "458312.76",
            format_satoshis(Decimal("45831275.748"), decimal_point=2))
        self.assertEqual(
            "458312.7575",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=2,
                            precision=2))
        self.assertEqual(
            "458312.75748",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=2,
                            precision=3))

        self.assertEqual("458.31276",
                         format_satoshis(Decimal("45831276"), decimal_point=5))
        self.assertEqual(
            "458.31276",
            format_satoshis(Decimal("45831275.748"), decimal_point=5))
        self.assertEqual(
            "458.3127575",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=5,
                            precision=2))
        self.assertEqual(
            "458.31275748",
            format_satoshis(Decimal("45831275.748"),
                            decimal_point=5,
                            precision=3))
Пример #6
0
 def test_format_satoshis_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234))
Пример #7
0
 def test_format_satoshis_to_mbtc(self):
     self.assertEqual("0.01234", format_satoshis(1234, decimal_point=5))
Пример #8
0
 def test_format_satoshis_add_thousands_sep(self):
     self.assertEqual(
         "178 890 000.",
         format_satoshis(Decimal(178890000),
                         decimal_point=0,
                         add_thousands_sep=True))
     self.assertEqual(
         "458 312.757 48",
         format_satoshis(Decimal("45831275.748"),
                         decimal_point=2,
                         add_thousands_sep=True,
                         precision=5))
     # is_diff
     self.assertEqual(
         "+4 583 127.574 8",
         format_satoshis(Decimal("45831275.748"),
                         decimal_point=1,
                         is_diff=True,
                         add_thousands_sep=True,
                         precision=4))
     self.assertEqual(
         "+456 789 112.004 56",
         format_satoshis(Decimal("456789112.00456"),
                         decimal_point=0,
                         is_diff=True,
                         add_thousands_sep=True,
                         precision=5))
     self.assertEqual(
         "-0.000 012 34",
         format_satoshis(-1234, is_diff=True, add_thousands_sep=True))
     self.assertEqual(
         "-456 789.000 012 34",
         format_satoshis(-45678900001234,
                         is_diff=True,
                         add_thousands_sep=True))
     # num_zeros
     self.assertEqual(
         "-456 789.123 400",
         format_satoshis(-45678912340000,
                         num_zeros=6,
                         add_thousands_sep=True))
     self.assertEqual(
         "-456 789.123 4",
         format_satoshis(-45678912340000,
                         num_zeros=2,
                         add_thousands_sep=True))
     # whitespaces
     self.assertEqual(
         "      1 432.731 11",
         format_satoshis(143273111,
                         decimal_point=5,
                         add_thousands_sep=True,
                         whitespaces=True))
     self.assertEqual(
         "      1 432.731   ",
         format_satoshis(143273100,
                         decimal_point=5,
                         add_thousands_sep=True,
                         whitespaces=True))
     self.assertEqual(
         " 67 891 432.731   ",
         format_satoshis(6789143273100,
                         decimal_point=5,
                         add_thousands_sep=True,
                         whitespaces=True))
     self.assertEqual(
         "       143 273 100.",
         format_satoshis(143273100,
                         decimal_point=0,
                         add_thousands_sep=True,
                         whitespaces=True))
     self.assertEqual(
         " 6 789 143 273 100.",
         format_satoshis(6789143273100,
                         decimal_point=0,
                         add_thousands_sep=True,
                         whitespaces=True))
     self.assertEqual(
         "56 789 143 273 100.",
         format_satoshis(56789143273100,
                         decimal_point=0,
                         add_thousands_sep=True,
                         whitespaces=True))
Пример #9
0
 def test_format_satoshis(self):
     self.assertEqual("0.00001234", format_satoshis(1234))
Пример #10
0
 def test_format_satoshis_diff_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234, is_diff=True))
     self.assertEqual("-456789.00001234",
                      format_satoshis(-45678900001234, is_diff=True))
Пример #11
0
 def test_format_satoshis_diff_positive(self):
     self.assertEqual("+0.00001234", format_satoshis(1234, is_diff=True))
     self.assertEqual("+456789.00001234",
                      format_satoshis(45678900001234, is_diff=True))
Пример #12
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))