请选择 进入手机版 | 继续访问电脑版

4Ameta

 找回密码
 立即注册
搜索
查看: 83|回复: 0

write a blockchain in Python【4】Methods to realize mining

[复制链接]

26

主题

26

帖子

119

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
119
发表于 2022-9-10 15:03:10 | 显示全部楼层 |阅读模式
write a blockchain in Python【4】Methods to realize mining





  1. def mine_block(self, difficulty):
  2. '''
  3. mine
  4. :param difficulty: difficulty
  5. :return:
  6. '''
  7. time_start = time.clock()
  8. # The value of the first few (difficulty) bits of the hash value is required to be 0
  9. while self.hash[0: difficulty] != ''.join(['0'] * difficulty):
  10. # Meet the requirements
  11. self.nonce += 1
  12. self.hash = self.calculate_hash()
  13. print("Dig to block:%s, time consuming: %f-s" % (self.hash, time.clock() - time_start))


复制代码

next_Lesson>>>



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|4ameta

GMT+8, 2022-10-4 10:34 , Processed in 0.033783 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表