跳转到主要内容

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

  • 请确保您的系统上已安装 cmake。这是 ccurl 库的构建依赖项。

  • 根据 构建说明 构建 ccurl,并将 .so 库放入 src 文件夹,或者运行主文件夹中的 init 脚本以构建和初始化

$ ./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 查看散列值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面