Domob1812 namecoin id2 #409
|
@ -14,7 +14,7 @@ except ImportError:
|
||||||
from addresses import *
|
from addresses import *
|
||||||
import shared
|
import shared
|
||||||
from bitmessageui import *
|
from bitmessageui import *
|
||||||
from class_namecoin import namecoinConnection
|
from namecoin import namecoinConnection
|
||||||
from newaddressdialog import *
|
from newaddressdialog import *
|
||||||
from newsubscriptiondialog import *
|
from newsubscriptiondialog import *
|
||||||
from regenerateaddresses import *
|
from regenerateaddresses import *
|
||||||
|
|
|
@ -3,6 +3,8 @@ import ConfigParser
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from namecoin import ensureNamecoinOptions
|
||||||
|
|
||||||
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder.
|
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder.
|
||||||
|
|
||||||
def loadConfig():
|
def loadConfig():
|
||||||
|
@ -64,6 +66,7 @@ def loadConfig():
|
||||||
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', '0')
|
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', '0')
|
||||||
shared.config.set(
|
shared.config.set(
|
||||||
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
|
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
|
||||||
|
ensureNamecoinOptions()
|
||||||
|
|
||||||
if storeConfigFilesInSameDirectoryAsProgramByDefault:
|
if storeConfigFilesInSameDirectoryAsProgramByDefault:
|
||||||
# Just use the same directory as the program and forget about
|
# Just use the same directory as the program and forget about
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import shared
|
||||||
|
|
||||||
|
configSection = "bitmessagesettings"
|
||||||
|
|
||||||
# Error thrown when the RPC call returns an error.
|
# Error thrown when the RPC call returns an error.
|
||||||
class RPCError (Exception):
|
class RPCError (Exception):
|
||||||
|
@ -40,10 +45,11 @@ class namecoinConnection (object):
|
||||||
queryid = 1
|
queryid = 1
|
||||||
|
|
||||||
def __init__ (self):
|
def __init__ (self):
|
||||||
self.user = "daniel"
|
ensureNamecoinOptions ()
|
||||||
self.password = "password"
|
self.user = shared.config.get (configSection, "namecoinrpcuser")
|
||||||
self.host = "localhost"
|
self.password = shared.config.get (configSection, "namecoinrpcpassword")
|
||||||
self.port = "8336"
|
self.host = shared.config.get (configSection, "namecoinrpchost")
|
||||||
|
self.port = shared.config.get (configSection, "namecoinrpcport")
|
||||||
|
|
||||||
# Query for the bitmessage address corresponding to the given identity
|
# Query for the bitmessage address corresponding to the given identity
|
||||||
# string. If it doesn't contain a slash, id/ is prepended. We return
|
# string. If it doesn't contain a slash, id/ is prepended. We return
|
||||||
|
@ -138,3 +144,67 @@ class namecoinConnection (object):
|
||||||
|
|
||||||
except socket.error as exc:
|
except socket.error as exc:
|
||||||
raise Exception ("Socket error in RPC connection: %s" % str (exc))
|
raise Exception ("Socket error in RPC connection: %s" % str (exc))
|
||||||
|
|
||||||
|
# Look up the namecoin data folder.
|
||||||
|
# FIXME: Check whether this works on other platforms as well!
|
||||||
|
def lookupNamecoinFolder ():
|
||||||
|
app = "namecoin"
|
||||||
|
from os import path, environ
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
if "HOME" in environ:
|
||||||
|
dataFolder = path.join (os.environ["HOME"],
|
||||||
|
"Library/Application Support/", app) + '/'
|
||||||
|
else:
|
||||||
|
print ("Could not find home folder, please report this message"
|
||||||
|
+ " and your OS X version to the BitMessage Github.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
elif "win32" in sys.platform or "win64" in sys.platform:
|
||||||
|
dataFolder = path.join(environ["APPDATA"], app) + "\\"
|
||||||
|
else:
|
||||||
|
dataFolder = path.join(environ["HOME"], ".%s" % app) + "/"
|
||||||
|
|
||||||
|
return dataFolder
|
||||||
|
|
||||||
|
# Ensure all namecoin options are set, by setting those to default values
|
||||||
|
# that aren't there.
|
||||||
|
def ensureNamecoinOptions ():
|
||||||
|
if not shared.config.has_option (configSection, "namecoinrpchost"):
|
||||||
|
shared.config.set (configSection, "namecoinrpchost", "localhost")
|
||||||
|
if not shared.config.has_option (configSection, "namecoinrpcport"):
|
||||||
|
shared.config.set (configSection, "namecoinrpcport", "8336")
|
||||||
|
|
||||||
|
hasUser = shared.config.has_option (configSection, "namecoinrpcuser")
|
||||||
|
hasPass = shared.config.has_option (configSection, "namecoinrpcpassword")
|
||||||
|
|
||||||
|
# Try to read user/password from .namecoin configuration file.
|
||||||
|
if (not hasUser) or (not hasPass):
|
||||||
|
try:
|
||||||
|
nmcFolder = lookupNamecoinFolder ()
|
||||||
|
nmcConfig = nmcFolder + "bitcoin.conf"
|
||||||
|
nmc = open (nmcConfig, "r")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
line = nmc.readline ()
|
||||||
|
if line == "":
|
||||||
|
break
|
||||||
|
parts = line.split ("=")
|
||||||
|
if len (parts) == 2:
|
||||||
|
key = parts[0]
|
||||||
|
val = parts[1].rstrip ()
|
||||||
|
|
||||||
|
if key == "rpcuser" and not hasUser:
|
||||||
|
shared.config.set (configSection,
|
||||||
|
"namecoinrpcuser", val)
|
||||||
|
if key == "rpcpassword" and not hasPass:
|
||||||
|
shared.config.set (configSection,
|
||||||
|
"namecoinrpcpassword", val)
|
||||||
|
|
||||||
|
nmc.close ()
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
print "Failure reading namecoin config file: %s" % str (exc)
|
||||||
|
if (not hasUser):
|
||||||
|
shared.config.set (configSection, "namecoinrpcuser", "")
|
||||||
|
if (not hasPass):
|
||||||
|
shared.config.set (configSection, "namecoinrpcpassword", "")
|
Reference in New Issue
Block a user