oflyhigh avatar

HIVE上使用steem-python的一些尝试 (下)

oflyhigh

Published: 23 Mar 2020 › Updated: 23 Mar 2020HIVE上使用steem-python的一些尝试 (下)

HIVE上使用steem-python的一些尝试 (下)

上一篇文章写到尝试在机器上安装hivepy,可惜尽管装上了,还是不好用,当然很可能是我没装好或者没会使用。于是决定直接从steem-python入手,看看到底差些什么。

image.png
(图源 :pixabay)

安装方面,虽然pip install steem指令可能好用,但是我记得pip安装的是furion@furion维护的版本,可能依旧好用但是应该有些过时,所以我觉得还是用源码方式安装。

源码安装参考steem-python的github上的说明:

git clone https://github.com/steemit/steem-python.git
cd steem-python
python3 setup.py install # python setup.py install for 2.7

因为之前已经解决了python3-dev、libssl-dev等问题,所以安装非常顺利,然后来执行一下试试看:

steempy info

显示效果如下:

image.png

虽然好用,但是很明显得到的信息是STEEM链上的。

steempy config看一下节点信息,内容为空,应该用的是代码中默认节点:

image.png

设置一下节点,用HIVE的节点:

steempy set nodes https://api.hive.blog

设置完成后用steempy config再看一下,结果出现一堆错误:

image.png

当然了,信息量最大的就是这句了:

AssertionError: The chain you are connecting to is not supported

搜索一下代码,发现这句错误出现在steem-python/steem/steemd.py中:

image.png

而其中的known_chains是使用如下语句导入的:

from steembase.chains import known_chains

那就来看一下steem-python/steembase/chains.py 这个文件喽:

image.png

可见这里边定义了三条链,STEEM、GOLOS、TESTNET,所以理论上我再把HIVE加进去就可以了,据说chainid啥的都一样,那么就是把STEEM/SBD改成HIVE/HBD就可以了。

不过保险起见,还是看看pharesim@pharesim 大神咋改的这个文件,果然是加入如下内容:

    "HIVE": {
        "chain_id": "0" * int(256 / 4),
        "prefix": "STM",
        "hive_symbol": "HIVE",
        "hbd_symbol": "HBD",
        "vests_symbol": "VESTS",
    },

那么我也在这个文件中加入上述代码好了,加入完成后再重新执行一下安装。

python3 setup.py install

再用steempy config查看节点信息,可见已经设置成功了

image.png

再用steempy info看一下基本信息,可见已经切换到HIVE链上了:

image.png

steempy balance oflyhigh看一下我的资产情况,发现显示的还是STEEM/SBD,不过就是个表头啦,无伤大雅:

image.png

弄个钱包,添加个私钥试试:

steempy addkey

首次弄钱包需要设置密码:

image.png

现在已经都OK了,试着给刘美女 deanliu@deanliu 点一个小赞试试:
steempy upvote --account oflyhigh --weight 25 @deanliu/q7l3o7

去HIVE区块链浏览器里看一下:https://hiveblocks.com/@oflyhigh

image.png

哇咔咔,终于搞定了,又可以愉快地玩耍了。至于叫steempy还是叫hivepy,有那么重要吗?而且现在这一份代码可以支持两条链,这样它不香吗?

相关链接

Leave HIVE上使用steem-python的一些尝试 (下) to:

Written by

Programmer, Maker, Freelancer, Witness. Make friends, Make money, Make life better!

Read more #hive posts


Best Posts From oflyhigh

We have not curated any of oflyhigh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From oflyhigh