Skip to content

Commit

Permalink
Namecoin: Add Manage Names tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Oct 1, 2018
1 parent eeca38d commit 55deaa0
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Electrum-NMC - Lightweight Namecoin client

::

Licence: GNU GPLv3+ for Electrum-DOGE components; MIT Licence for all other components
Licence: GNU GPLv3+ for Electrum-DOGE components; CC BY 4.0 for Namecoin logo, MIT Licence for all other components
Author: The Namecoin developers; based on Electrum by Thomas Voegtlin and Electrum-DOGE by The Electrum-DOGE contributors
Language: Python (>= 3.6)
Homepage: https://www.namecoin.org/ ; original Electrum Homepage at https://electrum.org/
Expand Down Expand Up @@ -68,7 +68,7 @@ Run install (this should install dependencies)::

Render the SVG icons to PNGs (optional)::

for i in lock unlock confirmed status_lagging status_disconnected status_connected_proxy status_connected status_waiting preferences; do convert -background none icons/$i.svg icons/$i.png; done
for i in lock unlock confirmed status_lagging status_disconnected status_connected_proxy status_connected status_waiting preferences namecoin-logo; do convert -background none icons/$i.svg icons/$i.png; done

Compile the icons file for Qt::

Expand Down
8 changes: 7 additions & 1 deletion electrum_nmc/address_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def get_addr_balance(self, address):
return c, u, x

@with_local_height_cached
def get_utxos(self, domain=None, excluded=None, mature=False, confirmed_only=False):
def get_utxos(self, domain=None, excluded=None, mature=False, confirmed_only=False, include_names=True):
coins = []
if domain is None:
domain = self.get_addresses()
Expand All @@ -809,6 +809,12 @@ def get_utxos(self, domain=None, excluded=None, mature=False, confirmed_only=Fal
continue
if mature and x['coinbase'] and x['height'] + COINBASE_MATURITY > self.get_local_height():
continue
if not include_names:
txid = x['prevout_hash']
vout = x['prevout_n']
name_op = self.transactions[txid].outputs()[vout].name_op
if name_op is not None:
continue
coins.append(x)
continue
return coins
Expand Down
33 changes: 33 additions & 0 deletions electrum_nmc/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def __init__(self, gui_object, wallet):
self.utxo_tab = self.create_utxo_tab()
self.console_tab = self.create_console_tab()
self.contacts_tab = self.create_contacts_tab()
self.names_tab = self.create_names_tab()
tabs.addTab(self.create_history_tab(), QIcon(":icons/tab_history.png"), _('History'))
tabs.addTab(self.send_tab, QIcon(":icons/tab_send.png"), _('Send'))
tabs.addTab(self.receive_tab, QIcon(":icons/tab_receive.png"), _('Receive'))
tabs.addTab(self.names_tab, QIcon(":icons/namecoin-logo.png"), _('Manage Names'))

def add_optional_tab(tabs, tab, icon, description, name):
tab.tab_icon = icon
Expand Down Expand Up @@ -788,6 +790,7 @@ def update_tabs(self):
self.request_list.update()
self.address_list.update()
self.utxo_list.update()
self.names_uno_list.update()
self.contact_list.update()
self.invoice_list.update()
self.update_completions()
Expand Down Expand Up @@ -1783,6 +1786,7 @@ def set_frozen_state(self, addrs, freeze):
self.wallet.set_frozen_state(addrs, freeze)
self.address_list.update()
self.utxo_list.update()
self.names_uno_list.update()
self.update_fee()

def create_list_tab(self, l, toolbar=None):
Expand Down Expand Up @@ -3247,3 +3251,32 @@ def save_transaction_into_wallet(self, tx):
"to see it, you need to broadcast it."))
win.msg_box(QPixmap(":icons/offline_tx.png"), None, _('Success'), msg)
return True

def create_names_tab(self):
self.names_vbox = vbox = QVBoxLayout()

self.names_your_names_label = QLabel(_('Your registered names (pending and unconfirmed names have blank expiration):'))
vbox.addWidget(self.names_your_names_label)

# List of names
from .uno_list import UNOList
self.names_uno_list = l = UNOList(self)
vbox.addWidget(self.create_list_tab(l))

self.names_actions_hbox = QHBoxLayout()

# Components of names_actions_hbox
self.names_configure_button = QPushButton(_('Configure Name...'))
self.names_renew_button = QPushButton(_('Renew Name'))

self.names_actions_hbox.addWidget(self.names_configure_button)
self.names_actions_hbox.addWidget(self.names_renew_button)

self.names_actions = QWidget()
self.names_actions.setLayout(self.names_actions_hbox)
# TODO: enable name actions
#vbox.addWidget(self.names_actions)

w = QWidget()
w.setLayout(vbox)
return w
99 changes: 99 additions & 0 deletions electrum_nmc/gui/qt/uno_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python
#
# Electrum-NMC - lightweight Namecoin client
# Copyright (C) 2018 Namecoin Developers
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from electrum_nmc.i18n import _
from electrum_nmc.names import format_name_identifier, format_name_value

from .util import *
from .utxo_list import UTXOList

# TODO: It'd be nice if we could further reduce code duplication against
# UTXOList.
class UNOList(UTXOList):
# TODO: fix this for UNOList
filter_columns = [0, 2] # Address, Label

def __init__(self, parent=None):
MyTreeWidget.__init__(self, parent, self.create_menu, [ _('Name'), _('Value'), _('Expires In'), _('Status')], 1)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.setSortingEnabled(True)

def on_update(self):
self.wallet = self.parent.wallet
self.network = self.parent.network
item = self.currentItem()
self.clear()
self.utxos = self.wallet.get_utxos()
for x in self.utxos:
txid = x['prevout_hash']
vout = x['prevout_n']
name_op = self.wallet.transactions[txid].outputs()[vout].name_op
if name_op is None:
continue

# TODO: Support name_new
if 'name' in name_op:
name = format_name_identifier(name_op['name'])
value = format_name_value(name_op['value'])
else:
name = ''
value = ''

height = x.get('height')
chain_height = self.network.blockchain().height()
expires_in = height - chain_height + 36000

status = ''

utxo_item = SortableTreeWidgetItem([name, value, '%d'%expires_in, status])
utxo_item.setFont(0, QFont(MONOSPACE_FONT))
utxo_item.setFont(1, QFont(MONOSPACE_FONT))
utxo_item.setData(0, Qt.UserRole, self.get_name(x))
utxo_item.setData(1, Qt.UserRole, name)

address = x.get('address')
if self.wallet.is_frozen(address):
utxo_item.setBackground(0, ColorScheme.BLUE.as_color(True))
self.addChild(utxo_item)

def create_menu(self, position):
selected = [x.data(0, Qt.UserRole) for x in self.selectedItems()]
if not selected:
return
menu = QMenu()
coins = filter(lambda x: self.get_name(x) in selected, self.utxos)

# TODO: implement Renew
#menu.addAction(_("Renew"), lambda: self.parent.spend_coins(coins))
if len(selected) == 1:
txid = selected[0].split(':')[0]
tx = self.wallet.transactions.get(txid)
if tx:
# TODO: implement Configure
#menu.addAction(_("Configure"), lambda: self.parent.show_transaction(tx))
menu.addAction(_("Transaction Details"), lambda: self.parent.show_transaction(tx))

menu.exec_(self.viewport().mapToGlobal(position))

4 changes: 2 additions & 2 deletions electrum_nmc/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ def get_tx_info(self, tx):

return tx_hash, status, label, can_broadcast, can_bump, amount, fee, height, conf, timestamp, exp_n

def get_spendable_coins(self, domain, config):
def get_spendable_coins(self, domain, config, include_names=False):
confirmed_only = config.get('confirmed_only', False)
return self.get_utxos(domain, excluded=self.frozen_addresses, mature=True, confirmed_only=confirmed_only)
return self.get_utxos(domain, excluded=self.frozen_addresses, mature=True, confirmed_only=confirmed_only, include_names=include_names)

def dummy_address(self):
return self.get_receiving_addresses()[0]
Expand Down
1 change: 1 addition & 0 deletions icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<file>icons/ledger_unpaired.png</file>
<file>icons/lock.png</file>
<file>icons/microphone.png</file>
<file>icons/namecoin-logo.png</file>
<file>icons/network.png</file>
<file>icons/offline_tx.png</file>
<file>icons/revealer.png</file>
Expand Down
92 changes: 92 additions & 0 deletions icons/namecoin-logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 55deaa0

Please sign in to comment.