Omnibus commited on
Commit
9782510
·
1 Parent(s): 6a42cf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -57
app.py CHANGED
@@ -382,69 +382,88 @@ def issue_tokens(send,rec,amount):
382
  #is_valid='True'
383
  mes = None
384
  try:
385
- r = requests.get(f'{main_balance}/{send}')
386
  lod = json.loads(r.text)
 
387
  except:
388
  lod=[]
 
 
389
  pass
390
- block = {'index': len(lod) + 1,
391
- 'timestamp': str(datetime.datetime.now()),
392
- 'sender': f'{send}',
393
- 'recipient':f'{rec}',
394
-
395
- 'amount': f'{amount}'}
396
- lod.append(block)
397
 
398
- json_object = json.dumps(lod, indent=4)
399
- with open("tmp1.json", "w") as outfile:
400
- outfile.write(json_object)
401
- try:
402
- api.upload_file(
403
- path_or_fileobj="tmp1.json",
404
- path_in_repo=f'{main_balance.split("main/",1)[1]}/{send}.json',
405
- repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
406
- token=token_self,
407
- repo_type="dataset",
408
- )
409
- os.remove("tmp1.json")
410
- except Exception as e:
411
- mes=e
412
- pass
413
- lod.clear()
414
 
415
- try:
416
- r = requests.get(f'{main_balance}/{rec}')
417
- lod = json.loads(r.text)
418
- except:
419
- lod=[]
420
- pass
421
- block = {'index': len(lod) + 1,
422
- 'timestamp': str(datetime.datetime.now()),
423
- 'sender': f'{send}',
424
- 'recipient':f'{rec}',
425
-
426
- 'amount': f'{amount}'}
427
- lod.append(block)
428
 
429
- json_object = json.dumps(lod, indent=4)
430
- with open("tmp1.json", "w") as outfile:
431
- outfile.write(json_object)
432
- try:
433
- api.upload_file(
434
- path_or_fileobj="tmp1.json",
435
- path_in_repo=f'{main_balance.split("main/",1)[1]}/{rec}.json',
436
- repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
437
- token=token_self,
438
- repo_type="dataset",
439
- )
440
- os.remove("tmp1.json")
441
-
442
- except Exception as e:
443
- mes = e
444
- pass
445
- if mes == None:
446
- mes = f'{amount} sent from {send} to {rec}'
447
- return mes
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
  with gr.Blocks() as bc:
450
  with gr.Row(visible=True) as invalid:
@@ -486,7 +505,7 @@ with gr.Blocks() as bc:
486
  with gr.Accordion("Tokens", open=False):
487
  issue_btn=gr.Button()
488
 
489
- issue_btn.click(issue_tokens,[send,rec,am],block_text)
490
 
491
  node_add.click(add_node,[this_space,node_repo,node_space,node_file],block_text)
492
  pass_btn.click(checkp,pass_box,[invalid,valida])
 
382
  #is_valid='True'
383
  mes = None
384
  try:
385
+ r = requests.get(f'{main_balance}/{send}.json')
386
  lod = json.loads(r.text)
387
+ p=True
388
  except:
389
  lod=[]
390
+ p=False
391
+ mes = "Sender has no wallet"
392
  pass
 
 
 
 
 
 
 
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
 
396
+
397
+ if p==True:
398
+
399
+ balance = lod[-1]["balance"]
400
+ print (balance)
401
+ balance =int(balance)-int(amount)
402
+ if balance >=0:
403
+ block = {'index': len(lod) + 1,
404
+ 'timestamp': str(datetime.datetime.now()),
405
+ 'sender': f'{send}',
406
+ 'recipient':f'{rec}',
407
+ 'amount': f'{amount}'},
408
+ 'balance': f'{balance}'
409
+ lod.append(block)
410
+
411
+ json_object = json.dumps(lod, indent=4)
412
+ with open("tmp1.json", "w") as outfile:
413
+ outfile.write(json_object)
414
+ try:
415
+ api.upload_file(
416
+ path_or_fileobj="tmp1.json",
417
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{send}.json',
418
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
419
+ token=token_self,
420
+ repo_type="dataset",
421
+ )
422
+ os.remove("tmp1.json")
423
+ except Exception as e:
424
+ mes=e
425
+ pass
426
+
427
+ try:
428
+ r = requests.get(f'{main_balance}/{rec}.json')
429
+ lod = json.loads(r.text)
430
+ except:
431
+ lod=[]
432
+ pass
433
+ balance = lod[-1]["balance"]
434
+ print (balance)
435
+ balance =int(balance)+int(amount)
436
+ block = {'index': len(lod) + 1,
437
+ 'timestamp': str(datetime.datetime.now()),
438
+ 'sender': f'{send}',
439
+ 'recipient':f'{rec}',
440
+ 'amount': f'{amount}',
441
+ 'balance': f'{balance}'}
442
+ lod.append(block)
443
+
444
+ json_object = json.dumps(lod, indent=4)
445
+ with open("tmp1.json", "w") as outfile:
446
+ outfile.write(json_object)
447
+ try:
448
+ api.upload_file(
449
+ path_or_fileobj="tmp1.json",
450
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{rec}.json',
451
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
452
+ token=token_self,
453
+ repo_type="dataset",
454
+ )
455
+ os.remove("tmp1.json")
456
+
457
+ except Exception as e:
458
+ mes = e
459
+ pass
460
+ if mes == None:
461
+ mes = f'{amount} sent from {send} to {rec}'
462
+ if balance < 0:
463
+ mes ="Not enough tokens"
464
+ p = False
465
+
466
+ return mes,p
467
 
468
  with gr.Blocks() as bc:
469
  with gr.Row(visible=True) as invalid:
 
505
  with gr.Accordion("Tokens", open=False):
506
  issue_btn=gr.Button()
507
 
508
+ issue_btn.click(issue_tokens,[send,rec,am],[block_text,None])
509
 
510
  node_add.click(add_node,[this_space,node_repo,node_space,node_file],block_text)
511
  pass_btn.click(checkp,pass_box,[invalid,valida])