Example #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 = []
        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)))
Example #2
0
    def get_tx_details(self, tx_hash):
        import datetime
        if not tx_hash: return ''
        tx = self.wallet.transactions.get(tx_hash)
        tx.deserialize()
        is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
        conf, timestamp = self.wallet.get_confirmations(tx_hash)

        if timestamp:
            time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
        else:
            time_str = 'pending'

        inputs = map(lambda x: x.get('address'), tx.inputs)
        outputs = map(lambda x: x[0], tx.get_outputs())
        tx_details = "Transaction Details" +"\n\n" \
            + "Transaction ID:\n" + tx_hash + "\n\n" \
            + "Status: %d confirmations\n"%conf
        if is_mine:
            if fee: 
                tx_details += "Amount sent: %s\n"% format_satoshis(v-fee, False) \
                              + "Transaction fee: %s\n"% format_satoshis(fee, False)
            else:
                tx_details += "Amount sent: %s\n"% format_satoshis(v, False) \
                              + "Transaction fee: unknown\n"
        else:
            tx_details += "Amount received: %s\n"% format_satoshis(v, False) \

        tx_details += "Date: %s\n\n"%time_str \
            + "Inputs:\n-"+ '\n-'.join(inputs) + "\n\n" \
            + "Outputs:\n-"+ '\n-'.join(outputs)

        return tx_details
Example #3
0
    def update_history_tab(self):
        cursor = self.history_treeview.get_cursor()[0]
        self.history_list.clear()

        for item in self.wallet.get_history():
            tx_hash, conf, value, timestamp, balance = item
            if conf > 0:
                try:
                    time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "------"
                conf_icon = Gtk.STOCK_APPLY
            elif conf == -1:
                time_str = 'unverified'
                conf_icon = None
            else:
                time_str = 'pending'
                conf_icon = Gtk.STOCK_EXECUTE

            label, is_default_label = self.wallet.get_label(tx_hash)
            tooltip = tx_hash + "\n%d confirmations"%conf if tx_hash else ''
            details = self.get_tx_details(tx_hash)

            self.history_list.prepend( [tx_hash, conf_icon, time_str, label, is_default_label,
                                        format_satoshis(value,True,self.num_zeros, whitespaces=True),
                                        format_satoshis(balance,False,self.num_zeros, whitespaces=True), tooltip, details] )
        if cursor: self.history_treeview.set_cursor( cursor )
Example #4
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"
        b = 0
        messages = []

        for item in self.wallet.get_history():
            tx_hash, confirmations, value, timestamp, balance = item
            if confirmations:
                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(value, whitespaces=True),
                 format_satoshis(balance, whitespaces=True)))

        self.print_list(
            messages[::-1], format_str %
            (_("Date"), _("Description"), _("Amount"), _("Balance")))
Example #5
0
    def update_status_bar(self):

        if self.funds_error:
            text = "Not enough funds"
        elif self.network.is_connected():
            host, port, _,_,_ = self.network.get_parameters()
            port = int(port)
            height = self.network.get_local_height()
            self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(host, port, height))
            if not self.wallet.up_to_date:
                self.status_image.set_from_stock(Gtk.STOCK_REFRESH, Gtk.IconSize.MENU)
                text = "Synchronizing..."
            else:
                self.status_image.set_from_stock(Gtk.STOCK_YES, Gtk.IconSize.MENU)
                c, u, x = self.wallet.get_balance()
                text = "Balance: %s "%(format_satoshis(c, False, self.num_zeros))
                if u:
                    text += "[%s unconfirmed]"%(format_satoshis(u, True, self.num_zeros).strip())
                if x:
                    text += "[%s unmatured]"%(format_satoshis(x, True, self.num_zeros).strip())
        else:
            self.status_image.set_from_stock(Gtk.STOCK_NO, Gtk.IconSize.MENU)
            self.network_button.set_tooltip_text("Not connected.")
            text = "Not connected"

        self.status_bar.pop(self.context_id) 
        self.status_bar.push(self.context_id, text)

        if self.wallet.up_to_date and self.wallet_updated:
            self.update_history_tab()
            self.update_receiving_tab()
            # addressbook too...
            self.info.set_text( self.network.banner )
            self.wallet_updated = False
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
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")))
Example #11
0
    def print_history(self):
        messages = []

        hist_list = reversed(self.wallet.get_history(config=self.config))
        show_dip2 = self.config.get('show_dip2_tx_type', False)
        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) 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"), 'DIP2', _("Description"), _("Amount"),
                              _("Balance")))
        else:
            self.print_list(
                messages[::-1], format_str %
                (_("Date"), _("Description"), _("Amount"), _("Balance")))
Example #12
0
    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)
Example #13
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)
Example #14
0
 def settings_dialog(self):
     out = self.run_dialog('Settings', [
         {'label':'Default GUI', 'type':'list', 'choices':['classic','lite','gtk','text'], 'value':self.config.get('gui')},
         {'label':'Default fee', 'type':'satoshis', 'value': format_satoshis(self.wallet.fee_per_kb).strip() }
         ], buttons = 1)
     if out:
         if out.get('Default GUI'):
             self.config.set_key('gui', out['Default GUI'], True)
         if out.get('Default fee'):
             fee = int(Decimal(out['Default fee']) * COIN)
             self.config.set_key('fee_per_kb', fee, True)
Example #15
0
 def update_receiving_tab(self):
     self.recv_list.clear()
     for address in self.wallet.addresses(True):
         Type = "R"
         c = u = 0
         if self.wallet.is_change(address): Type = "C"
         if address in self.wallet.imported_keys.keys():
             Type = "I"
         c, u, x = self.wallet.get_addr_balance(address)
         if self.wallet.is_frozen(address): Type = Type + "F"
         label = self.wallet.labels.get(address)
         h = self.wallet.history.get(address,[])
         n = len(h)
         tx = "0" if n==0 else "%d"%n
         self.recv_list.append((address, label, tx, format_satoshis(c+u+x, False, self.num_zeros), Type ))
Example #16
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) ) )
Example #17
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")))
Example #18
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"
        b = 0 
        messages = []

        for item in self.wallet.get_history():
            tx_hash, confirmations, value, timestamp, balance = item
            if confirmations:
                try:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "unknown"
            else:
                time_str = 'pending'

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

        self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
Example #19
0
 def test_format_satoshis_diff_positive(self):
     self.assertEqual("+0.00001234", format_satoshis(1234, is_diff=True))
Example #20
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))
Example #21
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))
Example #22
0
 def test_format_satoshis_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234))
Example #23
0
 def format_amount(self, x, is_diff=False, whitespaces=False):
     return format_satoshis(x, is_diff, 0, self.decimal_point(),
                            whitespaces)
Example #24
0
 def test_format_satoshis_diff_negative(self):
     result = format_satoshis(-1234, is_diff=True)
     expected = "-0.00001234"
     self.assertEqual(expected, result)
Example #25
0
 def test_format_fee(self):
     result = format_satoshis(1700/1000, 0, 0)
     expected = "1.7"
     self.assertEqual(expected, result)
Example #26
0
 def test_format_satoshis_decimal(self):
     self.assertEqual("0.00001234", format_satoshis(Decimal(1234)))
Example #27
0
 def test_format_satoshis(self):
     result = format_satoshis(1234)
     expected = "0.00001234"
     self.assertEqual(expected, result)
Example #28
0
 def test_format_satoshis_diff_negative(self):
     self.assertEqual("-0.00001234", format_satoshis(-1234, is_diff=True))
Example #29
0
 def test_format_satoshis(self):
     self.assertEqual("0.00001234", format_satoshis(1234))
Example #30
0
 def test_format_fee(self):
     result = format_satoshis(1700 / 1000, 0, 0)
     expected = "1.7"
     self.assertEqual(expected, result)
Example #31
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)
Example #32
0
 def test_format_satoshis_diff_negative(self):
     result = format_satoshis(-1234, is_diff=True)
     expected = "-0.00001234"
     self.assertEqual(expected, result)
Example #33
0
 def test_format_satoshis_to_mbtc(self):
     self.assertEqual("0.01234", format_satoshis(1234, decimal_point=5))
Example #34
0
 def test_format_satoshis(self):
     result = format_satoshis(1234)
     expected = "0.00001234"
     self.assertEqual(expected, result)