# Dyson协议测试网 **Published by:** [hao](https://paragraph.com/@ethnbb/) **Published on:** 2022-09-19 **URL:** https://paragraph.com/@ethnbb/dyson ## Content 什么是戴森协议? 简而言之,Dyson 协议的创建考虑了开发人员。关键思想是创建一个能够运行简单脚本的安全区块链,其中表示和界面都是完全分布式的并内置在协议中。换句话说:一切都在链上。 Dyson 区块链上的脚本在 Python 的简单子集(称为 Dyslang)和HTTP(特别是WSGI 协议)上运行,因此您可以使用您已经熟悉的工具编写完全分布式的应用程序或网站。 在底层,Dyson 协议使用Cosmos SDK及其跨链通信协议,因此它与 Cosmos 生态系统完全互操作。 我们有很多令人兴奋的项目,我们将在此过程中寻找明星开发人员、beta 测试人员和验证人员。我们这个项目的主要目标之一是奖励早期采用者和开发人员,所以我们希望您能加入我们!包括对早期采用者/测试者的奖励! 官方推特:https://twitter.com/DysonProtocol 官方教程:https://medium.com/@dysonprotocol正文:首先打开测试网https://dys.dysonvalidator.com/连接KepIr钱包,点击批准会自动添加Dyson链然后复制钱包地址去DC https://discord.gg/87rwhNJA 的testnet-airdrop频道领水,一分钟左右就到账了接下来开始测试:一:如何制作您的第一个基本 Dyson 协议功能1,单击您的脚本按钮2:在编辑器中输入以下函数,然后点击save保存后钱包批准def my_function(): print('hello world') return 123 3: 点击Query my_function4:再点击Run my_function然后钱包批准二:如何在 Dyson 协议上更新函数和接受参数1: 把之前的代码替换成以下代码,点击save保存钱包批准,然后my_name框里输入你要的名字,点击 Query say_hello,下面会显示出你的名字def say_hello(my_name: str): print('hello '+ my_name) return 123 三:如何在戴森协议上保存到存储1:步骤如图,第二步是输入dyson,第四步是你的钱包地址,第五步是钱包地址后面加/my_greeting 第六步是输入this is a test2:重新开一个测试网页,步骤如图,搜索“dyson”,第四步是你的地址加/my_greeting 第五步的运行结果和你填写的一致就对了3: 点击最上方你的地址打开编辑器,把原来的代码替换成以下代码,然后保存,钱包批准,第六步显示的名字是你取的就对了!然后重复上图步骤检验一下,你会发现运行结果变成了你的钱包地址和名字就对了from dys import _chain, get_script_address def say_hello(my_name: str): data = "hello " + my_name print(data) # to help debug return _chain( "dyson/sendMsgCreateStorage", creator=get_script_address(), index=get_script_address() + "/my_greeting", data=data, force=True, ) 四:如何在 Dyson 协议上读取存储和渲染网站1:将第1行代码替换成以下第一个代码,然后在第4行下面添加另一个代码,保存,批准from dys import _chain, get_script_address, get_caller assert get_script_address() == get_caller(), "permission denied" 2:在代码末尾留两行,然后添加以下代码,保存,批准,左侧会多出来一个命令框,步骤如图def get_greeting(): return _chain( "dyson/QueryStorage", index=get_script_address() + "/my_greeting", ) 3:再次代码末行留两行,添加以下代码,保存,批准,然后用这个网址新开个网页 https://你的钱包地址.dysonvalidator.com 如图显示def application(environ, start_response): start_response("200 ok", [("Content-type", "text/plain")]) return ["Test WSGI website says: hello world".encode()] 4:将最后一行代码替换成以下代码,保存,批准,然后刷新你的那个网站,会变成你的名字greeting_data = get_greeting()["result"]["storage"]["data"] return [greeting_data.encode()] 五:如何在 Dyson 协议上使用 HTML 和 CSS 更改网站的外观1:将代码全部替换成以下代码,保存,批准,然后点击左侧的Query render_page按钮,然后刷新你的网站,会发现多了一层颜色就对了!如图 最后这步要添加很多代码,麻烦,我直接用了完整代码了,想看的可以去看官方教程import html from string import Template from dys import _chain, get_script_address, get_caller def say_hello(my_name: str): assert get_script_address() == get_caller(), "permission denied" data = "hello " + my_name print(data) # to help debug return _chain( "dyson/sendMsgCreateStorage", creator=get_script_address(), index=get_script_address() + "/my_greeting", data=data, force=True, ) def get_greeting(): return _chain( "dyson/QueryStorage", index=get_script_address() + "/my_greeting", ) def render_page(body:str): return Template( """<!doctype html> <html> <head> <title>Hello World</title> <meta charset=utf-8> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous"> <style> .heading { text-shadow: #FC0 1px 0 10px; } </style> </head> <body> <div class="container"> <h1 class="heading">Greeting!</h1> <p>$body</p> </div> </body> </html> """ ).safe_substitute(body=body) def application(environ, start_response): start_response("200 ok", [("Content-type", "text/html")]) greeting_data = get_greeting()["result"]["storage"]["data"] return [ render_page(html.escape(greeting_data)).encode(), ] 六:如何循环存储以呈现有关戴森协议的博客1:把原来的代码全部替换成以下代码,保存,批准import re2 import html from string import Template from dys import _chain, get_script_address, get_caller def new_post(title: str, body: str): assert get_script_address() == get_caller(), "permission denied" data = f"{title} -- {body}" title_slug = re2.sub("\W+", "-", title) print(data) # to help debug return _chain( "dyson/sendMsgCreateStorage", creator=get_script_address(), index=get_script_address() + "/post/v1/" + title_slug, data=data, force=True, ) def get_all_posts(): response = _chain( "dyson/QueryPrefixStorage", prefix=get_script_address() + "/post/v1/" ) return response["result"] def render_page(body: str): return Template( """<!doctype html> <html> <head> <title>Hello World</title> <meta charset=utf-8> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous"> <style> .heading { text-shadow: #FC0 1px 0 10px; } </style> </head> <body> <div class="container"> <h1 class="heading">Posts!</h1> <p>$body</p> </div> </body> </html> """ ).safe_substitute(body=body) def render_posts(posts: list[dict[str, str]]): return ( "<ul>" + "".join(["<li>" + html.escape(s["data"]) + "</li>" for s in posts]) + "</ul>" ) def application(environ, start_response): start_response("200 ok", [("Content-type", "text/html")]) post_data = get_all_posts() return [ render_page(render_posts(post_data["storage"])).encode(), ] 2:步骤如图,你想要写多篇文章就重复图中123步就可以了3:这样的就可以了!可以看出我是写了3篇文章到这里就暂时结束了,后面还有后续步骤,官方教程还没出,出了再写后续 作者推特:https://twitter.com/qazplm456456 ## Publication Information - [hao](https://paragraph.com/@ethnbb/): Publication homepage - [All Posts](https://paragraph.com/@ethnbb/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@ethnbb): Subscribe to updates