Exemple #1
0
def verify_proof(entry, proof, root):
    # Verifies proof for entry and given root. Returns boolean.
    # Entry must be a node
    # proof must be a list of Nodes
    # root to be compared (if entry + proof == root, return True)
    current_entry = entry
    for nodes in proof:
        # debug
        # print("FOR {}\nPROOF {}\nPOSITION {}".format(current_entry, nodes[0], nodes[1]))
        if nodes[1] == 1:
            # right child
            current_entry = MerkleNode(
                "",
                hashItem(current_entry.data["Transaction"] +
                         nodes[0].data["Transaction"]))
        else:
            current_entry = MerkleNode(
                "",
                hashItem(nodes[0].data["Transaction"] +
                         current_entry.data["Transaction"]))

    if current_entry.data["Transaction"] == root.data["Transaction"]:
        return True
    # print("expected: {}\nfound: {}".format(root.data["Transaction"], current_entry.data["Transaction"]))
    return False
Exemple #2
0
    def completeTransaction(self, _transaction):
        sendr_addr = _transaction.data["Receiver"]
        recv_addr = _transaction.data["Receiver"]
        amount = _transaction.data["Amount"]

        self.data["Balance"][sendr_addr] -= amount
        if recv_addr not in self.data:
            self.data["Balance"][recv_addr] = 0
        self.data["Balance"][recv_addr] += amount
        self.header = hashItem(self.header + hashItem(_transaction))
Exemple #3
0
 def __init__(self, _type, _transaction):
     self.data = {
         "Type": _type,
         "Transaction": hashItem(_transaction)
     }
     self.parent = None
     self.children = [None, None]
Exemple #4
0
def createNewNode(_merging_node, _incoming_node):
    new_transaction = hashItem(_merging_node.data["Transaction"] + _incoming_node.data["Transaction"])

    n = MerkleNode("", new_transaction)
    n.setChild(0, _merging_node)
    n.setChild(1, _incoming_node)
    _merging_node.setParent(n)
    _incoming_node.setParent(n)

    return n
Exemple #5
0
def verify_proof(entry, proof, root):
    # Verifies proof for entry and given root. Returns boolean.
    # Entry must be a node
    # proof must be a list of Nodes
    # root to be compared (if entry + proof == root, return True)
    current_entry = entry
    for nodes in proof:
        # debug
        # print("FOR {}\nPROOF {}\nPOSITION {}".format(current_entry, nodes[0], nodes[1]))
        if nodes[1] == 1:
            # right child
            current_entry = MerkleNode("", hashItem(current_entry.data["Transaction"] + nodes[0].data["Transaction"]))
        else:
            current_entry = MerkleNode("", hashItem(nodes[0].data["Transaction"] + current_entry.data["Transaction"]))

    if current_entry.data["Transaction"] == root.data["Transaction"]:
        return True
    # print("expected: {}\nfound: {}".format(root.data["Transaction"], current_entry.data["Transaction"]))
    return False
Exemple #6
0
def createNewNode(_merging_node, _incoming_node):
    new_transaction = hashItem(_merging_node.data["Transaction"] +
                               _incoming_node.data["Transaction"])

    n = MerkleNode("", new_transaction)
    n.setChild(0, _merging_node)
    n.setChild(1, _incoming_node)
    _merging_node.setParent(n)
    _incoming_node.setParent(n)

    return n
Exemple #7
0
    def verify(self, _prev_header, _tx_list):
        final_hash = _prev_header
        for tx in _tx_list:
            final_hash = hashItem(final_hash + hashItem(tx))

        return final_hash == self.header
Exemple #8
0
 def __init__(self, _type, _transaction):
     self.data = {"Type": _type, "Transaction": hashItem(_transaction)}
     self.parent = None
     self.children = [None, None]