<p dir="auto"><br /><span>最近学习了<a href="/@oflyhigh">@oflyhigh写的python-bitshares系列相关文章,试着自己写了些代码,发现学习过程中有些问题,记录下来。<span>
python-bitshares是<a href="/@xeroc">@xeroc大神维护的库 ,uptick就是用的这个库。
<blockquote>
<p dir="auto"><br />
或<br /><span><a href="https://github.com/bitshares/python-bitshares" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/bitshares/python-bitshares<span>
<a href="https://github.com/xeroc/python-bitshares" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/xeroc/python-bitshares
<h4>安装:
<pre><code>pip install bitshares
<h4>升级:
<pre><code>pip install --user --upgrade
<p dir="auto">然后我们就可以开发自己的bitshares应用程序了。
<pre><code>from bitshares import BitShares
from pprint import pprint
node = "wss://ws.gdex.top"
bts = BitShares(node)
pprint(bts.info())
<p dir="auto">ok,看起来貌似一切正常,但是,当我们newWallet,addPrivateKey,并且set_default_account(account)操作时,诡异的事情发生了:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmY8is5pTiZQ5PXDpu5Rg2g5fb223JS9RWmnDc8pZorqWa/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmY8is5pTiZQ5PXDpu5Rg2g5fb223JS9RWmnDc8pZorqWa/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmY8is5pTiZQ5PXDpu5Rg2g5fb223JS9RWmnDc8pZorqWa/%E5%9B%BE%E7%89%87.png 2x" /><br />
发现我们设置的node没起作用,竟然连接到
<blockquote>
<p dir="auto">wss://node.bitshares.eu
<p dir="auto">经过代码跟踪,发现这是storage.py这个单元中的class Configuration(DataDir)这个类中设定的默认认值:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmeQaPAW3bmb4eBn2n299hruue15sgZ4e8Z9vs8mtBRfMk/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmeQaPAW3bmb4eBn2n299hruue15sgZ4e8Z9vs8mtBRfMk/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmeQaPAW3bmb4eBn2n299hruue15sgZ4e8Z9vs8mtBRfMk/%E5%9B%BE%E7%89%87.png 2x" /><br />
找到问题就容易解决了,添加如下代码,搞定:
<pre><code>Configuration.config_defaults["node"] = node
<p dir="auto">那么bug成因是什么呢?看代码:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmcyQv5Jy2ZUx1BY9Sq7g4MFLtNiippfiBmcTJEEKF58Px/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmcyQv5Jy2ZUx1BY9Sq7g4MFLtNiippfiBmcTJEEKF58Px/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmcyQv5Jy2ZUx1BY9Sq7g4MFLtNiippfiBmcTJEEKF58Px/%E5%9B%BE%E7%89%87.png 2x" /><br />
因为set_default_account函数创建了一个Account实例,但是没有传bitshares_instance参数,而Account类的父类BlockchainObject在bitshares_instance=None时又调用了instance.py单元的shared_bitshares_instance函数:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmPDDDnF1AuLkgVJ6Y521EjKanATwPTV2GnzcStU34P5cj/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmPDDDnF1AuLkgVJ6Y521EjKanATwPTV2GnzcStU34P5cj/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmPDDDnF1AuLkgVJ6Y521EjKanATwPTV2GnzcStU34P5cj/%E5%9B%BE%E7%89%87.png 2x" /><br />
再看shared_bitshares_instance函数干了什么:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQmed5VLmdW5b3ytvSyzBz9gw3r46hf29zoCC713Ne4oEYu/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQmed5VLmdW5b3ytvSyzBz9gw3r46hf29zoCC713Ne4oEYu/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQmed5VLmdW5b3ytvSyzBz9gw3r46hf29zoCC713Ne4oEYu/%E5%9B%BE%E7%89%87.png 2x" /><br />
创建了一个新的BitShares实例,并传入了空的配置,然后再回到bitshares.py单元:<br />
<img src="https://images.hive.blog/768x0/https://steemitimages.com/DQma8GAS2FaVc73BSturkLGnHcPVeAxua7DpU6AZcZ2hEDv/%E5%9B%BE%E7%89%87.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/DQma8GAS2FaVc73BSturkLGnHcPVeAxua7DpU6AZcZ2hEDv/%E5%9B%BE%E7%89%87.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/DQma8GAS2FaVc73BSturkLGnHcPVeAxua7DpU6AZcZ2hEDv/%E5%9B%BE%E7%89%87.png 2x" /><br />
一切都已明了,在BitShares对象创建时,如果node传空参,就去storage.py中读取默认值config_defaults["node"]。<br />
搞完,收工。
Get 到了
Congratulations @siow! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
<p dir="auto"><a href="http://steemitboard.com/@siow" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link"><img src="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstpost.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstpost.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstpost.png 2x" /> You published your First Post<br /> <a href="http://steemitboard.com/@siow" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link"><img src="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstvoted.png" srcset="https://images.hive.blog/768x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstvoted.png 1x, https://images.hive.blog/1536x0/https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstvoted.png 2x" /> You got a First Vote <p dir="auto">Click on any badge to view your own Board of Honor on SteemitBoard.<br /> For more information about SteemitBoard, click <a href="https://steemit.com/@steemitboard" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here <p dir="auto">If you no longer want to receive notifications, reply to this comment with the word <code>STOP <blockquote> <p dir="auto">Upvote this notification to help all Steemit users. Learn why <a href="https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here!多谢,解决了我的问题,但Configuration.config_defaults["node"] = node 这句添加在哪个文件中啊?我是直接把‘wss://node.bitshares.eu’替换掉了。
Congratulations @siow! You received a personal award!
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!