Omnibus commited on
Commit
adc07b6
·
1 Parent(s): e40196a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -3
app.py CHANGED
@@ -14,9 +14,9 @@ import crypt
14
 
15
  from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
16
 
17
- main_chain='https://huggingface.co/datasets/Omnibus/blockchain-sim-2/raw/main/chains/'
18
- main_balance='https://huggingface.co/datasets/Omnibus/blockchain-sim-2/raw/main/balance/'
19
- main_trans='https://huggingface.co/datasets/Omnibus/blockchain-sim-2/raw/main/transact/'
20
 
21
  #main_nodes='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/node_file1.json'
22
  #main_pending='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/pending1.json'
@@ -442,6 +442,19 @@ with gr.Blocks() as bc:
442
  gr.Markdown("""<h1><center>Blockchain Simulator<br><h3>(Transactions have no value)<br><h4>Chain will reset at 20 blocks""")
443
  #blockchain = gr.State()
444
  with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  with gr.Tab("OG"):
446
  with gr.Row():
447
  with gr.Column():
@@ -552,6 +565,123 @@ with gr.Blocks() as bc:
552
  print (e)
553
  return e,None,None,e
554
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
 
556
  gen_wal_btn.click(crypt.generate_keys,None,[out2,out1, img3,out3,img1,img2]).then(create_new_chain,out3,[json_out,block_text,send,rec]).then(crypt.test_fn,[img1,img2],[priv_key_in,pub_key_in,priv_key_in1])
557
  rsa_enc_btn.click(crypt.encrypt_text,[rsa_to_enc,pub_key_in,priv_key_in1,out3],[rsa_enc_mes,qr_enc_mes]).then(crypt.test_fn2,qr_enc_mes,mes_in)
 
14
 
15
  from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
16
 
17
+ main_chain='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/chains/'
18
+ main_balance='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/balance/'
19
+ main_trans='https://huggingface.co/datasets/Omnibus/chat-at/raw/main/transact/'
20
 
21
  #main_nodes='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/node_file1.json'
22
  #main_pending='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/pending1.json'
 
442
  gr.Markdown("""<h1><center>Blockchain Simulator<br><h3>(Transactions have no value)<br><h4>Chain will reset at 20 blocks""")
443
  #blockchain = gr.State()
444
  with gr.Row():
445
+ with gr.Tab("Messages"):
446
+ with gr.Accordion("Key"):
447
+ with gr.Row():
448
+ input_address = gr.Image(label="Wallet",type="filepath")
449
+ input_key = gr.Image(label="Key",type="filepath")
450
+
451
+ with gr.Row():
452
+ with gr.Column():
453
+
454
+ send_mes=gr.Textbox(label="Message", lines=6)
455
+ send_mes_btn=gr.Button()
456
+ rec_mes = gr.Textbox(lines=6)
457
+
458
  with gr.Tab("OG"):
459
  with gr.Row():
460
  with gr.Column():
 
565
  print (e)
566
  return e,None,None,e
567
 
568
+ def send_message(send,rec,amount):
569
+ response_send={}
570
+ response_rec={}
571
+ show_chain_send={}
572
+ show_chain_rec={}
573
+ data_send=None
574
+ data_rec=None
575
+ rec_send=None
576
+ rec_drop=None
577
+ message_send=None
578
+ message_rec=None
579
+ trans_data=None
580
+ trans_mes=None
581
+ balance_send = 0
582
+ balance_rec = 0
583
+ mes = "blank message"
584
+ try:
585
+ b_mes,z=bc_utils.valid()
586
+ if z == True:
587
+ try:
588
+ response,message = get_my_chain_send(send)
589
+ #print (f'response:{response}::message{message}')
590
+ #r = requests.get(f'{main_balance}{send}.json')
591
+ lod=response
592
+ #lod = json.loads(response)
593
+ #print (lod)
594
+ p=True
595
+ except Exception as e:
596
+ lod=[]
597
+ p=False
598
+ mes = f"Sender has no wallet {e}"
599
+ pass
600
+ mes1,val,mes2,ind = valid_send()
601
+ print (f'val:: {val}')
602
+ if val == False:
603
+ p=False
604
+ mes = f"Sender: {send} Blockchain is not valid. {mes2} at Index {ind}"
605
+ #mes = "Blockchain is not valid."
606
+
607
+ #if val == True:
608
+ if p==True:
609
+ try:
610
+ balance = lod["chain"][-1]["balance"]
611
+ except Exception:
612
+ balance = 0
613
+ p=False
614
+ #print (balance)
615
+ balance_send =int(balance)-int(amount)
616
+ if balance_send >=0:
617
+ p=True
618
+ response,message = get_my_chain_rec(rec)
619
+ lod_rec = response
620
+ mes1,val,mes2,ind = valid_rec()
621
+ print (f'val:: {val}')
622
+ if val == False:
623
+ p=False
624
+ mes = f"Recipient: {rec} Blockchain is not valid. {mes2} at Index {ind}"
625
+ #mes = "Blockchain is not valid."
626
+ #print (lod_rec)
627
+ if val == True:
628
+ try:
629
+ balance = lod_rec["chain"][-1]["balance"]
630
+ #print (balance)
631
+ except Exception:
632
+ p=False
633
+ balance = 0
634
+ balance_rec =int(balance)+int(amount)
635
+
636
+ if balance_send < 0:
637
+ mes ="Not enough tokens"
638
+ p = False
639
+
640
+ print(mes)
641
+
642
+ if z==False:
643
+ mes = b_mes
644
+ p=False
645
+ except Exception as e:
646
+ mes = f"Blockchain not loaded? {e}"
647
+ p=False
648
+ print (mes)
649
+
650
+ if p==False:
651
+ return (mes, p,None,None,None,None,None,None,None,None,None,None,None)
652
+
653
+ #return (mes, p,{},{},{},{},{},{},None,None,None,None,{})
654
+ #json, json, json, json, dataframe, dataframe, textbox, textbox, dropdown, dropdown, dataframe
655
+ if p==True:
656
+
657
+
658
+ mychain_send.new_transaction(f"{send}",f"{rec}",f"{amount}",f"{balance_send}")
659
+ mychain_trans.new_transaction(f"{send}",f"{rec}",f"{amount}",f"{balance_send}")
660
+
661
+ message_send = "Transaction Added to Pool"
662
+ data_send = pd.DataFrame(mychain_send.pending_transactions)
663
+ mychain_rec.new_transaction(f"{send}",f"{rec}",f"{amount}",f"{balance_rec}")
664
+ message_rec = "Transaction Added to Pool"
665
+ data_rec = pd.DataFrame(mychain_rec.pending_transactions)
666
+ response_send, show_chain_send, message_send = mychain_mine_block_send(balance_send, chain_r=None,chain_n=send)
667
+
668
+ mychain_mine_block_trans(balance_send, chain_r=None,chain_n=send)
669
+
670
+ response_rec, show_chain_rec, message_rec = mychain_mine_block_rec(balance_rec, chain_r=None,chain_n=rec)
671
+ mes = (f'Send: {message_send} :: Recieve: {message_rec}')
672
+ _,rec_send=update_send_list()
673
+ _,rec_drop=update_rec_list()
674
+ trans_bx = merge_trans()
675
+ trans_data, mes = bc_utils.bc_transactions(trans_bx)
676
+ 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)
677
+
678
+
679
+
680
+ #os.environ['PRIV'] = ""
681
+
682
+
683
+ send_mes_btn.click(send_message,[send,rec,send_mes],[block_text,out_box_bool,json_out_send,json_out_rec,chain_json_send,chain_json_rec,trans_data_send,trans_data_rec,block_text_send,block_text_rec,send,rec,trans_data])
684
+ #send_mes_btn.click(send_message,[send_mes,input_address,input_key],[rec_mes])
685
 
686
  gen_wal_btn.click(crypt.generate_keys,None,[out2,out1, img3,out3,img1,img2]).then(create_new_chain,out3,[json_out,block_text,send,rec]).then(crypt.test_fn,[img1,img2],[priv_key_in,pub_key_in,priv_key_in1])
687
  rsa_enc_btn.click(crypt.encrypt_text,[rsa_to_enc,pub_key_in,priv_key_in1,out3],[rsa_enc_mes,qr_enc_mes]).then(crypt.test_fn2,qr_enc_mes,mes_in)