| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- from tkinter import *
- from lib.chain import Chain, Block
- from lib.transaction import Transaction
- from lib.contract import Contract
- from lib.block import CURRENT
- from create_keys import get_keys
- import rpyc
- import time
- import json
- ###########################
- # OLD CODE PLEASE IGONORE #
- ###########################
- def add_contract():
- # add contract to the blockchain
- def add():
- contract1 = Contract()
- s = get_keys(sender.get())
- r = get_keys(recipient.get())
- contract1.create(title=title.get(),
- desc=description.get(),
- deadline=int(deadline.get()),
- price=float(price.get()),
- state=False,
- client=str(s),
- contractor=str(r))
- add_term(contract1)
- def add_term(contract1):
-
- def process_term():
- term1 = Contract.Term()
- term1.create(title=title2.get(),
- desc=description2.get(),
- deadline=int(deadline2.get()))
- contract1.add_term(term=term1)
- term_window.destroy()
- add_term(contract1)
- def complete():
- conn = rpyc.connect(host='localhost', port=42069, keepalive=True)
- # Bind contract to transaction
- transaction1 = Transaction()
- transaction1.set_contract(contract=contract1)
- r = recipient.get()
- transaction1.hash(recipient=r)
- transaction1.timestamp = time.time()
- # keys need to be in plain text, otherwise the json dump fucks up
- transaction1.sender = str(get_keys(sender.get()))
- transaction1.receiver = str(get_keys(recipient.get()))
- transaction1.data = str(transaction1.hash_value)
- output = transaction1.serialize()
- output = json.dumps(output, sort_keys=True)
- print(output, type(output))
- conn.root.push_transaction(output)
- conn.close()
- term_window.destroy()
- newWindow.destroy()
- term_window = Toplevel(newWindow)
- term_window.title('Add term')
- Label(term_window, text='Title: ').grid(row=0, column=0)
- title2 = Entry(term_window, width=35, borderwidth=5)
- title2.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
- Label(term_window, text='Description: ').grid(row=1, column=0)
- description2 = Entry(term_window, width=35, borderwidth=5)
- description2.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
- Label(term_window, text='Deadline: ').grid(row=2, column=0)
- deadline2 = Entry(term_window, width=35, borderwidth=5)
- deadline2.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
- Label(term_window, text='Recipient: ').grid(row=3, column=0)
- recipient1 = Entry(term_window, width=35, borderwidth=5)
- recipient1.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
- Button(term_window, text='Add term', command=process_term).grid(row=4,column=0)
- Button(term_window, text='Done', command=complete).grid(row=4,column=1)
-
- # make new window for adding the information for the contract
- newWindow = Tk()
- newWindow.title('Add contract')
- # create all text boxes
- Label(newWindow, text='Title: ').grid(row=0, column=0)
- title = Entry(newWindow, width=35, borderwidth=5)
- title.grid(row=0, column=1, columnspan=3, padx=10, pady=10)
- Label(newWindow, text='Description: ').grid(row=1, column=0)
- description = Entry(newWindow, width=35, borderwidth=5)
- description.grid(row=1, column=1, columnspan=3, padx=10, pady=10)
- Label(newWindow, text='Deadline: ').grid(row=2, column=0)
- deadline = Entry(newWindow, width=35, borderwidth=5)
- deadline.grid(row=2, column=1, columnspan=3, padx=10, pady=10)
- Label(newWindow, text='Price: ').grid(row=3, column=0)
- price = Entry(newWindow, width=35, borderwidth=5)
- price.grid(row=3, column=1, columnspan=3, padx=10, pady=10)
- Label(newWindow, text='Sender: ').grid(row=4, column=0)
- sender = Entry(newWindow, width=35, borderwidth=5)
- sender.grid(row=4, column=1, columnspan=3, padx=10, pady=10)
- Label(newWindow, text='Recipient: ').grid(row=5, column=0)
- recipient = Entry(newWindow, width=35, borderwidth=5)
- recipient.grid(row=5, column=1, columnspan=3, padx=10, pady=10)
- # create the add contract button
- Button(newWindow, text = "Create contract", command=add).grid(row=6, column=1)
|