Omnibus commited on
Commit
29346dc
·
0 Parent(s):

Duplicate from Omnibus/Blockchain-Simulator-dev2

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +12 -0
  3. app.py +548 -0
  4. chain1.json +16 -0
  5. node_file.json +12 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Blockchain Simulator
3
+ emoji: 🔗
4
+ colorFrom: purple
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 3.17.0
8
+ app_file: app.py
9
+ duplicated_from: Omnibus/Blockchain-Simulator-dev2
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,548 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import datetime
4
+ import hashlib
5
+ import json
6
+ import os
7
+ import requests
8
+ from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
9
+
10
+ main_chain='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/'
11
+ main_balance='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/balance/'
12
+
13
+ main_nodes='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/node_file1.json'
14
+ main_pending='https://huggingface.co/datasets/Omnibus/blockchain-sim/raw/main/pending1.json'
15
+ token_self = os.environ['HF_TOKEN']
16
+ pa=os.environ['PASS']
17
+ repo_d='Omnibus/static-bin'
18
+ chain_d='chain1.json'
19
+ node_file='node_file.json'
20
+ space='blockchain-simulator-dev1'
21
+ api = HfApi(token=token_self)
22
+
23
+ class Balance_sheet:
24
+ def create_block(self, proof, previous_hash,chain_r=None,chain_n=None,balance=None):
25
+ if chain_r=="" or chain_r==None:
26
+ chain_r=f"{main_chain.split('datasets/',1)[1].split('/raw',1)[0]}"
27
+ if chain_n=="" or chain_n==None:
28
+ chain_n=chain_d
29
+ block = {'index': len(self.chain) + 1,
30
+ 'timestamp': str(datetime.datetime.now()),
31
+ 'transactions': self.pending_transactions,
32
+ #'balance':self.balance
33
+ 'proof': proof,
34
+ 'previous_hash': previous_hash}
35
+ if self.block_valid(block) == True:
36
+
37
+ self.pending_transactions = []
38
+ self.chain.append(block)
39
+ json_object = json.dumps(self.chain, indent=4)
40
+ with open("tmp.json", "w") as outfile:
41
+ outfile.write(json_object)
42
+ try:
43
+ api.upload_file(
44
+ path_or_fileobj="tmp.json",
45
+ path_in_repo=chain_n,
46
+ repo_id=chain_r,
47
+ token=token_self,
48
+ repo_type="dataset",
49
+ )
50
+ os.remove("tmp.json")
51
+
52
+ except Exception as e:
53
+ print(e)
54
+ pass
55
+ return block
56
+ else:
57
+ block = {"Not Valid"}
58
+ print("not Valid")
59
+ return block
60
+ def print_previous_block(self):
61
+ return self.chain[-1]
62
+ def new_transaction(self, sender, recipient, amount):
63
+ transaction = {
64
+ 'sender': sender,
65
+ 'recipient': recipient,
66
+ 'amount': amount
67
+ }
68
+ self.pending_transactions.append(transaction)
69
+
70
+ class Blockchain:
71
+
72
+ def __init__(self,load=None,create=None):
73
+
74
+ self.pending_transactions = []
75
+ if load == None or load=="":
76
+ self.chain = []
77
+ self.create_block(proof=1, previous_hash='0',chain_n=create)
78
+ elif load != None and load !="":
79
+ #r = requests.get(load)
80
+ lod = json.loads(load)
81
+ self.chain = lod
82
+ def reset(self,create=None):
83
+ self.chain = []
84
+ self.pending_transactions = []
85
+ self.create_block(proof=1, previous_hash='0',chain_n=create)
86
+ def create_block(self, proof, previous_hash,chain_r=None,chain_n=None):
87
+ if chain_r=="" or chain_r==None:
88
+ chain_r=f"{main_chain.split('datasets/',1)[1].split('/raw',1)[0]}"
89
+ if chain_n=="" or chain_n==None:
90
+ chain_n=chain_d
91
+ block = {'index': len(self.chain) + 1,
92
+ 'timestamp': str(datetime.datetime.now()),
93
+ 'transactions': self.pending_transactions,
94
+ 'proof': proof,
95
+ 'previous_hash': previous_hash}
96
+ if self.block_valid(block) == True:
97
+
98
+ self.pending_transactions = []
99
+ self.chain.append(block)
100
+ json_object = json.dumps(self.chain, indent=4)
101
+ with open("tmp.json", "w") as outfile:
102
+ outfile.write(json_object)
103
+ try:
104
+ api.upload_file(
105
+ path_or_fileobj="tmp.json",
106
+ path_in_repo=chain_n,
107
+ repo_id=chain_r,
108
+ token=token_self,
109
+ repo_type="dataset",
110
+ )
111
+ os.remove("tmp.json")
112
+
113
+ except Exception as e:
114
+ print(e)
115
+ pass
116
+ return block
117
+ else:
118
+ block = {"Not Valid"}
119
+ print("not Valid")
120
+ return block
121
+ def print_previous_block(self):
122
+ return self.chain[-1]
123
+ def new_transaction(self, sender, recipient, amount):
124
+ transaction = {
125
+ 'sender': sender,
126
+ 'recipient': recipient,
127
+ 'amount': amount
128
+ }
129
+ self.pending_transactions.append(transaction)
130
+ def proof_of_work(self, previous_proof):
131
+ new_proof = 1
132
+ check_proof = False
133
+ while check_proof is False:
134
+ hash_operation = hashlib.sha256(
135
+ str(new_proof**2 - previous_proof**2).encode()).hexdigest()
136
+ if hash_operation[:5] == '00000':
137
+ check_proof = True
138
+ else:
139
+ new_proof += 1
140
+ return new_proof
141
+
142
+ def hash(self, block):
143
+ encoded_block = json.dumps(block, sort_keys=True).encode()
144
+ return hashlib.sha256(encoded_block).hexdigest()
145
+ def block_valid(self, block):
146
+ print (block)
147
+ #prev_block=len(self.chain)
148
+ if len(self.chain) > 0:
149
+ prev_block = len(self.chain)-1
150
+ previous_block = self.chain[prev_block]
151
+ print (previous_block)
152
+ out=True
153
+ ind=None
154
+ mes=None
155
+ if block['previous_hash'] != self.hash(previous_block):
156
+ out=False
157
+ #ind=block_index
158
+ mes='Hash'
159
+
160
+ previous_proof = previous_block['proof']
161
+ proof = block['proof']
162
+ hash_operation = hashlib.sha256(
163
+ str(proof**2 - previous_proof**2).encode()).hexdigest()
164
+
165
+ if hash_operation[:5] != '00000':
166
+ out=False
167
+ #ind=block_index+1
168
+ mes='Proof'
169
+ previous_block = block
170
+ else:
171
+ out = True
172
+ return out
173
+
174
+ def chain_valid(self, chain):
175
+ previous_block = chain[0]
176
+ block_index = 1
177
+ out=True
178
+ ind=None
179
+ mes=None
180
+ while block_index < len(chain):
181
+ block = chain[block_index]
182
+ if block['previous_hash'] != self.hash(previous_block):
183
+ out=False
184
+ ind=block_index
185
+ mes='Hash'
186
+ break
187
+
188
+ previous_proof = previous_block['proof']
189
+ proof = block['proof']
190
+ hash_operation = hashlib.sha256(
191
+ str(proof**2 - previous_proof**2).encode()).hexdigest()
192
+
193
+ if hash_operation[:5] != '00000':
194
+ out=False
195
+ ind=block_index+1
196
+ mes='Proof'
197
+ break
198
+ previous_block = block
199
+ block_index += 1
200
+
201
+ return out, ind, mes
202
+ #def check_balance(sender,amount):
203
+
204
+
205
+
206
+ def bc_transactions(sender,recipient,amount):
207
+ mes, out = issue_tokens(sender,recipient,amount)
208
+ if out == True:
209
+ blockchain.new_transaction(f"{sender}",f"{recipient}",f"{amount}")
210
+ message = "Transaction Added to Pool"
211
+ data = pd.DataFrame(blockchain.pending_transactions)
212
+ if out == False:
213
+ message = mes
214
+ data = None
215
+ return data,message,None,None,None
216
+
217
+ def create_chain(create=None):
218
+ global blockchain
219
+ blockchain = Blockchain(create=create)
220
+ #blockchain.reset(create=create)
221
+ return "New Chain Created",None,display_chain()
222
+
223
+ def display_chain():
224
+ response = {'chain': blockchain.chain,
225
+ 'length': len(blockchain.chain)}
226
+ return response
227
+
228
+ def mine_block(chain_r=None,chain_n=None):
229
+ previous_block = blockchain.print_previous_block()
230
+ previous_proof = previous_block['proof']
231
+ proof = blockchain.proof_of_work(previous_proof)
232
+ previous_hash = blockchain.hash(previous_block)
233
+ block = blockchain.create_block(proof, previous_hash,chain_r,chain_n)
234
+
235
+ response = {'message': 'A block is MINED',
236
+ 'index': block['index'],
237
+ 'timestamp': block['timestamp'],
238
+ 'proof': block['proof'],
239
+ 'previous_hash': block['previous_hash']}
240
+ message = "A block is MINED"
241
+ show_chain = display_chain()
242
+ if len(blockchain.chain) > 1000:
243
+ blockchain.reset()
244
+ response = None
245
+ show_chain=display_chain()
246
+ message = "New Chain Created at Max 20 Blocks"
247
+ return response, show_chain,pd.DataFrame(blockchain.pending_transactions), message
248
+
249
+ def sort_valid():
250
+ #nodes=main_nodes.replace("'","")
251
+ f = requests.get(f'{main_nodes}')
252
+ t = open('tmp.json','w')
253
+ t.write(f.text)
254
+ t.close()
255
+ f = open('tmp.json','r')
256
+ f = f.read()
257
+ j = json.loads(f)
258
+ #j=f.json()
259
+ print (len(j))
260
+ cnt=0
261
+ valid_chains=[]
262
+ not_valid=[]
263
+ response=''
264
+ while cnt < len(j):
265
+ try:
266
+ r = requests.get(f'{j[cnt]["url"]}')
267
+ g = open('tmp1.json','w')
268
+ g.write(r.text)
269
+ g.close()
270
+ gg = open('tmp1.json','r')
271
+ ggg=gg.read()
272
+ print (ggg)
273
+ leng=len(json.loads(ggg))
274
+ print(f'Blockchain {cnt}: Length {leng} ')
275
+ valid,ind,mes = blockchain.chain_valid(json.loads(ggg))
276
+ except Exception:
277
+ valid=False
278
+ leng="No Data"
279
+ if valid:
280
+ valid_chains.append({"Chain": cnt, "Length": leng})
281
+ response = f'{response} Valid: {cnt}'
282
+ else:
283
+ not_valid.append({"Chain": cnt, "Length": leng})
284
+ response = f'{response} Invalid:{cnt}'
285
+
286
+ per = ((len(valid_chains)+1)/(len(j)+1))*100
287
+ cnt+=1
288
+ response=f'{int(per)}%-{response}'
289
+ print (f'Valid: {valid_chains}')
290
+ print (f'Not Valid: {not_valid}')
291
+ #p = json.loads(str(valid_chains))
292
+ p = valid_chains
293
+ cnt2=0
294
+ bot=0
295
+ out=[]
296
+ while cnt2 < len(p):
297
+ if p[cnt2]['Length'] > bot:
298
+ bot = p[cnt2]['Length']
299
+ out = [cnt2,bot]
300
+ else:
301
+ pass
302
+ cnt2+=1
303
+ print (out)
304
+ return response
305
+
306
+ def valid():
307
+ valid,ind,mes = blockchain.chain_valid(blockchain.chain)
308
+ if valid:
309
+ response = 'The Blockchain is valid.'
310
+ z=True
311
+ else:
312
+ response = f'Blockchain is not valid. {mes} at Index {ind}'
313
+ z=False
314
+ return response,z
315
+
316
+ def get_chain(repo_name=None,chain_name=None,token=None):
317
+ if repo_name == "":
318
+ repo_name = repo_d
319
+ if chain_name=="":
320
+ chain_name = chain_d
321
+ #src = f"https://huggingface.co/spaces/{repo_name}/raw/main/{chain_name}"
322
+
323
+ #ff = open('chain1.json','r')
324
+ #src = ff.read()
325
+ #src = json.loads(ff)
326
+
327
+
328
+ try:
329
+ r = requests.get(f'{main_chain}{chain_name}')
330
+ #create_chain(load=r.text)
331
+ global blockchain
332
+ blockchain = Blockchain(load=r.text)
333
+ #return "New Chain Created",display_chain()
334
+
335
+
336
+
337
+ #create_chain(src)
338
+ response = {'chain': blockchain.chain,
339
+ 'length': len(blockchain.chain)}
340
+ message = f"Blockchain loaded from: {main_chain}{chain_name}"
341
+ return response,message
342
+ except:
343
+ message = f"Error loading from: {src}"
344
+ return ["Error Loading Chain"],message
345
+ def checkp(inp):
346
+ if inp == pa:
347
+ return gr.update(visible=False), gr.update(visible=True)
348
+ elif inp != pa:
349
+ return gr.update(visible=True), gr.update(visible=False)
350
+ def add_node(this_space,repo,space,chain_file):
351
+ #print(f"{api.whoami(['name'])}")
352
+ #repo = f'omnibus/{space}'
353
+ is_valid='True'
354
+ r = requests.get(f'{main_nodes}')
355
+ try:
356
+ lod = json.loads(r.text)
357
+ except:
358
+ lod=[]
359
+ pass
360
+ block = {'index': len(lod) + 1,
361
+ 'timestamp': str(datetime.datetime.now()),
362
+ 'url': f'https://huggingface.co/datasets/{repo}/{space}/raw/main/{chain_file}',
363
+ 'valid': f'{is_valid}'}
364
+ lod.append(block)
365
+
366
+ json_object = json.dumps(lod, indent=4)
367
+ with open("tmp1.json", "w") as outfile:
368
+ outfile.write(json_object)
369
+ try:
370
+ api.upload_file(
371
+ path_or_fileobj="tmp1.json",
372
+ path_in_repo=main_nodes.split('main/',1)[1],
373
+ repo_id=main_nodes.split('datasets/',1)[1].split('/raw',1)[0],
374
+ token=token_self,
375
+ repo_type="dataset",
376
+ )
377
+ os.remove("tmp1.json")
378
+
379
+ except Exception as e:
380
+ pass
381
+
382
+
383
+
384
+
385
+ start_tokens = 10000000
386
+ source="Main"
387
+ def issue_tokens(send,rec,amount):
388
+ #print(f"{api.whoami(['name'])}")
389
+ #repo = f'omnibus/{space}'
390
+ #is_valid='True'
391
+ try:
392
+ _,z=valid()
393
+ if z == True:
394
+ mes = None
395
+ try:
396
+ r = requests.get(f'{main_balance}{send}.json')
397
+ lod = json.loads(r.text)
398
+ p=True
399
+ except:
400
+ lod=[]
401
+ p=False
402
+ mes = "Sender has no wallet"
403
+ pass
404
+ if p==True:
405
+ balance = lod[-1]["balance"]
406
+ print (balance)
407
+ balance =int(balance)-int(amount)
408
+ if balance >=0:
409
+ block = {'index': len(lod) + 1,
410
+ 'timestamp': str(datetime.datetime.now()),
411
+ 'sender': f'{send}',
412
+ 'recipient':f'{rec}',
413
+ 'amount': f'{amount}',
414
+ 'balance': f'{balance}'
415
+ }
416
+ lod.append(block)
417
+
418
+ json_object = json.dumps(lod, indent=4)
419
+ with open("tmp1.json", "w") as outfile:
420
+ outfile.write(json_object)
421
+ try:
422
+ api.upload_file(
423
+ path_or_fileobj="tmp1.json",
424
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{send}.json',
425
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
426
+ token=token_self,
427
+ repo_type="dataset",
428
+ )
429
+ os.remove("tmp1.json")
430
+ except Exception as e:
431
+ mes=e
432
+ pass
433
+
434
+ try:
435
+ r = requests.get(f'{main_balance}{rec}.json')
436
+ lod = json.loads(r.text)
437
+ balance = lod[-1]["balance"]
438
+
439
+ except:
440
+ lod=[]
441
+ balance=0
442
+ pass
443
+ print (balance)
444
+ balance =int(balance)+int(amount)
445
+ block = {'index': len(lod) + 1,
446
+ 'timestamp': str(datetime.datetime.now()),
447
+ 'sender': f'{send}',
448
+ 'recipient':f'{rec}',
449
+ 'amount': f'{amount}',
450
+ 'balance': f'{balance}'}
451
+ lod.append(block)
452
+
453
+ json_object = json.dumps(lod, indent=4)
454
+ with open("tmp1.json", "w") as outfile:
455
+ outfile.write(json_object)
456
+ try:
457
+ api.upload_file(
458
+ path_or_fileobj="tmp1.json",
459
+ path_in_repo=f'{main_balance.split("main/",1)[1]}/{rec}.json',
460
+ repo_id=main_balance.split('datasets/',1)[1].split('/raw',1)[0],
461
+ token=token_self,
462
+ repo_type="dataset",
463
+ )
464
+ os.remove("tmp1.json")
465
+
466
+ except Exception as e:
467
+ mes = e
468
+ pass
469
+ if mes == None:
470
+ mes = f'{amount} sent from {send} to {rec}'
471
+ if balance < 0:
472
+ mes ="Not enough tokens"
473
+ p = False
474
+ if z==False:
475
+ mes = "Invalid Blockchain"
476
+ p=False
477
+ except Exception:
478
+ mes = "Blockchain not loaded?"
479
+ p=False
480
+ return mes,p
481
+ #api = HfApi(token=token)
482
+ repo = main_balance.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[0]
483
+ name = main_balance.split('datasets/',1)[1].split('/raw',1)[0].split('/',1)[1]
484
+
485
+ f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="dataset"))
486
+ send_list =[]
487
+ for i,ea in enumerate(f_ist):
488
+ if "balance/" in ea:
489
+ try:
490
+ send_list.append(ea.split("/",1)[1].split(".",1)[0])
491
+ except Exception:
492
+ pass
493
+ with gr.Blocks() as bc:
494
+ with gr.Row(visible=True) as invalid:
495
+ pass_box = gr.Textbox()
496
+ pass_btn = gr.Button()
497
+
498
+ with gr.Box(visible=False) as valida:
499
+ gr.Markdown("""<h1><center>Blockchain Simulator<br><h3>(Transactions have no value)<br><h4>Chain will reset at 20 blocks""")
500
+ blockchain = gr.State()
501
+ with gr.Row():
502
+ with gr.Column():
503
+ with gr.Accordion(label="Load",open=False):
504
+ with gr.Row():
505
+ chain_repo=gr.Textbox(label="repo/name")
506
+ chain_n=gr.Textbox(label="Chain file")
507
+ with gr.Row():
508
+ in_chain_btn=gr.Button("Load Chain")
509
+ create_bc = gr.Button("Create New Blockchain")
510
+ #send=gr.Textbox(label="Sender")
511
+ send = gr.Dropdown(label="Sender", choices=[f for f in send_list], value = "Bank")
512
+ rec=gr.Textbox(label="Recipient")
513
+ am=gr.Textbox(label="Amount")
514
+ send_trans=gr.Button("Post Transaction")
515
+ mine_b = gr.Button("Mine Block")
516
+ check = gr.Button("Check Chain")
517
+ check_all = gr.Button("Check All")
518
+ with gr.Column():
519
+ block_text = gr.Textbox()
520
+ trans_data = gr.Dataframe()
521
+ json_out = gr.JSON()
522
+ chain_json = gr.JSON()
523
+ with gr.Accordion("Nodes", open=False):
524
+ with gr.Row():
525
+ this_space=gr.Textbox(label="This Repo/Space")
526
+ with gr.Row():
527
+ node_repo=gr.Textbox(label="Node Repo")
528
+ node_space=gr.Textbox(label="Node Space")
529
+ node_file=gr.Textbox(label="Node File")
530
+ node_add=gr.Button("Add Node")
531
+ with gr.Accordion("Tokens", open=False):
532
+ issue_btn=gr.Button()
533
+ out_box_bool=gr.Textbox()
534
+
535
+ issue_btn.click(issue_tokens,[send,rec,am],[block_text,out_box_bool])
536
+
537
+ node_add.click(add_node,[this_space,node_repo,node_space,node_file],block_text)
538
+ pass_btn.click(checkp,pass_box,[invalid,valida])
539
+ in_chain_btn.click(get_chain,[chain_repo,chain_n],[chain_json,block_text])
540
+ create_bc.click(create_chain,[chain_n],[block_text,json_out,chain_json])
541
+ check.click(valid,None,[block_text,out_box_bool])
542
+ check_all.click(sort_valid,None,block_text)
543
+
544
+ send_trans.click(bc_transactions,[send,rec,am],[trans_data,block_text,send,rec,am])
545
+ mine_b.click(mine_block,[chain_repo,chain_n],[json_out,chain_json,trans_data,block_text])
546
+
547
+
548
+ bc.launch(enable_queue=False)
chain1.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "index": 1,
4
+ "timestamp": "2023-03-19 20:02:31.090095",
5
+ "transactions": [],
6
+ "proof": 1,
7
+ "previous_hash": "0"
8
+ },
9
+ {
10
+ "index": 2,
11
+ "timestamp": "2023-03-19 20:02:35.707703",
12
+ "transactions": [],
13
+ "proof": 632238,
14
+ "previous_hash": "384ef5450d6f22e593e1edf3ee051c0fff6c55e92563ebbc149c30e37b3be7ea"
15
+ }
16
+ ]
node_file.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "index": 1,
4
+ "timestamp": "2023-03-20 03:43:39.828736",
5
+ "url": "https://huggingface.co/spaces/Omnibus/static-bin/raw/main/chain2.json"
6
+ },
7
+ {
8
+ "index": 2,
9
+ "timestamp": "2023-03-20 03:44:35.183872",
10
+ "url": "https://huggingface.co/spaces/Omnibus/static-bin/raw/main/chain1.json"
11
+ }
12
+ ]