python-bitshares指定node节点的坑

in bitshares •  7 years ago 

最近学习了@oflyhigh写的python-bitshares系列相关文章,试着自己写了些代码,发现学习过程中有些问题,记录下来。
python-bitshares是@xeroc大神维护的库 ,uptick就是用的这个库。

https://github.com/bitshares/python-bitshares

https://github.com/xeroc/python-bitshares

安装:

pip install bitshares

升级:

pip install --user --upgrade

然后我们就可以开发自己的bitshares应用程序了。

from bitshares import BitShares
from pprint import pprint

node = "wss://ws.gdex.top"
bts = BitShares(node)
pprint(bts.info())

ok,看起来貌似一切正常,但是,当我们newWallet,addPrivateKey,并且set_default_account(account)操作时,诡异的事情发生了:

发现我们设置的node没起作用,竟然连接到

wss://node.bitshares.eu

经过代码跟踪,发现这是storage.py这个单元中的class Configuration(DataDir)这个类中设定的默认认值:

找到问题就容易解决了,添加如下代码,搞定:

Configuration.config_defaults["node"] = node

那么bug成因是什么呢?看代码:

因为set_default_account函数创建了一个Account实例,但是没有传bitshares_instance参数,而Account类的父类BlockchainObject在bitshares_instance=None时又调用了instance.py单元的shared_bitshares_instance函数:

再看shared_bitshares_instance函数干了什么:

创建了一个新的BitShares实例,并传入了空的配置,然后再回到bitshares.py单元:

一切都已明了,在BitShares对象创建时,如果node传空参,就去storage.py中读取默认值config_defaults["node"]。
搞完,收工。

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Get 到了

Congratulations @siow! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

多谢,解决了我的问题,但Configuration.config_defaults["node"] = node 这句添加在哪个文件中啊?我是直接把‘wss://node.bitshares.eu’替换掉了。

Congratulations @siow! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!