-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbloco.py
More file actions
24 lines (19 loc) · 807 Bytes
/
Copy pathbloco.py
File metadata and controls
24 lines (19 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import datetime
from hashlib import sha256
# Dados alterados para transações
class Bloco:
def __init__(self, transacoes, hash_anterior):
self.carimbo_de_hora = datetime.datetime.now()
self.transacoes = transacoes
self.hash_anterior = hash_anterior
self.nonce = 0
self.hash = self.gerar_hash()
def gerar_hash(self):
bloco_header = str(self.carimbo_de_hora) + str(self.transacoes) + str(self.hash_anterior) + str(self.nonce)
bloco_hash = sha256(bloco_header.encode())
return bloco_hash.hexdigest()
def print_conteudo(self):
print("Carimbo de hora:", self.carimbo_de_hora)
print("Transacoes:", self.transacoes)
print("Hash atual:", self.gerar_hash())
print("Hash anterior:", self.hash_anterior)