Fixing namecoin button again (broken in c7d3784):

* separate method MyForm.resetNamecoinConnection() - sets MyForm.namecoin
    to fresh instance of namecoin.namecoinConnection, tests it and shows or
    hides "Fetch Namecoin ID" button;
  * that method is called when MyForm initializes and when settingsDialog
    instance is accepted;
  * namecoin.namecoinConnection.query() checks found address and always
    prepends it with display name, if query result doesn't contain "name"
    field it will be the query string.
This commit is contained in:
Dmitri Bogomolov 2018-11-07 13:56:06 +02:00
parent 8ad064dcac
commit ea38e91839
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 59 additions and 43 deletions

View File

@ -798,19 +798,7 @@ class MyForm(settingsmixin.SMainWindow):
"valueChanged(int)"), self.updateTTL)
self.initSettings()
namecoin.ensureNamecoinOptions()
self.namecoin = namecoin.namecoinConnection()
# Check to see whether we can connect to namecoin.
# Hide the 'Fetch Namecoin ID' button if we can't.
if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'
) or self.namecoin.test()[0] == 'failed':
logger.warning(
'There was a problem testing for a Namecoin daemon. Hiding the'
' Fetch Namecoin ID button')
self.ui.pushButtonFetchNamecoinID.hide()
self.resetNamecoinConnection()
def updateTTL(self, sliderPosition):
TTL = int(sliderPosition ** 3.199 + 3600)
@ -2160,9 +2148,8 @@ class MyForm(settingsmixin.SMainWindow):
))
def click_pushButtonFetchNamecoinID(self):
nc = namecoinConnection()
identities = str(self.ui.lineEditTo.text().toUtf8()).split(";")
err, addr = nc.query(identities[-1].strip())
err, addr = self.namecoin.query(identities[-1].strip())
if err is not None:
self.updateStatusBar(
_translate("MainWindow", "Error: %1").arg(err))
@ -2481,6 +2468,7 @@ class MyForm(settingsmixin.SMainWindow):
self.settingsDialogInstance.ui.lineEditNamecoinUser.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcpassword', str(
self.settingsDialogInstance.ui.lineEditNamecoinPassword.text()))
self.resetNamecoinConnection()
# Demanded difficulty tab
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
@ -4129,6 +4117,22 @@ class MyForm(settingsmixin.SMainWindow):
else:
self.statusbar.showMessage(message, 10000)
def resetNamecoinConnection(self):
namecoin.ensureNamecoinOptions()
self.namecoin = namecoin.namecoinConnection()
# Check to see whether we can connect to namecoin.
# Hide the 'Fetch Namecoin ID' button if we can't.
if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'
) or self.namecoin.test()[0] == 'failed':
logger.warning(
'There was a problem testing for a Namecoin daemon. Hiding the'
' Fetch Namecoin ID button')
self.ui.pushButtonFetchNamecoinID.hide()
else:
self.ui.pushButtonFetchNamecoinID.show()
def initSettings(self):
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
@ -4356,8 +4360,8 @@ class settingsDialog(QtGui.QDialog):
else:
self.ui.lineEditNamecoinPort.setText("9000")
# Test the namecoin settings specified in the settings dialog.
def click_pushButtonNamecoinTest(self):
"""Test the namecoin settings specified in the settings dialog."""
self.ui.labelNamecoinTestResult.setText(_translate(
"MainWindow", "Testing..."))
options = {}
@ -4366,13 +4370,11 @@ class settingsDialog(QtGui.QDialog):
options["port"] = str(self.ui.lineEditNamecoinPort.text().toUtf8())
options["user"] = str(self.ui.lineEditNamecoinUser.text().toUtf8())
options["password"] = str(self.ui.lineEditNamecoinPassword.text().toUtf8())
nc = namecoinConnection(options)
response = nc.test()
responseStatus = response[0]
responseText = response[1]
self.ui.labelNamecoinTestResult.setText(responseText)
if responseStatus== 'success':
self.parent.ui.pushButtonFetchNamecoinID.show()
nc = namecoin.namecoinConnection(options)
status, text = nc.test()
self.ui.labelNamecoinTestResult.setText(text)
if status == 'success':
self.parent.namecoin = nc
# In order for the time columns on the Inbox and Sent tabs to be sorted

View File

@ -34,6 +34,7 @@ import os
import socket
import sys
from addresses import decodeAddress
from debug import logger
import defaults
import tr # translate
@ -102,7 +103,10 @@ class namecoinConnection(object):
"""
slashPos = string.find("/")
if slashPos < 0:
display_name = string
string = "id/" + string
else:
display_name = string.split("/")[1]
try:
if self.nmctype == "namecoind":
@ -112,7 +116,9 @@ class namecoinConnection(object):
res = self.callRPC("data", ["getValue", string])
res = res["reply"]
if not res:
return (tr._translate("MainWindow", 'The name %1 was not found.').arg(unicode(string)), None)
return (tr._translate(
"MainWindow", 'The name %1 was not found.'
).arg(unicode(string)), None)
else:
assert False
except RPCError as exc:
@ -121,29 +127,37 @@ class namecoinConnection(object):
errmsg = exc.error["message"]
else:
errmsg = exc.error
return (tr._translate("MainWindow", 'The namecoin query failed (%1)').arg(unicode(errmsg)), None)
return (tr._translate(
"MainWindow", 'The namecoin query failed (%1)'
).arg(unicode(errmsg)), None)
except AssertionError:
return (tr._translate(
"MainWindow", 'Unknown namecoin interface type: %1'
).arg(unicode(self.nmctype)), None)
except Exception:
logger.exception("Namecoin query exception")
return (tr._translate("MainWindow", 'The namecoin query failed.'), None)
return (tr._translate(
"MainWindow", 'The namecoin query failed.'), None)
try:
val = json.loads(res)
except:
logger.exception("Namecoin query json exception")
return (tr._translate("MainWindow", 'The name %1 has no valid JSON data.').arg(unicode(string)), None)
if "bitmessage" in val:
if "name" in val:
ret = "%s <%s>" % (val["name"], val["bitmessage"])
res = json.loads(res)
except ValueError:
pass
else:
ret = val["bitmessage"]
return (None, ret)
try:
display_name = res["name"]
except KeyError:
pass
res = res.get("bitmessage")
valid = decodeAddress(res)[0] == 'success'
return (
None, "%s <%s>" % (display_name, res)
) if valid else (
tr._translate(
"MainWindow",
'The name %1 has no associated Bitmessage address.').arg(
unicode(string)),
None)
'The name %1 has no associated Bitmessage address.'
).arg(unicode(string)), None)
def test(self):
"""