Test block parsing at startup
This commit is contained in:
parent
58f0b0d0a1
commit
1f612fa1b0
1 changed files with 17 additions and 10 deletions
|
@ -14,7 +14,7 @@ def publish():
|
||||||
call(" ".join(command_sign_publish), shell=True)
|
call(" ".join(command_sign_publish), shell=True)
|
||||||
|
|
||||||
|
|
||||||
def processNameOp(domain, value):
|
def processNameOp(domain, value, test=False):
|
||||||
if not value.strip().startswith("{"):
|
if not value.strip().startswith("{"):
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
|
@ -32,6 +32,9 @@ def processNameOp(domain, value):
|
||||||
print "Invalid domain: ", domain
|
print "Invalid domain: ", domain
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if test:
|
||||||
|
return True
|
||||||
|
|
||||||
if "slave" in sys.argv:
|
if "slave" in sys.argv:
|
||||||
print "Waiting for master update arrive"
|
print "Waiting for master update arrive"
|
||||||
time.sleep(30) # Wait 30 sec to allow master updater
|
time.sleep(30) # Wait 30 sec to allow master updater
|
||||||
|
@ -61,7 +64,7 @@ def processNameOp(domain, value):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def processBlock(block_id):
|
def processBlock(block_id, test=False):
|
||||||
print "Processing block #%s..." % block_id
|
print "Processing block #%s..." % block_id
|
||||||
s = time.time()
|
s = time.time()
|
||||||
block_hash = rpc.getblockhash(block_id)
|
block_hash = rpc.getblockhash(block_id)
|
||||||
|
@ -75,7 +78,7 @@ def processBlock(block_id):
|
||||||
for vout in transaction.get("vout", []):
|
for vout in transaction.get("vout", []):
|
||||||
if "scriptPubKey" in vout and "nameOp" in vout["scriptPubKey"] and "name" in vout["scriptPubKey"]["nameOp"]:
|
if "scriptPubKey" in vout and "nameOp" in vout["scriptPubKey"] and "name" in vout["scriptPubKey"]["nameOp"]:
|
||||||
name_op = vout["scriptPubKey"]["nameOp"]
|
name_op = vout["scriptPubKey"]["nameOp"]
|
||||||
updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"])
|
updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"], test)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print "Error processing tx #%s %s" % (tx, err)
|
print "Error processing tx #%s %s" % (tx, err)
|
||||||
print "Done in %.3fs (updated %s)." % (time.time() - s, updated)
|
print "Done in %.3fs (updated %s)." % (time.time() - s, updated)
|
||||||
|
@ -140,15 +143,19 @@ if sys.platform == 'win32':
|
||||||
|
|
||||||
# Initialize rpc connection
|
# Initialize rpc connection
|
||||||
rpc_auth, rpc_timeout = initRpc(namecoin_location + "namecoin.conf")
|
rpc_auth, rpc_timeout = initRpc(namecoin_location + "namecoin.conf")
|
||||||
|
rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout)
|
||||||
|
last_block = int(rpc.getinfo()["blocks"])
|
||||||
|
|
||||||
if not config["lastprocessed"]: # Start processing from last block
|
if not config["lastprocessed"]: # First startup: Start processing from last block
|
||||||
config["lastprocessed"] = int(AuthServiceProxy(rpc_auth, timeout=rpc_timeout).getinfo()["blocks"])
|
config["lastprocessed"] = last_block
|
||||||
|
|
||||||
# processBlock(223911) # Testing zeronetwork.bit
|
|
||||||
# processBlock(227052) # Testing brainwallets.bit
|
print "- Testing domain parsing..."
|
||||||
# processBlock(236824) # Utf8 domain name (invalid should skip)
|
assert processBlock(223911, test=True) # Testing zeronetwork.bit
|
||||||
# processBlock(236752) # Uppercase domain (invalid should skip)
|
assert processBlock(227052, test=True) # Testing brainwallets.bit
|
||||||
# processBlock(236870) # Encoded domain (should pass)
|
assert not processBlock(236824, test=True) # Utf8 domain name (invalid should skip)
|
||||||
|
assert not processBlock(236752, test=True) # Uppercase domain (invalid should skip)
|
||||||
|
assert processBlock(236870, test=True) # Encoded domain (should pass)
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
|
|
Loading…
Reference in a new issue