2
0
Эх сурвалжийг харах

added feature to remove terms

justtheboss97 4 жил өмнө
parent
commit
1ef4f6eb2b
2 өөрчлөгдсөн 21 нэмэгдсэн , 33 устгасан
  1. 0 0
      data/block.json
  2. 21 33
      gui/data.py

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
data/block.json


+ 21 - 33
gui/data.py

@@ -2,6 +2,7 @@ import json
 import os
 import time
 from tkinter import *
+import pprint
 
 import rpyc
 from create_keys import get_plain_key, get_private_key, make_keys
@@ -94,14 +95,17 @@ def find_transaction():
         conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
         iden = get_plain_key(str(key.get()))
         transactions = conn.root.find_transactions(iden)
-        transactions = decrypt_transactions(transactions, str(key.get()))
-        print(current_contract_state(transactions, iden=iden))
+        if len(transactions) == 0:
+            print('No contract found')
+        else:
+            transactions = decrypt_transactions(transactions, str(key.get()))
+            pprint.pprint(current_contract_state(transactions, iden=iden))
 
         conn.close()
         newWindow.destroy()
 
     newWindow = Tk()
-    newWindow.title('Add contract')
+    newWindow.title('Find contract')
 
     Label(newWindow, text='Contract key: ').grid(row=0, column=0)
     key = Entry(newWindow, width=35, borderwidth=5)
@@ -123,7 +127,9 @@ def add_term():
         transactions = decrypt_transactions(transactions, str(contract.get()))
         state = current_contract_state(transactions, iden)
 
-        if attr in state['data'] or attr in state['terms']:
+        if value == '':
+            t = 'remove'
+        elif attr in state['data'] or attr in state['terms']:
             t = 'modify'
         else: t = 'update'
                 
@@ -133,8 +139,10 @@ def add_term():
                 'updated':attr,
                 'type':t,
                 'last update':time.time(),
-                'accepted': False,
-                'change':{attr:value}}
+                'accepted': False}
+
+        if t != 'remove':
+            update['change'] = {attr:value}
         
         # check if comment is passed and add it if necassary
         if comment:
@@ -145,29 +153,11 @@ def add_term():
         t.hash(contract=str(contract.get()))
         conn.root.push_transaction(t.serialize(out_json=True))
 
-        #### TEST CODE PLEASE IGONRE ####
-        # update = {
-        #     'id':iden,
-        #     'update id':0,
-        #     'accept':True,
-        #     'type':'accept',
-        #     'last update':time.time()
-        # }
-        # if comment:
-        #     update['comment'] = comment
-
-        # t = Transaction()
-        # t.set_contract(update)
-        # t.hash(contract=str(contract.get()))
-        # conn.root.push_transaction(t.serialize(out_json=True))
-
-        #### END TEST CODE PLEASE DONT IGONRE ####
-
         conn.close()
         newWindow.destroy()
 
     newWindow = Tk()
-    newWindow.title('Add contract')
+    newWindow.title('Add term')
 
     # create all text boxes
     Label(newWindow, text='Contract: ').grid(row=0, column=0)
@@ -180,7 +170,7 @@ def add_term():
     change.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
     change.insert(0, 'progress')
 
-    Label(newWindow, text='New value: ').grid(row=2, column=0)
+    Label(newWindow, text='New value (to remove, keep empty): ').grid(row=2, column=0)
     values = Entry(newWindow, width=35, borderwidth=5)
     values.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
     values.insert(0, '50%')
@@ -205,7 +195,7 @@ def accept_updates():
         else:
             print('Updates that still need to be accepted: \n')
             for update in updates:
-                print(update, '\n')
+                pprint.pprint(update)
 
     def accept():
         conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
@@ -215,10 +205,8 @@ def accept_updates():
         if answer == 'True':
             answer = True
         else: answer = False
-        print(answer)
-        comment_text = str(comment.get())
 
-        print(answer)
+        comment_text = str(comment.get())
 
         update = {
             'id':get_plain_key(name),
@@ -290,7 +278,7 @@ def current_contract_state(transactions, iden):
 
             # if update is not accept update, save it to updates dict
             if item['type'] != 'accept':
-                
+
                 # comments are always accepted
                 if item['updated'] != 'comments':
                     updates[item['update id']] = item
@@ -300,8 +288,9 @@ def current_contract_state(transactions, iden):
             elif item['accept'] == True:
                 item = updates[item['update id']]
             
+            else: continue
+            
             # set attr to whatever has been updated
-            print(item)
             attr = item['updated']
             
             # check if the update was removal
@@ -378,7 +367,6 @@ def retrieve_updates(all_updates, iden, accepted=None):
     updates = {}
     
     for item in all_updates:
-        print(item)
         if item['type'] == 'init':
             continue
         if item['type'] != 'accept' and item['updated'] != 'comments':

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно