Esempio n. 1
0
def main():
    # Start with an empty_tree
    global MerkleTree, Trees
    #RB = HashTableRB(MerkleNodeDigest, table=LevelDict(hashtable), validate=True)
    RB = MerkleRedBlack(MerkleNodeDigest)
    #start = 226274; MerkleTree = unhexlify("8f19e9e653edbe752e346585bfbe10711ff372f9810e96df4c2fc9d306452bb1")
    #start = 216573; MerkleTree = unhexlify("ac3b14a1a4295ce58b27d5eb6925364ec5f75e39ad0fc4a211fb76895776dc42")
    #start = 175005; MerkleTree = unhexlify("e4ca15dd2b5f8063e340ed884924a9355719fb341a7a4bdc513d173ab609ec0b")
    #start = 128285; MerkleTree = unhexlify("74ac1d7315faa41b21ef8546e6baed5dc50d29fbd28f07d796c2b8141770dd2a")
    #start = 26528; MerkleTree = unhexlify('4f56e9c4f27b8acd59beb7dac8236602107b957e96422cbb8974e1d787cd2425')
    #start = 10092; MerkleTree = unhexlify('06fcf352f291a6f7242590266c0d80ca6514b779f8b9c4803887c0bf415b028c')
    #start = 1532; MerkleTree = unhexlify('c52fe74601b83ef8e55c138293741901ae474d34d7dbf344713f0a21bbc5fe5c')
    start = -1
    MerkleTree = RB.E

    txs = transactions_in_order()

    Trees = []
    utxo_size = 0
    txouts = 0
    for i, (nHeight, tx_id, txn) in enumerate(txs):
        #RB = HashTableRB(MerkleNodeDigest, table=LevelDict(hashtable), validate=True)
        RB = MerkleRedBlack(MerkleNodeDigest)
        if i <= start: continue
        MerkleTree = reduce(partial(apply_update, RB),
                            updates_in_transaction(nHeight, tx_id, txn),
                            MerkleTree)
        #utxo_size += len(txn['txOut']) - len([1 for txin in txn['txIn'] if txin['prevout_hash'] != genesis])
        #txouts += len(txn['txOut'])
        #Trees.append(MerkleTree)
        print i, hexlify(MerkleTree[0])
        #if nHeight >= 200000: break
        if nHeight >= 1000: break
Esempio n. 2
0
def demo_merkle():
    RB = MerkleRedBlack()
    D = RB.E
    print D
    for i in range(10):
        D = RB.insert(i, D)
    print D
Esempio n. 3
0
def demo_merkle():
    RB = MerkleRedBlack()
    D = RB.E
    print D
    for i in range(10):
        D = RB.insert(i, D)
    print D
Esempio n. 4
0
def demo_record():
    # Start with an empty_tree
    global MerkleTree, Trees, RB
    #RB = HashTableRB(MerkleNodeDigest, table=LevelDict(hashtable), validate=True)
    RB = MerkleRedBlack(MerkleNodeDigest)
    start = -1
    MerkleTree = RB.E

    txs = transactions_in_order()

    Trees = []
    utxo_size = 0
    txouts = 0
    RB = RecordTraversal(MerkleNodeDigest)
    with open('testdb/vofile.json', 'w') as vofile:
        for i, (nHeight, tx_id, txn) in enumerate(txs):
            if i <= start: continue
            RB = RecordTraversal(MerkleNodeDigest)
            #RB = HashTableRB(MerkleNodeDigest, table=LevelDict(hashtable), validate=True)
            #RB = MerkleRedBlack(MerkleNodeDigest)
            MerkleTree = reduce(partial(apply_update, RB),
                                updates_in_transaction(nHeight, tx_id, txn),
                                MerkleTree)
            #vo = pickle.dumps(RB.VO)
            #vofile.write(vo)
            print nHeight, i, hexlify(MerkleTree[0])
            if nHeight > 0x100000: break
Esempio n. 5
0
def demo_recordreplay():
    RB = MerkleRedBlack()
    D = RB.E
    print D
    for i in range(10):
        D = RB.insert(i, D)
    print D

    roothash = D[0]

    record = RecordTraversal()
    for i in range(10):
        D = record.delete(i, D)
    print D
    print record.VO

    replay = ReplayTraversal(record.VO)
    D = roothash
    for i in range(9):
        D = replay.delete(i, D)
    print D
Esempio n. 6
0
def demo_recordreplay():
    RB = MerkleRedBlack()
    D = RB.E
    print D
    for i in range(10):
        D = RB.insert(i, D)
    print D

    roothash = D[0]

    record = RecordTraversal()
    for i in range(10):
        D = record.delete(i, D)
    print D
    print record.VO

    replay = ReplayTraversal(record.VO)
    D = roothash
    for i in range(9):
        D = replay.delete(i, D)
    print D
Esempio n. 7
0
import subprocess
import unittest
import random
from Crypto.Hash import SHA256
import json
import redblack
reload(redblack)
from redblack import MerkleRedBlack

H = lambda x: SHA256.new(json.dumps(x)).hexdigest()[:4]
RB = MerkleRedBlack(H, 4 * '0')
insert = RB.insert
delete = RB.delete


def tree2dot_plain(D):
    layer = """
digraph BST {
node [fontname="Arial"];

%s
}
    """

    def edges(D, level=0):
        if not D: return

        (c, L, k, R) = D
        d0, dL, dR = map(lambda x: abs(hash(x)), (D, L, R))

        node = 'N%d_%s' % (level, d0)
Esempio n. 8
0
 def setUp(self):
     self.RB = MerkleRedBlack()