在之前的几篇文章中,我们简单介绍了如何安装python-bitshares 、python-bitshares的钱包相关操作、BitShares类以及Account类、Market类、Dex类、Block类、Blockchain类。
详情可以参考文末的参考链接。
(图源 :pixabay)
这节我们来继续学习python-bitshares 。
Memo类
创建实例
我们可以使用以下代码创建Memo类实例
from bitshares.memo import Memo
m = Memo("from_account", "to_account")
其中:
from_account
: 发送Memo的账户to_account
: 接收Memo的账户
因为Account类实例可以由帐户名创建,也可以由账户ID创建,所以我们可以传入类似test2018
或者1.2.534782
的形式。
加密Memo
加密Memo即将明文信息转换成为密文,我们可以使用encrypt方法加密Memo
from pprint import pprint
encrypted_msg = m.encrypt("foobar")
pprint(encrypted_msg)
加密Memo需要首先导入from_account
的active key或者memo key,否则会出如下错误提示:
raise MissingKeyError("Memo key for %s missing!" % self.from_account["name"])
bitshares.exceptions.MissingKeyError: Memo key for test2018 missing!
导入私钥后重新执行上述代码:
解密Memo
加密Memo即将密文信息转换成为明文,我们可以使用decrypt方法解密Memo
plaintext_msg = m.decrypt(enc)
print(plaintext_msg)
解密Memo需要首先导入to_account的active key或者memo key,否则会出如下错误提示:
raise MissingKeyError("Memo key for %s missing!" % self.to_account["name"])
bitshares.exceptions.MissingKeyError: Memo key for oflyhigh-bts missing!
导入私钥后重新执行上述代码:
解密出来的内容和我们加密的内容是一致的。
测试
为了验证我们上述学习的内容,我使用测试账户转账并附加Memo
在活动记录中我们看到的操作信息以及明文Memo为:
在区块链浏览器上我们查看到的原始信息为:
from bitshares.memo import Memo
m = Memo("1.2.534782", "1.2.170436")
enc = {
"from": "BTS6Eq6kGgYRuujDpFtYduCAjdgMfvkHZ3f8SbHVmsjSC9HgCnxFt",
"message": "33b980c72e22f942454a8ae6b6740a54",
"nonce": "387853483215441",
"to": "BTS8HbXtZPbLACch1pvfrZEPH2xbt74VMPMD4ZSZwYeT96jwkpHFo"}
plaintext_msg = m.decrypt(enc)
print(plaintext_msg)
运行结果如下:
和我们输入的信息一般无二哦😀
总结
Memo类提供了bitshares区块链Memo信息加密和解密的方法。本文通过实例介绍了如何使用Memo类加密消息以及解密Memo。
在文末,本文以一个实际的例子来验证Memo类的功能。
文中信息仅供参考,使用文中代码造成损失概不负责!
参考信息
- https://github.com/xeroc/python-bitshares
- python-bitshares 边学边记 (一) : 简介与安装
- python-bitshares 边学边记 (二) : 钱包操作
- python-bitshares 边学边记 (三) / BitShares类
- python-bitshares 边学边记 (四) / Account类
- python-bitshares 边学边记 (五) / Market类
- python-bitshares 边学边记 (六) / Dex类
- python-bitshares 边学边记 (七) / Block类
- python-bitshares 边学边记 (八) / Blockchain类
hard working post,, thanks
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
It would be so helpful if you also provided English translation. :(
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hello, I set up my blog on steemit. I like to take a selfie, travel, contact me, enter my blog and see what's new https://steemit.com/life/@beyonndkiller/asia-s-latest-selfie-sexy-goddess-daily-life4
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Winderful post! Thanks for the information you shared concerning python bitshares, your message is very interest. Thanks. I follow and upvote you.
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
O老师你好
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow man just amazing I like it post 👏👍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good post about bitshares
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Top 5 Cloud mining
https://steemit.com/bitcoin/@wbayderda/top-5-cloud-mining
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great post. If you provide English translation, it will be very helpful. It is not like saying. Thank you so much for posting this way.
Thanks for sharing
@oflyhigh
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Such a complicated thing to master but interesting to learn :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This is amazing , follow so we could upvote for upvote
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This is amazing , follow so we could upvote for upvote
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
just see you post it's very nice very helpful ...i followed you for more and informative stuff..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I love to learn new things and now a days learning python so please provide english version of your artcle please
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
遊覽
我真的很喜歡旅遊,而且旅行中的這個東西太便宜了,所以真的很吸引人留在我這裡。你可以在一天的巴士票價格為15至20美元,而國家本身有很多東西可以提供:南方的陽光島,任何地方的山,北方的積雪,還有許多非凡的文化可供選擇。到其他亞洲國際場所旅遊也比來自歐洲或美國的道路更便宜和更接近。
保護
沒有哪個地方像我在中國一樣安全。到處都是人類,晚上也是。這使得我與世界各地相比,我的體驗如此安全。其實,這裡有很多可怕的地方,犯罪就是現在,但是我只是在中國得到一種保護。我所有的其他外籍朋友都感覺到完全一樣的方式。
貨幣奇蹟
大家都知道:中國經濟正在蓬勃發展。幾個月之內城鎮就從這裡走出來,中等城市變成了大都市。作為這種增長的一部分,我可以說是非常激動人心的。我從來沒有經歷過這樣的上升。顯然非常獨特。
中國的招待
我在中國的任何地方,我總是感到歡迎。我沒有“種族主義者”享受任何。我相信有不少中國人不僅喜歡外國人湧入他們的美國,而且至少我從來沒有這樣的親身經歷。
從不沉悶
而我以前在中國,經常變得有趣。在每個海外生活的開始,每天都很漂亮,但通常在幾個星期/幾個月之內,一切都將成為日常的生活方式。對我來說,不再是中國。無論我去哪裡,我都注意到了一些我以前沒有看見的東西,或者我嘗試過我以前沒有嚐過的東西。它從來沒有無聊。
購買
許可證的臉,我是一個女人,幾乎每個女人都喜歡購物。中國是一個購物者的天堂。至少對我來說。你可以在每個角落髮現瘋狂的東西和可愛的服裝。質量是每一個故事,但至少它是便宜的,我可以買很多很多的東西...😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
up voted you ..............i dont have to fear you i got to say this ...........................i just drop a post i think you should drop by and chick
vote and comment plz
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