import time from rpyc.utils.server import ThreadedServer from lib.chain import Chain, Block from lib.rpc import RPC from lib.transaction import Transaction from lib.contract import Contract if __name__ == '__main__': # Initialize the chain (Creates empty chain) chain = Chain() # Initialize the genesis block initial = Block() initial.previous_hash = 'This is the founding block for our DSP project' initial.proof = 69 # Lock block initial.lock_hash_finish() # Add the genesis block to the chain chain.add_block(block=initial) # Chain work starts from here # Static chain interaction block1 = Block() block1.previous_hash = chain.last_block().hash_value # Create a new contract contract1 = Contract() contract1.title = 'Digital legal handshake' contract1.description = 'Hereby you declare to fulfill the following terms' contract1.deadline = int(time.time()) contract1.price = 420 # Create a new term term1 = Contract.Term() term1.title = 'U gotta work' term1.description = 'Finish this' term1.deadline = int(time.time()) # Add term to contract1 contract1.add_term(term=term1) # Bind contract to transaction transaction1 = Transaction() transaction1.set_contract(contract=contract1) # Add transaction to current block block1.add_transaction(trans=transaction1) # Finish block and all its transactions block1.lock_hash_finish() block2 = Block(previous=block1) server = ThreadedServer(RPC, port=42069) server.start() # Create a loop that starts to sleep for 10 seconds / mocking a 10 second block time while True: # Wait 10 seconds time.sleep(10) # Possible TODO's: # * Upon adding transaction to block check if transaction is already locked