def get_merkle_chains(self, root_key_name_yesterday):
k=ndb.Key('DocRoot', root_key_name_yesterday)
doc_root=k.get()
if (doc_root.doc_root_hash!=''):
raise Exception('ERROR! doc_root_hash already used!')
my_list=DocLine.get_doclines_from_root(root_key_name_yesterday)
if len(my_list)==0:
raise Exception('WARNING. No documents to proof.')
my_list2=map(lambda x:x.content_hash,my_list)
tree = MerkleTree(my_list2, True)
tree.build()
doc_root_hash=binascii.hexlify(tree.root.val)
for i in range(len(my_list2)):
merkle_chain=tree.get_chain(i)
merkle_chain2=map(lambda x: (binascii.hexlify(x[0]),x[1]), merkle_chain)
my_list[i].merkle_chain=db.Text(str(merkle_chain2), encoding="latin-1")
my_list[i].doc_root=doc_root_hash
my_list[i].put()
doc_root=k.get()
doc_root.doc_root_hash=doc_root_hash
doc_root.date_broadcast=test.utcnow()
doc_root.nodes=db.Text(str(map(lambda x: binascii.hexlify(x.val), tree.leaves)), encoding='latin-1')
doc_root.put()
return doc_root_hash
评论列表
文章目录