| 86 | # the result as (Error, Address) pair, where the Error is an error |
| 87 | # message to display or None in case of success. |
| 88 | def query (self, string): |
| 89 | slashPos = string.find ("/") |
| 90 | if slashPos < 0: |
| 91 | string = "id/" + string |
| 92 | |
| 93 | try: |
| 94 | if self.nmctype == "namecoind": |
| 95 | res = self.callRPC ("name_show", [string]) |
| 96 | res = res["value"] |
| 97 | elif self.nmctype == "nmcontrol": |
| 98 | res = self.callRPC ("data", ["getValue", string]) |
| 99 | res = res["reply"] |
| 100 | if res == False: |
| 101 | return (tr._translate("MainWindow",'The name %1 was not found.').arg(unicode(string)), None) |
| 102 | else: |
| 103 | assert False |
| 104 | except RPCError as exc: |
| 105 | logger.exception("Namecoin query RPC exception") |
| 106 | if isinstance(exc.error, dict): |
| 107 | errmsg = exc.error["message"] |
| 108 | else: |
| 109 | errmsg = exc.error |
| 110 | return (tr._translate("MainWindow",'The namecoin query failed (%1)').arg(unicode(errmsg)), None) |
| 111 | except Exception as exc: |
| 112 | logger.exception("Namecoin query exception") |
| 113 | return (tr._translate("MainWindow",'The namecoin query failed.'), None) |
| 114 | |
| 115 | try: |
| 116 | val = json.loads (res) |
| 117 | except: |
| 118 | logger.exception("Namecoin query json exception") |
| 119 | return (tr._translate("MainWindow",'The name %1 has no valid JSON data.').arg(unicode(string)), None) |
| 120 | |
| 121 | if "bitmessage" in val: |
| 122 | if "name" in val: |
| 123 | ret = "%s <%s>" % (val["name"], val["bitmessage"]) |
| 124 | else: |
| 125 | ret = val["bitmessage"] |
| 126 | return (None, ret) |
| 127 | return (tr._translate("MainWindow",'The name %1 has no associated Bitmessage address.').arg(unicode(string)), None) |
| 128 | |
| 129 | # Test the connection settings. This routine tries to query a "getinfo" |
| 130 | # command, and builds either an error message or a success message with |