def gen_next_block(self, public_key, transactions): prev_block = self.chain[-1] index = prev_block.index + 1 timestamp = datetime.datetime.now() data = transactions hashed_block = prev_block.gen_hashed_block() self.chain.append(Block(index, timestamp, data, hashed_block, public_key))
def generate_genesis(self): with open('genesis_data.json') as json_file: data = json.dumps(json.load(json_file)) genesis_block = Block( 0, str(time.time()), data, "Why are we still here? Just to suffer? Every night, I can feel my leg… and my arm… even my fingers. The body I’ve lost… the comrades I’ve lost… won’t stop hurting… It’s like they’re all still there. You feel it, too, don’t you?" ) self.block_data.append(genesis_block)
def validate_block(self, block): last_block = self.block_data[-1] veri_block = Block(last_block.index + 1, block.timestamp, block.data, last_block.curr_hash) return veri_block.curr_hash == block.curr_hash
def create_block(self, data): curr_block = self.block_data[-1] new_block = Block(curr_block.index + 1, str(time.time()), data, curr_block.curr_hash) return new_block
def gen_genesis_block(): transaction = ["XX:XX:XX:XX:XX"] return Block(0, datetime.datetime.now(), transaction, "0", "0")