Ccurl PoW接口用于PyOTA
项目描述
一个Python接口,用于加载Ccurl库并在本地执行工作量证明,而不依赖于节点。与PyOTA(IOTA的Python客户端库)一起使用。更多信息,请阅读文档。
动机
目前,PyOTA 不支持本地进行工作量证明(PoW)。attach_to_tangle API 命令将准备好的交易 trytes 发送到 IOTA 节点,节点通过填写 attachment_timestamp* 字段并使用 Curl P-81 计算非整数(nonce)来完成 PoW。对于打包的交易,通过它们的 transaction hash 来链接在一起。
安装
要使用此模块,请按照以下步骤操作:- 从 GitHub 克隆仓库
$ git clone https://github.com/iotaledger/ccurl.interface.py.git
$ ./init.sh
创建虚拟环境/激活您用于 PyOTA 的虚拟环境。
通过运行以下命令从源安装 Python 包:
$ pip install -e .
如何使用?
安装完成后,您可以使用此模块替换 PyOTA 中的 attach_to_tangle 核心API调用。只需从 pow 包导入 ccurl_interface 模块即可。
以下示例代码展示了如何为一个包含两个交易的打包进行 PoW。
代码示例
import iota
from pprint import pprint
from pow import ccurl_interface
# Generate seed
myseed = iota.crypto.types.Seed.random()
# Generate two addresses
addres_generator = iota.crypto.addresses.AddressGenerator(myseed)
addys = addres_generator.get_addresses(1, count=2)
# Preparing transactions
pt = iota.ProposedTransaction(address = iota.Address(addys[0]),
tag = iota.Tag(b'LOCALATTACHINTERFACE99999'),
value = 0)
pt2 = iota.ProposedTransaction(address = iota.Address(addys[1]),
tag = iota.Tag(b'LOCALATTACHINTERFACE99999'),
value = 0)
# Preparing bundle that consists of both transactions prepared in the previous example
pb = iota.ProposedBundle(transactions=[pt2,pt])
# Generate bundle hash
pb.finalize()
# Declare an api instance
api = iota.Iota("https://nodes.thetangle.org:443")
# Get tips to be approved by your bundle
gta = api.get_transactions_to_approve(depth=3)
minimum_weight_magnitude = 14 # target is mainnet
# perform PoW locally
bundle_trytes =\
ccurl_interface.attach_to_tangle(
pb.as_tryte_strings(),
gta['trunkTransaction'],
gta['branchTransaction'],
mwm
)
# Broadcast transactions on the Tangle
broadcasted = api.broadcast_and_store(bundle_trytes)
bundle_broadcasted =iota.Bundle.from_tryte_strings(broadcasted['trytes'])
pprint('Local pow broadcasted transactions are:')
pprint(bundle_broadcasted.as_json_compatible())
测试
运行 nosetests 在当前环境中进行测试。运行 tox -v -p all 在 Python 2.7、3.5、3.6 和 3.8 中进行测试。
贡献
提出问题:https://github.com/iotaledger/ccurl.interface.py/issues
项目详情
下载文件
下载适合您平台的项目文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分布
PyOTA-PoW-1.1.0.tar.gz (41.7 kB 查看散列值)
构建分布
PyOTA_PoW-1.1.0-py3-none-any.whl (35.4 kB 查看散列值)
关闭
PyOTA-PoW-1.1.0.tar.gz 的散列值
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | 3c4c4f8aaa47bf5d86f7ec2b3f17a06e8ff3e97b2932219da29818bc9aafba39 |
|
| MD5 | a6c3dedd2ca0a8880634e958d69a60ae |
|
| BLAKE2b-256 | b3b8b4678b80a96b8fba181f1305938ed2d9329cbd747f251dc6c016fb2d4777 |
关闭
PyOTA_PoW-1.1.0-py3-none-any.whl 的散列值
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | 40b5f373cf5d8a6f1470214a5109ac3159a6d6a4001464812ef7715e4f02171d |
|
| MD5 | 2d121ed9795dcc63b6759124bd372b19 |
|
| BLAKE2b-256 | 52158c5bd85239f4830ad031a1ad2890a371bb8430679f618eb84dcec0ac7b12 |