一个简单的区块链包。

tinyblock的Python项目详细描述


https://travis-ci.org/zshvvhm/tinyblock.svg?branch=masterhttps://coveralls.io/repos/github/zshvvhm/tinyblock/badge.svghttps://img.shields.io/pypi/v/tinyblock.svghttps://img.shields.io/pypi/l/tinyblock.svghttps://img.shields.io/pypi/pyversions/tinyblock.svg

安装

使用pip

安装和更新
$ pip install tinyblock

dict({'previous_hash'(str):'...','timestamp'(int):'...','data'(any):'...','nonce'(int):'...','next_hash'(str):'...'})

用法

  • 定义一个简单的区块链:

    fromtinyblockimporttinyblock#The initial variable should be a list of blocks. If not set it, the default chain would be an empty list.my_blockchain=tinyblock()
  • 向链中添加块:

    #The parameter is the data of this blockmy_blockchain.add('This is a block.')
  • 使用语句查找块:

    #Find the blocks with features below. The return elements will content the index in origin chain list.#Completely match: previous_hash, nonce, next_hash.#Partly match: data. (Currently support str, int, float, list, dict, bool and tuple)#Range match: timestamp.(Could be an int, list or tuple)my_blockchain.find(previous_hash='',timestamp='',data='',nonce='',next_hash='')
  • 弹出链的最后一个区块:

    my_blockchain.pop()
  • 检查区块链是否正确:

    my_blockchain.chainCheck(print_option=True)
  • 修复区块链(带开始和停止索引):

    my_blockchain.chainFix(start=0,stop=4)
  • 获取阻止列表:

    my_blockchain.getChain()
  • 自定义挖掘新块的规则:

    #The default rule is hash start with '0000'.#To change the rule, you can override the mineRule function.defnewRule(hash):ifhash[0:5]=='0'*5:returnTruereturnFalsemy_blockchain.mineRule=newRule

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java什么数据库最类似于Map,每个用户/id存储无限多个“键”和“值”?   java仅使用super pom进行测试   内存不足如何解析java。OutOfMemoryError:Java堆空间在增加堆大小的情况下将意味着延迟OutOfMemoryError   来自另一个类的mysql和java jdbc调用[运行时应用程序]   java通过下拉菜单更改搜索框搜索的内容   JAVAlang.ClassNotFoundException:sun。jdbc。odbc。JdbcOdbcDriver   java Selenium点击链接   JavaSpringHibernate:从唯一值列表中获取对象列表   java Bing广告与桌面身份验证问题   java如何在没有任何外部SDK的情况下从安卓打印到收据打印机?   未调用java菜单片段类   java在IDEA和PyCharm中同时为同一个项目工作   java我们如何为同一个异常提供不同的海关信息   jakarta ee中是否预定义了“请求”和“响应”变量或值?   java更好地解决“之前和之后”难题?   尝试将数据从Excel添加到Java   发送电子邮件的Java代码只适用于一个电子邮件id?   java如何从资产解析XML?