Skip to content

Commit

Permalink
moved generateGenesis to BlockChain
Browse files Browse the repository at this point in the history
  • Loading branch information
lee195 committed Jun 17, 2019
1 parent a431855 commit e866a5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 10 additions & 6 deletions Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class MerkleTree:
"""

def __init__(self, data):
"""Takes a list of tx and calculates pairwise hashes until only one element remains
Parameters:
data (list): List of tx
Sets:
self.data (nested list): List of original data and all lists of pairwise hashes
"""

def hash_data(data_a, data_b):
hasher = hashlib.sha256()
hasher.update(str(data_a).encode() + str(data_b).encode())
Expand Down Expand Up @@ -78,9 +87,4 @@ def hash_val(self):
return hasher.hexdigest()

def get_tx(self):
return self.data.data[0]


#TODO: move to different module
def generate_genesis():
return Block(["Genesis tx"], 0)
return self.data.data[0]
5 changes: 5 additions & 0 deletions BlockChain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

#TODO: replace with netstats at some point


def generate_genesis():
return Block.Block(['Genesis tx'], 0)


if __name__ == "__main__":
print('Blockchain Simulation: Distributed Object Ordering with Fairness\n')
memory.append(Block.generate_genesis())
Expand Down
4 changes: 2 additions & 2 deletions Consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@author: jisu
"""

import hashlib, Block, random
import hashlib, Block, random, BlockChain

random.seed(0)

Expand Down Expand Up @@ -111,7 +111,7 @@ def consensus_reached(proposals):
ids = ['1', '2', '3']
prios = ['top', 'normal', 'top']
print(priority_sort(ids, prios))
gen = Block.generate_genesis()
gen = BlockChain.generate_genesis()
print(consistency(gen, gen))
test_block1 = Block.Block([1], 0)
print(consistency(gen, test_block1))
Expand Down

0 comments on commit e866a5e

Please sign in to comment.