Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add access path guide #1246

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/website/pages/docs/developer-guides/access-path.en-US.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Access path

Access path
Rooch's data is stored in StateDB. When we interact with the chain, different call requests will correspond to corresponding read and write requests.

In order to accurately add, delete, check and modify certain data in these operations, the correct storage path of the data must be passed. Access Path specifies how to access the corresponding data.

There are 4 different types of data in Rooch, so 4 different path prefixes are set to identify the access path.

- `Object`: `/object/ObjectID1 [, ObjectID2 ... ObjectIDn]`
- `Resource`: `/resource/Account_Address/Resource_Type1 [, Resource_Type2 ... Resource_Typen]`
- `Module`: `/module/Account_Address/Module_Type1 [, Module_Type2 ... Module_Typen]`
- `Table`: `/table/Table_Handle/key1 [, key2 ... keyn]`

## Using access paths in RPC requests

```shell
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"rooch_listStates","params":["/resource/0x3", null, null, {"decode":true}],"id":1}' https://dev-seed.rooch.network:443 | jq
```

You can see that in the parameter list of the RPC request, we use the `/resource/0xaddress` prefix to access all resources at the `0x3` address.

For more usage examples, please refer to [Rooch JSON-RPC](./rpc.en-US.mdx).
22 changes: 22 additions & 0 deletions docs/website/pages/docs/developer-guides/access-path.zh-CN.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Access path

Rooch 的数据存放在 StateDB 里,当我们跟链交互时,不同的调用请求会对应着对应的读写请求。

在这些操作中要准确地对某些数据进行增删查改,就必须传递数据的正确存放路径。访问路径(Access Path)就指定要访问对应数据的方式。

Rooch 中有 4 类不同的数据,因此设置了 4 个不同的路径前缀用来标识访问路径。

- 对象:`/object/对象ID1 [, 对象 ID2 ... 对象 IDn]`
- 资源:`/resource/账户地址/资源类型1 [, 资源类型2 ... 资源类型n]`
- 模块:`/module/账户地址/模块类型1 [, 模块类型2 ... 模块类型n]`
- 表:`/table/table_handle/key1 [, key2, keyn]`

## 在 RPC 请求中使用访问路径

```shell
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"rooch_listStates","params":["/resource/0x3", null, null, {"decode":true}],"id":1}' https://dev-seed.rooch.network:443 | jq
```

可以看到在 RPC 请求的参数列表中,我们使用了 `/resource/0x地址` 这个前缀来访问 `0x3` 这个地址的所有资源。

更多使用示例,请参考 [Rooch JSON-RPC](./rpc.zh-CN.mdx)。
2 changes: 2 additions & 0 deletions docs/website/pages/docs/developer-guides/rpc.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ When the call is successful, you can see that the prompt on the right has respon

List states by `access_path`. If `StateOptions.decode` is `true`, decode the state and return the decoded value in the response.

> See more about [Access path](./access-path.en-US.mdx).

```shell
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"rooch_listStates","params":["/resource/0x3", null, null, {"decode":true}],"id":1}' https://dev-seed.rooch.network:443 | jq
```
Expand Down
2 changes: 2 additions & 0 deletions docs/website/pages/docs/developer-guides/rpc.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ curl --location 'https://dev-seed.rooch.network/' --header 'Content-Type: applic

按 `access_path` 列出状态。如果 `StateOptions.decode` 为 `true`,则对状态进行解码并在响应中返回解码后的值。

> 参阅更多 [Access path](./access-path.zh-CN.mdx) 的内容。

```shell
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"rooch_listStates","params":["/resource/0x3", null, null, {"decode":true}],"id":1}' https://dev-seed.rooch.network:443 | jq
```
Expand Down
Loading