一个简单的区块链包。

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程序在minecraft中移动minecraft角色的相机   java输出文本文件中的变量   java LazyLoadingException在我尝试从多通关系获取对象时出现   java json rest API的错误:ClassCastException:org。json。无法将JSONObject强制转换为组织。json。杰索纳雷   java BigInteger。C中的intValue()等价物#   java大写所有字符,但不包括带引号字符串中的字符   java获取特殊字符   javascript为什么Selenium中的所有getX()调用都需要这么长时间?   rabbitmq rabbitmq java客户端并行消费   如何使用selenium Java在popover窗口中提取文本   对象在java中构造一类对象   java Room数据库未实现   json JSONObject可以使用java保存大的格式化双值吗?   有时限的旅行推销员   java HttpsURLConnection openConnection查询   java无法使用Spring@Entity注释创建MySQL表   lambda Java 8仅映射到值类型集合   java提供OSGi服务而不实现接口   java单个对象重写对象数组,不确定原因