From bddf8638b388f1f6bf8841f0671bf54b99eb1410 Mon Sep 17 00:00:00 2001 From: therealhamad <1ds22cg022@dsce.edu.in> Date: Thu, 25 Jul 2024 15:55:49 +0000 Subject: [PATCH 1/3] my new nada program --- nohup.out | 8 + .../client_code/run_my_first_program.py | 137 ++++++++++++++++++ .../nada-project.toml | 7 + .../nada_quickstart_programs/src/main.py | 12 ++ .../target/main.nada.bin | Bin 0 -> 901 bytes .../nada_quickstart_programs/src/main.py | 28 ++++ .../src/secret_addition_complete.py | 12 -- .../target/secret_addition_complete.nada.bin | Bin 975 -> 975 bytes 8 files changed, 192 insertions(+), 12 deletions(-) create mode 100644 nohup.out create mode 100644 quickstart/nada_quickstart_programs/nada-project.toml create mode 100644 quickstart/nada_quickstart_programs/src/main.py create mode 100644 quickstart/nada_quickstart_programs/target/main.nada.bin create mode 100644 quickstart_complete/nada_quickstart_programs/src/main.py delete mode 100644 quickstart_complete/nada_quickstart_programs/src/secret_addition_complete.py diff --git a/nohup.out b/nohup.out new file mode 100644 index 00000000..eb62c05a --- /dev/null +++ b/nohup.out @@ -0,0 +1,8 @@ +ℹ️ cluster id is 9e68173f-9c23-4acc-ba81-4f079b639964 +ℹ️ using 256 bit prime +ℹ️ storing state in /tmp/.tmpxw189i (77.97Gbs available) +🏃 starting nilchain node in: /tmp/.tmpxw189i/nillion-chain +Error: launching nilchain proxy + +Caused by: + Address in use (os error 98) diff --git a/quickstart/client_code/run_my_first_program.py b/quickstart/client_code/run_my_first_program.py index e69de29b..f8b258f4 100644 --- a/quickstart/client_code/run_my_first_program.py +++ b/quickstart/client_code/run_my_first_program.py @@ -0,0 +1,137 @@ +from datetime import datetime + +def display_tasks(tasks): + if not tasks: + print("Your to-do list is empty.") + return + + print("Your To-Do List:") + for index, task in enumerate(tasks, start=1): + status = "Done" if task['done'] else "Not done" + priority = task['priority'] + due_date = task['due_date'] if task['due_date'] else "No due date" + print(f"{index}. {task['task']} - [{status}] (Priority: {priority}) (Due: {due_date})") + +def add_task(tasks): + task = input("Enter a new task: ") + priority = input("Enter priority (low, medium, high): ").lower() + if priority not in ["low", "medium", "high"]: + priority = "low" + due_date = input("Enter due date (YYYY-MM-DD) or leave blank: ") + try: + due_date = datetime.strptime(due_date, "%Y-%m-%d").date() if due_date else None + except ValueError: + print("Invalid date format. No due date set.") + due_date = None + tasks.append({"task": task, "done": False, "priority": priority, "due_date": due_date}) + print(f"Task '{task}' added with priority '{priority}' and due date '{due_date}'.") + +def remove_task(tasks): + task_number = int(input("Enter the number of the task to remove: ")) + if 0 < task_number <= len(tasks): + removed_task = tasks.pop(task_number - 1) + print(f"Task '{removed_task['task']}' removed.") + else: + print("Invalid task number.") + +def mark_task_done(tasks): + task_number = int(input("Enter the number of the task to mark as done: ")) + if 0 < task_number <= len(tasks): + tasks[task_number - 1]['done'] = True + print(f"Task '{tasks[task_number - 1]['task']}' marked as done.") + else: + print("Invalid task number.") + +def edit_task(tasks): + task_number = int(input("Enter the number of the task to edit: ")) + if 0 < task_number <= len(tasks): + task = tasks[task_number - 1] + new_task = input(f"Enter new task description (current: '{task['task']}') or press Enter to keep it: ") + new_priority = input(f"Enter new priority (low, medium, high) (current: '{task['priority']}') or press Enter to keep it: ").lower() + new_due_date = input(f"Enter new due date (YYYY-MM-DD) (current: '{task['due_date']}') or press Enter to keep it: ") + + if new_task: + task['task'] = new_task + if new_priority in ["low", "medium", "high"]: + task['priority'] = new_priority + if new_due_date: + try: + task['due_date'] = datetime.strptime(new_due_date, "%Y-%m-%d").date() + except ValueError: + print("Invalid date format. Due date not changed.") + print("Task updated.") + else: + print("Invalid task number.") + +def sort_tasks(tasks, by): + if by == 'priority': + tasks.sort(key=lambda x: ['low', 'medium', 'high'].index(x['priority'])) + elif by == 'status': + tasks.sort(key=lambda x: x['done']) + elif by == 'due_date': + tasks.sort(key=lambda x: (x['due_date'] is None, x['due_date'])) + print(f"Tasks sorted by {by}.") + +def save_tasks(tasks, filename="tasks.txt"): + with open(filename, "w") as file: + for task in tasks: + file.write(f"{task['task']}|{task['done']}|{task['priority']}|{task['due_date']}\n") + print("Tasks saved to file.") + +def load_tasks(filename="tasks.txt"): + tasks = [] + try: + with open(filename, "r") as file: + for line in file: + task, done, priority, due_date = line.strip().split("|") + due_date = datetime.strptime(due_date, "%Y-%m-%d").date() if due_date != 'None' else None + tasks.append({"task": task, "done": done == "True", "priority": priority, "due_date": due_date}) + except FileNotFoundError: + print("No saved tasks found.") + return tasks + +def main(): + tasks = load_tasks() + while True: + print("\nOptions:") + print("1. View tasks") + print("2. Add task") + print("3. Remove task") + print("4. Mark task as done") + print("5. Edit task") + print("6. Sort tasks by priority") + print("7. Sort tasks by status") + print("8. Sort tasks by due date") + print("9. Save tasks") + print("10. Quit") + + choice = input("Select an option (1-10): ") + + if choice == '1': + display_tasks(tasks) + elif choice == '2': + add_task(tasks) + elif choice == '3': + remove_task(tasks) + elif choice == '4': + mark_task_done(tasks) + elif choice == '5': + edit_task(tasks) + elif choice == '6': + sort_tasks(tasks, 'priority') + elif choice == '7': + sort_tasks(tasks, 'status') + elif choice == '8': + sort_tasks(tasks, 'due_date') + elif choice == '9': + save_tasks(tasks) + elif choice == '10': + save_tasks(tasks) + break + else: + print("Invalid choice. Try again.") + +if __name__ == "__main__": + main() + + diff --git a/quickstart/nada_quickstart_programs/nada-project.toml b/quickstart/nada_quickstart_programs/nada-project.toml new file mode 100644 index 00000000..da166dde --- /dev/null +++ b/quickstart/nada_quickstart_programs/nada-project.toml @@ -0,0 +1,7 @@ +name = "nada_quickstart_programs" +version = "0.1.0" +authors = [""] + +[[programs]] +path = "src/main.py" +prime_size = 128 diff --git a/quickstart/nada_quickstart_programs/src/main.py b/quickstart/nada_quickstart_programs/src/main.py new file mode 100644 index 00000000..49e9e7e6 --- /dev/null +++ b/quickstart/nada_quickstart_programs/src/main.py @@ -0,0 +1,12 @@ +from nada_dsl import * + +def nada_main(): + party1 = Party(name="Party1") + party2 = Party(name="Party2") + party3 = Party(name="Party3") + a = SecretInteger(Input(name="A", party=party1)) + b = SecretInteger(Input(name="B", party=party2)) + + result = a + b + + return [Output(result, "my_output", party3)] \ No newline at end of file diff --git a/quickstart/nada_quickstart_programs/target/main.nada.bin b/quickstart/nada_quickstart_programs/target/main.nada.bin new file mode 100644 index 0000000000000000000000000000000000000000..23366cf50e29b3ed3117023079d7d30d78cf180b GIT binary patch literal 901 zcmaKq%}T^D5XbAc7V+Q{#GYDR#BDtZE3~)8gMvqqC2O;?ut`fcJ@g>>0D?Z0@8NqW zf|DkrZH)$oNv6O5%p@JpGi%NIP3y0yRP}Jno;aP0T z&cZFY3SKYWN+ke6figseHiS!S=xr+iUHy+03DBUk*!YE$&g9 zI<)O)MXq6*=_%oXt#FPf!@0`2<$k%oZ7uX2?Q8IU5CL z;DYFfh+Rb7CK4BsSc1aGYj!7@8VkklnGDAQexNOv1_RT_$aE8#!qb06SyvQ;sA*TS gWwlTsrR0cAF{Uah$jxOlHlaZVB>0{r%#}p9UoSMcL;wH) literal 0 HcmV?d00001 diff --git a/quickstart_complete/nada_quickstart_programs/src/main.py b/quickstart_complete/nada_quickstart_programs/src/main.py new file mode 100644 index 00000000..f757e818 --- /dev/null +++ b/quickstart_complete/nada_quickstart_programs/src/main.py @@ -0,0 +1,28 @@ +import requests + + +GITHUB_TOKEN = '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' +REPO_OWNER = 'therealhamad' +REPO_NAME = 'nillion-python-starter' + +def get_pull_requests(owner, repo): + url = f"https://api.github.com/repos/{owner}/{repo}/pulls" + headers = { + 'Authorization': f'token {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}', + 'Accept': 'application/vnd.github.v3+json' + } + response = requests.get(url, headers=headers) + return response.json() + +pull_requests = get_pull_requests(REPO_OWNER, REPO_NAME) + +print("Open Pull Requests:") +for pr in pull_requests: + number = pr['number'] + title = pr['title'] + user = pr['user']['login'] + created_at = pr['created_at'] + pr_url = pr['html_url'] + print(f"PR #{number}: {title} by {user} - Created at {created_at}") + print(f"URL: {pr_url}\n") + diff --git a/quickstart_complete/nada_quickstart_programs/src/secret_addition_complete.py b/quickstart_complete/nada_quickstart_programs/src/secret_addition_complete.py deleted file mode 100644 index be9daa13..00000000 --- a/quickstart_complete/nada_quickstart_programs/src/secret_addition_complete.py +++ /dev/null @@ -1,12 +0,0 @@ -from nada_dsl import * -def nada_main(): - - party1 = Party(name="Party1") - - my_int1 = SecretInteger(Input(name="my_int1", party=party1)) - - my_int2 = SecretInteger(Input(name="my_int2", party=party1)) - - new_int = my_int1 + my_int2 - - return [Output(new_int, "my_output", party1)] \ No newline at end of file diff --git a/quickstart_complete/nada_quickstart_programs/target/secret_addition_complete.nada.bin b/quickstart_complete/nada_quickstart_programs/target/secret_addition_complete.nada.bin index 4351b211b5ee0e0c053040d7af6f7bfb2346d48a..8a7ddc400179a64f02a085ad21da94458755d495 100644 GIT binary patch delta 102 zcmX@lex7}UIwR}aWf7mMChIVI3pFeTF&P;67#J8J?8%*su8Lp<3=AwlQ2{6$rm|r- VSo3>EQy~Zwsu?W2*^Fr>BLL)6Cxie1 delta 102 zcmX@lex7}UIwR|suS|>#lXV!qg#>P;0htU8d_W9gPwr%NRRk+wU|<1>LfJ5t0oTBq T-!qyDL6{KD5cXy>rkRWY4j~x8 From 75056c5ffc515dd5202308e0dd8d172dfc9a914b Mon Sep 17 00:00:00 2001 From: therealhamad <1ds22cg022@dsce.edu.in> Date: Thu, 25 Jul 2024 15:57:48 +0000 Subject: [PATCH 2/3] my new nada program --- quickstart_complete/nada_quickstart_programs/src/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quickstart_complete/nada_quickstart_programs/src/main.py b/quickstart_complete/nada_quickstart_programs/src/main.py index f757e818..f479170f 100644 --- a/quickstart_complete/nada_quickstart_programs/src/main.py +++ b/quickstart_complete/nada_quickstart_programs/src/main.py @@ -1,14 +1,14 @@ import requests -GITHUB_TOKEN = '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' -REPO_OWNER = 'therealhamad' +GITHUB_TOKEN = 'github-token' +REPO_OWNER = 'owner_name' REPO_NAME = 'nillion-python-starter' def get_pull_requests(owner, repo): url = f"https://api.github.com/repos/{owner}/{repo}/pulls" headers = { - 'Authorization': f'token {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}', + 'Authorization': f'token {github-token}', 'Accept': 'application/vnd.github.v3+json' } response = requests.get(url, headers=headers) From f71786465494bd2a47a55d88fa2ccad5a64f631e Mon Sep 17 00:00:00 2001 From: therealhamad <1ds22cg022@dsce.edu.in> Date: Thu, 25 Jul 2024 15:58:30 +0000 Subject: [PATCH 3/3] my new nada program --- .../nada_quickstart_programs/src/main.py | 163 +++++++++++++++--- 1 file changed, 136 insertions(+), 27 deletions(-) diff --git a/quickstart_complete/nada_quickstart_programs/src/main.py b/quickstart_complete/nada_quickstart_programs/src/main.py index f479170f..f1aabf02 100644 --- a/quickstart_complete/nada_quickstart_programs/src/main.py +++ b/quickstart_complete/nada_quickstart_programs/src/main.py @@ -1,28 +1,137 @@ -import requests - - -GITHUB_TOKEN = 'github-token' -REPO_OWNER = 'owner_name' -REPO_NAME = 'nillion-python-starter' - -def get_pull_requests(owner, repo): - url = f"https://api.github.com/repos/{owner}/{repo}/pulls" - headers = { - 'Authorization': f'token {github-token}', - 'Accept': 'application/vnd.github.v3+json' - } - response = requests.get(url, headers=headers) - return response.json() - -pull_requests = get_pull_requests(REPO_OWNER, REPO_NAME) - -print("Open Pull Requests:") -for pr in pull_requests: - number = pr['number'] - title = pr['title'] - user = pr['user']['login'] - created_at = pr['created_at'] - pr_url = pr['html_url'] - print(f"PR #{number}: {title} by {user} - Created at {created_at}") - print(f"URL: {pr_url}\n") +from datetime import datetime + +def display_tasks(tasks): + if not tasks: + print("Your to-do list is empty.") + return + + print("Your To-Do List:") + for index, task in enumerate(tasks, start=1): + status = "Done" if task['done'] else "Not done" + priority = task['priority'] + due_date = task['due_date'] if task['due_date'] else "No due date" + print(f"{index}. {task['task']} - [{status}] (Priority: {priority}) (Due: {due_date})") + +def add_task(tasks): + task = input("Enter a new task: ") + priority = input("Enter priority (low, medium, high): ").lower() + if priority not in ["low", "medium", "high"]: + priority = "low" + due_date = input("Enter due date (YYYY-MM-DD) or leave blank: ") + try: + due_date = datetime.strptime(due_date, "%Y-%m-%d").date() if due_date else None + except ValueError: + print("Invalid date format. No due date set.") + due_date = None + tasks.append({"task": task, "done": False, "priority": priority, "due_date": due_date}) + print(f"Task '{task}' added with priority '{priority}' and due date '{due_date}'.") + +def remove_task(tasks): + task_number = int(input("Enter the number of the task to remove: ")) + if 0 < task_number <= len(tasks): + removed_task = tasks.pop(task_number - 1) + print(f"Task '{removed_task['task']}' removed.") + else: + print("Invalid task number.") + +def mark_task_done(tasks): + task_number = int(input("Enter the number of the task to mark as done: ")) + if 0 < task_number <= len(tasks): + tasks[task_number - 1]['done'] = True + print(f"Task '{tasks[task_number - 1]['task']}' marked as done.") + else: + print("Invalid task number.") + +def edit_task(tasks): + task_number = int(input("Enter the number of the task to edit: ")) + if 0 < task_number <= len(tasks): + task = tasks[task_number - 1] + new_task = input(f"Enter new task description (current: '{task['task']}') or press Enter to keep it: ") + new_priority = input(f"Enter new priority (low, medium, high) (current: '{task['priority']}') or press Enter to keep it: ").lower() + new_due_date = input(f"Enter new due date (YYYY-MM-DD) (current: '{task['due_date']}') or press Enter to keep it: ") + + if new_task: + task['task'] = new_task + if new_priority in ["low", "medium", "high"]: + task['priority'] = new_priority + if new_due_date: + try: + task['due_date'] = datetime.strptime(new_due_date, "%Y-%m-%d").date() + except ValueError: + print("Invalid date format. Due date not changed.") + print("Task updated.") + else: + print("Invalid task number.") + +def sort_tasks(tasks, by): + if by == 'priority': + tasks.sort(key=lambda x: ['low', 'medium', 'high'].index(x['priority'])) + elif by == 'status': + tasks.sort(key=lambda x: x['done']) + elif by == 'due_date': + tasks.sort(key=lambda x: (x['due_date'] is None, x['due_date'])) + print(f"Tasks sorted by {by}.") + +def save_tasks(tasks, filename="tasks.txt"): + with open(filename, "w") as file: + for task in tasks: + file.write(f"{task['task']}|{task['done']}|{task['priority']}|{task['due_date']}\n") + print("Tasks saved to file.") + +def load_tasks(filename="tasks.txt"): + tasks = [] + try: + with open(filename, "r") as file: + for line in file: + task, done, priority, due_date = line.strip().split("|") + due_date = datetime.strptime(due_date, "%Y-%m-%d").date() if due_date != 'None' else None + tasks.append({"task": task, "done": done == "True", "priority": priority, "due_date": due_date}) + except FileNotFoundError: + print("No saved tasks found.") + return tasks + +def main(): + tasks = load_tasks() + while True: + print("\nOptions:") + print("1. View tasks") + print("2. Add task") + print("3. Remove task") + print("4. Mark task as done") + print("5. Edit task") + print("6. Sort tasks by priority") + print("7. Sort tasks by status") + print("8. Sort tasks by due date") + print("9. Save tasks") + print("10. Quit") + + choice = input("Select an option (1-10): ") + + if choice == '1': + display_tasks(tasks) + elif choice == '2': + add_task(tasks) + elif choice == '3': + remove_task(tasks) + elif choice == '4': + mark_task_done(tasks) + elif choice == '5': + edit_task(tasks) + elif choice == '6': + sort_tasks(tasks, 'priority') + elif choice == '7': + sort_tasks(tasks, 'status') + elif choice == '8': + sort_tasks(tasks, 'due_date') + elif choice == '9': + save_tasks(tasks) + elif choice == '10': + save_tasks(tasks) + break + else: + print("Invalid choice. Try again.") + +if __name__ == "__main__": + main() +