Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,11 +28,11 @@ api = HfApi(token=token_self)
|
|
| 28 |
|
| 29 |
######################## BLOCKCHAIN START ###############################
|
| 30 |
|
| 31 |
-
def bc_transactions(block
|
| 32 |
#mes, out = issue_tokens(sender,recipient,amount)
|
| 33 |
|
| 34 |
try:
|
| 35 |
-
blockchain.new_transaction(block
|
| 36 |
message = "Transaction Added to Pool"
|
| 37 |
data = pd.DataFrame(blockchain.trans_data_out)
|
| 38 |
except Exception as e:
|
|
@@ -210,13 +210,13 @@ name = main_balance.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[1]
|
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
-
def get_my_chain_send(sender_name=None
|
| 214 |
global mychain_send
|
| 215 |
|
| 216 |
try:
|
| 217 |
r = requests.get(f'{main_balance}{sender_name}.json')
|
| 218 |
#print (f'r={r.text}')
|
| 219 |
-
mychain_send = MyChainSend(chain_load=main_balance,
|
| 220 |
response = {'chain': mychain_send.chain,
|
| 221 |
'length': len(mychain_send.chain)}
|
| 222 |
#print (f'response={response}')
|
|
@@ -226,19 +226,19 @@ def get_my_chain_send(sender_name=None,prev_block=None):
|
|
| 226 |
message = f"Error loading from: {sender_name}"
|
| 227 |
return ["Error Loading Chain"],message
|
| 228 |
|
| 229 |
-
def get_my_chain_rec(recipient_name=None
|
| 230 |
global mychain_rec
|
| 231 |
|
| 232 |
try:
|
| 233 |
r = requests.get(f'{main_balance}{recipient_name}.json')
|
| 234 |
-
mychain_rec = MyChainRec(chain_load=main_balance,
|
| 235 |
response = {'chain': mychain_rec.chain,
|
| 236 |
'length': len(mychain_rec.chain)}
|
| 237 |
message = f"Blockchain loaded from: {main_balance}{recipient_name}.json"
|
| 238 |
return response,message
|
| 239 |
except Exception:
|
| 240 |
try:
|
| 241 |
-
mychain_rec = MyChainRec(chain_load=main_balance,
|
| 242 |
response = {'chain': mychain_rec.chain,
|
| 243 |
'length': len(mychain_rec.chain)}
|
| 244 |
|
|
@@ -333,11 +333,8 @@ def merge_trans():
|
|
| 333 |
trans_bx = []
|
| 334 |
previous_post_send = mychain_send.print_previous_block()
|
| 335 |
previous_post_rec = mychain_rec.print_previous_block()
|
| 336 |
-
|
| 337 |
-
previous_block = blockchain.chain[prev_block]
|
| 338 |
-
|
| 339 |
send_block = {
|
| 340 |
-
'block': previous_block["index"]+1,
|
| 341 |
'role': 'Sender',
|
| 342 |
'name': previous_post_send['transactions'][0]['sender'],
|
| 343 |
'index': previous_post_send['index'],
|
|
@@ -348,7 +345,6 @@ def merge_trans():
|
|
| 348 |
'proof': previous_post_send['proof'],
|
| 349 |
'previous_hash': previous_post_send['previous_hash']}
|
| 350 |
rec_block = {
|
| 351 |
-
'block': previous_block["index"]+1,
|
| 352 |
'role': 'Recipient',
|
| 353 |
'name': previous_post_rec['transactions'][0]['recipient'],
|
| 354 |
'index': previous_post_rec['index'],
|
|
@@ -360,7 +356,7 @@ def merge_trans():
|
|
| 360 |
'previous_hash': previous_post_rec['previous_hash']}
|
| 361 |
trans_bx.append(send_block)
|
| 362 |
trans_bx.append(rec_block)
|
| 363 |
-
return trans_bx
|
| 364 |
|
| 365 |
|
| 366 |
|
|
@@ -466,8 +462,8 @@ def issue_tokens(send,rec,amount):
|
|
| 466 |
mes = (f'Send: {message_send} :: Recieve: {message_rec}')
|
| 467 |
_,rec_send=update_send_list()
|
| 468 |
_,rec_drop=update_rec_list()
|
| 469 |
-
trans_bx
|
| 470 |
-
trans_data, mes = bc_transactions(trans_bx
|
| 471 |
return (mes, p, response_send, response_rec, show_chain_send, show_chain_rec, data_send, data_rec, message_send, message_rec, rec_send, rec_drop,trans_data)
|
| 472 |
|
| 473 |
|
|
@@ -615,4 +611,4 @@ with gr.Blocks() as bc:
|
|
| 615 |
mine_b.click(mine_block,[chain_repo,chain_n],[json_out,chain_json,trans_data,block_text])
|
| 616 |
|
| 617 |
|
| 618 |
-
bc.launch(enable_queue=False)
|
|
|
|
| 28 |
|
| 29 |
######################## BLOCKCHAIN START ###############################
|
| 30 |
|
| 31 |
+
def bc_transactions(block):
|
| 32 |
#mes, out = issue_tokens(sender,recipient,amount)
|
| 33 |
|
| 34 |
try:
|
| 35 |
+
blockchain.new_transaction(block)
|
| 36 |
message = "Transaction Added to Pool"
|
| 37 |
data = pd.DataFrame(blockchain.trans_data_out)
|
| 38 |
except Exception as e:
|
|
|
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
+
def get_my_chain_send(sender_name=None):
|
| 214 |
global mychain_send
|
| 215 |
|
| 216 |
try:
|
| 217 |
r = requests.get(f'{main_balance}{sender_name}.json')
|
| 218 |
#print (f'r={r.text}')
|
| 219 |
+
mychain_send = MyChainSend(chain_load=main_balance,load=r.text)
|
| 220 |
response = {'chain': mychain_send.chain,
|
| 221 |
'length': len(mychain_send.chain)}
|
| 222 |
#print (f'response={response}')
|
|
|
|
| 226 |
message = f"Error loading from: {sender_name}"
|
| 227 |
return ["Error Loading Chain"],message
|
| 228 |
|
| 229 |
+
def get_my_chain_rec(recipient_name=None):
|
| 230 |
global mychain_rec
|
| 231 |
|
| 232 |
try:
|
| 233 |
r = requests.get(f'{main_balance}{recipient_name}.json')
|
| 234 |
+
mychain_rec = MyChainRec(chain_load=main_balance,load=r.text)
|
| 235 |
response = {'chain': mychain_rec.chain,
|
| 236 |
'length': len(mychain_rec.chain)}
|
| 237 |
message = f"Blockchain loaded from: {main_balance}{recipient_name}.json"
|
| 238 |
return response,message
|
| 239 |
except Exception:
|
| 240 |
try:
|
| 241 |
+
mychain_rec = MyChainRec(chain_load=main_balance,create=recipient_name)
|
| 242 |
response = {'chain': mychain_rec.chain,
|
| 243 |
'length': len(mychain_rec.chain)}
|
| 244 |
|
|
|
|
| 333 |
trans_bx = []
|
| 334 |
previous_post_send = mychain_send.print_previous_block()
|
| 335 |
previous_post_rec = mychain_rec.print_previous_block()
|
| 336 |
+
|
|
|
|
|
|
|
| 337 |
send_block = {
|
|
|
|
| 338 |
'role': 'Sender',
|
| 339 |
'name': previous_post_send['transactions'][0]['sender'],
|
| 340 |
'index': previous_post_send['index'],
|
|
|
|
| 345 |
'proof': previous_post_send['proof'],
|
| 346 |
'previous_hash': previous_post_send['previous_hash']}
|
| 347 |
rec_block = {
|
|
|
|
| 348 |
'role': 'Recipient',
|
| 349 |
'name': previous_post_rec['transactions'][0]['recipient'],
|
| 350 |
'index': previous_post_rec['index'],
|
|
|
|
| 356 |
'previous_hash': previous_post_rec['previous_hash']}
|
| 357 |
trans_bx.append(send_block)
|
| 358 |
trans_bx.append(rec_block)
|
| 359 |
+
return trans_bx
|
| 360 |
|
| 361 |
|
| 362 |
|
|
|
|
| 462 |
mes = (f'Send: {message_send} :: Recieve: {message_rec}')
|
| 463 |
_,rec_send=update_send_list()
|
| 464 |
_,rec_drop=update_rec_list()
|
| 465 |
+
trans_bx = merge_trans()
|
| 466 |
+
trans_data, mes = bc_transactions(trans_bx)
|
| 467 |
return (mes, p, response_send, response_rec, show_chain_send, show_chain_rec, data_send, data_rec, message_send, message_rec, rec_send, rec_drop,trans_data)
|
| 468 |
|
| 469 |
|
|
|
|
| 611 |
mine_b.click(mine_block,[chain_repo,chain_n],[json_out,chain_json,trans_data,block_text])
|
| 612 |
|
| 613 |
|
| 614 |
+
bc.launch(enable_queue=False)
|