connector

This commit is contained in:
4tochka 2019-05-09 00:14:24 +04:00
parent 07ad03bb6a
commit 2de3d7e73e

View File

@ -200,56 +200,59 @@ class Worker:
self.loop.run_forever()
async def load_blocks(self, height):
batch = list()
h_list = list()
while True:
batch.append(["getblockhash", height])
h_list.append(height)
if len(batch) >= self.rpc_batch_limit:
try:
batch = list()
h_list = list()
while True:
batch.append(["getblockhash", height])
h_list.append(height)
if len(batch) >= self.rpc_batch_limit:
height += 1
break
height += 1
break
height += 1
result = await self.rpc.batch(batch)
h = list()
batch = list()
for lh, r in zip(h_list, result):
if r["result"] is not None:
batch.append(["getblock", r["result"], 0])
h.append(lh)
result = await self.rpc.batch(batch)
blocks = dict()
for x, y in zip(h, result):
if y["result"] is not None:
block = decode_block_tx(y["result"])
for z in block["rawTx"]:
for i in block["rawTx"][z]["vIn"]:
inp = block["rawTx"][z]["vIn"][i]
outpoint = b"".join((inp["txId"], int_to_bytes(inp["vOut"])))
result = await self.rpc.batch(batch)
h = list()
batch = list()
for lh, r in zip(h_list, result):
if r["result"] is not None:
batch.append(["getblock", r["result"], 0])
h.append(lh)
result = await self.rpc.batch(batch)
blocks = dict()
for x, y in zip(h, result):
if y["result"] is not None:
block = decode_block_tx(y["result"])
for z in block["rawTx"]:
for i in block["rawTx"][z]["vIn"]:
inp = block["rawTx"][z]["vIn"][i]
outpoint = b"".join((inp["txId"], int_to_bytes(inp["vOut"])))
try:
r = self.coins[outpoint]
block["rawTx"][z]["vIn"][i]["__coin__"] = (outpoint, r[0], r[1], r[2])
self.destroyed_coins[r[0]] = True
except:
pass
for i in block["rawTx"][z]["vOut"]:
o = b"".join((block["rawTx"][z]["txId"], int_to_bytes(i)))
pointer = (x << 42) + (z << 21) + i
try:
address = block["rawTx"][z]["vOut"][i]["scriptPubKey"]
except:
address = b"".join((bytes([block["rawTx"][z]["vOut"][i]["nType"]]),
block["rawTx"][z]["vOut"][i]["addressHash"]))
self.coins[o] = (pointer, block["rawTx"][z]["vOut"][i], address)
for x in blocks:
for y in blocks[x]["rawTx"]:
for i in blocks[x]["rawTx"][y]["vOut"]:
try:
r = self.coins[outpoint]
block["rawTx"][z]["vIn"][i]["__coin__"] = (outpoint, r[0], r[1], r[2])
self.destroyed_coins[r[0]] = True
except:
pass
for i in block["rawTx"][z]["vOut"]:
o = b"".join((block["rawTx"][z]["txId"], int_to_bytes(i)))
pointer = (x << 42) + (z << 21) + i
try:
address = block["rawTx"][z]["vOut"][i]["scriptPubKey"]
except:
address = b"".join((bytes([block["rawTx"][z]["vOut"][i]["nType"]]),
block["rawTx"][z]["vOut"][i]["addressHash"]))
self.coins[o] = (pointer, block["rawTx"][z]["vOut"][i], address)
for x in blocks:
for y in blocks[x]["rawTx"]:
for i in blocks[x]["rawTx"][y]["vOut"]:
try:
pointer = (x << 42) + (y << 21) + i
blocks[x]["rawTx"][y]["vOut"]["__spent__"] = self.destroyed_coins[pointer]
except: pass
blocks[x] = pickle.dumps(blocks[x])
pointer = (x << 42) + (y << 21) + i
blocks[x]["rawTx"][y]["vOut"]["__spent__"] = self.destroyed_coins[pointer]
except: pass
blocks[x] = pickle.dumps(blocks[x])
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
self.pipe_sent_msg(b'result', pickle.dumps(blocks))
except:
self.log.critical(str(traceback.format_exc()))
async def message_loop(self):
try: