@wowok/agent-mcp 2.2.11 → 2.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs/index.d.ts +3 -0
- package/dist/docs/index.js +2 -0
- package/dist/docs/loader.d.ts +12 -0
- package/dist/docs/loader.js +177 -0
- package/dist/docs/search.d.ts +17 -0
- package/dist/docs/search.js +325 -0
- package/dist/docs/types.d.ts +55 -0
- package/dist/docs/types.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +146 -39
- package/docs/README.md +249 -0
- package/docs/WIP.md +388 -0
- package/docs/WTS.md +536 -0
- package/docs/docs/account.md +914 -0
- package/docs/docs/allocation.md +635 -0
- package/docs/docs/arbitration.md +1804 -0
- package/docs/docs/arbitration_state_machine.md +270 -0
- package/docs/docs/contact.md +709 -0
- package/docs/docs/demand.md +948 -0
- package/docs/docs/guard.md +1465 -0
- package/docs/docs/localinfo.md +432 -0
- package/docs/docs/localmark.md +583 -0
- package/docs/docs/machine.md +2490 -0
- package/docs/docs/messenger.md +2098 -0
- package/docs/docs/onchain_events.md +267 -0
- package/docs/docs/order.md +1001 -0
- package/docs/docs/payment.md +512 -0
- package/docs/docs/permission.md +1438 -0
- package/docs/docs/personal.md +742 -0
- package/docs/docs/progress.md +1748 -0
- package/docs/docs/query.md +467 -0
- package/docs/docs/repository.md +1043 -0
- package/docs/docs/reward.md +833 -0
- package/docs/docs/service.md +2130 -0
- package/docs/docs/stage-01-introduction.md +243 -0
- package/docs/docs/stage-02-trust.md +302 -0
- package/docs/docs/stage-03-collaboration.md +337 -0
- package/docs/docs/stage-04-transaction.md +277 -0
- package/docs/docs/stage-05-business.md +151 -0
- package/docs/docs/stage-06-personal.md +203 -0
- package/docs/docs/stage-07-query.md +572 -0
- package/docs/docs/stage-08-examples.md +184 -0
- package/docs/docs/treasury.md +1149 -0
- package/docs/docs/wowok_buildin_info.md +740 -0
- package/docs/examples/Insurance/Insurance.md +594 -0
- package/docs/examples/Insurance/Insurance_TestResults.md +481 -0
- package/docs/examples/Insurance/insurance_complete_guard_v1.json +50 -0
- package/docs/examples/MyShop/MyShop.md +1353 -0
- package/docs/examples/MyShop/MyShop_TestResults.md +1003 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced.md +1898 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced_MerchantSystem_TestResults.md +1297 -0
- package/docs/examples/MyShop_Advanced/MyShop_Advanced_OrderFlow_TestResults.md +743 -0
- package/docs/examples/MyShop_Advanced/machine_nodes.json +222 -0
- package/docs/examples/ThreeBody_Signature/ThreeBody_Signature.md +776 -0
- package/docs/examples/ThreeBody_Signature/ThreeBody_Signature_TestResults.md +599 -0
- package/docs/examples/Travel/Travel.md +1157 -0
- package/docs/examples/Travel/Travel_TestResults.md +743 -0
- package/docs/examples/Travel/calc-weather-timestamps.js +8 -0
- package/docs/examples/Travel/travel_machine_v2_export.json +104 -0
- package/docs/examples/Travel/weather_check_guard_v1.json +51 -0
- package/docs/skills/WOWOK.md +650 -0
- package/docs/skills/onchain_operations/_common.md +406 -0
- package/docs/skills/onchain_operations/_index.md +196 -0
- package/docs/skills/onchain_operations/allocation.md +28 -0
- package/docs/skills/onchain_operations/arbitration.md +106 -0
- package/docs/skills/onchain_operations/contact.md +40 -0
- package/docs/skills/onchain_operations/demand.md +53 -0
- package/docs/skills/onchain_operations/gen_passport.md +23 -0
- package/docs/skills/onchain_operations/guard.md +56 -0
- package/docs/skills/onchain_operations/machine.md +89 -0
- package/docs/skills/onchain_operations/order.md +56 -0
- package/docs/skills/onchain_operations/payment.md +24 -0
- package/docs/skills/onchain_operations/permission.md +68 -0
- package/docs/skills/onchain_operations/personal.md +58 -0
- package/docs/skills/onchain_operations/progress.md +38 -0
- package/docs/skills/onchain_operations/repository.md +70 -0
- package/docs/skills/onchain_operations/reward.md +38 -0
- package/docs/skills/onchain_operations/service.md +78 -0
- package/docs/skills/onchain_operations/treasury.md +68 -0
- package/docs/skills/schema-account_operation.md +402 -0
- package/docs/skills/schema-guard2file.md +153 -0
- package/docs/skills/schema-local_info_operation.md +160 -0
- package/docs/skills/schema-local_mark_operation.md +148 -0
- package/docs/skills/schema-machineNode2file.md +155 -0
- package/docs/skills/schema-messenger_operation.md +547 -0
- package/docs/skills/schema-onchain_events.md +201 -0
- package/docs/skills/schema-onchain_table_data.md +334 -0
- package/docs/skills/schema-query_toolkit.md +395 -0
- package/docs/skills/schema-wip_file.md +240 -0
- package/docs/skills/schema-wowok_buildin_info.md +296 -0
- package/docs/wip-examples/three_body.html +57 -0
- package/docs/wip-examples/three_body.wip +30 -0
- package/package.json +3 -2
|
@@ -0,0 +1,1465 @@
|
|
|
1
|
+
# Guard Component (🛡️ Programmable Validation Rules)
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Component Overview
|
|
6
|
+
|
|
7
|
+
The Guard component creates immutable programmable validation rules that return boolean results (pass/fail). Guards can define complex validation logic for use cases like service marketplaces, permission management, workflow templates, and more.
|
|
8
|
+
|
|
9
|
+
**Note**: Use the `guard2file` tool (see [Sub-feature 3](#sub-feature-3-export-guard-to-file-guard2file)) to export existing Guard definitions from the blockchain, then use [Sub-feature 2](#sub-feature-2-create-guard-from-file-type-file) to quickly build new trust verification Guard objects. Use `gen_passport` (see [Sub-feature 4](#sub-feature-4-generate-verified-passport-gen_passport)) to generate verifiable credentials for Messenger stranger verification. Use the `wowok_buildin_info` tool with 'guard instructions' to query all available operations.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
## Function List
|
|
13
|
+
|
|
14
|
+
| Function Name | Purpose | Usage Scenario | Significance |
|
|
15
|
+
|---------------|---------|----------------|--------------|
|
|
16
|
+
| **Create Guard with Direct Nodes** | Create a Guard by directly providing a GuardNode computation tree through `root.type: "node"` | Quick creation of simple to moderately complex Guards; no external file needed | Core function for Guard creation; enables immediate validation logic definition |
|
|
17
|
+
| **Create Guard from File** | Load a Guard definition from a JSON or Markdown file through `root.type: "file"` | Reusing existing Guard definitions; editing Guards in external files; version control of Guard logic | Enables Guard templates and reusability; simplifies complex Guard management |
|
|
18
|
+
| **Name Guard** | Assign a name and optional tags to a new Guard using `namedNew` | Identifying Guards by meaningful names; categorizing Guards with tags; sharing Guards publicly | Essential for Guard discoverability and organization; enables public on-chain identities |
|
|
19
|
+
| **Set Guard Description** | Add a description to explain the Guard's purpose | Documenting what the Guard validates; helping other users understand Guard usage | Improves Guard usability and maintainability |
|
|
20
|
+
| **Define Data Table** | Define the data table that the Guard uses for validation | Specifying user-submitted data and fixed constants for validation logic | Foundation of Guard validation; all data must be defined here |
|
|
21
|
+
| **Set Dependencies** | Define Guards that this Guard depends on using `rely` | Building composite validation logic from multiple simpler Guards; reusing existing Guards | Enables modular Guard design; reduces redundant validation logic |
|
|
22
|
+
| **Export Guard to File** | Export an existing Guard's definition from the blockchain to a local JSON or Markdown file | Backing up Guards; editing Guard definitions locally; creating new Guards from templates | Enables Guard template workflow; facilitates Guard sharing and version control |
|
|
23
|
+
| **Generate Verified Passport** | Create immutable verified Passport object after Guard validation passes | Offline friend verification in Messenger; transaction condition verification | Creates verifiable credentials; enables trust-based interactions without on-chain validation every time |
|
|
24
|
+
| **Use Query Nodes** | Access real-time on-chain object data using `query` nodes | Building validation logic based on current on-chain state (e.g., Treasury balance, Service price, Permission status) | Most powerful Guard feature; enables dynamic, state-aware validation |
|
|
25
|
+
| **Use Logic Nodes** | Combine and transform boolean results using logic operations | Building complex boolean expressions from simpler conditions | Core of Guard validation; enables multi-condition checks |
|
|
26
|
+
| **Use Context Nodes** | Access system context like Signer, Clock, and Guard | Validating based on transaction sender, current time, or Guard itself | Enables time-based, sender-based, and self-referential validation |
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
## Query Instructions and On-chain Object Access
|
|
30
|
+
|
|
31
|
+
### Overview
|
|
32
|
+
|
|
33
|
+
Guards can access data from ANY on-chain object using `query` nodes! This is a powerful feature that allows you to build validation logic based on real-time on-chain state.
|
|
34
|
+
|
|
35
|
+
### Total Instructions
|
|
36
|
+
|
|
37
|
+
There are **400+ guard instructions** available, including:
|
|
38
|
+
- Logic operations (12)
|
|
39
|
+
- Calculation operations (8)
|
|
40
|
+
- Type conversion operations (11)
|
|
41
|
+
- Data and vector operations (20+)
|
|
42
|
+
- Context operations (3)
|
|
43
|
+
- Object query operations (400+ query instructions)
|
|
44
|
+
|
|
45
|
+
Use the `wowok_buildin_info` tool with `'guard instructions' to query the complete list of available operations.
|
|
46
|
+
|
|
47
|
+
### Queryable Object Types
|
|
48
|
+
|
|
49
|
+
Guards can query data from the following on-chain objects:
|
|
50
|
+
|
|
51
|
+
| Object Type | Description | Instructions | Common Use Cases |
|
|
52
|
+
|-------------|-------------|--------------|----------------|
|
|
53
|
+
| **Permission** | Access control management | 13 | Check if user is owner, admin, or has specific permissions |
|
|
54
|
+
| **Service** | Service marketplace listings | 40 | Check service details, pricing, availability |
|
|
55
|
+
| **Machine** | Workflow templates | 25 | Check workflow state, node definitions |
|
|
56
|
+
| **Progress** | Order progress tracking | 65 | Check order status, task completion, history records |
|
|
57
|
+
| **Repository** | On-chain database | 23 | Read stored data, policies |
|
|
58
|
+
| **Arbitration** | Dispute resolution | 13 | Check voting status, arbitration results |
|
|
59
|
+
| **Treasury** | Team funds management | 23 | Check balance, deposit/withdrawal rules |
|
|
60
|
+
| **Reward** | Incentive pools | 21 | Check reward pool balance, claim conditions |
|
|
61
|
+
| **Allocation** | Auto-distribution plans | 18 | Check distribution rules, recipients |
|
|
62
|
+
| **Demand** | Service requests | 21 | Check demand details, reward pools |
|
|
63
|
+
| **Order** | Order management | 25 | Check order status, payment info |
|
|
64
|
+
| **Payment** | Direct coin transfers | 15 | Check payment amount, time, recipients |
|
|
65
|
+
| **Contact** | IM management | 8 | Check messenger configurations |
|
|
66
|
+
| **Arb** | Arbitration voting and execution | 38 | Check voting records, execution state |
|
|
67
|
+
| **Discount** | Discount and promotion management | 9 | Check discount rates, validity periods |
|
|
68
|
+
| **EntityLinker** | Entity relationship management | 9 | Check entity links and associations |
|
|
69
|
+
| **EntityRegistrar** | Entity registration system | 11 | Check registered entities and their status |
|
|
70
|
+
| **Passport** | Verified credentials and identities | 16 | Check passport validity, verified attributes |
|
|
71
|
+
| **Proof** | Proof and verification records | 11 | Check proof existence, verification status |
|
|
72
|
+
| **Resource** | Publicly available on-chain data of the account | 5 | Check resource availability, ownership |
|
|
73
|
+
|
|
74
|
+
**Total: 409 query instructions across all object types**
|
|
75
|
+
|
|
76
|
+
### Query Node Syntax
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"type": "query",
|
|
81
|
+
"query": "query_name",
|
|
82
|
+
"object": "object_name_or_id",
|
|
83
|
+
"parameters": [ ... ]
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Guard Node Type Reference
|
|
90
|
+
|
|
91
|
+
### Logic Operation Nodes (Return Bool)
|
|
92
|
+
|
|
93
|
+
| Node Type | Description | Parameters |
|
|
94
|
+
|-----------|-------------|------------|
|
|
95
|
+
| `logic_and` | Logical AND | `nodes: GuardNode[]` (2-8 nodes) |
|
|
96
|
+
| `logic_or` | Logical OR | `nodes: GuardNode[]` (2-8 nodes) |
|
|
97
|
+
| `logic_not` | Logical NOT | `node: GuardNode` |
|
|
98
|
+
| `logic_equal` | Equality comparison | `nodes: GuardNode[]` (2-8 nodes) |
|
|
99
|
+
| `logic_as_u256_greater` | Greater than | `nodes: GuardNode[]` (2-8 nodes) |
|
|
100
|
+
| `logic_as_u256_lesser` | Less than | `nodes: GuardNode[]` (2-8 nodes) |
|
|
101
|
+
| `logic_as_u256_greater_or_equal` | Greater than or equal | `nodes: GuardNode[]` (2-8 nodes) |
|
|
102
|
+
| `logic_as_u256_lesser_or_equal` | Less than or equal | `nodes: GuardNode[]` (2-8 nodes) |
|
|
103
|
+
| `logic_as_u256_equal` | Numeric equality | `nodes: GuardNode[]` (2-8 nodes) |
|
|
104
|
+
| `logic_string_contains` | String contains | `nodes: GuardNode[]` (2-8 nodes) |
|
|
105
|
+
| `logic_string_nocase_contains` | String contains (case-insensitive) | `nodes: GuardNode[]` (2-8 nodes) |
|
|
106
|
+
| `logic_string_nocase_equal` | String equality (case-insensitive) | `nodes: GuardNode[]` (2-8 nodes) |
|
|
107
|
+
|
|
108
|
+
### Calculation Nodes
|
|
109
|
+
|
|
110
|
+
| Node Type | Return Type | Description | Parameters |
|
|
111
|
+
|-----------|-------------|-------------|------------|
|
|
112
|
+
| `calc_number_add` | U256 | Addition | `nodes: GuardNode[]` |
|
|
113
|
+
| `calc_number_subtract` | U256 | Subtraction | `nodes: GuardNode[]` |
|
|
114
|
+
| `calc_number_multiply` | U256 | Multiplication | `nodes: GuardNode[]` |
|
|
115
|
+
| `calc_number_divide` | U256 | Division | `nodes: GuardNode[]` |
|
|
116
|
+
| `calc_number_mod` | U256 | Modulo | `nodes: GuardNode[]` |
|
|
117
|
+
| `calc_string_length` | U64 | String length | `node: GuardNode` |
|
|
118
|
+
| `calc_string_indexof` | U64 | Find substring | `nodeLeft, nodeRight, order` |
|
|
119
|
+
| `calc_string_nocase_indexof` | U64 | Find substring (case-insensitive) | `nodeLeft, nodeRight, order` |
|
|
120
|
+
|
|
121
|
+
### Type Conversion Nodes
|
|
122
|
+
|
|
123
|
+
| Node Type | Return Type | Description | Parameters |
|
|
124
|
+
|-----------|-------------|-------------|------------|
|
|
125
|
+
| `convert_number_address` | Address | Number to address | `node: GuardNode` |
|
|
126
|
+
| `convert_address_number` | U256 | Address to number | `node: GuardNode` |
|
|
127
|
+
| `convert_number_string` | String | Number to string | `node: GuardNode` |
|
|
128
|
+
| `convert_string_number` | U256 | String to number | `node: GuardNode` |
|
|
129
|
+
| `convert_safe_u8` | U8 | Safe convert to U8 | `node: GuardNode` |
|
|
130
|
+
| `convert_safe_u16` | U16 | Safe convert to U16 | `node: GuardNode` |
|
|
131
|
+
| `convert_safe_u32` | U32 | Safe convert to U32 | `node: GuardNode` |
|
|
132
|
+
| `convert_safe_u64` | U64 | Safe convert to U64 | `node: GuardNode` |
|
|
133
|
+
| `convert_safe_u128` | U128 | Safe convert to U128 | `node: GuardNode` |
|
|
134
|
+
| `convert_safe_u256` | U256 | Safe convert to U256 | `node: GuardNode` |
|
|
135
|
+
|
|
136
|
+
### Data Nodes
|
|
137
|
+
|
|
138
|
+
| Node Type | Return Type | Description | Parameters |
|
|
139
|
+
|-----------|-------------|-------------|------------|
|
|
140
|
+
| `identifier` | Depends on table item | Reference data from table | `identifier: number` (0-255) |
|
|
141
|
+
| `query` | Depends on query | **Powerful feature!** Query on-chain object data. Use this to access real-time state from Permission, Service, Machine, Treasury, etc. | `query: string`, `object: string`, `parameters: GuardNode[]` |
|
|
142
|
+
| `value_type` | U8 | Get value type of a node | `node: GuardNode` |
|
|
143
|
+
|
|
144
|
+
#### Query Node Examples
|
|
145
|
+
The `query` node is your gateway to on-chain data! Some common query patterns:
|
|
146
|
+
- `permission.owner`: Get Permission object owner (Address)
|
|
147
|
+
- `permission.admin has`: Check if user has admin permission (Bool)
|
|
148
|
+
- `permission.entity.perm has`: Check if user has specific permission (Bool)
|
|
149
|
+
- `treasury.balance`: Get Treasury balance (U256)
|
|
150
|
+
- `service.price`: Get Service price (U256)
|
|
151
|
+
|
|
152
|
+
### Context Nodes
|
|
153
|
+
|
|
154
|
+
| Node Type | Return Type | Description | Parameters |
|
|
155
|
+
|-----------|-------------|-------------|------------|
|
|
156
|
+
| `context` | Depends on context | System context information | `context: "Signer" \| "Clock" \| "Guard"` |
|
|
157
|
+
|
|
158
|
+
**Important**: Context nodes return non-bool types! **NEVER use them directly in logic gates like logic_and or logic_or.**
|
|
159
|
+
- `Signer`: Address type (transaction sender)
|
|
160
|
+
- `Clock`: U64 type (timestamp in milliseconds)
|
|
161
|
+
- `Guard`: Address type (current Guard object ID)
|
|
162
|
+
|
|
163
|
+
**Correct Usage**:
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"type": "logic_equal",
|
|
167
|
+
"nodes": [
|
|
168
|
+
{ "type": "context", "context": "Signer" },
|
|
169
|
+
{ "type": "identifier", "identifier": 0 }
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Use context nodes as inputs to calculations or comparisons, not directly in logic gates.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
## Constraint Constants
|
|
178
|
+
|
|
179
|
+
| Constant Name | Value | Description |
|
|
180
|
+
|---------------|-------|-------------|
|
|
181
|
+
| `identifierMin` | 0 | Minimum identifier value |
|
|
182
|
+
| `identifierMax` | 255 | Maximum identifier value |
|
|
183
|
+
| `nameMaxLength` | 64 | Maximum name length (BCS characters) |
|
|
184
|
+
| `maxMultiOperands` | 8 | Maximum operands for multi-operand nodes |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Schema Tree
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
guard (Guard Object)
|
|
192
|
+
├── operation_type: "guard" (fixed value)
|
|
193
|
+
├── data (Guard data definition)
|
|
194
|
+
│ ├── namedNew (optional)
|
|
195
|
+
│ │ ├── name (optional, Guard name)
|
|
196
|
+
│ │ ├── tags (optional, tag list)
|
|
197
|
+
│ │ ├── onChain (optional, publish on-chain)
|
|
198
|
+
│ │ └── replaceExistName (optional, force name replacement)
|
|
199
|
+
│ ├── description (optional, Guard description)
|
|
200
|
+
│ ├── table (optional, data table)
|
|
201
|
+
│ │ └── GuardTableItem[]
|
|
202
|
+
│ │ ├── identifier (0-255)
|
|
203
|
+
│ │ ├── b_submission (user submission required)
|
|
204
|
+
│ │ ├── value_type (Bool/Address/String/U8/U16/U32/U64/U128/U256/etc)
|
|
205
|
+
│ │ ├── value (optional, fixed value)
|
|
206
|
+
│ │ └── name (optional, data name)
|
|
207
|
+
│ ├── root (root node definition, required)
|
|
208
|
+
│ │ ├── type (discriminator)
|
|
209
|
+
│ │ ├── type: "node"
|
|
210
|
+
│ │ │ └── node (GuardNode computation tree)
|
|
211
|
+
│ │ └── type: "file"
|
|
212
|
+
│ │ ├── file_path (file path)
|
|
213
|
+
│ │ └── format (optional, json/markdown)
|
|
214
|
+
│ └── rely (optional, dependent Guards)
|
|
215
|
+
│ ├── guards (dependent Guard ID/name list)
|
|
216
|
+
│ └── logic_or (optional, use OR logic)
|
|
217
|
+
└── env (optional, execution environment)
|
|
218
|
+
├── account (optional, use specified account)
|
|
219
|
+
├── permission_guard (optional, permission Guard list)
|
|
220
|
+
├── no_cache (optional, disable cache)
|
|
221
|
+
├── network (optional, localnet/testnet)
|
|
222
|
+
└── referrer (optional, referrer ID)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Complete Tool Call Structure
|
|
228
|
+
|
|
229
|
+
Guard operations use the following top-level structure:
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"operation_type": "guard",
|
|
234
|
+
"data": { ... },
|
|
235
|
+
"env": { ... }
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Sub-feature 1: Create Guard with Direct Nodes (type: "node")
|
|
242
|
+
|
|
243
|
+
### Feature Description
|
|
244
|
+
Create a Guard by directly providing a GuardNode computation tree through `root.type: "node"`, without requiring an external file.
|
|
245
|
+
|
|
246
|
+
### Parameter Description
|
|
247
|
+
|
|
248
|
+
| Parameter Path | Type | Required | Description | Constraints |
|
|
249
|
+
|----------------|------|----------|-------------|-------------|
|
|
250
|
+
| `operation_type` | string | Yes | Operation type | Fixed value "guard" |
|
|
251
|
+
| `data.namedNew.name` | string | No | Guard name | Max 64 BCS characters, cannot start with '0x' |
|
|
252
|
+
| `data.namedNew.tags` | array | No | Tag list | String array |
|
|
253
|
+
| `data.namedNew.onChain` | boolean | No | Whether to publish on-chain | true=public; false/undefined=local only (default) |
|
|
254
|
+
| `data.namedNew.replaceExistName` | boolean | No | Whether to replace existing name | true=force replace; false=error if name exists (default) |
|
|
255
|
+
| `data.description` | string | No | Guard description | Maximum length limit |
|
|
256
|
+
| `data.table` | array | Yes | Data table | GuardTableItem array (cannot be empty) |
|
|
257
|
+
| `data.table[].identifier` | number | Yes | Identifier | Integer between 0-255 |
|
|
258
|
+
| `data.table[].b_submission` | boolean | Yes | Whether user submission is required | true=user submits; false=fixed value |
|
|
259
|
+
| `data.table[].value_type` | enum | Yes | Value type | Bool/Address/String/U8/U16/U32/U64/U128/U256/etc |
|
|
260
|
+
| `data.table[].value` | any | No | Actual value | Provide when b_submission=false |
|
|
261
|
+
| `data.table[].name` | string | No | Data name | Default is empty string |
|
|
262
|
+
| `data.root.type` | string | Yes | Root node type | Fixed value "node" |
|
|
263
|
+
| `data.root.node` | object | Yes | GuardNode computation tree | Must return Bool value |
|
|
264
|
+
| `data.rely.guards` | array | No | Dependent Guard list | Guard ID or name array |
|
|
265
|
+
| `data.rely.logic_or` | boolean | No | Dependency logic | true=OR; false=AND (default) |
|
|
266
|
+
| `env.account` | string | No | Use specified account | Empty string '' uses default account |
|
|
267
|
+
| `env.permission_guard` | array | No | Permission Guard list | Guard ID array |
|
|
268
|
+
| `env.no_cache` | boolean | No | Whether to disable cache | true=disable; false=enable |
|
|
269
|
+
| `env.network` | enum | No | Network selection | "localnet" or "testnet" |
|
|
270
|
+
| `env.referrer` | string | No | Referrer ID | Account name or address |
|
|
271
|
+
|
|
272
|
+
### Important Notes
|
|
273
|
+
|
|
274
|
+
#### ⚠️ Network and Account Configuration
|
|
275
|
+
|
|
276
|
+
All examples in this document use the **testnet** network and **default account** (empty string `""`). When using in production, please configure according to your actual environment:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
{
|
|
280
|
+
"operation_type": "guard",
|
|
281
|
+
"data": { ... },
|
|
282
|
+
"env": {
|
|
283
|
+
"account": "", // Empty string for default account, or use account name/address
|
|
284
|
+
"network": "testnet" // Options: "testnet" | "localnet"
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Note**: If the `env` field is not specified, the operation will use the **default account** and the **last used network** for execution.
|
|
290
|
+
|
|
291
|
+
#### ⚠️ Guard Creation Constraints
|
|
292
|
+
|
|
293
|
+
- **Guards are immutable once created!** Ensure your validation logic is correct before creating.
|
|
294
|
+
- **Root must return Bool type**, otherwise validation will fail.
|
|
295
|
+
- **Identifier range is 0-255**, values outside this range will cause errors.
|
|
296
|
+
- **Dependent Guards must already exist**, otherwise creation will fail.
|
|
297
|
+
|
|
298
|
+
### Examples
|
|
299
|
+
|
|
300
|
+
#### Example 1.0: Always True Guard (Simplest Guard)
|
|
301
|
+
|
|
302
|
+
**Prompt**: Create the simplest Guard that always returns true. This Guard has no validation logic and always passes. Useful for testing or as a placeholder Guard.
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"operation_type": "guard",
|
|
307
|
+
"data": {
|
|
308
|
+
"namedNew": {
|
|
309
|
+
"name": "always_true_guard",
|
|
310
|
+
"onChain": true
|
|
311
|
+
},
|
|
312
|
+
"description": "A simple guard that always returns true for testing purposes",
|
|
313
|
+
"table": [
|
|
314
|
+
{
|
|
315
|
+
"identifier": 0,
|
|
316
|
+
"b_submission": false,
|
|
317
|
+
"value_type": "Bool",
|
|
318
|
+
"value": true
|
|
319
|
+
}
|
|
320
|
+
],
|
|
321
|
+
"root": {
|
|
322
|
+
"type": "node",
|
|
323
|
+
"node": {
|
|
324
|
+
"type": "identifier",
|
|
325
|
+
"identifier": 0
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
"env": {
|
|
330
|
+
"account": "",
|
|
331
|
+
"network": "testnet"
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**Execution Result**:
|
|
337
|
+
```json
|
|
338
|
+
{
|
|
339
|
+
"status": "success",
|
|
340
|
+
"object": "0x3d0e02...6a5ad",
|
|
341
|
+
"type": "Guard",
|
|
342
|
+
"version": "10316067",
|
|
343
|
+
"change": "created"
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
#### Example 1.1: Minimal Guard (root only, no naming)
|
|
350
|
+
|
|
351
|
+
**Prompt**: Create a simple Guard that verifies if an age is at least 18. The age will be provided by the user, and the minimum age is fixed at 18. Do not give the Guard a name.
|
|
352
|
+
|
|
353
|
+
```json
|
|
354
|
+
{
|
|
355
|
+
"operation_type": "guard",
|
|
356
|
+
"data": {
|
|
357
|
+
"table": [
|
|
358
|
+
{
|
|
359
|
+
"identifier": 0,
|
|
360
|
+
"b_submission": true,
|
|
361
|
+
"value_type": "U64",
|
|
362
|
+
"name": "age"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"identifier": 1,
|
|
366
|
+
"b_submission": false,
|
|
367
|
+
"value_type": "U64",
|
|
368
|
+
"value": "18",
|
|
369
|
+
"name": "min_age"
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"root": {
|
|
373
|
+
"type": "node",
|
|
374
|
+
"node": {
|
|
375
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
376
|
+
"nodes": [
|
|
377
|
+
{ "type": "identifier", "identifier": 0 },
|
|
378
|
+
{ "type": "identifier", "identifier": 1 }
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
"env": {
|
|
384
|
+
"account": "",
|
|
385
|
+
"network": "testnet"
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
#### Example 1.2: Complete Guard with Name, Tags, and Description
|
|
393
|
+
|
|
394
|
+
**Prompt**: Create an age verification Guard that checks if age is at least 18. Name this Guard "public_age_check", add tags "age", "verification", and "public", add a description explaining its purpose.
|
|
395
|
+
|
|
396
|
+
```json
|
|
397
|
+
{
|
|
398
|
+
"operation_type": "guard",
|
|
399
|
+
"data": {
|
|
400
|
+
"namedNew": {
|
|
401
|
+
"name": "public_age_check",
|
|
402
|
+
"tags": ["age", "verification", "public"]
|
|
403
|
+
},
|
|
404
|
+
"description": "Public age verification Guard - validates age is at least 18",
|
|
405
|
+
"table": [
|
|
406
|
+
{
|
|
407
|
+
"identifier": 0,
|
|
408
|
+
"b_submission": true,
|
|
409
|
+
"value_type": "U64",
|
|
410
|
+
"name": "age"
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
"identifier": 1,
|
|
414
|
+
"b_submission": false,
|
|
415
|
+
"value_type": "U64",
|
|
416
|
+
"value": "18",
|
|
417
|
+
"name": "min_age"
|
|
418
|
+
}
|
|
419
|
+
],
|
|
420
|
+
"root": {
|
|
421
|
+
"type": "node",
|
|
422
|
+
"node": {
|
|
423
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
424
|
+
"nodes": [
|
|
425
|
+
{ "type": "identifier", "identifier": 0 },
|
|
426
|
+
{ "type": "identifier", "identifier": 1 }
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
"env": {
|
|
432
|
+
"account": "",
|
|
433
|
+
"network": "testnet"
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
#### Example 1.3: Order Validation Guard with Multiple Conditions
|
|
441
|
+
|
|
442
|
+
**Prompt**: Create an order validation Guard that checks two conditions: quantity must be greater than 0, and quantity must be less than or equal to available stock. Name this Guard "order_validation", add tags "order", "validation", and "ecommerce", and add a description.
|
|
443
|
+
|
|
444
|
+
```json
|
|
445
|
+
{
|
|
446
|
+
"operation_type": "guard",
|
|
447
|
+
"data": {
|
|
448
|
+
"namedNew": {
|
|
449
|
+
"name": "order_validation",
|
|
450
|
+
"tags": ["order", "validation", "ecommerce"]
|
|
451
|
+
},
|
|
452
|
+
"description": "Order validation Guard - validates quantity is between 0 and available stock",
|
|
453
|
+
"table": [
|
|
454
|
+
{
|
|
455
|
+
"identifier": 0,
|
|
456
|
+
"b_submission": true,
|
|
457
|
+
"value_type": "U64",
|
|
458
|
+
"name": "quantity"
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
"identifier": 1,
|
|
462
|
+
"b_submission": false,
|
|
463
|
+
"value_type": "U64",
|
|
464
|
+
"value": "0",
|
|
465
|
+
"name": "min_quantity"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
"identifier": 2,
|
|
469
|
+
"b_submission": true,
|
|
470
|
+
"value_type": "U64",
|
|
471
|
+
"name": "stock"
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
"root": {
|
|
475
|
+
"type": "node",
|
|
476
|
+
"node": {
|
|
477
|
+
"type": "logic_and",
|
|
478
|
+
"nodes": [
|
|
479
|
+
{
|
|
480
|
+
"type": "logic_as_u256_greater",
|
|
481
|
+
"nodes": [
|
|
482
|
+
{ "type": "identifier", "identifier": 0 },
|
|
483
|
+
{ "type": "identifier", "identifier": 1 }
|
|
484
|
+
]
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
"type": "logic_as_u256_lesser_or_equal",
|
|
488
|
+
"nodes": [
|
|
489
|
+
{ "type": "identifier", "identifier": 0 },
|
|
490
|
+
{ "type": "identifier", "identifier": 2 }
|
|
491
|
+
]
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
"env": {
|
|
498
|
+
"account": "",
|
|
499
|
+
"network": "testnet"
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
---
|
|
505
|
+
|
|
506
|
+
#### Example 1.4: Guard with Dependencies (AND Logic)
|
|
507
|
+
|
|
508
|
+
**Prompt**: Create a composite Guard named "composite_guard" that depends on both "order_validation" and "public_age_check". Both dependent Guards must pass for this Guard to pass (use AND logic). Also verify that age is greater than or equal to 18.
|
|
509
|
+
|
|
510
|
+
```json
|
|
511
|
+
{
|
|
512
|
+
"operation_type": "guard",
|
|
513
|
+
"data": {
|
|
514
|
+
"namedNew": {
|
|
515
|
+
"name": "composite_guard"
|
|
516
|
+
},
|
|
517
|
+
"table": [
|
|
518
|
+
{
|
|
519
|
+
"identifier": 0,
|
|
520
|
+
"b_submission": true,
|
|
521
|
+
"value_type": "U64",
|
|
522
|
+
"name": "age"
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
"identifier": 1,
|
|
526
|
+
"b_submission": false,
|
|
527
|
+
"value_type": "U64",
|
|
528
|
+
"value": "18",
|
|
529
|
+
"name": "min_age"
|
|
530
|
+
}
|
|
531
|
+
],
|
|
532
|
+
"root": {
|
|
533
|
+
"type": "node",
|
|
534
|
+
"node": {
|
|
535
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
536
|
+
"nodes": [
|
|
537
|
+
{ "type": "identifier", "identifier": 0 },
|
|
538
|
+
{ "type": "identifier", "identifier": 1 }
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
"rely": {
|
|
543
|
+
"guards": ["order_validation", "public_age_check"],
|
|
544
|
+
"logic_or": false
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
"env": {
|
|
548
|
+
"account": "",
|
|
549
|
+
"network": "testnet"
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
---
|
|
555
|
+
|
|
556
|
+
#### Example 1.5: Guard with Dependencies (OR Logic)
|
|
557
|
+
|
|
558
|
+
**Prompt**: Create a flexible Guard named "flexible_guard" that depends on either "order_validation" or "public_age_check". Only one of the dependent Guards needs to pass for this Guard to pass (use OR logic). Also verify that a dummy value equals 0.
|
|
559
|
+
|
|
560
|
+
```json
|
|
561
|
+
{
|
|
562
|
+
"operation_type": "guard",
|
|
563
|
+
"data": {
|
|
564
|
+
"namedNew": {
|
|
565
|
+
"name": "flexible_guard"
|
|
566
|
+
},
|
|
567
|
+
"table": [
|
|
568
|
+
{
|
|
569
|
+
"identifier": 0,
|
|
570
|
+
"b_submission": true,
|
|
571
|
+
"value_type": "U64",
|
|
572
|
+
"name": "dummy_value"
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
"identifier": 1,
|
|
576
|
+
"b_submission": false,
|
|
577
|
+
"value_type": "U64",
|
|
578
|
+
"value": "0",
|
|
579
|
+
"name": "zero"
|
|
580
|
+
}
|
|
581
|
+
],
|
|
582
|
+
"root": {
|
|
583
|
+
"type": "node",
|
|
584
|
+
"node": {
|
|
585
|
+
"type": "logic_as_u256_equal",
|
|
586
|
+
"nodes": [
|
|
587
|
+
{ "type": "identifier", "identifier": 0 },
|
|
588
|
+
{ "type": "identifier", "identifier": 1 }
|
|
589
|
+
]
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
"rely": {
|
|
593
|
+
"guards": ["order_validation", "public_age_check"],
|
|
594
|
+
"logic_or": true
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
"env": {
|
|
598
|
+
"account": "",
|
|
599
|
+
"network": "testnet"
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
#### Example 1.6: Complete Parameter Guard with All Fields
|
|
607
|
+
|
|
608
|
+
**Prompt**: Create a comprehensive Guard named "full_guard" with tags "complete" and "example". This Guard should verify two things: email contains "@" symbol, and age is >= 18. It should also depend on "public_age_check". Specify the network as testnet and use the default account.
|
|
609
|
+
|
|
610
|
+
```json
|
|
611
|
+
{
|
|
612
|
+
"operation_type": "guard",
|
|
613
|
+
"data": {
|
|
614
|
+
"namedNew": {
|
|
615
|
+
"name": "full_guard",
|
|
616
|
+
"tags": ["complete", "example"],
|
|
617
|
+
"onChain": false,
|
|
618
|
+
"replaceExistName": false
|
|
619
|
+
},
|
|
620
|
+
"description": "Complete parameter example Guard",
|
|
621
|
+
"table": [
|
|
622
|
+
{
|
|
623
|
+
"identifier": 0,
|
|
624
|
+
"b_submission": true,
|
|
625
|
+
"value_type": "String",
|
|
626
|
+
"name": "email"
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
"identifier": 1,
|
|
630
|
+
"b_submission": true,
|
|
631
|
+
"value_type": "U64",
|
|
632
|
+
"name": "age"
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
"identifier": 2,
|
|
636
|
+
"b_submission": false,
|
|
637
|
+
"value_type": "String",
|
|
638
|
+
"value": "@",
|
|
639
|
+
"name": "at_symbol"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
"identifier": 3,
|
|
643
|
+
"b_submission": false,
|
|
644
|
+
"value_type": "U64",
|
|
645
|
+
"value": "18",
|
|
646
|
+
"name": "min_age"
|
|
647
|
+
}
|
|
648
|
+
],
|
|
649
|
+
"root": {
|
|
650
|
+
"type": "node",
|
|
651
|
+
"node": {
|
|
652
|
+
"type": "logic_and",
|
|
653
|
+
"nodes": [
|
|
654
|
+
{
|
|
655
|
+
"type": "logic_string_contains",
|
|
656
|
+
"nodes": [
|
|
657
|
+
{ "type": "identifier", "identifier": 0 },
|
|
658
|
+
{ "type": "identifier", "identifier": 2 }
|
|
659
|
+
]
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
663
|
+
"nodes": [
|
|
664
|
+
{ "type": "identifier", "identifier": 1 },
|
|
665
|
+
{ "type": "identifier", "identifier": 3 }
|
|
666
|
+
]
|
|
667
|
+
}
|
|
668
|
+
]
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
"rely": {
|
|
672
|
+
"guards": ["public_age_check"],
|
|
673
|
+
"logic_or": false
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
"env": {
|
|
677
|
+
"account": "",
|
|
678
|
+
"network": "testnet"
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
---
|
|
684
|
+
|
|
685
|
+
## Sub-feature 2: Create Guard from File (type: "file")
|
|
686
|
+
|
|
687
|
+
### Feature Description
|
|
688
|
+
Load a Guard definition from a JSON or Markdown file through `root.type: "file"`. The file can contain all Guard fields, and fields defined in the schema will override the file content.
|
|
689
|
+
|
|
690
|
+
### Parameter Description
|
|
691
|
+
|
|
692
|
+
| Parameter Path | Type | Required | Description | Constraints |
|
|
693
|
+
|----------------|------|----------|-------------|-------------|
|
|
694
|
+
| `operation_type` | string | Yes | Operation type | Fixed value "guard" |
|
|
695
|
+
| `data.namedNew` | object | No | New Guard naming | Will override namedNew in file |
|
|
696
|
+
| `data.description` | string | No | Guard description | Will override description in file |
|
|
697
|
+
| `data.table` | array | No | Data table | Will override table in file |
|
|
698
|
+
| `data.root.type` | string | Yes | Root node type | Fixed value "file" |
|
|
699
|
+
| `data.root.file_path` | string | Yes | File path | JSON or Markdown file path |
|
|
700
|
+
| `data.root.format` | enum | No | File format | "json" (default) or "markdown" |
|
|
701
|
+
| `data.rely` | object | No | Dependent Guards | Will override rely in file |
|
|
702
|
+
| `env` | object | No | Execution environment | Same as above |
|
|
703
|
+
|
|
704
|
+
### Important Notes
|
|
705
|
+
|
|
706
|
+
⚠️ **When using type: "file"**, fields defined in the schema (namedNew, description, table, rely) will override corresponding fields in the file.
|
|
707
|
+
|
|
708
|
+
⚠️ **File paths**: Both absolute and relative paths are supported.
|
|
709
|
+
|
|
710
|
+
### Examples
|
|
711
|
+
|
|
712
|
+
First, let's create a sample JSON file that we'll use in the examples.
|
|
713
|
+
|
|
714
|
+
**File: guard-definition.json**
|
|
715
|
+
```json
|
|
716
|
+
{
|
|
717
|
+
"description": "Guard loaded from file",
|
|
718
|
+
"table": [
|
|
719
|
+
{
|
|
720
|
+
"identifier": 0,
|
|
721
|
+
"b_submission": true,
|
|
722
|
+
"value_type": "U64",
|
|
723
|
+
"name": "amount"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
"identifier": 1,
|
|
727
|
+
"b_submission": false,
|
|
728
|
+
"value_type": "U64",
|
|
729
|
+
"value": "100",
|
|
730
|
+
"name": "min_amount"
|
|
731
|
+
}
|
|
732
|
+
],
|
|
733
|
+
"root": {
|
|
734
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
735
|
+
"nodes": [
|
|
736
|
+
{ "type": "identifier", "identifier": 0 },
|
|
737
|
+
{ "type": "identifier", "identifier": 1 }
|
|
738
|
+
]
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
---
|
|
744
|
+
|
|
745
|
+
#### Example 2.1: Create from JSON File (No Override)
|
|
746
|
+
|
|
747
|
+
**Prompt**: Create a Guard using the definition from guard-definition.json. Use the file exactly as it is without overriding any fields.
|
|
748
|
+
|
|
749
|
+
```json
|
|
750
|
+
{
|
|
751
|
+
"operation_type": "guard",
|
|
752
|
+
"data": {
|
|
753
|
+
"root": {
|
|
754
|
+
"type": "file",
|
|
755
|
+
"file_path": "...",
|
|
756
|
+
"format": "json"
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
764
|
+
#### Example 2.2: Create from JSON File and Override namedNew
|
|
765
|
+
|
|
766
|
+
**Prompt**: Create a Guard from guard-definition.json, but give it a custom name "file_based_guard" and add tags "file" and "json".
|
|
767
|
+
|
|
768
|
+
```json
|
|
769
|
+
{
|
|
770
|
+
"operation_type": "guard",
|
|
771
|
+
"data": {
|
|
772
|
+
"namedNew": {
|
|
773
|
+
"name": "file_based_guard",
|
|
774
|
+
"tags": ["file", "json"]
|
|
775
|
+
},
|
|
776
|
+
"root": {
|
|
777
|
+
"type": "file",
|
|
778
|
+
"file_path": "..."
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
---
|
|
785
|
+
|
|
786
|
+
#### Example 2.3: Create from JSON File and Override Multiple Fields
|
|
787
|
+
|
|
788
|
+
**Prompt**: Create a Guard from guard-definition.json, but override the description, table, and rely fields. Name it "custom_guard", change the minimum amount to 50, and make it depend on "order_validation".
|
|
789
|
+
|
|
790
|
+
```json
|
|
791
|
+
{
|
|
792
|
+
"operation_type": "guard",
|
|
793
|
+
"data": {
|
|
794
|
+
"namedNew": {
|
|
795
|
+
"name": "custom_guard"
|
|
796
|
+
},
|
|
797
|
+
"description": "Overridden description",
|
|
798
|
+
"table": [
|
|
799
|
+
{
|
|
800
|
+
"identifier": 0,
|
|
801
|
+
"b_submission": true,
|
|
802
|
+
"value_type": "U64",
|
|
803
|
+
"name": "custom_amount"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
"identifier": 1,
|
|
807
|
+
"b_submission": false,
|
|
808
|
+
"value_type": "U64",
|
|
809
|
+
"value": "50",
|
|
810
|
+
"name": "custom_min"
|
|
811
|
+
}
|
|
812
|
+
],
|
|
813
|
+
"root": {
|
|
814
|
+
"type": "file",
|
|
815
|
+
"file_path": "..."
|
|
816
|
+
},
|
|
817
|
+
"rely": {
|
|
818
|
+
"guards": ["order_validation"],
|
|
819
|
+
"logic_or": false
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
---
|
|
826
|
+
|
|
827
|
+
## Sub-feature 3: Export Guard to File (guard2file)
|
|
828
|
+
|
|
829
|
+
### Feature Description
|
|
830
|
+
|
|
831
|
+
Use the `guard2file` tool to export a Guard object's definition from the blockchain to a local JSON or Markdown file. The exported file can be edited and used to create new Guard objects, enabling rapid reuse and reconstruction of validation rules.
|
|
832
|
+
|
|
833
|
+
**Core Benefits:**
|
|
834
|
+
- Quickly extract Guard definitions from ANY on-chain Guard
|
|
835
|
+
- Edit and refine validation logic offline
|
|
836
|
+
- Use exported files with "Create Guard from File" (Sub-feature 2) to build new Guards
|
|
837
|
+
- Create validation template libraries and backups
|
|
838
|
+
|
|
839
|
+
### Schema Tree (4-Level Structure)
|
|
840
|
+
|
|
841
|
+
```
|
|
842
|
+
guard2file (Guard to File)
|
|
843
|
+
├── guard (required)
|
|
844
|
+
│ └── [Guard name or Address/ID]
|
|
845
|
+
├── file_path (required)
|
|
846
|
+
│ └── [Output file path]
|
|
847
|
+
├── format (optional)
|
|
848
|
+
│ ├── "json" (default)
|
|
849
|
+
│ └── "markdown"
|
|
850
|
+
└── env (optional)
|
|
851
|
+
├── account (optional)
|
|
852
|
+
├── permission_guard (optional)
|
|
853
|
+
├── no_cache (optional)
|
|
854
|
+
├── network (optional)
|
|
855
|
+
└── referrer (optional)
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
### Parameter Description
|
|
859
|
+
|
|
860
|
+
| Parameter Path | Type | Required | Description | Constraints |
|
|
861
|
+
|----------------|------|----------|-------------|-------------|
|
|
862
|
+
| `guard` | string | Yes | Guard object ID or name to export | Use name (preferred) or ID |
|
|
863
|
+
| `file_path` | string | Yes | Output file path | Absolute or relative path |
|
|
864
|
+
| `format` | enum | No | Output format | "json" (default) or "markdown" |
|
|
865
|
+
| `env.account` | string | No | Use specified account | Empty string '' uses default account |
|
|
866
|
+
| `env.network` | enum | No | Network selection | "localnet" or "testnet" |
|
|
867
|
+
| `env.no_cache` | boolean | No | Disable caching | true=bypass cache |
|
|
868
|
+
|
|
869
|
+
### Important Notes
|
|
870
|
+
|
|
871
|
+
⚠️ **This is a read-only operation!** Does not modify any on-chain state.
|
|
872
|
+
|
|
873
|
+
⚠️ **Use names instead of 0x addresses!** Reference Guards by name for clarity.
|
|
874
|
+
|
|
875
|
+
⚠️ **Exported file matches Guard structure!** The output format is compatible with "Create Guard from File" (Sub-feature 2).
|
|
876
|
+
|
|
877
|
+
### Return Result
|
|
878
|
+
|
|
879
|
+
Returns the exported file path, format, and Guard object:
|
|
880
|
+
|
|
881
|
+
```json
|
|
882
|
+
{
|
|
883
|
+
"result": {
|
|
884
|
+
"status": "success",
|
|
885
|
+
"data": {
|
|
886
|
+
"file_path": "./exported_guard.json",
|
|
887
|
+
"format": "json",
|
|
888
|
+
"guard_object": "public_age_check"
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
```
|
|
893
|
+
|
|
894
|
+
---
|
|
895
|
+
|
|
896
|
+
### Examples
|
|
897
|
+
|
|
898
|
+
#### Example 3.1: Export to JSON (Default Format)
|
|
899
|
+
|
|
900
|
+
**Prompt**: Export the "order_validation" Guard to a JSON file named "order_validation_export.json".
|
|
901
|
+
|
|
902
|
+
```json
|
|
903
|
+
{
|
|
904
|
+
"guard": "order_validation",
|
|
905
|
+
"file_path": "./order_validation_export.json"
|
|
906
|
+
}
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
#### Example 3.2: Export to Markdown Format
|
|
910
|
+
|
|
911
|
+
**Prompt**: Export the "public_age_check" Guard to a Markdown file for documentation.
|
|
912
|
+
|
|
913
|
+
```json
|
|
914
|
+
{
|
|
915
|
+
"guard": "public_age_check",
|
|
916
|
+
"file_path": "public_age_check.md",
|
|
917
|
+
"format": "markdown"
|
|
918
|
+
}
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
#### Example 3.3: Export with Custom Network
|
|
922
|
+
|
|
923
|
+
**Prompt**: Export "public_template" Guard from testnet to "template_backup.json".
|
|
924
|
+
|
|
925
|
+
```json
|
|
926
|
+
{
|
|
927
|
+
"guard": "public_template",
|
|
928
|
+
"file_path": "template_backup.json",
|
|
929
|
+
"format": "json",
|
|
930
|
+
"env": {
|
|
931
|
+
"network": "testnet"
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
#### Example 3.4: Guard Reuse Pattern
|
|
937
|
+
|
|
938
|
+
**Prompt**: Export "proven_guard" definition, edit to create a new variant, then use Sub-feature 2 to import into a new Guard.
|
|
939
|
+
|
|
940
|
+
Step 1: Export
|
|
941
|
+
```json
|
|
942
|
+
{
|
|
943
|
+
"guard": "proven_guard",
|
|
944
|
+
"file_path": "guard_template.json"
|
|
945
|
+
}
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
Step 2: Edit `guard_template.json` (modify validation logic as needed)
|
|
949
|
+
|
|
950
|
+
Step 3: Import into new Guard (see Sub-feature 2)
|
|
951
|
+
```json
|
|
952
|
+
{
|
|
953
|
+
"operation_type": "guard",
|
|
954
|
+
"data": {
|
|
955
|
+
"namedNew": {
|
|
956
|
+
"name": "new_guard_variant"
|
|
957
|
+
},
|
|
958
|
+
"root": {
|
|
959
|
+
"type": "file",
|
|
960
|
+
"file_path": "guard_template.json"
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
---
|
|
967
|
+
|
|
968
|
+
## Sub-feature 4: Generate Verified Passport (gen_passport)
|
|
969
|
+
|
|
970
|
+
### Feature Description
|
|
971
|
+
|
|
972
|
+
Generate an immutable verified Passport object after Guard validation passes. Passports can be used for offline friend verification in Messenger, transaction condition verification, and more.
|
|
973
|
+
|
|
974
|
+
**Core Benefits:**
|
|
975
|
+
- Create verifiable credentials that prove Guard validation passed
|
|
976
|
+
- Use Passports in Messenger to verify strangers before accepting messages
|
|
977
|
+
- Passports are immutable and tamper-proof on-chain
|
|
978
|
+
- Enables trust-based interactions without direct on-chain validation every time
|
|
979
|
+
|
|
980
|
+
### Schema Tree (4-Level Structure)
|
|
981
|
+
|
|
982
|
+
```
|
|
983
|
+
gen_passport (Generate Verified Passport)
|
|
984
|
+
├── operation_type: "gen_passport" (fixed)
|
|
985
|
+
├── guard (required)
|
|
986
|
+
│ └── [Guard name or Address/ID]
|
|
987
|
+
├── info (optional)
|
|
988
|
+
│ └── [Submission data]
|
|
989
|
+
└── env (optional)
|
|
990
|
+
├── account (optional)
|
|
991
|
+
├── permission_guard (optional)
|
|
992
|
+
├── no_cache (optional)
|
|
993
|
+
├── network (optional)
|
|
994
|
+
└── referrer (optional)
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
### Parameter Description
|
|
998
|
+
|
|
999
|
+
| Parameter Path | Type | Required | Description | Constraints |
|
|
1000
|
+
|----------------|------|----------|-------------|-------------|
|
|
1001
|
+
| `operation_type` | string | Yes | Operation type | Fixed value "gen_passport" |
|
|
1002
|
+
| `guard` | string \| string[] | Yes | Guard object ID(s) to verify and generate passport from | Single guard (string) or multiple guards (array). Supports names or addresses |
|
|
1003
|
+
| `info` | object | No | Optional submission data | If not provided, will attempt to get existing submissions from the guard |
|
|
1004
|
+
| `env.account` | string | No | Use specified account | Empty string '' uses default account |
|
|
1005
|
+
| `env.network` | enum | No | Network selection | "localnet" or "testnet" |
|
|
1006
|
+
|
|
1007
|
+
### Features
|
|
1008
|
+
|
|
1009
|
+
- **Single Guard**: Pass a single guard ID or name as a string
|
|
1010
|
+
- **Multiple Guards**: Pass an array of guard IDs or names to verify multiple guards at once
|
|
1011
|
+
- **Name Resolution**: Supports both guard addresses and LocalMark names
|
|
1012
|
+
|
|
1013
|
+
### Important Notes
|
|
1014
|
+
|
|
1015
|
+
⚠️ **Guard validation must pass!** The Passport is only generated if the Guard validation succeeds.
|
|
1016
|
+
|
|
1017
|
+
⚠️ **Passports are immutable!** Once created, Passports cannot be modified.
|
|
1018
|
+
|
|
1019
|
+
⚠️ **Use names instead of 0x addresses!** Reference Guards by name for clarity.
|
|
1020
|
+
|
|
1021
|
+
⚠️ **Messenger integration!** Passports can be used in Messenger tools to verify strangers before accepting messages.
|
|
1022
|
+
|
|
1023
|
+
### Return Result
|
|
1024
|
+
|
|
1025
|
+
Returns the created Passport object.
|
|
1026
|
+
|
|
1027
|
+
---
|
|
1028
|
+
|
|
1029
|
+
### Examples
|
|
1030
|
+
|
|
1031
|
+
#### Example 4.1: Generate Passport with Submission Data
|
|
1032
|
+
|
|
1033
|
+
**Prompt**: Generate a Passport using the "public_age_check" Guard. Submit age 25 to pass validation.
|
|
1034
|
+
|
|
1035
|
+
```json
|
|
1036
|
+
{
|
|
1037
|
+
"operation_type": "gen_passport",
|
|
1038
|
+
"guard": "public_age_check",
|
|
1039
|
+
"info": {
|
|
1040
|
+
"submissions": [
|
|
1041
|
+
{
|
|
1042
|
+
"identifier": 0,
|
|
1043
|
+
"value": "25"
|
|
1044
|
+
}
|
|
1045
|
+
]
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
#### Example 4.2: Generate Passport with Existing Submissions
|
|
1051
|
+
|
|
1052
|
+
**Prompt**: Generate a Passport from "order_validation" Guard, using existing submissions already attached to the Guard.
|
|
1053
|
+
|
|
1054
|
+
```json
|
|
1055
|
+
{
|
|
1056
|
+
"operation_type": "gen_passport",
|
|
1057
|
+
"guard": "order_validation"
|
|
1058
|
+
}
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
#### Example 4.3: Generate Passport with Custom Network
|
|
1062
|
+
|
|
1063
|
+
**Prompt**: Generate a Passport from "identity_verify" Guard on testnet.
|
|
1064
|
+
|
|
1065
|
+
```json
|
|
1066
|
+
{
|
|
1067
|
+
"operation_type": "gen_passport",
|
|
1068
|
+
"guard": "identity_verify",
|
|
1069
|
+
"info": {
|
|
1070
|
+
"submissions": [
|
|
1071
|
+
{
|
|
1072
|
+
"identifier": 0,
|
|
1073
|
+
"value": "verified_user"
|
|
1074
|
+
}
|
|
1075
|
+
]
|
|
1076
|
+
},
|
|
1077
|
+
"env": {
|
|
1078
|
+
"network": "testnet"
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
```
|
|
1082
|
+
|
|
1083
|
+
#### Example 4.4: Passport Usage in Messenger
|
|
1084
|
+
|
|
1085
|
+
**Prompt**: Use a Passport to verify a stranger in Messenger. First generate the Passport, then reference it in Messenger's permission checks.
|
|
1086
|
+
|
|
1087
|
+
Step 1: Generate Passport
|
|
1088
|
+
```json
|
|
1089
|
+
{
|
|
1090
|
+
"operation_type": "gen_passport",
|
|
1091
|
+
"guard": "friend_verification",
|
|
1092
|
+
"info": {
|
|
1093
|
+
"submissions": [
|
|
1094
|
+
{
|
|
1095
|
+
"identifier": 0,
|
|
1096
|
+
"value": "mutual_friend_verified"
|
|
1097
|
+
}
|
|
1098
|
+
]
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
Step 2: Use Passport in Messenger (see [messenger.md](messenger.md)) to verify strangers before accepting messages.
|
|
1104
|
+
|
|
1105
|
+
---
|
|
1106
|
+
|
|
1107
|
+
## Constraint Constants
|
|
1108
|
+
|
|
1109
|
+
| Constant Name | Value | Description |
|
|
1110
|
+
|---------------|-------|-------------|
|
|
1111
|
+
| `identifierMin` | 0 | Minimum identifier value |
|
|
1112
|
+
| `identifierMax` | 255 | Maximum identifier value |
|
|
1113
|
+
| `nameMaxLength` | 64 | Maximum name length (BCS characters) |
|
|
1114
|
+
| `maxMultiOperands` | 8 | Maximum operands for multi-operand nodes |
|
|
1115
|
+
|
|
1116
|
+
---
|
|
1117
|
+
|
|
1118
|
+
## Guard Node Type Reference
|
|
1119
|
+
|
|
1120
|
+
### Logic Operation Nodes (Return Bool)
|
|
1121
|
+
|
|
1122
|
+
| Node Type | Description | Parameters |
|
|
1123
|
+
|-----------|-------------|------------|
|
|
1124
|
+
| `logic_and` | Logical AND | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1125
|
+
| `logic_or` | Logical OR | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1126
|
+
| `logic_not` | Logical NOT | `node: GuardNode` |
|
|
1127
|
+
| `logic_equal` | Equality comparison | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1128
|
+
| `logic_as_u256_greater` | Greater than | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1129
|
+
| `logic_as_u256_lesser` | Less than | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1130
|
+
| `logic_as_u256_greater_or_equal` | Greater than or equal | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1131
|
+
| `logic_as_u256_lesser_or_equal` | Less than or equal | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1132
|
+
| `logic_as_u256_equal` | Numeric equality | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1133
|
+
| `logic_string_contains` | String contains | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1134
|
+
| `logic_string_nocase_contains` | String contains (case-insensitive) | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1135
|
+
| `logic_string_nocase_equal` | String equality (case-insensitive) | `nodes: GuardNode[]` (2-8 nodes) |
|
|
1136
|
+
|
|
1137
|
+
### Data Nodes
|
|
1138
|
+
|
|
1139
|
+
| Node Type | Return Type | Description | Parameters |
|
|
1140
|
+
|-----------|-------------|-------------|------------|
|
|
1141
|
+
| `identifier` | Depends on table item | Reference data from table | `identifier: number` (0-255) |
|
|
1142
|
+
| `query` | Depends on query | Query on-chain object data | `query: string`, `object: { identifier: number }`, `parameters: GuardNode[]` |
|
|
1143
|
+
| `context` | Depends on context | System context information | `context: "Signer" \| "Clock" \| "Guard"` |
|
|
1144
|
+
|
|
1145
|
+
**Important**: Context nodes return non-bool types! Never use them directly in logic gates like logic_and or logic_or.
|
|
1146
|
+
|
|
1147
|
+
### Vector Operation Nodes
|
|
1148
|
+
|
|
1149
|
+
| Node Type | Return Type | Description | Parameters |
|
|
1150
|
+
|-----------|-------------|-------------|------------|
|
|
1151
|
+
| `vec_length` | U64 | Get vector length | `node: GuardNode` (must be Vec type) |
|
|
1152
|
+
| `vec_contains_bool` | Bool | Check if vector contains boolean values | `nodes: GuardNode[]` (2-8 nodes: VecBool + Bool values) |
|
|
1153
|
+
| `vec_contains_address` | Bool | Check if vector contains address values | `nodes: GuardNode[]` (2-8 nodes: VecAddress + Address values) |
|
|
1154
|
+
| `vec_contains_string` | Bool | Check if vector contains string values | `nodes: GuardNode[]` (2-8 nodes: VecString + String values) |
|
|
1155
|
+
| `vec_contains_string_nocase` | Bool | Check if vector contains strings (case-insensitive) | `nodes: GuardNode[]` (2-8 nodes: VecString + String values) |
|
|
1156
|
+
| `vec_contains_number` | Bool | Check if vector contains number values | `nodes: GuardNode[]` (2-8 nodes: VecU8-VecU256 + U8-U256 values) |
|
|
1157
|
+
| `vec_indexof_bool` | U64 | Find boolean in vector | `nodeLeft: GuardNode` (VecBool), `nodeRight: GuardNode` (Bool), `order: "forward" \| "backward"` |
|
|
1158
|
+
| `vec_indexof_address` | U64 | Find address in vector | `nodeLeft: GuardNode` (VecAddress), `nodeRight: GuardNode` (Address), `order: "forward" \| "backward"` |
|
|
1159
|
+
| `vec_indexof_string` | U64 | Find string in vector | `nodeLeft: GuardNode` (VecString), `nodeRight: GuardNode` (String), `order: "forward" \| "backward"` |
|
|
1160
|
+
| `vec_indexof_string_nocase` | U64 | Find string in vector (case-insensitive) | `nodeLeft: GuardNode` (VecString), `nodeRight: GuardNode` (String), `order: "forward" \| "backward"` |
|
|
1161
|
+
| `vec_indexof_number` | U64 | Find number in vector | `nodeLeft: GuardNode` (VecU8-VecU256), `nodeRight: GuardNode` (U8-U256), `order: "forward" \| "backward"` |
|
|
1162
|
+
|
|
1163
|
+
### Reward Record Query Nodes
|
|
1164
|
+
|
|
1165
|
+
| Node Type | Return Type | Description | Parameters |
|
|
1166
|
+
|-----------|-------------|-------------|------------|
|
|
1167
|
+
| `query_reward_record_find` | Value | Find first/last reward record matching filters | `object: { identifier: number }`, `find: "first" \| "last"`, `recipient: GuardNode`, `where: { guard?, timeMin?, timeMax?, amountMin?, amountMax?, storeFromId? }` |
|
|
1168
|
+
| `query_reward_record_count` | U64 | Count reward records matching filters | `object: { identifier: number }`, `recipient: GuardNode`, `where: { guard?, timeMin?, timeMax?, amountMin?, amountMax?, storeFromId? }` |
|
|
1169
|
+
| `query_reward_record_exists` | Bool | Check if reward record exists matching filters | `object: { identifier: number }`, `recipient: GuardNode`, `where: { guard?, timeMin?, timeMax?, amountMin?, amountMax?, storeFromId? }` |
|
|
1170
|
+
|
|
1171
|
+
### Progress History Query Nodes
|
|
1172
|
+
|
|
1173
|
+
| Node Type | Return Type | Description | Parameters |
|
|
1174
|
+
|-----------|-------------|-------------|------------|
|
|
1175
|
+
| `query_progress_history_find` | Value | Find first/last history entry | `object: { identifier: number }`, `where: { node?, nextNode?, timeMin?, timeMax?, indexMin?, indexMax? }`, `find: "first" \| "last"` |
|
|
1176
|
+
| `query_progress_history_session_find` | Value | Find first/last session in history | `object: { identifier: number }`, `historyIdx: GuardNode`, `where: { nextNode? }`, `find: "first" \| "last"` |
|
|
1177
|
+
| `query_progress_history_session_forward_find` | Value | Find first/last forward operation | `object: { identifier: number }`, `historyIdx: GuardNode`, `sessionIdx: GuardNode`, `where: { who?, operation?, accomplished?, timeMin?, timeMax? }`, `find: "first" \| "last"` |
|
|
1178
|
+
| `query_progress_history_session_count` | U64 | Count sessions in history entry | `object: { identifier: number }`, `historyIdx: GuardNode` |
|
|
1179
|
+
| `query_progress_history_session_forward_count` | U64 | Count forward operations in session | `object: { identifier: number }`, `historyIdx: GuardNode`, `sessionIdx: GuardNode` |
|
|
1180
|
+
| `query_progress_history_session_forward_retained_submission_count` | U64 | Count retained submissions in forward | `object: { identifier: number }`, `historyIdx: GuardNode`, `sessionIdx: GuardNode`, `forwardIdx: GuardNode` |
|
|
1181
|
+
|
|
1182
|
+
**Note on Range Filter Types**: All time and amount range filters (`timeMin`, `timeMax`, `amountMin`, `amountMax`, `indexMin`, `indexMax`) use **string type** to represent U64 values. This ensures compatibility with JavaScript's number precision limitations.
|
|
1183
|
+
|
|
1184
|
+
---
|
|
1185
|
+
|
|
1186
|
+
## Query Instructions and Witness Types
|
|
1187
|
+
|
|
1188
|
+
### Overview
|
|
1189
|
+
|
|
1190
|
+
Guards can access data from ANY on-chain object using `query` nodes! This is a powerful feature that allows you to build validation logic based on real-time on-chain state.
|
|
1191
|
+
|
|
1192
|
+
### Query Node Structure
|
|
1193
|
+
|
|
1194
|
+
```json
|
|
1195
|
+
{
|
|
1196
|
+
"type": "query",
|
|
1197
|
+
"query": 1253,
|
|
1198
|
+
"object": {
|
|
1199
|
+
"identifier": 0,
|
|
1200
|
+
"convert_witness": 100
|
|
1201
|
+
},
|
|
1202
|
+
"parameters": []
|
|
1203
|
+
}
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
**Parameters:**
|
|
1207
|
+
- `query`: Query instruction ID (number) or name (string). Use the `wowok_buildin_info` tool with `'guard instructions'` to query all available IDs.
|
|
1208
|
+
- `object.identifier`: References the object ID from the Guard table (identifier 0-255).
|
|
1209
|
+
- `object.convert_witness` (optional): **Critical for cross-object queries!** When specified, the query retrieves data from an associated object instead of the object itself.
|
|
1210
|
+
|
|
1211
|
+
### Special System Addresses for Entity Queries
|
|
1212
|
+
|
|
1213
|
+
When querying **EntityLinker** or **EntityRegistrar** data, use these system addresses in the Guard table:
|
|
1214
|
+
|
|
1215
|
+
| System Address | Value | Description |
|
|
1216
|
+
|----------------|-------|-------------|
|
|
1217
|
+
| `ENTITY_LINKER_ADDRESS` | `0xaaa` | Use for EntityLinker queries |
|
|
1218
|
+
| `ENTITY_REGISTRAR_ADDRESS` | `0xaab` | Use for EntityRegistrar queries |
|
|
1219
|
+
|
|
1220
|
+
**Example**: To query entity registration data, set `object.identifier` to reference a Guard table entry containing `0xaaa` (for EntityLinker) or `0xaab` (for EntityRegistrar).
|
|
1221
|
+
|
|
1222
|
+
### Witness Types for Cross-Object Queries
|
|
1223
|
+
|
|
1224
|
+
When you submit one object type but need to query data from a related object, use `convert_witness`:
|
|
1225
|
+
|
|
1226
|
+
| Witness Type | Value | Description | Use Case |
|
|
1227
|
+
|--------------|-------|-------------|----------|
|
|
1228
|
+
| `TypeOrderProgress` | 100 | Order → Progress | Query order's progress status |
|
|
1229
|
+
| `TypeOrderMachine` | 101 | Order → Machine | Query order's workflow machine |
|
|
1230
|
+
| `TypeOrderService` | 102 | Order → Service | Query order's service details |
|
|
1231
|
+
| `TypeProgressMachine` | 103 | Progress → Machine | Query progress's machine |
|
|
1232
|
+
| `TypeArbOrder` | 104 | Arbitration → Order | Query arbitration's order |
|
|
1233
|
+
| `TypeArbArbitration` | 105 | Arb → Arbitration | Query arb's arbitration |
|
|
1234
|
+
| `TypeArbProgress` | 106 | Arb → Progress | Query arb's progress |
|
|
1235
|
+
| `TypeArbMachine` | 107 | Arb → Machine | Query arb's machine |
|
|
1236
|
+
| `TypeArbService` | 108 | Arb → Service | Query arb's service |
|
|
1237
|
+
|
|
1238
|
+
### Common Progress Query Instructions
|
|
1239
|
+
|
|
1240
|
+
When querying Progress objects (directly or via witness), these instructions are frequently used:
|
|
1241
|
+
|
|
1242
|
+
| ID | Name | Return Type | Description | Parameters |
|
|
1243
|
+
|----|------|-------------|-------------|------------|
|
|
1244
|
+
| 1253 | `progress.current` | String | Current node name | None |
|
|
1245
|
+
| 1271 | `progress.session.forward.time` | U64 | Timestamp of specific operation | [next_node_name, forward_name] |
|
|
1246
|
+
| 1254 | `progress.task some` | Bool | Whether task object is set | None |
|
|
1247
|
+
| 1255 | `progress.task` | Address | Task object ID | None |
|
|
1248
|
+
| 1272 | `progress.history count` | U64 | Number of history records | None |
|
|
1249
|
+
|
|
1250
|
+
### New BCS Query Instructions (ID 1270-1276)
|
|
1251
|
+
|
|
1252
|
+
These instructions use BCS serialization for efficient querying:
|
|
1253
|
+
|
|
1254
|
+
| ID | Name | Return Type | Description | Query Parameters (BCS encoded) |
|
|
1255
|
+
|----|------|-------------|-------------|-------------------------------|
|
|
1256
|
+
| 1270 | `progress.history.find` | U64 | Find history index by conditions | `HistoryFindConditions`: `{ node?, next_node?, time_min?, time_max?, index_min?, index_max?, find }` |
|
|
1257
|
+
| 1271 | `progress.session.forward.time` | U64 | Get forward operation timestamp | `[next_node_name, forward_name]` |
|
|
1258
|
+
| 1275 | `progress.history.session.find` | U64 | Find session index in history | `SessionFindConditions`: `{ next_node?, find }` |
|
|
1259
|
+
| 1276 | `progress.history.session.forward.find` | U64 | Find forward operation index | `ForwardFindConditions`: `{ who?, operation?, accomplished?, time_min?, time_max?, find }` |
|
|
1260
|
+
| 1277 | `progress.history.session.count` | U64 | Count sessions in history | None |
|
|
1261
|
+
| 1278 | `progress.history.session.forward.count` | U64 | Count forward operations | None |
|
|
1262
|
+
| 1279 | `progress.history.session.forward.retained_submission.count` | U64 | Count retained submissions | None |
|
|
1263
|
+
|
|
1264
|
+
**Note**: For query instructions 1270, 1275, and 1276, use the corresponding Guard node types (`query_progress_history_find`, `query_progress_history_session_find`, `query_progress_history_session_forward_find`) which automatically handle BCS serialization.
|
|
1265
|
+
|
|
1266
|
+
### Example: Query Order's Progress Status
|
|
1267
|
+
|
|
1268
|
+
**Scenario**: Create a Guard that checks if an order has reached "Completed" status.
|
|
1269
|
+
|
|
1270
|
+
```json
|
|
1271
|
+
{
|
|
1272
|
+
"operation_type": "guard",
|
|
1273
|
+
"data": {
|
|
1274
|
+
"namedNew": {
|
|
1275
|
+
"name": "order_completed_guard"
|
|
1276
|
+
},
|
|
1277
|
+
"description": "Verify order is in Completed node. Submit order object ID.",
|
|
1278
|
+
"table": [
|
|
1279
|
+
{
|
|
1280
|
+
"identifier": 0,
|
|
1281
|
+
"b_submission": true,
|
|
1282
|
+
"value_type": "Address",
|
|
1283
|
+
"name": "order_id"
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
"identifier": 1,
|
|
1287
|
+
"b_submission": false,
|
|
1288
|
+
"value_type": "String",
|
|
1289
|
+
"value": "Completed",
|
|
1290
|
+
"name": "completed_node"
|
|
1291
|
+
}
|
|
1292
|
+
],
|
|
1293
|
+
"root": {
|
|
1294
|
+
"type": "node",
|
|
1295
|
+
"node": {
|
|
1296
|
+
"type": "logic_equal",
|
|
1297
|
+
"nodes": [
|
|
1298
|
+
{
|
|
1299
|
+
"type": "query",
|
|
1300
|
+
"query": 1253,
|
|
1301
|
+
"object": {
|
|
1302
|
+
"identifier": 0,
|
|
1303
|
+
"convert_witness": 100
|
|
1304
|
+
},
|
|
1305
|
+
"parameters": []
|
|
1306
|
+
},
|
|
1307
|
+
{
|
|
1308
|
+
"type": "identifier",
|
|
1309
|
+
"identifier": 1
|
|
1310
|
+
}
|
|
1311
|
+
]
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
"env": {
|
|
1316
|
+
"account": "",
|
|
1317
|
+
"network": "testnet"
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
**Key Points:**
|
|
1323
|
+
1. User submits `order_id` (identifier 0)
|
|
1324
|
+
2. Query uses `convert_witness: 100` (TypeOrderProgress) to access the order's Progress object
|
|
1325
|
+
3. Query ID `1253` (`progress.current`) retrieves the current node name
|
|
1326
|
+
4. Compares with "Completed" to verify order status
|
|
1327
|
+
|
|
1328
|
+
### Example: Check Order Completion Time
|
|
1329
|
+
|
|
1330
|
+
**Scenario**: Create a Guard that checks if an order was completed more than 15 days ago.
|
|
1331
|
+
|
|
1332
|
+
```json
|
|
1333
|
+
{
|
|
1334
|
+
"operation_type": "guard",
|
|
1335
|
+
"data": {
|
|
1336
|
+
"namedNew": {
|
|
1337
|
+
"name": "withdraw_guard"
|
|
1338
|
+
},
|
|
1339
|
+
"description": "Verify order completed > 15 days ago. Submit order object ID.",
|
|
1340
|
+
"table": [
|
|
1341
|
+
{
|
|
1342
|
+
"identifier": 0,
|
|
1343
|
+
"b_submission": true,
|
|
1344
|
+
"value_type": "Address",
|
|
1345
|
+
"name": "order_id"
|
|
1346
|
+
},
|
|
1347
|
+
{
|
|
1348
|
+
"identifier": 1,
|
|
1349
|
+
"b_submission": false,
|
|
1350
|
+
"value_type": "String",
|
|
1351
|
+
"value": "Completed",
|
|
1352
|
+
"name": "completed_node"
|
|
1353
|
+
},
|
|
1354
|
+
{
|
|
1355
|
+
"identifier": 2,
|
|
1356
|
+
"b_submission": false,
|
|
1357
|
+
"value_type": "String",
|
|
1358
|
+
"value": "Complete Order",
|
|
1359
|
+
"name": "forward_name"
|
|
1360
|
+
},
|
|
1361
|
+
{
|
|
1362
|
+
"identifier": 3,
|
|
1363
|
+
"b_submission": false,
|
|
1364
|
+
"value_type": "U64",
|
|
1365
|
+
"value": "1296000000",
|
|
1366
|
+
"name": "15_days_ms"
|
|
1367
|
+
}
|
|
1368
|
+
],
|
|
1369
|
+
"root": {
|
|
1370
|
+
"type": "node",
|
|
1371
|
+
"node": {
|
|
1372
|
+
"type": "logic_and",
|
|
1373
|
+
"nodes": [
|
|
1374
|
+
{
|
|
1375
|
+
"type": "logic_equal",
|
|
1376
|
+
"nodes": [
|
|
1377
|
+
{
|
|
1378
|
+
"type": "query",
|
|
1379
|
+
"query": 1253,
|
|
1380
|
+
"object": {
|
|
1381
|
+
"identifier": 0,
|
|
1382
|
+
"convert_witness": 100
|
|
1383
|
+
},
|
|
1384
|
+
"parameters": []
|
|
1385
|
+
},
|
|
1386
|
+
{
|
|
1387
|
+
"type": "identifier",
|
|
1388
|
+
"identifier": 1
|
|
1389
|
+
}
|
|
1390
|
+
]
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
"type": "logic_as_u256_greater_or_equal",
|
|
1394
|
+
"nodes": [
|
|
1395
|
+
{
|
|
1396
|
+
"type": "context",
|
|
1397
|
+
"context": "Clock"
|
|
1398
|
+
},
|
|
1399
|
+
{
|
|
1400
|
+
"type": "calc_number_add",
|
|
1401
|
+
"nodes": [
|
|
1402
|
+
{
|
|
1403
|
+
"type": "query",
|
|
1404
|
+
"query": 1271,
|
|
1405
|
+
"object": {
|
|
1406
|
+
"identifier": 0,
|
|
1407
|
+
"convert_witness": 100
|
|
1408
|
+
},
|
|
1409
|
+
"parameters": [
|
|
1410
|
+
{
|
|
1411
|
+
"type": "identifier",
|
|
1412
|
+
"identifier": 1
|
|
1413
|
+
},
|
|
1414
|
+
{
|
|
1415
|
+
"type": "identifier",
|
|
1416
|
+
"identifier": 2
|
|
1417
|
+
}
|
|
1418
|
+
]
|
|
1419
|
+
},
|
|
1420
|
+
{
|
|
1421
|
+
"type": "identifier",
|
|
1422
|
+
"identifier": 3
|
|
1423
|
+
}
|
|
1424
|
+
]
|
|
1425
|
+
}
|
|
1426
|
+
]
|
|
1427
|
+
}
|
|
1428
|
+
]
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
"env": {
|
|
1433
|
+
"account": "",
|
|
1434
|
+
"network": "testnet"
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
**Note**: The `context` node with `"Clock"` returns the current on-chain timestamp (U64).
|
|
1440
|
+
|
|
1441
|
+
---
|
|
1442
|
+
|
|
1443
|
+
## Query Instructions and On-chain Object Access
|
|
1444
|
+
|
|
1445
|
+
Guards can access data from ANY on-chain object using `query` nodes! Use the `wowok_buildin_info` tool with `'guard instructions'` to query the complete list of available operations.
|
|
1446
|
+
|
|
1447
|
+
---
|
|
1448
|
+
|
|
1449
|
+
## Related Components
|
|
1450
|
+
|
|
1451
|
+
| Component | Description |
|
|
1452
|
+
|-----------|-------------|
|
|
1453
|
+
| **[Service](service.md)** | WYSIWYG product trading - can bind Guards for service validation |
|
|
1454
|
+
| **[Demand](demand.md)** | Service requests - uses Guards to validate recommended services |
|
|
1455
|
+
| **[Machine](machine.md)** | Workflow template - uses Guards for workflow validation |
|
|
1456
|
+
| **[Progress](progress.md)** | Workflow instance - carries Guard validation during execution |
|
|
1457
|
+
| **[Order](order.md)** | Order management - uses Guards for order validation |
|
|
1458
|
+
| **[Reward](reward.md)** | Marketing incentives - uses Guards for claiming conditions |
|
|
1459
|
+
| **[Repository](repository.md)** | Data ownership - uses Guards for data write permissions |
|
|
1460
|
+
| **[Treasury](treasury.md)** | Team fund management - uses Guards for external operation validation |
|
|
1461
|
+
| **[Allocation](allocation.md)** | Automatic fund distribution - uses Guards for distribution conditions |
|
|
1462
|
+
| **[Arbitration](arbitration.md)** | Dispute resolution - uses Guards for arbitration validation |
|
|
1463
|
+
| **[Permission](permission.md)** | Permission management - Guards can be used as permission entities |
|
|
1464
|
+
| **[Messenger](messenger.md)** | Encrypted messaging - uses Guards for passport/reputation verification |
|
|
1465
|
+
| **[WoWok Build-in Info](wowok_buildin_info.md)** | Query guard instructions and value types |
|