|
@@ -2,6 +2,7 @@ import json
|
|
|
import os
|
|
import os
|
|
|
import time
|
|
import time
|
|
|
from tkinter import *
|
|
from tkinter import *
|
|
|
|
|
+import pprint
|
|
|
|
|
|
|
|
import rpyc
|
|
import rpyc
|
|
|
from create_keys import get_plain_key, get_private_key, make_keys
|
|
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)
|
|
conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
|
iden = get_plain_key(str(key.get()))
|
|
iden = get_plain_key(str(key.get()))
|
|
|
transactions = conn.root.find_transactions(iden)
|
|
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()
|
|
conn.close()
|
|
|
newWindow.destroy()
|
|
newWindow.destroy()
|
|
|
|
|
|
|
|
newWindow = Tk()
|
|
newWindow = Tk()
|
|
|
- newWindow.title('Add contract')
|
|
|
|
|
|
|
+ newWindow.title('Find contract')
|
|
|
|
|
|
|
|
Label(newWindow, text='Contract key: ').grid(row=0, column=0)
|
|
Label(newWindow, text='Contract key: ').grid(row=0, column=0)
|
|
|
key = Entry(newWindow, width=35, borderwidth=5)
|
|
key = Entry(newWindow, width=35, borderwidth=5)
|
|
@@ -123,7 +127,9 @@ def add_term():
|
|
|
transactions = decrypt_transactions(transactions, str(contract.get()))
|
|
transactions = decrypt_transactions(transactions, str(contract.get()))
|
|
|
state = current_contract_state(transactions, iden)
|
|
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'
|
|
t = 'modify'
|
|
|
else: t = 'update'
|
|
else: t = 'update'
|
|
|
|
|
|
|
@@ -133,8 +139,10 @@ def add_term():
|
|
|
'updated':attr,
|
|
'updated':attr,
|
|
|
'type':t,
|
|
'type':t,
|
|
|
'last update':time.time(),
|
|
'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
|
|
# check if comment is passed and add it if necassary
|
|
|
if comment:
|
|
if comment:
|
|
@@ -145,29 +153,11 @@ def add_term():
|
|
|
t.hash(contract=str(contract.get()))
|
|
t.hash(contract=str(contract.get()))
|
|
|
conn.root.push_transaction(t.serialize(out_json=True))
|
|
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()
|
|
conn.close()
|
|
|
newWindow.destroy()
|
|
newWindow.destroy()
|
|
|
|
|
|
|
|
newWindow = Tk()
|
|
newWindow = Tk()
|
|
|
- newWindow.title('Add contract')
|
|
|
|
|
|
|
+ newWindow.title('Add term')
|
|
|
|
|
|
|
|
# create all text boxes
|
|
# create all text boxes
|
|
|
Label(newWindow, text='Contract: ').grid(row=0, column=0)
|
|
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.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
|
|
|
change.insert(0, 'progress')
|
|
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 = Entry(newWindow, width=35, borderwidth=5)
|
|
|
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%')
|
|
@@ -205,7 +195,7 @@ def accept_updates():
|
|
|
else:
|
|
else:
|
|
|
print('Updates that still need to be accepted: \n')
|
|
print('Updates that still need to be accepted: \n')
|
|
|
for update in updates:
|
|
for update in updates:
|
|
|
- print(update, '\n')
|
|
|
|
|
|
|
+ pprint.pprint(update)
|
|
|
|
|
|
|
|
def accept():
|
|
def accept():
|
|
|
conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
|
|
@@ -215,10 +205,8 @@ def accept_updates():
|
|
|
if answer == 'True':
|
|
if answer == 'True':
|
|
|
answer = True
|
|
answer = True
|
|
|
else: answer = False
|
|
else: answer = False
|
|
|
- print(answer)
|
|
|
|
|
- comment_text = str(comment.get())
|
|
|
|
|
|
|
|
|
|
- print(answer)
|
|
|
|
|
|
|
+ comment_text = str(comment.get())
|
|
|
|
|
|
|
|
update = {
|
|
update = {
|
|
|
'id':get_plain_key(name),
|
|
'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 update is not accept update, save it to updates dict
|
|
|
if item['type'] != 'accept':
|
|
if item['type'] != 'accept':
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
# comments are always accepted
|
|
# comments are always accepted
|
|
|
if item['updated'] != 'comments':
|
|
if item['updated'] != 'comments':
|
|
|
updates[item['update id']] = item
|
|
updates[item['update id']] = item
|
|
@@ -300,8 +288,9 @@ def current_contract_state(transactions, iden):
|
|
|
elif item['accept'] == True:
|
|
elif item['accept'] == True:
|
|
|
item = updates[item['update id']]
|
|
item = updates[item['update id']]
|
|
|
|
|
|
|
|
|
|
+ else: continue
|
|
|
|
|
+
|
|
|
# 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
|
|
@@ -378,7 +367,6 @@ def retrieve_updates(all_updates, iden, accepted=None):
|
|
|
updates = {}
|
|
updates = {}
|
|
|
|
|
|
|
|
for item in all_updates:
|
|
for item in all_updates:
|
|
|
- print(item)
|
|
|
|
|
if item['type'] == 'init':
|
|
if item['type'] == 'init':
|
|
|
continue
|
|
continue
|
|
|
if item['type'] != 'accept' and item['updated'] != 'comments':
|
|
if item['type'] != 'accept' and item['updated'] != 'comments':
|