|
@@ -133,7 +133,7 @@ def add_term():
|
|
|
'updated':attr,
|
|
'updated':attr,
|
|
|
'type':t,
|
|
'type':t,
|
|
|
'last update':time.time(),
|
|
'last update':time.time(),
|
|
|
- 'accepted': True,
|
|
|
|
|
|
|
+ 'accepted': False,
|
|
|
'change':{attr:value}}
|
|
'change':{attr:value}}
|
|
|
|
|
|
|
|
# check if comment is passed and add it if necassary
|
|
# check if comment is passed and add it if necassary
|
|
@@ -146,20 +146,20 @@ def add_term():
|
|
|
conn.root.push_transaction(t.serialize(out_json=True))
|
|
conn.root.push_transaction(t.serialize(out_json=True))
|
|
|
|
|
|
|
|
#### TEST CODE PLEASE IGONRE ####
|
|
#### 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))
|
|
|
|
|
|
|
+ # 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 ####
|
|
#### END TEST CODE PLEASE DONT IGONRE ####
|
|
|
|
|
|
|
@@ -173,7 +173,7 @@ def add_term():
|
|
|
Label(newWindow, text='Contract: ').grid(row=0, column=0)
|
|
Label(newWindow, text='Contract: ').grid(row=0, column=0)
|
|
|
contract = Entry(newWindow, width=35, borderwidth=5)
|
|
contract = Entry(newWindow, width=35, borderwidth=5)
|
|
|
contract.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
|
|
contract.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
|
|
|
- contract.insert(0, '1')
|
|
|
|
|
|
|
+ contract.insert(0, 'test')
|
|
|
|
|
|
|
|
Label(newWindow, text='What to change or add: ').grid(row=1, column=0)
|
|
Label(newWindow, text='What to change or add: ').grid(row=1, column=0)
|
|
|
change = Entry(newWindow, width=35, borderwidth=5)
|
|
change = Entry(newWindow, width=35, borderwidth=5)
|
|
@@ -185,13 +185,87 @@ def add_term():
|
|
|
values.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
|
|
values.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
|
|
|
values.insert(0, '50%')
|
|
values.insert(0, '50%')
|
|
|
|
|
|
|
|
- Label(newWindow, text='comment (optional): ').grid(row=2, column=0)
|
|
|
|
|
|
|
+ Label(newWindow, text='comment (optional): ').grid(row=3, column=0)
|
|
|
comments = Entry(newWindow, width=35, borderwidth=5)
|
|
comments = Entry(newWindow, width=35, borderwidth=5)
|
|
|
comments.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
|
|
comments.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
|
|
|
comments.insert(0, 'dit is een comment')
|
|
comments.insert(0, 'dit is een comment')
|
|
|
|
|
|
|
|
Button(newWindow, text='Add term', command=add).grid(row=4, column=1)
|
|
Button(newWindow, text='Add term', command=add).grid(row=4, column=1)
|
|
|
|
|
|
|
|
|
|
+def accept_updates():
|
|
|
|
|
+ def show():
|
|
|
|
|
+ conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
|
|
+ name = str(contract.get())
|
|
|
|
|
+ transactions = conn.root.find_transactions(get_plain_key(name))
|
|
|
|
|
+ transactions = decrypt_transactions(transactions, name)
|
|
|
|
|
+ updates = retrieve_updates(transactions, name, accepted=False)
|
|
|
|
|
+ conn.close()
|
|
|
|
|
+ if len(updates) == 0:
|
|
|
|
|
+ print('No updates to accept')
|
|
|
|
|
+ else:
|
|
|
|
|
+ print('Updates that still need to be accepted: \n')
|
|
|
|
|
+ for update in updates:
|
|
|
|
|
+ print(update, '\n')
|
|
|
|
|
+
|
|
|
|
|
+ def accept():
|
|
|
|
|
+ conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
|
|
+ name = str(contract.get())
|
|
|
|
|
+ update_id = int(change.get())
|
|
|
|
|
+ answer = accept_status.get()
|
|
|
|
|
+ if answer == 'True':
|
|
|
|
|
+ answer = True
|
|
|
|
|
+ else: answer = False
|
|
|
|
|
+ print(answer)
|
|
|
|
|
+ comment_text = str(comment.get())
|
|
|
|
|
+
|
|
|
|
|
+ print(answer)
|
|
|
|
|
+
|
|
|
|
|
+ update = {
|
|
|
|
|
+ 'id':get_plain_key(name),
|
|
|
|
|
+ 'update id':update_id,
|
|
|
|
|
+ 'accept':answer,
|
|
|
|
|
+ 'type':'accept',
|
|
|
|
|
+ 'last update':time.time()
|
|
|
|
|
+ }
|
|
|
|
|
+ if comment_text:
|
|
|
|
|
+ update['comment'] = comment_text
|
|
|
|
|
+
|
|
|
|
|
+ t = Transaction()
|
|
|
|
|
+ t.set_contract(update)
|
|
|
|
|
+ t.hash(contract=str(contract.get()))
|
|
|
|
|
+ conn.root.push_transaction(t.serialize(out_json=True))
|
|
|
|
|
+ conn.close()
|
|
|
|
|
+ newWindow.destroy()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ newWindow = Tk()
|
|
|
|
|
+ newWindow.title('Accept updates')
|
|
|
|
|
+
|
|
|
|
|
+ Label(newWindow, text='Contract: ').grid(row=0, column=0)
|
|
|
|
|
+ contract = Entry(newWindow, width=35, borderwidth=5)
|
|
|
|
|
+ contract.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
|
|
|
|
|
+ contract.insert(0, 'test')
|
|
|
|
|
+
|
|
|
|
|
+ Label(newWindow, text='Id of update: ').grid(row=1, column=0)
|
|
|
|
|
+ change = Entry(newWindow, width=35, borderwidth=5)
|
|
|
|
|
+ change.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
|
|
|
|
|
+ change.insert(0, '0')
|
|
|
|
|
+
|
|
|
|
|
+ Label(newWindow, text='Awnser: ').grid(row=2, column=0)
|
|
|
|
|
+ accept_status = StringVar(newWindow)
|
|
|
|
|
+ accept_status.set('False') # default value
|
|
|
|
|
+ OptionMenu(newWindow, accept_status, 'False', 'True').grid(row=2, column=1)
|
|
|
|
|
+
|
|
|
|
|
+ Label(newWindow, text='Comment (optional): ').grid(row=3, column=0)
|
|
|
|
|
+ comment = Entry(newWindow, width=35, borderwidth=5)
|
|
|
|
|
+ comment.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
|
|
|
|
|
+ comment.insert(0, 'test test')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Button(newWindow, text='Show updates to accept', command=show).grid(row=4, column=0, padx=10, pady=5)
|
|
|
|
|
+ Button(newWindow, text='Accept', command=accept).grid(row=4, column=1, padx=10, pady=5)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def current_contract_state(transactions, iden):
|
|
def current_contract_state(transactions, iden):
|
|
|
# set up contract state
|
|
# set up contract state
|
|
@@ -227,6 +301,7 @@ def current_contract_state(transactions, iden):
|
|
|
item = updates[item['update id']]
|
|
item = updates[item['update id']]
|
|
|
|
|
|
|
|
# set attr to whatever has been updated
|
|
# set attr to whatever has been updated
|
|
|
|
|
+ print(item)
|
|
|
attr = item['updated']
|
|
attr = item['updated']
|
|
|
|
|
|
|
|
# check if the update was removal
|
|
# check if the update was removal
|
|
@@ -297,20 +372,28 @@ def get_updates(transactions, iden=None, attr=None, accepted=None):
|
|
|
updates.append(item)
|
|
updates.append(item)
|
|
|
return updates
|
|
return updates
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+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':
|
|
|
|
|
+ updates[item['update id']] = item
|
|
|
|
|
+ else:
|
|
|
|
|
+ try:
|
|
|
|
|
+ updates[item['update id']]['accepted'] = item['accept']
|
|
|
|
|
+ except:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ if accepted == None:
|
|
|
|
|
+ return updates
|
|
|
|
|
+
|
|
|
|
|
+ return [updates[x] for x in list(updates.keys()) if updates[x]['accepted'] == accepted]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def decrypt_transactions(transactions, name):
|
|
def decrypt_transactions(transactions, name):
|
|
|
- decrypted_data = [json.loads(decrypt_data(name, x)) for x in transactions]
|
|
|
|
|
- print(type(decrypted_data[0]))
|
|
|
|
|
-
|
|
|
|
|
- # old code
|
|
|
|
|
- # for encrypted in transactions:
|
|
|
|
|
- # decrypting_message = private_key.decrypt(
|
|
|
|
|
- # encrypted,
|
|
|
|
|
- # padding.OAEP(
|
|
|
|
|
- # mgf=padding.MGF1(algorithm=hashes.SHA256()),
|
|
|
|
|
- # algorithm=hashes.SHA256(),
|
|
|
|
|
- # label=None
|
|
|
|
|
- # )
|
|
|
|
|
- # )
|
|
|
|
|
- # decrypted.append(decrypting_message)
|
|
|
|
|
-
|
|
|
|
|
- return decrypted_data
|
|
|
|
|
|
|
+ return [json.loads(decrypt_data(name, x)) for x in transactions]
|