1 Star 0 Fork 2

Aaron_ou/DataChain

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
block.py 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
Aaron_ou 提交于 2018-02-06 17:36 . finish beta vision1
# -*- coding:UTF-8 -*-
"""
基础的 block类
block = {
data:data,
record:{
puser:puser
user:user
}
pHash:pHash
nouce:nouce
timetap:timetap
}
"""
import hashlib
class block():
def __init__(self,block):
self.data = block['data']
self.record = block['record']
self.pHash = block['pHash']
self.nouce = block['nouce']
self.index = block['index']
self.timetap = block['timetap']
def chain_check(self):
if(self.data != b''):
hash_check = hashlib.sha256()
hash_check.update((str(self.data)+str(self.record)+str(self.pHash)+str(self.timetap)+str(self.nouce)).encode("utf-8"))
re = hash_check.hexdigest()
if(re[-3:] == '000'):
return 0
else:
return 1
else:
return 0
def get_set(self):
block = {
'data':self.data,
'record':self.record,
'pHash':self.pHash,
'nouce':self.nouce,
'index':self.index,
'timetap':self.timetap
}
return block
def get_hash(self):
hash_check = hashlib.sha256()
hash_check.update((str(self.data) + str(self.record) + str(self.pHash) + str(self.timetap) + str(self.nouce)).encode("utf-8"))
re = hash_check.hexdigest()
return re
def get_data(self):
hash_check = hashlib.sha256()
hash_check.update((str(self.data) + str(self.record) + str(self.timetap)).encode("utf-8"))
re = hash_check.hexdigest()
return re
def change_record(self,record):
if(record['puser'] == self.record['user']):
self.record['puser'] = self.record['user']
self.record['user'] = record['user']
return 1
else:
return 0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Aaron_ou/DataChain.git
git@gitee.com:Aaron_ou/DataChain.git
Aaron_ou
DataChain
DataChain
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385