Merge pull request #385 from TheNain38/patch-1
Support all custom namecoin.conf parameters
This commit is contained in:
commit
34c5a7ccde
2 changed files with 63 additions and 21 deletions
|
@ -83,6 +83,35 @@ def processBlock(block_id):
|
||||||
if updated:
|
if updated:
|
||||||
publish()
|
publish()
|
||||||
|
|
||||||
|
# Connecting to RPC
|
||||||
|
def initRpc(config):
|
||||||
|
"""Initialize Namecoin RPC"""
|
||||||
|
rpc_data = {
|
||||||
|
'connect': '127.0.0.1',
|
||||||
|
'port': '8336',
|
||||||
|
'user': 'PLACEHOLDER',
|
||||||
|
'password': 'PLACEHOLDER',
|
||||||
|
'clienttimeout': '900'
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
fptr = open(config, 'r')
|
||||||
|
lines = fptr.readlines()
|
||||||
|
fptr.close()
|
||||||
|
except:
|
||||||
|
return None # Or take some other appropriate action
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if not line.startswith('rpc'):
|
||||||
|
continue
|
||||||
|
key_val = line.split(None, 1)[0]
|
||||||
|
(key, val) = key_val.split('=', 1)
|
||||||
|
if not key or not val:
|
||||||
|
continue
|
||||||
|
rpc_data[key[3:]] = val
|
||||||
|
|
||||||
|
url = 'http://%(user)s:%(password)s@%(connect)s:%(port)s' % rpc_data
|
||||||
|
|
||||||
|
return AuthServiceProxy(url, timeout=int(rpc_data['clienttimeout']))
|
||||||
|
|
||||||
# Loading config...
|
# Loading config...
|
||||||
|
|
||||||
|
@ -106,15 +135,8 @@ config = json.load(open(config_path))
|
||||||
names_path = "%s/data/%s/data/names.json" % (config["zeronet_path"], config["site"])
|
names_path = "%s/data/%s/data/names.json" % (config["zeronet_path"], config["site"])
|
||||||
os.chdir(config["zeronet_path"]) # Change working dir - tells script where Zeronet install is.
|
os.chdir(config["zeronet_path"]) # Change working dir - tells script where Zeronet install is.
|
||||||
|
|
||||||
# Getting rpc connect details
|
# Initialize rpc connection
|
||||||
namecoin_conf = open(namecoin_location + "namecoin.conf").read()
|
rpc = initRpc(namecoin_location + "namecoin.conf")
|
||||||
|
|
||||||
# Connecting to RPC
|
|
||||||
rpc_user = re.search("rpcuser=(.*)$", namecoin_conf, re.M).group(1)
|
|
||||||
rpc_pass = re.search("rpcpassword=(.*)$", namecoin_conf, re.M).group(1)
|
|
||||||
rpc_url = "http://%s:%s@127.0.0.1:8336" % (rpc_user, rpc_pass)
|
|
||||||
|
|
||||||
rpc = AuthServiceProxy(rpc_url, timeout=60 * 5)
|
|
||||||
|
|
||||||
last_block = int(rpc.getinfo()["blocks"])
|
last_block = int(rpc.getinfo()["blocks"])
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,36 @@
|
||||||
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||||
import time, json, os, sys, re, socket
|
import time, json, os, sys, re, socket
|
||||||
|
|
||||||
|
# Connecting to RPC
|
||||||
|
def initRpc(config):
|
||||||
|
"""Initialize Namecoin RPC"""
|
||||||
|
rpc_data = {
|
||||||
|
'connect': '127.0.0.1',
|
||||||
|
'port': '8336',
|
||||||
|
'user': 'PLACEHOLDER',
|
||||||
|
'password': 'PLACEHOLDER',
|
||||||
|
'clienttimeout': '900'
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
fptr = open(config, 'r')
|
||||||
|
lines = fptr.readlines()
|
||||||
|
fptr.close()
|
||||||
|
except:
|
||||||
|
return None # Or take some other appropriate action
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if not line.startswith('rpc'):
|
||||||
|
continue
|
||||||
|
key_val = line.split(None, 1)[0]
|
||||||
|
(key, val) = key_val.split('=', 1)
|
||||||
|
if not key or not val:
|
||||||
|
continue
|
||||||
|
rpc_data[key[3:]] = val
|
||||||
|
|
||||||
|
url = 'http://%(user)s:%(password)s@%(connect)s:%(port)s' % rpc_data
|
||||||
|
|
||||||
|
return AuthServiceProxy(url, timeout=int(rpc_data['clienttimeout']))
|
||||||
|
|
||||||
# Either returns domain's address or none if it doesn't exist
|
# Either returns domain's address or none if it doesn't exist
|
||||||
# Supports subdomains and .bit on the end
|
# Supports subdomains and .bit on the end
|
||||||
def lookupDomain(domain):
|
def lookupDomain(domain):
|
||||||
|
@ -43,15 +73,5 @@ if sys.platform == "win32":
|
||||||
else:
|
else:
|
||||||
namecoin_location = os.path.expanduser("~/.namecoin/")
|
namecoin_location = os.path.expanduser("~/.namecoin/")
|
||||||
|
|
||||||
# Getting rpc connect details
|
# Initialize rpc connection
|
||||||
namecoin_conf = open(namecoin_location + "namecoin.conf").read()
|
rpc = initRpc(namecoin_location + "namecoin.conf")
|
||||||
|
|
||||||
# Connecting to RPC
|
|
||||||
rpc_user = re.search(r"^\s*rpcuser\s*=(\S+)\s*(?:#.*)?$", namecoin_conf, re.M).group(1)
|
|
||||||
rpc_pass = re.search(r"^\s*rpcpassword\s*=(\S+)\s*(?:#.*)?$", namecoin_conf, re.M).group(1)
|
|
||||||
rpc_port = re.search(r"^\s*rpcport\s*=(\d{1,5})\s*(?:#.*)?$", namecoin_conf, re.M)
|
|
||||||
rpc_port = rpc_port.group(1) if rpc_port is not None else "8336"
|
|
||||||
|
|
||||||
rpc_url = "http://%s:%s@127.0.0.1:%s" % (rpc_user, rpc_pass, rpc_port)
|
|
||||||
|
|
||||||
rpc = AuthServiceProxy(rpc_url, timeout=60*5)
|
|
||||||
|
|
Loading…
Reference in a new issue