Spaces:
Runtime error
Runtime error
Update chatchain.py
Browse files- chatchain.py +15 -15
chatchain.py
CHANGED
@@ -14,42 +14,44 @@ chain_t="trans1.json"
|
|
14 |
|
15 |
def get_my_chain_send(sender_name=None):
|
16 |
global mychain_send
|
|
|
17 |
mes_error = ""
|
18 |
try:
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
mychain_send = MyChainSend(chain_load=
|
23 |
|
24 |
response = {'chain': mychain_send.chain,
|
25 |
'length': len(mychain_send.chain)}
|
26 |
#print (f'response={response}')
|
27 |
-
|
28 |
|
29 |
-
message = f"Blockchain loaded from: {
|
30 |
return response,message
|
31 |
except Exception:
|
32 |
message = f"Error loading from: {sender_name}"
|
33 |
print (message)
|
34 |
-
return
|
35 |
|
36 |
def get_my_chain_rec(recipient_name=None):
|
37 |
global mychain_rec
|
38 |
-
|
39 |
try:
|
40 |
-
|
41 |
-
|
|
|
42 |
response = {'chain': mychain_rec.chain,
|
43 |
'length': len(mychain_rec.chain)}
|
44 |
-
message = f"Blockchain loaded from: {
|
45 |
return response,message
|
46 |
except Exception:
|
47 |
try:
|
48 |
-
mychain_rec = MyChainRec(chain_load=
|
49 |
response = {'chain': mychain_rec.chain,
|
50 |
'length': len(mychain_rec.chain)}
|
51 |
|
52 |
-
message = f"Blockchain loaded from: {
|
53 |
return response,message
|
54 |
except Exception:
|
55 |
message = f"Error loading from: {recipient_name}"
|
@@ -76,7 +78,7 @@ def valid_send():
|
|
76 |
return response,z,mes,ind
|
77 |
|
78 |
def valid_rec():
|
79 |
-
valid,ind,mes =
|
80 |
if valid:
|
81 |
response = 'The Blockchain is valid.'
|
82 |
z=True
|
@@ -85,8 +87,6 @@ def valid_rec():
|
|
85 |
z=False
|
86 |
return response,z, mes, ind
|
87 |
|
88 |
-
|
89 |
-
|
90 |
def mychain_mine_block_send(chain_r=None,chain_n=None):
|
91 |
previous_block = mychain_send.print_previous_block()
|
92 |
previous_proof = previous_block['proof']
|
|
|
14 |
|
15 |
def get_my_chain_send(sender_name=None):
|
16 |
global mychain_send
|
17 |
+
print(sender_name)
|
18 |
mes_error = ""
|
19 |
try:
|
20 |
+
r1 = requests.get(f'{main_chain}{sender_name}/{sender_name}.json')
|
21 |
|
22 |
+
print (f's={r1.text}')
|
23 |
+
mychain_send = chatchain.MyChainSend(chain_load=f'{main_chain}{sender_name}/',load=r1.text)
|
24 |
|
25 |
response = {'chain': mychain_send.chain,
|
26 |
'length': len(mychain_send.chain)}
|
27 |
#print (f'response={response}')
|
28 |
+
|
29 |
|
30 |
+
message = f"Blockchain loaded from: {main_chain}{sender_name}/{sender_name}.json"
|
31 |
return response,message
|
32 |
except Exception:
|
33 |
message = f"Error loading from: {sender_name}"
|
34 |
print (message)
|
35 |
+
return {"MESSAGE":"Error Loading Chain"},message
|
36 |
|
37 |
def get_my_chain_rec(recipient_name=None):
|
38 |
global mychain_rec
|
39 |
+
print(recipient_name)
|
40 |
try:
|
41 |
+
r2 = requests.get(f'{main_chain}{recipient_name}/{recipient_name}.json')
|
42 |
+
print (f'r={r2.text}')
|
43 |
+
mychain_rec = MyChainRec(chain_load=f'{main_chain}{recipient_name}/',load=r2.text)
|
44 |
response = {'chain': mychain_rec.chain,
|
45 |
'length': len(mychain_rec.chain)}
|
46 |
+
message = f"Blockchain loaded from: {main_chain}{recipient_name}/{recipient_name}.json"
|
47 |
return response,message
|
48 |
except Exception:
|
49 |
try:
|
50 |
+
mychain_rec = MyChainRec(chain_load=main_chain,create=recipient_name)
|
51 |
response = {'chain': mychain_rec.chain,
|
52 |
'length': len(mychain_rec.chain)}
|
53 |
|
54 |
+
message = f"Blockchain loaded from: {main_chain}{recipient_name}/{recipient_name}.json"
|
55 |
return response,message
|
56 |
except Exception:
|
57 |
message = f"Error loading from: {recipient_name}"
|
|
|
78 |
return response,z,mes,ind
|
79 |
|
80 |
def valid_rec():
|
81 |
+
valid,ind,mes = mychain_rec.chain_valid(mychain_rec.chain)
|
82 |
if valid:
|
83 |
response = 'The Blockchain is valid.'
|
84 |
z=True
|
|
|
87 |
z=False
|
88 |
return response,z, mes, ind
|
89 |
|
|
|
|
|
90 |
def mychain_mine_block_send(chain_r=None,chain_n=None):
|
91 |
previous_block = mychain_send.print_previous_block()
|
92 |
previous_proof = previous_block['proof']
|