Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -565,115 +565,115 @@ with gr.Blocks() as bc:
|
|
565 |
print (e)
|
566 |
return e,None,None,e
|
567 |
|
568 |
-
def send_message(send,rec,amount):
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
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 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
if balance_send >=0:
|
617 |
p=True
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
649 |
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
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 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
|
678 |
|
679 |
|
|
|
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 |
|