Omnibus commited on
Commit
307ba70
·
1 Parent(s): 8813f2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -82
app.py CHANGED
@@ -386,90 +386,94 @@ def issue_tokens(send,rec,amount):
386
  #print(f"{api.whoami(['name'])}")
387
  #repo = f'omnibus/{space}'
388
  #is_valid='True'
389
- _,z=valid()
390
- if z == True:
391
- mes = None
392
- try:
393
- r = requests.get(f'{main_balance}{send}.json')
394
- lod = json.loads(r.text)
395
- p=True
396
- except:
397
- lod=[]
398
- p=False
399
- mes = "Sender has no wallet"
400
- pass
401
- if p==True:
402
- balance = lod[-1]["balance"]
403
- print (balance)
404
- balance =int(balance)-int(amount)
405
- if balance >=0:
406
- block = {'index': len(lod) + 1,
407
- 'timestamp': str(datetime.datetime.now()),
408
- 'sender': f'{send}',
409
- 'recipient':f'{rec}',
410
- 'amount': f'{amount}',
411
- 'balance': f'{balance}'
412
- }
413
- lod.append(block)
414
-
415
- json_object = json.dumps(lod, indent=4)
416
- with open("tmp1.json", "w") as outfile:
417
- outfile.write(json_object)
418
- try:
419
- api.upload_file(
420
- path_or_fileobj="tmp1.json",
421
- path_in_repo=f'{main_balance.split("main/",1)[1]}/{send}.json',
422
- repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
423
- token=token_self,
424
- repo_type="dataset",
425
- )
426
- os.remove("tmp1.json")
427
- except Exception as e:
428
- mes=e
429
- pass
430
-
431
- try:
432
- r = requests.get(f'{main_balance}{rec}.json')
433
- lod = json.loads(r.text)
434
- balance = lod[-1]["balance"]
435
-
436
- except:
437
- lod=[]
438
- balance=0
439
- pass
440
  print (balance)
441
- balance =int(balance)+int(amount)
442
- block = {'index': len(lod) + 1,
443
- 'timestamp': str(datetime.datetime.now()),
444
- 'sender': f'{send}',
445
- 'recipient':f'{rec}',
446
- 'amount': f'{amount}',
447
- 'balance': f'{balance}'}
448
- lod.append(block)
449
-
450
- json_object = json.dumps(lod, indent=4)
451
- with open("tmp1.json", "w") as outfile:
452
- outfile.write(json_object)
453
- try:
454
- api.upload_file(
455
- path_or_fileobj="tmp1.json",
456
- path_in_repo=f'{main_balance.split("main/",1)[1]}/{rec}.json',
457
- repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
458
- token=token_self,
459
- repo_type="dataset",
460
- )
461
- os.remove("tmp1.json")
 
 
 
 
 
462
 
463
- except Exception as e:
464
- mes = e
465
- pass
466
- if mes == None:
467
- mes = f'{amount} sent from {send} to {rec}'
468
- if balance < 0:
469
- mes ="Not enough tokens"
470
- p = False
471
- if z==False:
472
- mes = "No Blockchain Loaded"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
  p=False
474
  return mes,p
475
  #api = HfApi(token=token)
 
386
  #print(f"{api.whoami(['name'])}")
387
  #repo = f'omnibus/{space}'
388
  #is_valid='True'
389
+ try:
390
+ _,z=valid()
391
+ if z == True:
392
+ mes = None
393
+ try:
394
+ r = requests.get(f'{main_balance}{send}.json')
395
+ lod = json.loads(r.text)
396
+ p=True
397
+ except:
398
+ lod=[]
399
+ p=False
400
+ mes = "Sender has no wallet"
401
+ pass
402
+ if p==True:
403
+ balance = lod[-1]["balance"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  print (balance)
405
+ balance =int(balance)-int(amount)
406
+ if balance >=0:
407
+ block = {'index': len(lod) + 1,
408
+ 'timestamp': str(datetime.datetime.now()),
409
+ 'sender': f'{send}',
410
+ 'recipient':f'{rec}',
411
+ 'amount': f'{amount}',
412
+ 'balance': f'{balance}'
413
+ }
414
+ lod.append(block)
415
+
416
+ json_object = json.dumps(lod, indent=4)
417
+ with open("tmp1.json", "w") as outfile:
418
+ outfile.write(json_object)
419
+ try:
420
+ api.upload_file(
421
+ path_or_fileobj="tmp1.json",
422
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{send}.json',
423
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
424
+ token=token_self,
425
+ repo_type="dataset",
426
+ )
427
+ os.remove("tmp1.json")
428
+ except Exception as e:
429
+ mes=e
430
+ pass
431
 
432
+ try:
433
+ r = requests.get(f'{main_balance}{rec}.json')
434
+ lod = json.loads(r.text)
435
+ balance = lod[-1]["balance"]
436
+
437
+ except:
438
+ lod=[]
439
+ balance=0
440
+ pass
441
+ print (balance)
442
+ balance =int(balance)+int(amount)
443
+ block = {'index': len(lod) + 1,
444
+ 'timestamp': str(datetime.datetime.now()),
445
+ 'sender': f'{send}',
446
+ 'recipient':f'{rec}',
447
+ 'amount': f'{amount}',
448
+ 'balance': f'{balance}'}
449
+ lod.append(block)
450
+
451
+ json_object = json.dumps(lod, indent=4)
452
+ with open("tmp1.json", "w") as outfile:
453
+ outfile.write(json_object)
454
+ try:
455
+ api.upload_file(
456
+ path_or_fileobj="tmp1.json",
457
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{rec}.json',
458
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
459
+ token=token_self,
460
+ repo_type="dataset",
461
+ )
462
+ os.remove("tmp1.json")
463
+
464
+ except Exception as e:
465
+ mes = e
466
+ pass
467
+ if mes == None:
468
+ mes = f'{amount} sent from {send} to {rec}'
469
+ if balance < 0:
470
+ mes ="Not enough tokens"
471
+ p = False
472
+ if z==False:
473
+ mes = "Invalid Blockchain"
474
+ p=False
475
+ except Exception:
476
+ mes = "Blockchain not loaded?"
477
  p=False
478
  return mes,p
479
  #api = HfApi(token=token)