Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ def checkp(inp):
|
|
18 |
elif inp != pa:
|
19 |
return gr.update(visible=True), gr.update(visible=False)
|
20 |
|
|
|
|
|
21 |
def get_my_chain_send(sender_name=None):
|
22 |
global mychain_send
|
23 |
mes_error = ""
|
@@ -60,6 +62,59 @@ def get_my_chain_rec(recipient_name=None):
|
|
60 |
except Exception:
|
61 |
message = f"Error loading from: {recipient_name}"
|
62 |
return ["Error Loading Chain"],message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
############################################
|
64 |
def send_message(send,rec,message):
|
65 |
response_send={}
|
@@ -109,11 +164,11 @@ def send_message(send,rec,message):
|
|
109 |
mychain_rec.new_transaction(f"{send}",f"{rec}",f"{message}")
|
110 |
message_rec = "Transaction Added to Pool"
|
111 |
data_rec = pd.DataFrame(mychain_rec.pending_transactions)
|
112 |
-
response_send, show_chain_send, message_send =
|
113 |
|
114 |
#mychain_mine_block_trans(balance_send, chain_r=None,chain_n=send)
|
115 |
|
116 |
-
response_rec, show_chain_rec, message_rec =
|
117 |
mes = (f'Send: {message_send} :: Recieve: {message_rec}')
|
118 |
_,rec_send=update_send_list()
|
119 |
_,rec_drop=update_rec_list()
|
|
|
18 |
elif inp != pa:
|
19 |
return gr.update(visible=True), gr.update(visible=False)
|
20 |
|
21 |
+
|
22 |
+
|
23 |
def get_my_chain_send(sender_name=None):
|
24 |
global mychain_send
|
25 |
mes_error = ""
|
|
|
62 |
except Exception:
|
63 |
message = f"Error loading from: {recipient_name}"
|
64 |
return ["Error Loading Chain"],message
|
65 |
+
|
66 |
+
|
67 |
+
###################################################
|
68 |
+
|
69 |
+
|
70 |
+
def mychain_mine_block_send(chain_r=None,chain_n=None):
|
71 |
+
previous_block = mychain_send.print_previous_block()
|
72 |
+
previous_proof = previous_block['proof']
|
73 |
+
proof = mychain_send.proof_of_work(previous_proof)
|
74 |
+
previous_hash = mychain_send.hash(previous_block)
|
75 |
+
block = mychain_send.create_block(proof, previous_hash,chain_r,chain_n)
|
76 |
+
|
77 |
+
response = {'message': 'A block is MINED',
|
78 |
+
'index': block['index'],
|
79 |
+
'timestamp': block['timestamp'],
|
80 |
+
'proof': block['proof'],
|
81 |
+
'previous_hash': block['previous_hash']
|
82 |
+
}
|
83 |
+
|
84 |
+
message = "A block is MINED"
|
85 |
+
show_chain = display_chain_send()
|
86 |
+
|
87 |
+
if len(mychain_send.chain) > 1000:
|
88 |
+
mychain_send.reset()
|
89 |
+
response = None
|
90 |
+
show_chain=display_chain_send()
|
91 |
+
message = "New Chain Created at Max 20 Blocks"
|
92 |
+
|
93 |
+
return response, show_chain,message
|
94 |
+
|
95 |
+
def mychain_mine_block_rec(chain_r=None,chain_n=None):
|
96 |
+
previous_block = mychain_rec.print_previous_block()
|
97 |
+
previous_proof = previous_block['proof']
|
98 |
+
proof = mychain_rec.proof_of_work(previous_proof)
|
99 |
+
previous_hash = mychain_rec.hash(previous_block)
|
100 |
+
block = mychain_rec.create_block(proof, previous_hash,chain_r,chain_n)
|
101 |
+
|
102 |
+
response = {'message': 'A block is MINED',
|
103 |
+
'index': block['index'],
|
104 |
+
'timestamp': block['timestamp'],
|
105 |
+
'proof': block['proof'],
|
106 |
+
'previous_hash': block['previous_hash']
|
107 |
+
}
|
108 |
+
message = "A block is MINED"
|
109 |
+
show_chain = display_chain_rec()
|
110 |
+
if len(mychain_rec.chain) > 1000:
|
111 |
+
mychain_rec.reset()
|
112 |
+
response = None
|
113 |
+
show_chain=display_chain_rec()
|
114 |
+
message = "New Chain Created at Max 20 Blocks"
|
115 |
+
return response, show_chain, message
|
116 |
+
##############################################
|
117 |
+
|
118 |
############################################
|
119 |
def send_message(send,rec,message):
|
120 |
response_send={}
|
|
|
164 |
mychain_rec.new_transaction(f"{send}",f"{rec}",f"{message}")
|
165 |
message_rec = "Transaction Added to Pool"
|
166 |
data_rec = pd.DataFrame(mychain_rec.pending_transactions)
|
167 |
+
response_send, show_chain_send, message_send = mychain_mine_block_send(chain_r=None,chain_n=send)
|
168 |
|
169 |
#mychain_mine_block_trans(balance_send, chain_r=None,chain_n=send)
|
170 |
|
171 |
+
response_rec, show_chain_rec, message_rec = mychain_mine_block_rec(chain_r=None,chain_n=rec)
|
172 |
mes = (f'Send: {message_send} :: Recieve: {message_rec}')
|
173 |
_,rec_send=update_send_list()
|
174 |
_,rec_drop=update_rec_list()
|