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")))
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)
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)
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) ) )
def format_amount(self, x, is_diff=False, whitespaces=False): return format_satoshis(x, 0, self.decimal_point(), is_diff=is_diff, whitespaces=whitespaces)
def test_format_satoshis(self): result = format_satoshis(1234) expected = "0.00001234" self.assertEqual(expected, result)
def test_format_satoshis_diff_negative(self): result = format_satoshis(-1234, is_diff=True) expected = "-0.00001234" self.assertEqual(expected, result)
def test_format_fee(self): result = format_satoshis(1700 / 1000, 0, 0) expected = "1.7" self.assertEqual(expected, result)