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(previous=initial) # Create a new contract contract1 = Contract() contract1.create(title='Digital legal handshake', desc='Hereby you declare to fulfill the following terms', deadline=int(time.time()), price=420.69) # Create a new term term1 = Contract.Term() term1.create(title='U gotta work', desc='Finish this', 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