Spaces:
Runtime error
Runtime error
Update chatchain.py
Browse files- chatchain.py +18 -8
chatchain.py
CHANGED
@@ -5,6 +5,7 @@ import hashlib
|
|
5 |
import datetime
|
6 |
from huggingface_hub import (upload_file,HfApi)
|
7 |
|
|
|
8 |
token_self = os.environ['HF_TOKEN']
|
9 |
api = HfApi(token=token_self)
|
10 |
chain_d="chain1.json"
|
@@ -235,6 +236,7 @@ class MyChainSend:
|
|
235 |
'recipient': recipient,
|
236 |
'message': message,
|
237 |
}
|
|
|
238 |
self.pending_transactions.append(transaction)
|
239 |
def proof_of_work(self, previous_proof):
|
240 |
new_proof = 1
|
@@ -362,14 +364,14 @@ class MyChainSend:
|
|
362 |
|
363 |
class MyChainRec:
|
364 |
|
365 |
-
def __init__(self,chain_load, load=None,create=None):
|
366 |
global main_chain_rec
|
367 |
main_chain_rec=chain_load
|
368 |
|
369 |
self.pending_transactions = []
|
370 |
if load == None or load=="":
|
371 |
self.chain = []
|
372 |
-
self.create_block(proof=1, previous_hash='0',chain_n=create)
|
373 |
if load != None and load !="":
|
374 |
#r = requests.get(load)
|
375 |
lod = json.loads(load)
|
@@ -378,7 +380,7 @@ class MyChainRec:
|
|
378 |
self.chain = []
|
379 |
self.pending_transactions = []
|
380 |
self.create_block(proof=1, previous_hash='0',chain_n=create)
|
381 |
-
def create_block(self, proof, previous_hash,chain_r=None,chain_n=None):
|
382 |
if chain_r=="" or chain_r==None:
|
383 |
chain_r=f"{main_chain_rec.split('datasets/',1)[1].split('/raw',1)[0]}"
|
384 |
if chain_n !="" and chain_n !=None:
|
@@ -389,11 +391,19 @@ class MyChainRec:
|
|
389 |
|
390 |
#prev_block = len(blockchain.chain)-1
|
391 |
#previous_block = blockchain.chain[prev_block]
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
if self.block_valid(block) == True:
|
398 |
self.pending_transactions = []
|
399 |
self.chain.append(block)
|
|
|
5 |
import datetime
|
6 |
from huggingface_hub import (upload_file,HfApi)
|
7 |
|
8 |
+
import crypt
|
9 |
token_self = os.environ['HF_TOKEN']
|
10 |
api = HfApi(token=token_self)
|
11 |
chain_d="chain1.json"
|
|
|
236 |
'recipient': recipient,
|
237 |
'message': message,
|
238 |
}
|
239 |
+
transaction = crypt.encrypt_text(transaction)
|
240 |
self.pending_transactions.append(transaction)
|
241 |
def proof_of_work(self, previous_proof):
|
242 |
new_proof = 1
|
|
|
364 |
|
365 |
class MyChainRec:
|
366 |
|
367 |
+
def __init__(self,chain_load, load=None,create=None,pub_key=None):
|
368 |
global main_chain_rec
|
369 |
main_chain_rec=chain_load
|
370 |
|
371 |
self.pending_transactions = []
|
372 |
if load == None or load=="":
|
373 |
self.chain = []
|
374 |
+
self.create_block(proof=1, previous_hash='0',chain_n=create,pub_key=pub_key)
|
375 |
if load != None and load !="":
|
376 |
#r = requests.get(load)
|
377 |
lod = json.loads(load)
|
|
|
380 |
self.chain = []
|
381 |
self.pending_transactions = []
|
382 |
self.create_block(proof=1, previous_hash='0',chain_n=create)
|
383 |
+
def create_block(self, proof, previous_hash,chain_r=None,chain_n=None,pub_key=None):
|
384 |
if chain_r=="" or chain_r==None:
|
385 |
chain_r=f"{main_chain_rec.split('datasets/',1)[1].split('/raw',1)[0]}"
|
386 |
if chain_n !="" and chain_n !=None:
|
|
|
391 |
|
392 |
#prev_block = len(blockchain.chain)-1
|
393 |
#previous_block = blockchain.chain[prev_block]
|
394 |
+
if pub_key !=None and pub_key!="":
|
395 |
+
block = {'index': len(self.chain) + 1,
|
396 |
+
'timestamp': str(datetime.datetime.now()),
|
397 |
+
'message': pub_key,
|
398 |
+
'proof': proof,
|
399 |
+
'previous_hash': previous_hash}
|
400 |
+
else:
|
401 |
+
block = {'index': len(self.chain) + 1,
|
402 |
+
'timestamp': str(datetime.datetime.now()),
|
403 |
+
'message': self.pending_transactions,
|
404 |
+
'proof': proof,
|
405 |
+
'previous_hash': previous_hash}
|
406 |
+
|
407 |
if self.block_valid(block) == True:
|
408 |
self.pending_transactions = []
|
409 |
self.chain.append(block)
|