I am a beginner in python I want to transfer generated hash to a local 
database. I try it with socket programming but I fail. can anyone please help 
me ow I can do this?

class Block:
    def __init__( self, previous_block_hash, transaction_list ):
        self.previous_block_hash = previous_block_hash
        self.transaction_list = transaction_list

        self.block_data = f"{' - '.join(transaction_list)} - 
{previous_block_hash}"
        self.block_hash = hashlib.sha256(self.block_data.encode()).hexdigest()


class Blockchain:
    def __init__( self ):
        self.chain = [ ]
        self.generate_genesis_block()

    def generate_genesis_block( self ):
        self.chain.append(Block("0", [ 'Genesis Block' ]))

    def create_block_from_transaction( self, transaction_list ):
        previous_block_hash = self.last_block.block_hash
        self.chain.append(Block(previous_block_hash, transaction_list))

    def display_chain( self ):
        for i in range(len(self.chain)):
            print(f"Hash {i + 1}: {self.chain [ i ].block_hash}\n")

    @property
    def last_block( self ):
        return self.chain [ -1 ]


**t1 = Time_sensitive_df
t2 = "abcdefghijklmnopqrstuvwxyz"
t3 = normal_df
myblockchain = Blockchain()
myblockchain.create_block_from_transaction(t1)
myblockchain.create_block_from_transaction(t2)
myblockchain.create_block_from_transaction(t3)
myblockchain.display_chain()**
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to