Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,19 +22,37 @@ def checkp(inp):
|
|
22 |
|
23 |
def get_my_chain_send(sender_name=None):
|
24 |
global mychain_send
|
|
|
25 |
mes_error = ""
|
26 |
try:
|
27 |
-
r = requests.get(f'{
|
28 |
|
29 |
#print (f'r={r.text}')
|
30 |
-
mychain_send =
|
31 |
|
32 |
response = {'chain': mychain_send.chain,
|
33 |
'length': len(mychain_send.chain)}
|
34 |
#print (f'response={response}')
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
message = f"Blockchain loaded from: {
|
38 |
return response,message
|
39 |
except Exception:
|
40 |
message = f"Error loading from: {sender_name}"
|
@@ -45,27 +63,55 @@ def get_my_chain_rec(recipient_name=None):
|
|
45 |
global mychain_rec
|
46 |
|
47 |
try:
|
48 |
-
r = requests.get(f'{
|
49 |
-
mychain_rec =
|
50 |
response = {'chain': mychain_rec.chain,
|
51 |
'length': len(mychain_rec.chain)}
|
52 |
-
message = f"Blockchain loaded from: {
|
53 |
return response,message
|
54 |
except Exception:
|
55 |
try:
|
56 |
-
mychain_rec = MyChainRec(chain_load=
|
57 |
response = {'chain': mychain_rec.chain,
|
58 |
'length': len(mychain_rec.chain)}
|
59 |
|
60 |
-
message = f"Blockchain loaded from: {
|
61 |
return response,message
|
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()
|
@@ -92,6 +138,10 @@ def mychain_mine_block_send(chain_r=None,chain_n=None):
|
|
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']
|
|
|
22 |
|
23 |
def get_my_chain_send(sender_name=None):
|
24 |
global mychain_send
|
25 |
+
global mychain_trans
|
26 |
mes_error = ""
|
27 |
try:
|
28 |
+
r = requests.get(f'{main_balance}{sender_name}.json')
|
29 |
|
30 |
#print (f'r={r.text}')
|
31 |
+
mychain_send = MyChainSend(chain_load=main_balance,load=r.text)
|
32 |
|
33 |
response = {'chain': mychain_send.chain,
|
34 |
'length': len(mychain_send.chain)}
|
35 |
#print (f'response={response}')
|
36 |
+
try:
|
37 |
+
d = requests.get(f'{main_trans}{trans_name}')
|
38 |
+
mychain_trans = MyChainTrans(chain_load=main_trans,load=d.text)
|
39 |
+
except Exception as e:
|
40 |
+
print (f'error1:: {e}')
|
41 |
+
try:
|
42 |
+
mychain_trans = MyChainTrans(chain_load=main_trans,create=trans_name)
|
43 |
+
print ("this worked")
|
44 |
+
except Exception as ee:
|
45 |
+
print (f'error2:: {ee}')
|
46 |
+
pass
|
47 |
+
try:
|
48 |
+
response_trans = {'chain': mychain_trans.chain,
|
49 |
+
'length': len(mychain_trans.chain)}
|
50 |
+
print(f'response_trans:: {response_trans}')
|
51 |
+
except Exception as e:
|
52 |
+
print (e)
|
53 |
+
pass
|
54 |
|
55 |
+
message = f"Blockchain loaded from: {main_balance}{sender_name}.json"
|
56 |
return response,message
|
57 |
except Exception:
|
58 |
message = f"Error loading from: {sender_name}"
|
|
|
63 |
global mychain_rec
|
64 |
|
65 |
try:
|
66 |
+
r = requests.get(f'{main_balance}{recipient_name}.json')
|
67 |
+
mychain_rec = MyChainRec(chain_load=main_balance,load=r.text)
|
68 |
response = {'chain': mychain_rec.chain,
|
69 |
'length': len(mychain_rec.chain)}
|
70 |
+
message = f"Blockchain loaded from: {main_balance}{recipient_name}.json"
|
71 |
return response,message
|
72 |
except Exception:
|
73 |
try:
|
74 |
+
mychain_rec = MyChainRec(chain_load=main_balance,create=recipient_name)
|
75 |
response = {'chain': mychain_rec.chain,
|
76 |
'length': len(mychain_rec.chain)}
|
77 |
|
78 |
+
message = f"Blockchain loaded from: {main_balance}{recipient_name}.json"
|
79 |
return response,message
|
80 |
except Exception:
|
81 |
message = f"Error loading from: {recipient_name}"
|
82 |
return ["Error Loading Chain"],message
|
83 |
+
|
84 |
+
def display_chain_send():
|
85 |
+
response = {'chain': mychain_send.chain,
|
86 |
+
'length': len(mychain_send.chain)}
|
87 |
+
return response
|
88 |
+
|
89 |
+
def display_chain_rec():
|
90 |
+
response = {'chain': mychain_rec.chain,
|
91 |
+
'length': len(mychain_rec.chain)}
|
92 |
+
return response
|
93 |
+
|
94 |
+
def valid_send():
|
95 |
+
valid,ind,mes = mychain_send.chain_valid(mychain_send.chain)
|
96 |
+
if valid:
|
97 |
+
response = 'The Blockchain is valid.'
|
98 |
+
z=True
|
99 |
+
else:
|
100 |
+
response = f'Sender Blockchain is not valid. {mes} at Index {ind}'
|
101 |
+
z=False
|
102 |
+
return response,z,mes,ind
|
103 |
+
|
104 |
+
def valid_rec():
|
105 |
+
valid,ind,mes = mychain_rec.chain_valid(mychain_rec.chain)
|
106 |
+
if valid:
|
107 |
+
response = 'The Blockchain is valid.'
|
108 |
+
z=True
|
109 |
+
else:
|
110 |
+
response = f'Blockchain is not valid. {mes} at Index {ind}'
|
111 |
+
z=False
|
112 |
+
return response,z, mes, ind
|
113 |
|
114 |
|
|
|
|
|
115 |
|
116 |
def mychain_mine_block_send(chain_r=None,chain_n=None):
|
117 |
previous_block = mychain_send.print_previous_block()
|
|
|
138 |
|
139 |
return response, show_chain,message
|
140 |
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
def mychain_mine_block_rec(chain_r=None,chain_n=None):
|
146 |
previous_block = mychain_rec.print_previous_block()
|
147 |
previous_proof = previous_block['proof']
|