class Block(object):
def __init__(self,dictionary):
"Мы ищем индекс, метку времени, данные, prev_hash, nonce"
for key, value in dictionary.items():
if key in BLOCK_VAR_CONVERSIONS:
setattr(self, key, BLOCK_VAR_CONVERSIONS[key] (value))
else:
setattr(self, key ,value)
if not hasattr(self, 'hash'): #Создаем первый блок в будущем его удалим
self.hash = self.update_self_hash()
if not hasattr(self, 'nonce'):
self.nonce = 'None'
if not hasattr(self, 'index'):
self.index = 'index'
def header_string(self):
return str(self.index) + self.prev_hash + self.data + str(self.timestamp) + str(self.nonce)
def generate_header(index, prev_hash,data ,timestamp, nonce):
return str(index) + prev_hash + data + str(timestamp) + str(nonce)
def update_self_hash(self):
sha = hashlib.sha256()
sha.update(self.header_string())
new_hash = sha.hexdigest()
self.hash = new_hash
return new_hash
Вывод ошибки:"
File "C:\Users\tokan\Desktop\Blockchain\jbc\block.py", line 27, in __init__
self.hash = self.update_self_hash()
File "C:\Users\tokan\Desktop\Blockchain\jbc\block.py", line 41, in update_self_hash
sha.update(self.header_string())
File "C:\Users\tokan\Desktop\Blockchain\jbc\block.py", line 34, in header_string
return str(self.index) + self.prev_hash + self.data + str(self.timestamp) + str(self.nonce)
AttributeError: 'Block' object has no attribute 'index'
"