2
0

gui_helpers.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. from tkinter import *
  2. from lib.chain import Chain, Block
  3. from lib.transaction import Transaction
  4. from lib.contract import Contract
  5. from lib.block import CURRENT
  6. from create_keys import get_keys
  7. import rpyc
  8. import time
  9. import json
  10. ###########################
  11. # OLD CODE PLEASE IGONORE #
  12. ###########################
  13. def add_contract():
  14. # add contract to the blockchain
  15. def add():
  16. contract1 = Contract()
  17. s = get_keys(sender.get())
  18. r = get_keys(recipient.get())
  19. contract1.create(title=title.get(),
  20. desc=description.get(),
  21. deadline=int(deadline.get()),
  22. price=float(price.get()),
  23. state=False,
  24. client=str(s),
  25. contractor=str(r))
  26. add_term(contract1)
  27. def add_term(contract1):
  28. def process_term():
  29. term1 = Contract.Term()
  30. term1.create(title=title2.get(),
  31. desc=description2.get(),
  32. deadline=int(deadline2.get()))
  33. contract1.add_term(term=term1)
  34. term_window.destroy()
  35. add_term(contract1)
  36. def complete():
  37. conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
  38. # Bind contract to transaction
  39. transaction1 = Transaction()
  40. transaction1.set_contract(contract=contract1)
  41. r = recipient.get()
  42. transaction1.hash(recipient=r)
  43. transaction1.timestamp = time.time()
  44. # keys need to be in plain text, otherwise the json dump fucks up
  45. transaction1.sender = str(get_keys(sender.get()))
  46. transaction1.receiver = str(get_keys(recipient.get()))
  47. transaction1.data = str(transaction1.hash_value)
  48. output = transaction1.serialize()
  49. output = json.dumps(output, sort_keys=True)
  50. print(output, type(output))
  51. conn.root.push_transaction(output)
  52. conn.close()
  53. term_window.destroy()
  54. newWindow.destroy()
  55. term_window = Toplevel(newWindow)
  56. term_window.title('Add term')
  57. Label(term_window, text='Title: ').grid(row=0, column=0)
  58. title2 = Entry(term_window, width=35, borderwidth=5)
  59. title2.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  60. Label(term_window, text='Description: ').grid(row=1, column=0)
  61. description2 = Entry(term_window, width=35, borderwidth=5)
  62. description2.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  63. Label(term_window, text='Deadline: ').grid(row=2, column=0)
  64. deadline2 = Entry(term_window, width=35, borderwidth=5)
  65. deadline2.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  66. Label(term_window, text='Recipient: ').grid(row=3, column=0)
  67. recipient1 = Entry(term_window, width=35, borderwidth=5)
  68. recipient1.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  69. Button(term_window, text='Add term', command=process_term).grid(row=4,column=0)
  70. Button(term_window, text='Done', command=complete).grid(row=4,column=1)
  71. # make new window for adding the information for the contract
  72. newWindow = Tk()
  73. newWindow.title('Add contract')
  74. # create all text boxes
  75. Label(newWindow, text='Title: ').grid(row=0, column=0)
  76. title = Entry(newWindow, width=35, borderwidth=5)
  77. title.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
  78. Label(newWindow, text='Description: ').grid(row=1, column=0)
  79. description = Entry(newWindow, width=35, borderwidth=5)
  80. description.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
  81. Label(newWindow, text='Deadline: ').grid(row=2, column=0)
  82. deadline = Entry(newWindow, width=35, borderwidth=5)
  83. deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
  84. Label(newWindow, text='Price: ').grid(row=3, column=0)
  85. price = Entry(newWindow, width=35, borderwidth=5)
  86. price.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
  87. Label(newWindow, text='Sender: ').grid(row=4, column=0)
  88. sender = Entry(newWindow, width=35, borderwidth=5)
  89. sender.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
  90. Label(newWindow, text='Recipient: ').grid(row=5, column=0)
  91. recipient = Entry(newWindow, width=35, borderwidth=5)
  92. recipient.grid(row=5, column=1, columnspan=3, padx=10, pady=10)
  93. # create the add contract button
  94. Button(newWindow, text = "Create contract", command=add).grid(row=6, column=1)