From 85313c2186a966097fbdab1dde9cbaefc7358997 Mon Sep 17 00:00:00 2001 From: Idealcoder Date: Wed, 17 Jun 2015 21:10:21 +0100 Subject: [PATCH 1/4] Fixed zeroname_updater.py script under windows finding namecoin location Windows stores namecoin config in %appdata%/Namecoin rather than ~./namecoin, so the code now checks for the platform, and creates a variable called namecoin_location with the right location. --- plugins/Zeroname/updater/zeroname_updater.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index 30521afe..165e885f 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -69,7 +69,16 @@ def processBlock(block_id): # Loading config... -config_path = os.path.expanduser("~/.namecoin/zeroname_config.json") + +# Check whether platform is on windows or linux +# On linux namecoin is installed under ~/.namecoin, while on on windows it is in %appdata%/Namecoin + +if sys.platform == "win32": + namecoin_location = os.getenv('APPDATA') + "/Namecoin/" +else: + namecoin_location = os.path.expanduser("~/.namecoin/") + +config_path = namecoin_location + 'zeroname_config.json' if not os.path.isfile(config_path): # Create sample config open(config_path, "w").write( json.dumps({'site': 'site', 'zeronet_path': '/home/zeronet/', 'privatekey': '', 'lastprocessed': None}, indent=2) @@ -79,15 +88,16 @@ if not os.path.isfile(config_path): # Create sample config config = json.load(open(config_path)) names_path = "%s/data/%s/data/names.json" % (config["zeronet_path"], config["site"]) -os.chdir(config["zeronet_path"]) # Change working dir +os.chdir(config["zeronet_path"]) # Change working dir - tells script where Zeronet install is. # Getting rpc connect details -namecoin_conf = open(os.path.expanduser("~/.namecoin/namecoin.conf")).read() +namecoin_conf = open(namecoin_location + "namecoin.conf").read() # 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"]) From 61558998933f1bf744f7ad89ddedf29c7022711c Mon Sep 17 00:00:00 2001 From: Idealcoder Date: Wed, 17 Jun 2015 21:11:57 +0100 Subject: [PATCH 2/4] Added note on zeroname_updater.py Comment pointing out a data/names.json file has to exist in the site for it to work. --- plugins/Zeroname/updater/zeroname_updater.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index 165e885f..1434a1d5 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -28,6 +28,7 @@ def processNameOp(domain, value): print "Waiting for master update arrive" time.sleep(30) # Wait 30 sec to allow master updater + #Note: Requires the file data/names.json to exist and contain "{}" to work names_raw = open(names_path, "rb").read() names = json.loads(names_raw) for subdomain, address in data["zeronet"].items(): From 0fa87523fd7b95d9b9991d0d36fd7f7615409aa2 Mon Sep 17 00:00:00 2001 From: Idealcoder Date: Wed, 17 Jun 2015 21:14:41 +0100 Subject: [PATCH 3/4] Fixed zeroname_updater.py crashing underwindows with UTF8 For some reason windows doesn't like parsing namecoin domains with "weird" characters, so adding a try to catch exception stops a strange block crashing the script - instead it ignores and moves on. We just have to hope there doesn't happen to be a namecoin domain in a block with weird characters. --- plugins/Zeroname/updater/zeroname_updater.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index 1434a1d5..26191a87 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -59,11 +59,14 @@ def processBlock(block_id): print "Checking %s tx" % len(block["tx"]) updated = 0 for tx in block["tx"]: - transaction = rpc.getrawtransaction(tx, 1) - for vout in transaction.get("vout",[]): - if "scriptPubKey" in vout and "nameOp" in vout["scriptPubKey"] and "name" in vout["scriptPubKey"]["nameOp"]: - name_op = vout["scriptPubKey"]["nameOp"] - updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"]) + try: + transaction = rpc.getrawtransaction(tx, 1) + for vout in transaction.get("vout",[]): + if "scriptPubKey" in vout and "nameOp" in vout["scriptPubKey"] and "name" in vout["scriptPubKey"]["nameOp"]: + name_op = vout["scriptPubKey"]["nameOp"] + updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"]) + except Exception, err: + print "Error processing tx #%s %s" % (tx, err) print "Done in %.3fs (updated %s)." % (time.time()-s, updated) if updated: publish() From 4e1586acef71a993594cca713f67d878ea3cd3d2 Mon Sep 17 00:00:00 2001 From: Idealcoder Date: Wed, 17 Jun 2015 21:18:55 +0100 Subject: [PATCH 4/4] Changed zeroname_updater.py so that is starts be default on the first block with a namecoin domain Previously the default was null, causing the script to start from the latest block and so not scan any of the blocks that have happened before. 223911 is the first block with a namecoin domain, so there is no point starting before that. --- plugins/Zeroname/updater/zeroname_updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index 26191a87..ace15f62 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -85,7 +85,7 @@ else: config_path = namecoin_location + 'zeroname_config.json' if not os.path.isfile(config_path): # Create sample config open(config_path, "w").write( - json.dumps({'site': 'site', 'zeronet_path': '/home/zeronet/', 'privatekey': '', 'lastprocessed': None}, indent=2) + json.dumps({'site': 'site', 'zeronet_path': '/home/zeronet/', 'privatekey': '', 'lastprocessed': 223911}, indent=2) ) print "Example config written to %s" % config_path sys.exit(0)