闲着无聊,合计做一个bitshares的Memo监视功能,应该挺好玩的。比如说,谁给我转了50W BTS,并附加了备注,我一下子就会收到消息。如果再加上声光报警,语音提示,滴,你收到了一笔50W BTS的转账,这该多美啊!😍
(图源 :pixabay)
规划
说干就干,初步设想是这样滴:
- 监控bitshares区块链上的转账操作
- 如果转账的接收方是我指定的ID
- 解密Memo信息
发布消息到MQTT代理MQTT客户端收到订阅消息后在液晶屏上显示MQTT客户端声光报警- 在屏幕上显示Memo
想来想去,我的MQTT服务器早就被我扔垃圾堆里了,MQTT的客户端的代码我也早忘干净了,那么还是简化一下任务吧,在屏幕一下凑合吧。
代码
有了上述思路,以及我们之前的学习,那么代码实现起来是很简单的
一个粗糙无比的代码示例如下:
from pprint import pprint
from bitshares import BitShares
from bitshares.blockchain import Blockchain
from bitshares.memo import Memo
account = 'test2018'
bts = BitShares()
chain = Blockchain()
id = bts.rpc.get_account_by_name(account)['id']
print(id)
def get_memo_text(op):
m = Memo(op['from'], op['to'])
enc = op['memo']
plaintext = m.decrypt(enc)
return plaintext
for operation in chain.stream(opNames=['transfer']):
if operation['to'] == id:
print("You got Message")
msg = get_memo_text(operation)
from_user = bts.rpc.get_account(operation['from'])['name']
print(f"Message from {from_user}: {msg}")
#pprint(operations)
测试
下面我们来测试一下上边的代码是否工作。
接收到的信息如下(后边两条文本):
看起来我的程序是正常工作地。
需要改进的地方
- 监控多个用户
- 指定节点以提升处理速度
- 在Blockchain以及Memo类实例中指定bitshares_instance
- 在Blockchain实例中使用head模式,提升响应速度
- 在消息输出中显示时间
- 在消息中输出接收到的资产类型以及数量
如果再加上转账(发消息)功能,这就是一个聊天软件嘛。
问题
(图源 :pixabay)
尽管这个听起来很好玩,但是我不打算再去玩了,也不打算去完善了。为啥?上边截图中显示的转账费用竟然高达0.01759 BTS,按现在BTS 3.51人民币的价格计算,一条消息竟然需要至少6分钱!这太奢侈了吧,像我这种话痨,每天聊个几十万条不费劲,姑且算10W条吧,那就是6000多块钱啊。
如果这软件普及了,估计能让大家更深刻地理解沉默是金的道理吧。
Hi,
Very good post about bitcoin and bithare and lot of people sure get benegits from this work,
I like it kwep it up.
With Thanx.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这BTS的转帐费价格不菲,的确是尝试一次就够了~
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
觉得bts转账费不菲的怕是不是币圈的人吧。。。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice photography..good luck succes always..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
支付宝也有语音提示了哈哈哈钱哗哗入账!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这个入账语音提示,在人多的地方听到,有点略尴尬的.....
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
确实尴尬……所以我没开启!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
good work done dear
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I commend you very highly for your indepth analysis on both Bitcoin and Bithare. Many have benefitted from your good works. I upvote you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
语音提示,滴,你收到了一笔0.001 BTS的转账
這也美嗎?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
人艰不拆
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
瞄了一眼钱包 流口水了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
沉默是金
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Steem 不就是现成为聊天而设计的吗
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
steem不要手续费
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哥真是行动力强,说干就干
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这个能实时检测吗?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
使用head模式,并选取延迟比较小的节点,可以做到6秒以内收到
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
那还不错,改天试试,谢谢!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
噗啊哈哈哈哈哈,沉默是金真的绝了。😂
想不通为啥你们这些大佬总有想在区块链搞事情的想法。😂
呢个,你能给我聊半小时吗?我喜欢听你说话。😂
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我,秦始皇,打钱
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
😂你赢了。我给你打点狗狗币?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
话痨怎么做到沉默是金,停一会儿不说话浑身难受呀,哈哈
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit