def traverse_contracts(self, contract_id, contract_type):
        contract_of_type = None
        contract = self.data_manager.get_contract(contract_id) \
                   if self.data_manager.contract_on_blockchain(contract_id) else None

        # Traverse contract chain
        while contract:
            if contract.type == contract_type:
                contract_of_type = contract

            contracts = self.data_manager.find_contracts(Contract.previous_hash == contract.id)
            contracts = [contract for contract in list(contracts) if self.data_manager.contract_on_blockchain(contract.id)]

            if len(contracts) == 1:
                # Keep traversing the contract chain
                contract = contracts[0]
                continue

            elif len(contracts) == 0:
                # Found end of contract chain
                return contract if contract_type is None else contract_of_type

            break