Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 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)
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|