Beispiel #1
0
def dump_utxos(datadir, output_dir, n, convert_segwit, maxT=0, debug=True):

    i = 0
    k = 1

    print('new file')
    f = new_utxo_file(output_dir, k)
    for value in ldb_iter(datadir):

        tx_hash, height, index, amt, script = value
        if convert_segwit:
            script = unwitness(script, debug)

        if debug:
            print(k, i, hexlify(tx_hash[::-1]), height, index,
                  amt, hexlify(script))

        f.write(struct.pack('<QQ', amt, len(script)))
        f.write(script)
        f.write('\n')

        i += 1
        if i % n == 0:
            f.close()

            k += 1
            print('new file: {}'.format(k))
            f = new_utxo_file(output_dir, k)

        if maxT != 0 and i >= maxT:
            break

    f.close()
Beispiel #2
0
def dump_utxos(datadir, output_dir, n, convert_segwit, maxT, debug, fileNum):
    # print("Starting to write Z-transactions")
    j = 0  #total utxo
    i = 0  #keep track of utxo per file
    k = fileNum  #relative number of file
    n = 0  #number of files written

    print('new file')
    f = new_utxo_file(output_dir, k)
    n += 1
    print('new_utxo_file path: ', f)

    for value in ldb_iter(datadir):
        tx_hash, height, index, amt, script = value

        if debug:
            print "Height: %d" % height
            print "Reversed: "
            reversedString = hexlify(tx_hash)
            print("".join(
                reversed([
                    reversedString[x:x + 2]
                    for x in range(0, len(reversedString), 2)
                ])))
            print ""

        if convert_segwit:
            script = unwitness(script, debug)

        f.write(struct.pack('<QQ', amt, len(script)))
        f.write(script)

        # append first sha256(transaction + its length)
        sha = hashlib.sha256()
        sha.update(struct.pack('<QQ', amt, len(script)) + script)
        sha256_hash = sha.digest()
        # print("SHA256: ", hexlify(sha256_hash))
        # print("SHA256: ", hexlify(sha256_hash[::-1]))
        f.write(sha256_hash[::-1])
        f.write('\n')

        i += 1
        j += 1
        if i >= maxT:
            f.close()
            k += 1
            i = 0
            f = new_utxo_file(output_dir, k)
            n += 1

    f.close()
    print("##########################################")
    print("Total T written: \t%d" % j)
    print("##########################################")
    return {'t_transactions_total': j, 't_files_written': n}