Publish all changes at once, fix lastprocessed
This commit is contained in:
parent
382091cb1c
commit
9d7efade61
1 changed files with 15 additions and 19 deletions
|
@ -79,8 +79,7 @@ def processBlock(block_id):
|
||||||
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)
|
||||||
if updated:
|
return updated
|
||||||
publish()
|
|
||||||
|
|
||||||
# Connecting to RPC
|
# Connecting to RPC
|
||||||
def initRpc(config):
|
def initRpc(config):
|
||||||
|
@ -125,7 +124,7 @@ else:
|
||||||
config_path = namecoin_location + 'zeroname_config.json'
|
config_path = namecoin_location + 'zeroname_config.json'
|
||||||
if not os.path.isfile(config_path): # Create sample config
|
if not os.path.isfile(config_path): # Create sample config
|
||||||
open(config_path, "w").write(
|
open(config_path, "w").write(
|
||||||
json.dumps({'site': 'site', 'zeronet_path': '/home/zeronet', 'privatekey': '', 'lastprocessed': 223911}, indent=2)
|
json.dumps({'site': 'site', 'zeronet_path': '/home/zeronet', 'privatekey': '', 'lastprocessed': 223910}, indent=2)
|
||||||
)
|
)
|
||||||
print "Example config written to %s" % config_path
|
print "Example config written to %s" % config_path
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -141,17 +140,9 @@ 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"]: # Start processing from last block
|
||||||
config["lastprocessed"] = last_block
|
config["lastprocessed"] = int(AuthServiceProxy(rpc_auth, timeout=rpc_timeout).getinfo()["blocks"])
|
||||||
|
|
||||||
# Processing skipped blocks
|
|
||||||
print "Processing block from #%s to #%s..." % (config["lastprocessed"], last_block)
|
|
||||||
for block_id in range(config["lastprocessed"], last_block + 1):
|
|
||||||
processBlock(block_id)
|
|
||||||
|
|
||||||
# processBlock(223911) # Testing zeronetwork.bit
|
# processBlock(223911) # Testing zeronetwork.bit
|
||||||
# processBlock(227052) # Testing brainwallets.bit
|
# processBlock(227052) # Testing brainwallets.bit
|
||||||
|
@ -161,27 +152,32 @@ for block_id in range(config["lastprocessed"], last_block + 1):
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
config["lastprocessed"] = last_block
|
print "Waiting for new block"
|
||||||
open(config_path, "w").write(json.dumps(config, indent=2))
|
|
||||||
|
|
||||||
print "Waiting for new block",
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout)
|
rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout)
|
||||||
if (int(rpc.getinfo()["blocks"]) > last_block):
|
if (int(rpc.getinfo()["blocks"]) > config["lastprocessed"]):
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
rpc.waitforblock()
|
rpc.waitforblock()
|
||||||
print "Found"
|
print "Found"
|
||||||
break # Block found
|
break # Block found
|
||||||
except socket.timeout: # Timeout
|
except socket.timeout: # Timeout
|
||||||
print ".",
|
print "."
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print "Exception", err.__class__, err
|
print "Exception", err.__class__, err
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
last_block = int(rpc.getinfo()["blocks"])
|
last_block = int(rpc.getinfo()["blocks"])
|
||||||
|
should_publish = False
|
||||||
for block_id in range(config["lastprocessed"] + 1, last_block + 1):
|
for block_id in range(config["lastprocessed"] + 1, last_block + 1):
|
||||||
processBlock(block_id)
|
if processBlock(block_id):
|
||||||
|
should_publish = True
|
||||||
|
|
||||||
|
config["lastprocessed"] = last_block
|
||||||
|
open(config_path, "w").write(json.dumps(config, indent=2))
|
||||||
|
|
||||||
|
if should_publish:
|
||||||
|
publish()
|
||||||
|
|
Loading…
Reference in a new issue