示例#1
0
def write_blocks_to_file(directory, file_prefix, start_block, no_blocks):

    next_block = start_block
    counter = 0
    out = None
    filesize = 1024 * 1024 * 32
    while True:
        if not out or (out and (out.tell() > filesize)):
            if out:
                out.close()
            filename = os.path.join(directory,
                                    "%s_%s.bin" % (file_prefix, counter))
            print("Writing to file " + filename)
            out = open(filename, "wb")
        block_json = json.loads(blockutil.fetch_block_text(next_block))

        next_block, block, txs = blockutil.transform_json(block_json)
        block.append(txs)
        pickle.dump(block, out, -1)

        print("Wrote block %s" % counter, end="\r")
        if not next_block:
            break
        if no_blocks != 0:
            if counter >= no_blocks:
                break
        counter += 1
    out.close()
示例#2
0
 def write_next_blocks(self, start_block):
     next_block = blockutil.hash_str(start_block)
     while next_block:
         block_json = blockutil.fetch_block_json(next_block)
         if "nextblockhash" in block_json.keys():
             next_block, block, txs = blockutil.transform_json(block_json)
             batchStmt = BatchStatement()
             batchStmt.add(self.__insert_block_stmt, block)
             for transaction in txs:
                 batchStmt.add(self.__insert_transaction_stmt, transaction)
             while True:
                 try:
                     self.__session.execute(batchStmt)
                 except Exception as err:
                     print("Exception ", err, " retrying...", end="\r")
                     continue
                 break
             print("Wrote block %d" % (block[0]), end="\r")
 def write_next_blocks(self, start_block):
     next_block = blockutil.hash_str(start_block)
     while next_block:
         block_json = blockutil.fetch_block_json(next_block)
         next_block, block, txs = blockutil.transform_json(block_json)
         block_group = block[0] // 10000
         tx_number = 0
         try:
             self.__session.execute(self.__insert_block_stmt, block)
         except Exception as err:
             print("Exception ", err, " retrying...", end="\r")
             continue
         for transaction in txs:
             try:
                 self.__session.execute(self.__insert_transaction_stmt,[block_group, tx_number] + transaction)
             except Exception as err:
                 print("Exception ", err, " retrying...", end="\r")
                 continue
         print("Wrote block %d" % (block[0]), end="\r")