-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from permadao/main
Update cred-and-quests.md & cred-utils.md zh version
- Loading branch information
Showing
6 changed files
with
303 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# CRED Utils 蓝图 | ||
|
||
CRED Utils 蓝图是一个预先设计的模板,可帮助你快速的在`ao`测试网中查看你的 CRED 余额。 | ||
|
||
## 解密 CRED 工具蓝图 | ||
|
||
### `CRED` 信息表 | ||
|
||
- **CRED.balance**: 运行 `CRED.balance` 会显示您进程已知的最新 CRED 余额。如果您之前从未查询过余额,它将自动获取。如果你认为你的CRED最近发生变动,建议先运行`CRED.update`更新余额。 | ||
|
||
- **CRED.process**: 运行此命令会打印发行CRED代币的进程ID。 | ||
|
||
- **CRED.send**: 就像调用函数一样使用 `CRED.send(targetProcessId, amount)` 可以将 CRED 从您的 ao 进程发送到另一个 ao 进程。 | ||
|
||
- `targetProcessId`: **string**: 接收方的43位字符的进程 ID。 | ||
- `amount`: **integer**: 要发送的 CRED 单位数量。1 CRED等于1000份CRED。 | ||
|
||
- **CRED.update**: 运行`CRED.update`命令会向 CRED 发行方的进程发送消息,从而获取您最新的 CRED 余额。更新后的余额将由下文提到的 `UpdateCredBalance` 处理程序接收处理。 | ||
|
||
### Handler 定义 | ||
|
||
- **Credit Handler**: `CRED_Credit` handler支持 CRED 发行方进程(以及aos)在你的 CRED 余额增加时自动通知你。 | ||
|
||
- **Debit Handler**: `CRED_Debit` Handler支持 CRED 发行方进程(以及aos)在你的 CRED 余额减少时自动通知你。 | ||
|
||
- **Update Balance Handler**: `UpdateCredBalance` handler 接收所有 CRED.update 请求的响应。 | ||
|
||
## 如何使用蓝图 | ||
|
||
1. 打开终端。 | ||
2. 启动你的`aos` 进程。 | ||
3. 输入 `.load-blueprint credUtils`。 | ||
4. 输入 `CRED.balance` | ||
|
||
## CRED 工具蓝图中包含的内容: | ||
|
||
有关 `aos` 最新版本中提供的蓝图,请参阅 github 上`aos` [source code on GitHub](https://github.com/permaweb/aos/blob/main/blueprints/credUtils.lua)的源代码。 | ||
|
||
```lua | ||
CRED_PROCESS = "Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc" | ||
|
||
_CRED = { balance = "Your CRED balance has not been checked yet. Updating now." } | ||
|
||
local credMeta = { | ||
__index = function(t, key) | ||
-- sends CRED balance request | ||
if key == "update" then | ||
Send({ Target = CRED_PROCESS, Action = "Balance", Tags = { Target = ao.id } }) | ||
return "Balance update requested." | ||
-- prints local CRED balance, requests it if not set | ||
elseif key == "balance" then | ||
if _CRED.balance == "Your CRED balance has not been checked yet. Updating now." then | ||
Send({ Target = CRED_PROCESS, Action = "Balance", Tags = { Target = ao.id } }) | ||
end | ||
return _CRED.balance | ||
-- prints CRED process ID | ||
elseif key == "process" then | ||
return CRED_PROCESS | ||
-- tranfers CRED | ||
elseif key == "send" then | ||
return function(target, amount) | ||
-- ensures amount is string | ||
amount = tostring(amount) | ||
print("sending " .. amount .. "CRED to " .. target) | ||
Send({ Target = CRED_PROCESS, Action = "Transfer", Recipient = target, Quantity = amount }) | ||
end | ||
else | ||
return nil | ||
end | ||
end | ||
} | ||
|
||
|
||
CRED = setmetatable({}, credMeta) | ||
|
||
-- Function to evaluate if a message is a balance update | ||
local function isCredBalanceMessage(msg) | ||
if msg.From == CRED_PROCESS and msg.Tags.Balance then | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
-- Function to evaluate if a message is a Debit Notice | ||
local function isDebitNotice(msg) | ||
if msg.From == CRED_PROCESS and msg.Tags.Action == "Debit-Notice" then | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
-- Function to evaluate if a message is a Credit Notice | ||
local function isCreditNotice(msg) | ||
if msg.From == CRED_PROCESS and msg.Tags.Action == "Credit-Notice" then | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
local function formatBalance(balance) | ||
-- Ensure balance is treated as a string | ||
balance = tostring(balance) | ||
-- Check if balance length is more than 3 to avoid unnecessary formatting | ||
if #balance > 3 then | ||
-- Insert dot before the last three digits | ||
balance = balance:sub(1, -4) .. "." .. balance:sub(-3) | ||
end | ||
return balance | ||
end | ||
|
||
-- Handles Balance messages | ||
Handlers.add( | ||
"UpdateCredBalance", | ||
isCredBalanceMessage, | ||
function(msg) | ||
local balance = nil | ||
if msg.Tags.Balance then | ||
balance = msg.Tags.Balance | ||
end | ||
-- Format the balance if it's not set | ||
if balance then | ||
-- Format the balance by inserting a dot after the first three digits from the right | ||
local formattedBalance = formatBalance(balance) | ||
_CRED.balance = formattedBalance | ||
print("CRED Balance updated: " .. _CRED.balance) | ||
else | ||
print("An error occurred while updating CRED balance") | ||
end | ||
end | ||
) | ||
|
||
-- Handles Debit notices | ||
Handlers.add( | ||
"CRED_Debit", | ||
isDebitNotice, | ||
function(msg) | ||
print(msg.Data) | ||
end | ||
) | ||
|
||
-- Handles Credit notices | ||
Handlers.add( | ||
"CRED_Credit", | ||
isCreditNotice, | ||
function(msg) | ||
print(msg.Data) | ||
end | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
# FAQ | ||
|
||
## 所有权 (Ownership) | ||
|
||
<details> | ||
<summary><strong>进程的所有权</strong></summary> | ||
|
||
使用 aos 控制台创建一个新的进程,你的钱包地址就是进程的所有者。**aos** 使用 **Owner** 全局变量来标记进程的所有者。如果你想转移进程的所有权,或者将它变成无人可以控制的进程,你可以重定义 **Owner** 变量将它给其他钱包地址,或者设置为 **nil**。 | ||
|
||
</details> | ||
|
||
## JSON | ||
|
||
<details> | ||
<summary><strong>将数据编码为 json 格式</strong></summary> | ||
|
||
当你向其他进程或者外部服务发送数据,你可能希望使用 JSON 作为数据编码格式。使用 lua 的 json 模块,可以对 lua Table 中的值进行 **encode** 和 **decode** 操作。 | ||
|
||
```lua | ||
Send({Target = Router, Data = require('json').encode({hello = "world"})}) | ||
``` | ||
|
||
</details> | ||
|
||
## Send 和 ao.send 对比 | ||
|
||
<details> | ||
<summary><strong>什么时候使用 Send 或 ao.send</strong></summary> | ||
|
||
这两个方法都会将消息发送到一个进程,区别是 `ao.send` 可以返回消息,以便于记录日志或者进行故障排查。`Send` 哈数通常在控制台中使用,更方便访问。在 `handlers` 中更推荐使用 `ao.send`,但他们在 `aos`中是可以相互替换的。 | ||
|
||
</details> | ||
# FAQ | ||
|
||
## 所有权 (Ownership) | ||
|
||
<details> | ||
<summary><strong>进程的所有权</strong></summary> | ||
|
||
使用 aos 控制台创建一个新的进程,你的钱包地址就是进程的所有者。**aos** 使用 **Owner** 全局变量来标记进程的所有者。如果你想转移进程的所有权,或者将它变成无人可以控制的进程,你可以重定义 **Owner** 变量将它给其他钱包地址,或者设置为 **nil**。 | ||
|
||
</details> | ||
|
||
## JSON | ||
|
||
<details> | ||
<summary><strong>将数据编码为 json 格式</strong></summary> | ||
|
||
当你向其他进程或者外部服务发送数据,你可能希望使用 JSON 作为数据编码格式。使用 lua 的 json 模块,可以对 lua Table 中的值进行 **encode** 和 **decode** 操作。 | ||
|
||
```lua | ||
Send({Target = Router, Data = require('json').encode({hello = "world"})}) | ||
``` | ||
|
||
</details> | ||
|
||
## Send 和 ao.send 对比 | ||
|
||
<details> | ||
<summary><strong>什么时候使用 Send 或 ao.send</strong></summary> | ||
|
||
这两个方法都会将消息发送到一个进程,区别是 `ao.send` 可以返回消息,以便于记录日志或者进行故障排查。`Send` 函数通常在控制台中使用,更方便访问。在 `handlers` 中更推荐使用 `ao.send`,但他们在 `aos`中是可以相互替换的。 | ||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# CRED 和任务 FAQ | ||
|
||
::: info | ||
|
||
`ao`生态系统目前还处于非常早期的阶段,充满机遇。社区任务板提供了许多参与测试和构建软件以发展生态系统的方法,同时还能赚取`ao`生态系统的原生货币:CRED。 | ||
|
||
::: | ||
|
||
## 视频教程 | ||
|
||
<iframe width="680" height="350" src="https://www.youtube.com/embed/QA3OmkLcdRs?si=CLAZrIUhJ0aEGYxM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> | ||
|
||
## 什么是CRED? | ||
|
||
CRED是`ao`测试网的原生货币,用于奖励完成任务的用户。 | ||
|
||
## CRED有什么用? | ||
|
||
> CRED 代币是你的社交江湖地位,数字化身。 | ||
> | ||
> 无论是谁,谁拥有最多的 CRED 代币,谁就是当之无愧的社交达人、也是你最值得信任的人。 | ||
> | ||
> -Bobinstein (bobinstein), 来自 [Discord](https://discord.com/channels/1210396395643863101/1210606156582752436/1215723479672815647) | ||
> [CRED] 的未来,充满无限可能。 | ||
> | ||
> -Ros (rosmcmahon), 来自 [Discord](https://discord.com/channels/1210396395643863101/1210606156582752436/1217101371472478318) | ||
## 如何获得 CRED? | ||
|
||
你可以通过完成`ao`核心开发人员和社区贡献者制定的任务赚取 CRED。 | ||
|
||
## 想知道有哪些任务可以做吗? | ||
|
||
ao 本地网络中有一个开发聊天室,您可以在那里查询任务信息。首先,启动 aos: | ||
|
||
```sh | ||
$ aos | ||
``` | ||
|
||
接下来,加入 Quests 聊天室(如果你还没有加入的话)。你还可以将你的用户名/昵称作为第二个参数加入聊天室(可选)。 | ||
|
||
```lua | ||
aos> Join("Quests") | ||
# OR | ||
aos> Join("Quests", "MyScreenName") | ||
``` | ||
|
||
然后,你可以向聊天室发送 `/Quests` 命令。如果你加入了多个聊天室,还可以把第二个参数作为指定的聊天室名称,发送消息。 | ||
|
||
```lua | ||
aos> Say("/Quests") | ||
# OR | ||
aos> Say("/Quests", "Quests") | ||
``` | ||
|
||
几秒钟后,机器人会自动向聊天室发送所有可以做的任务信息。 | ||
|
||
## 如何查看任务详情? | ||
|
||
你可以通过向`Quests` 聊天室发送命令 /Quests:[index] 了解更多详细信息,其中 [index] 应该替换为任务编号,例如: | ||
|
||
```lua | ||
aos> Say("/Quests:1", "Quests") | ||
# OR | ||
aos> Say("/Quests:2", "Quests") | ||
``` | ||
|
||
### 任务1: "开始" | ||
|
||
本文档的[开始](/tutorials/begin/index) 教程将详细介绍任务1的操作步骤。 | ||
|
||
### 任务 2:“机器人和游戏” | ||
|
||
本教程的[机器人和游戏](/tutorials/bots-and-games/index)将详细介绍任务2的操作步骤 | ||
|
||
## 何完成任务? | ||
|
||
只要按照任务描述中的所有 步骤操作,包括提交领取奖励,就算完成任务啦! | ||
|
||
## 如何获得 CRED? | ||
|
||
每个任务的文本描述都会详细说明如何提交领取奖励的请求。 完成任务后,请务必按照任务描述中的指示提交领取奖励的请求。 只有完成任务的所有步骤,并提交请求,你才能获得CRED奖励。审核领取奖励的请求需要一些手动处理时间,请耐心等待。 | ||
|
||
## 我什么时候可以拿到我的CRED? | ||
|
||
你的领取奖励请求会经过人工审核,以确认你是否完成了所有必要步骤。请在工作日耐心等待约 24 小时,以便处理你的请求。 | ||
|
||
## 如何查看/核实我当前的 CRED 余额? | ||
|
||
你可以将`credUtils` 蓝图加载到你的 ao 进程中,以便快速查询你的 CRED 余额,甚至可以将 CRED 发送给朋友! | ||
|
||
```lua | ||
aos> .load-blueprint credUtils | ||
Loading... credUtils # sample output | ||
undefined # sample output | ||
aos> CRED.balance | ||
Your CRED balance has not been checked yet. Updating now. # sample output | ||
CRED Balance updated: 500.000 # sample output | ||
``` | ||
|
||
了解有关 [aos 蓝图](/guides/aos/blueprints/index)的更多信息。 |
9 changes: 9 additions & 0 deletions
9
src/zh/welcome/testnet-info.md → src/zh/welcome/testnet-info/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters