|
|
|
@ -13,7 +13,11 @@ import sys, cPickle
@@ -13,7 +13,11 @@ import sys, cPickle
|
|
|
|
|
|
|
|
|
|
dbFileName = "twisterDataGuard.pickle" |
|
|
|
|
nodeUserName = "twisterdataguard" |
|
|
|
|
blocksInStep = 10000 |
|
|
|
|
blocksInStep = 10 |
|
|
|
|
|
|
|
|
|
class MyDb: |
|
|
|
|
lastBlockHash = 0 |
|
|
|
|
dataLock = False |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
from bitcoinrpc.authproxy import AuthServiceProxy |
|
|
|
@ -27,37 +31,45 @@ if len(sys.argv) > 1:
@@ -27,37 +31,45 @@ if len(sys.argv) > 1:
|
|
|
|
|
|
|
|
|
|
twister = AuthServiceProxy(serverUrl) |
|
|
|
|
|
|
|
|
|
class MyDb: |
|
|
|
|
lastBlockHash = 0 |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
db = cPickle.load(open(dbFileName)) |
|
|
|
|
nextHash = db.lastBlockHash |
|
|
|
|
dataLock = db.dataLock |
|
|
|
|
except: |
|
|
|
|
db = MyDb() |
|
|
|
|
nextHash = twister.getblockhash(0) |
|
|
|
|
dataLock = db.dataLock |
|
|
|
|
|
|
|
|
|
if not dataLock: |
|
|
|
|
|
|
|
|
|
db.dataLock = True |
|
|
|
|
cPickle.dump(db, open(dbFileName, "w")) |
|
|
|
|
|
|
|
|
|
print "blockchain reading..." |
|
|
|
|
|
|
|
|
|
print "blockchain reading..." |
|
|
|
|
while True: |
|
|
|
|
|
|
|
|
|
while True: |
|
|
|
|
block = twister.getblock(nextHash) |
|
|
|
|
db.lastBlockHash = block["hash"] |
|
|
|
|
|
|
|
|
|
block = twister.getblock(nextHash) |
|
|
|
|
db.lastBlockHash = block["hash"] |
|
|
|
|
blocksInStep = blocksInStep - 1 |
|
|
|
|
if blocksInStep < 0: |
|
|
|
|
db.dataLock = False |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
blocksInStep = blocksInStep - 1 |
|
|
|
|
if blocksInStep < 0: |
|
|
|
|
break |
|
|
|
|
print "read block", str(block["height"])# + "\r", |
|
|
|
|
|
|
|
|
|
print "read block", str(block["height"])# + "\r", |
|
|
|
|
for u in block["usernames"]: |
|
|
|
|
print "follow", u |
|
|
|
|
twister.follow(nodeUserName, [u]) |
|
|
|
|
if block.has_key("nextblockhash"): |
|
|
|
|
nextHash = block["nextblockhash"] |
|
|
|
|
else: |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
for u in block["usernames"]: |
|
|
|
|
print "follow", u |
|
|
|
|
twister.follow(nodeUserName, [u]) |
|
|
|
|
if block.has_key("nextblockhash"): |
|
|
|
|
nextHash = block["nextblockhash"] |
|
|
|
|
else: |
|
|
|
|
break |
|
|
|
|
cPickle.dump(db, open(dbFileName, "w")) |
|
|
|
|
|
|
|
|
|
cPickle.dump(db,open(dbFileName, "w")) |
|
|
|
|
print "task completed." |
|
|
|
|
|
|
|
|
|
print "task completed." |
|
|
|
|
else: |
|
|
|
|
print "operation locked by the running process." |
|
|
|
|