跳转到主要内容

Ethereum Name Service 拍卖,Python实现

项目描述

Join the chat at https://gitter.im/ens-py/Lobby

使用此Python库访问Ethereum Name Service拍卖。注意:这是一个正在进行中的项目

使用此库并不是跳过学习如何使用ENS的途径。如果你正在注册一个名称,一点小的误解可能会导致你损失所有的押金。请先了解ENS。您的资金您负责。

测试版警告

这是一个供开发者预览的版本,也是对贡献的邀请。在移除此警告之前,请不要在生产环境中使用此版本,尤其是当涉及资金风险时。资金风险示例包括:向解析地址发送ether/代币和参与名称拍卖。

如果您提供类型为bytes的域名,它将被假定是UTF-8编码的,如Ethereum合约中所示。

安装

pip install ensauction

有任何问题?请参阅安装详情

用法

所有示例均在Python 3中

.eth结尾的名称拍卖

获取拍卖状态

以域名为‘payment.eth’的示例

from ensauction.auto import ethnames
from ensauction.registrar import Status

status = ethnames.status('payment.eth')
如果您在这里遇到错误,例如:> UnhandledRequest: No providers responded to the RPC request
方法:eth_getBlockByNumber
参数:[‘latest’,False]

如果您没有连接到您的节点,请参阅以下内容了解如何手动连接到您的节点:如何手动连接到您的节点

否则,请继续...

# if you forget to strip out .eth, ens.py will do it for you
assert ethnames.status('payment') == status

# these are the possible statuses

assert status in (
  Status.Open,
  Status.Auctioning,
  Status.Owned,
  Status.Forbidden,
  Status.Revealing,
  Status.NotYetAvailable
  )


# if you get the integer status from another source, you can compare it directly

assert Status.Owned == 2

开始拍卖

# start one auction (which tips people off that you're interested)

ethnames.start('you_saw_him_repressin_me_didnt_ya')


# start many auctions (which provides a bit of cover)

ethnames.start(['exchange', 'tickets', 'payment', 'trading', 'registry'])

竞标拍卖

用5211 ETH竞标“trading.eth”,并设置秘密“我保证我不会忘记我的秘密”

from web3.auto import w3

ethnames.bid(
      'trading',
      Web3.toWei('5211', 'ether'),
      "I promise I will not forget my secret",
      transact={'from': w3.eth.accounts[0]}
      )

(如果您想“隐藏”您的竞标,请在交易字典中设置更高的值)

揭示您的竞标

您必须始终揭示您的竞标,无论您是否获胜。否则,您将失去全部押金。

以下是在“registry.eth”上揭示您的竞标(0.01 ETH)和秘密“说实话:失去你的秘密意味着失去以太币”的示例

ethnames.reveal(
      'registry',
      Web3.toWei('0.01', 'ether'),
      "For real, though: losing your secret means losing ether",
      transact={'from': w3.eth.accounts[0]}
      )

声明您赢得的名称

即“最终确定”拍卖,使您成为 ENS 的所有者。

ethnames.finalize('gambling')

获取有关拍卖的详细信息

找出拍卖契据的所有者 - 请参阅关于拥有名称与契据之间区别的文档

deed = ethnames.deed('ethfinex')

assert deed.owner() == '0x9A02ed4Ca9AD55b75fF9A05DeBb36D5eb382E184'

拍卖何时完成?(一个时区感知的日期时间对象)

close_datetime = ethnames.close_at('ethfinex')

assert str(close_datetime) == '2017-06-05 08:10:03+00:00'

押金总额是多少?

from decimal import Decimal
from web3 import Web3

deposit = ethnames.deposit('ethfinex')

assert Web3.fromWei(deposit, 'ether') == Decimal('0.01')

最高出价是多少?

top_bid = ethnames.top_bid('ethfinex')

assert Web3.fromWei(top_bid, 'ether') == Decimal('201709.02')

设置细节

如果Python 2是您的默认环境,或者您不确定

在您的shell中

if pip --version | grep "python 2"; then
  python3 -m venv ~/.py3venv
  source ~/.py3venv/bin/activate
fi

现在,使用Python 3

在您的shell中: pip install ensauction

ensauction.py需要一个最新的以太坊区块链,最好是本地的。如果您的设置不起作用,请尝试运行 geth --fast 直至完全同步。我强烈建议使用默认的IPC通信方法,以提高速度和安全性。

“找不到匹配的发行版”

如果您看到如下内容

Collecting ensauction
  Could not find a version that satisfies the requirement ensauction (from versions: )
No matching distribution found for ensauction

这很可能是您在使用Python 2。请重试第一个设置部分,以确保您在使用Python 3

使用自定义web3提供程序

在Python中

from ensauction.registrar import Registrar
from ens import ENS
from web3 import IPCProvider

ns = ENS(IPCProvider('/your/custom/ipc/path'))
reg = Registrar(ns)

开发者设置

git clone git@github.com:carver/ensauction.py.git
cd ensauction.py/

python3 -m venv venv
. venv/bin/activate

pip install -e .
pip install -r requirements-dev.txt

测试设置

重新运行flake以检测文件更改

$ when-changed -s -1 -r ensauction/ tests/ -c "clear; echo; echo \"running flake - $(date)\"; warn()
{
notify-send -t 5000 'Flake8 failure ⚠⚠⚠⚠⚠' 'flake8 on ensauction.py failed'
}
if ! git diff | flake8 --diff | grep "\.py"; then if ! flake8 ensauction/ tests/; then warn; fi else warn; fi; echo done"

为什么ensauction.py需要Python 3?

简短版本

结果是,str和bytes之间的区别很重要。如果您想为未来(以太坊)编写代码,不要使用过去的语言。

长版本

与EVM交互需要明确您使用的位。例如,sha3散列期望接收一系列字节进行处理。计算字符串的sha3散列(或应该是)类型错误;哈希算法不知道如何处理一系列字符,即Unicode代码点。作为调用者,您需要知道您正在计算什么类型的哈希:1.一系列字节:b'[ c$o!\x91\xf1\x8f&u\xce\xdb\x8b(\x10.\x95tX' 2.由十六进制格式的字符串表示的字节:'0x5b2063246f2191f18f2675cedb8b28102e957458' 3.通过使用utf-8编码字符串生成的字节:Oops,从#1中读取的字节不能使用utf-8进行编码! 4.通过使用utf-16编码字符串生成的字节:'⁛④Ⅿ\uf191⚏칵诛ဨ键塴'

Python 3不允许您忽视许多这些细节。这是好事,因为处理EVM的精度至关重要。

如果您对此有抵触情绪 - 我理解,我也曾经历过。这对大多数人来说并不直观。但如果您要在以太坊之上进行开发,学习有关编码的知识绝对值得。您的ETH取决于它!

发布设置

对于类似Debian的系统

apt install pandoc

发布新版本

make release bump=$$VERSION_PART_TO_BUMP$$

如何使用bumpversion

本仓库的版本格式为稳定版 {major}.{minor}.{patch},和不稳定版 {major}.{minor}.{patch}-{stage}.{devnum}stage 可以为 alpha 或 beta)。

要发布下一个版本,指定要升级的部分,例如 make release bump=minormake release bump=devnum

如果您处于测试版,make release bump=stage 将切换到稳定版。

当当前版本为稳定版时,要发布一个不稳定版本,请明确指定新版本,例如 make release bump="--new-version 4.0.0-alpha.1 devnum"

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

ensauction-0.1.0b0.tar.gz (11.6 kB 查看哈希值)

上传时间

构建分布

ensauction-0.1.0b0-py3-none-any.whl (11.0 kB 查看哈希值)

上传时间 Python 3

支持者: