wowok 1.5.56 → 1.6.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.5.56",
3
+ "version": "1.6.59",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -40,7 +40,8 @@
40
40
  "treasury",
41
41
  "payment",
42
42
  "arbitration",
43
- "oracle"
43
+ "oracle",
44
+ "AI agent"
44
45
  ],
45
46
  "author": "wowok",
46
47
  "license": "Apache-2.0",
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Provide a JSON call interface for AI
3
+ *
4
+ */
5
+
6
+ import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
7
+ import { Protocol, } from '../protocol';
8
+ import { Bcs, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType, IsValidU8 } from '../utils'
9
+ import { Errors, ERROR} from '../exception'
10
+ import { MultiGetObjectsParams } from '@mysten/sui/client';
11
+ import { Permission, PermissionIndex } from '../permission';
12
+ import { BCS } from '@mysten/bcs';
13
+ import { PermissionAnswerItem, PermissionIndexType } from '../permission';
14
+ import { Entity } from '../entity';
15
+ import { Repository_Policy_Mode } from '../repository';
16
+ export interface AgentFuncParameter {
17
+ type: 'string' | 'number' | 'boolean' | 'struct' ;
18
+ name: string;
19
+ description: string;
20
+ required: boolean;
21
+ }
22
+
23
+ export interface AgentFuncReturn {
24
+ type: 'string' | 'number' | 'boolean' | 'struct' ;
25
+ name: string;
26
+ description: string;
27
+ }
28
+ export interface AgentFunc {
29
+ name: string;
30
+ description: string;
31
+ module: string;
32
+ permissionIndex: number;
33
+ parameter: AgentFuncParameter[];
34
+ return?: AgentFuncReturn;
35
+ }
36
+
37
+ export const AGENT_FUNC: AgentFunc[] = [
38
+ {permissionIndex:PermissionIndex.repository, name:'Repository', description:'Launch new Repository', module: 'repository', parameter:[
39
+ {type:'string', name:'permission', description:'permission', required:true},
40
+ {type:'number', name:'mode', description:'mode', required:false},
41
+ ]},
42
+ {permissionIndex:PermissionIndex.repository_description, name:'Description', description:'Set Repository description', module: 'repository', parameter:[
43
+ {type:'string', name:'object', description:'object', required:true},
44
+ {type:'string', name:'description', description:'description', required:true},
45
+ ]},
46
+ {permissionIndex:PermissionIndex.repository_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository', parameter:[]},
47
+ {permissionIndex:PermissionIndex.repository_policies, name:'Policy', description:'Add/Remove/Edit Repository policy', module: 'repository', parameter:[]},
48
+ {permissionIndex:PermissionIndex.repository_policy_description, name:'Policy Description', description:'Set Repository policy description', module: 'repository', parameter:[]},
49
+ {permissionIndex:PermissionIndex.repository_policy_permission, name:'Policy Permission', description:'Set Repository policy permission', module: 'repository', parameter:[]},
50
+ {permissionIndex:PermissionIndex.repository_reference, name:'Reference', description:'Set Repository reference', module: 'repository', parameter:[]},
51
+
52
+ {permissionIndex:PermissionIndex.service, name:'Service', description:'Launch new Service', module: 'service', parameter:[]},
53
+ {permissionIndex:PermissionIndex.service_description, name:'Description', description:'Set Service description', module: 'service', parameter:[]},
54
+ {permissionIndex:PermissionIndex.service_price, name:'Price', description:'Set Service item price', module: 'service', parameter:[]},
55
+ {permissionIndex:PermissionIndex.service_stock, name:'Inventory', description:'Set Service item inventory', module: 'service', parameter:[]},
56
+ {permissionIndex:PermissionIndex.service_payee, name:'Payee', description:'Set Service payee', module: 'service', parameter:[]},
57
+ {permissionIndex:PermissionIndex.service_repository, name:'Repository', description:'Set Service repositories', module: 'service', parameter:[]},
58
+ {permissionIndex:PermissionIndex.service_withdraw_guards, name:'Withdraw Guard', description:'Set Service withdraw guards', module: 'service', parameter:[]},
59
+ {permissionIndex:PermissionIndex.service_refund_guards, name:'Refund Guard', description:'Set Service refund guards', module: 'service', parameter:[]},
60
+ {permissionIndex:PermissionIndex.service_add_sales, name:'Add sales', description:'Add sale items for Service', module: 'service', parameter:[]},
61
+ {permissionIndex:PermissionIndex.service_remove_sales, name:'Remove sales', description:'Remove sale items for Service', module: 'service', parameter:[]},
62
+ {permissionIndex:PermissionIndex.service_discount_transfer, name:'Discount', description:'Launch discounts for Service', module: 'service', parameter:[]},
63
+ {permissionIndex:PermissionIndex.service_withdraw, name:'Withdraw', description:'Widthraw from Service orders', module: 'service', parameter:[]},
64
+ {permissionIndex:PermissionIndex.service_buyer_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service', parameter:[]},
65
+ {permissionIndex:PermissionIndex.service_machine, name:'Machine', description:'Set Machine for Service', module: 'service', parameter:[]},
66
+ {permissionIndex:PermissionIndex.service_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service', parameter:[]},
67
+ {permissionIndex:PermissionIndex.service_publish, name:'Publish', description:'Allowing the creation of Order', module: 'service', parameter:[]},
68
+ {permissionIndex:PermissionIndex.service_clone, name:'Clone', description:'Clone Service', module: 'service', parameter:[]},
69
+ {permissionIndex:PermissionIndex.service_customer_required, name:'Buyer info', description:'Set Service buyer info required', module: 'service', parameter:[]},
70
+ {permissionIndex:PermissionIndex.service_pause, name:'Pause', description:'Pause/Unpause Service', module: 'service', parameter:[]},
71
+ {permissionIndex:PermissionIndex.service_treasury, name:'Treasury', description:'Externally withdrawable treasury for compensation or rewards', module: 'service', parameter:[]},
72
+ {permissionIndex:PermissionIndex.service_arbitration, name:'Arbitration', description:'Add/Remove arbitration that allows refunds from orders at any time based on arbitration results', module: 'service', parameter:[]},
73
+
74
+ {permissionIndex:PermissionIndex.demand, name:'Demand', description:'Launch new Demand', module: 'demand', parameter:[]},
75
+ {permissionIndex:PermissionIndex.demand_refund, name:'Refund', description:'Refund from Demand', module: 'demand', parameter:[]},
76
+ {permissionIndex:PermissionIndex.demand_expand_time, name:'Expand deadline', description:'Expand Demand deadline', module: 'demand', parameter:[]},
77
+ {permissionIndex:PermissionIndex.demand_guard, name:'Guard', description:'Set Demand guard', module: 'demand', parameter:[]},
78
+ {permissionIndex:PermissionIndex.demand_description, name:'Description', description:'Set Demand description', module: 'demand', parameter:[]},
79
+ {permissionIndex:PermissionIndex.demand_yes, name:'Yes', description:'Pick the Deamand serice', module: 'demand', parameter:[]},
80
+
81
+ {permissionIndex:PermissionIndex.machine, name: 'Machine', description:'Launch new Machine', module: 'machine', parameter:[]},
82
+ {permissionIndex:PermissionIndex.machine_description, name: 'Description', description:'Set Machine description', module: 'machine', parameter:[]},
83
+ {permissionIndex:PermissionIndex.machine_repository, name: 'Repository', description:'Set Machine repository', module: 'machine', parameter:[]},
84
+ {permissionIndex:PermissionIndex.machine_clone, name: 'Clone', description:'Clone Machine', module: 'machine', parameter:[]},
85
+ {permissionIndex:PermissionIndex.machine_node, name: 'Node', description:'Set Machine nodes', module: 'machine', parameter:[]},
86
+ {permissionIndex:PermissionIndex.machine_endpoint, name: 'Endpoint', description:'Set Machine endpoint', module: 'machine', parameter:[]},
87
+ {permissionIndex:PermissionIndex.machine_pause, name: 'Pause', description:'Pause/Unpause Machine', module: 'machine', parameter:[]},
88
+ {permissionIndex:PermissionIndex.machine_publish, name: 'Publish', description:'Allowing the creation of Progress', module: 'machine', parameter:[]},
89
+
90
+ {permissionIndex:PermissionIndex.progress, name: 'Progress', description:'Launch new Progress', module: 'progress', parameter:[]},
91
+ {permissionIndex:PermissionIndex.progress_namedOperator, name: 'Operator', description:'Set Progress operators', module: 'progress', parameter:[]},
92
+ {permissionIndex:PermissionIndex.progress_bind_task, name: 'Bind', description:'Set Progress task', module: 'progress', parameter:[]},
93
+ {permissionIndex:PermissionIndex.progress_context_repository, name: 'Repository', description:'Set Progress repository', module: 'progress', parameter:[]},
94
+ {permissionIndex:PermissionIndex.progress_unhold, name: 'Unhold', description:'Release Progress holdings', module: 'progress', parameter:[]},
95
+ {permissionIndex:PermissionIndex.progress_parent, name: 'Parent', description:'Set Progress parent', module: 'progress', parameter:[]},
96
+
97
+ {permissionIndex:PermissionIndex.treasury, name: 'Treasury', description:'Launch new Treasury', module: 'treasury', parameter:[]},
98
+ {permissionIndex:PermissionIndex.treasury_deposit, name: 'Deposit', description:'Deposit coins', module: 'treasury', parameter:[]},
99
+ {permissionIndex:PermissionIndex.treasury_receive, name: 'Receive', description:'Receive coins from some address sent', module: 'treasury', parameter:[]},
100
+ {permissionIndex:PermissionIndex.treasury_withdraw, name: 'Withdraw', description:'Withdraw coins', module: 'treasury', parameter:[]},
101
+ {permissionIndex:PermissionIndex.treasury_withdraw_guard, name: 'Withdraw Guard', description:'Add/Remove Treasury withdraw guard', module: 'treasury', parameter:[]},
102
+ {permissionIndex:PermissionIndex.treasury_withdraw_mode, name: 'Withdraw mode', description:'Set Treasury withdraw mode', module: 'treasury', parameter:[]},
103
+ {permissionIndex:PermissionIndex.treasury_deposit_guard, name: 'Deposit Guard', description:'Set Treasury deposit guard', module: 'treasury', parameter:[]},
104
+ {permissionIndex:PermissionIndex.treasury_descritption, name: 'Description', description:'Set Treasury description', module: 'treasury', parameter:[]},
105
+
106
+ {permissionIndex:PermissionIndex.arbitration, name: 'Arbitration', description:'Launch new Arbitration', module: 'arbitration', parameter:[]},
107
+ {permissionIndex:PermissionIndex.arbitration_description, name: 'Description', description:'Set Arbitration description', module: 'arbitration', parameter:[]},
108
+ {permissionIndex:PermissionIndex.arbitration_endpoint, name: 'Endpoint', description:'Set Arbitration endpoint', module: 'arbitration', parameter:[]},
109
+ {permissionIndex:PermissionIndex.arbitration_fee, name: 'Fee', description:'Set Arbitration fee', module: 'arbitration', parameter:[]},
110
+ {permissionIndex:PermissionIndex.arbitration_guard, name: 'Guard', description:'Set Guard to apply for arbitration', module: 'arbitration', parameter:[]},
111
+ {permissionIndex:PermissionIndex.arbitration_arbitration, name: 'Arbitrate', description:'Determine the outcome of arbitration', module: 'arbitration', parameter:[]},
112
+ {permissionIndex:PermissionIndex.arbitration_pause, name: 'Pause', description:'Allowing/forbidding the creation of Arb', module: 'arbitration', parameter:[]},
113
+ {permissionIndex:PermissionIndex.arbitration_voting_guard, name: 'Voting Guard', description:'Add/Remove voting Guard', module: 'arbitration', parameter:[]},
114
+ {permissionIndex:PermissionIndex.arbitration_vote, name: 'Vote', description:'Vote on the application for arbitration', module: 'arbitration', parameter:[]},
115
+ {permissionIndex:PermissionIndex.arbitration_withdraw, name: 'Withdraw', description:'Withdraw the arbitration fee', module: 'arbitration', parameter:[]},
116
+ {permissionIndex:PermissionIndex.arbitration_treasury, name: 'Withdraw', description:'Set Treasury that fees was collected at the time of withdrawal', module: 'arbitration', parameter:[]},
117
+ ]
118
+ export class AgentCall {
119
+
120
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Provide a JSON query interface for AI
3
+ *
4
+ */
5
+
6
+ import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
7
+ import { Protocol, } from '../protocol';
8
+ import { Bcs, IsValidAddress } from '../utils'
9
+ import { Errors, ERROR} from '../exception'
10
+ import { Entity } from '../entity';
11
+
12
+
13
+ export interface EntityQuery {
14
+ address: string;
15
+ showTags?: boolean;
16
+ showMarks?: boolean;
17
+ }
18
+
19
+ export interface EntityDetail {
20
+ name: string;
21
+ description: string;
22
+ avatar: string;
23
+ x: string;
24
+ discord: string;
25
+ homepage: string;
26
+ }
27
+
28
+ export interface ObjectTag {
29
+ object: string;
30
+ nick_name: string;
31
+ tags: string[];
32
+ }
33
+
34
+ export interface ObjectMark {
35
+ mark_name: string;
36
+ objects: string[];
37
+ }
38
+
39
+ export interface EntityAnswer {
40
+ address: string;
41
+ like: number;
42
+ dislike: number;
43
+ details: EntityDetail;
44
+ resource_object?: string;
45
+ lastActive_digest?: string;
46
+ marks?: ObjectMark[];
47
+ tags?: ObjectTag[];
48
+ }
49
+
50
+ export class ENTITY_QUERY {
51
+ /*json: EntityQuery; return EntityAnswer */
52
+ static entity_json = async (json:string) : Promise<string> => {
53
+ try {
54
+ const q : EntityQuery = JSON.parse(json);
55
+ return JSON.stringify(await ENTITY_QUERY.entity(q));
56
+ } catch (e) {
57
+ return JSON.stringify({error:e});
58
+ }
59
+ }
60
+
61
+ static entity = async (query:EntityQuery) : Promise<EntityAnswer> => {
62
+ if (!IsValidAddress(query.address)) {
63
+ ERROR(Errors.IsValidAddress, 'entity.address')
64
+ }
65
+
66
+ const txb = new TransactionBlock();
67
+ Entity.From(txb).query_ent(query.address);
68
+
69
+ const res = await Protocol.Client().devInspectTransactionBlock({sender:query.address, transactionBlock:txb});
70
+ if (!res.results || res.results?.length !== 1 || res.results[0].returnValues?.length !== 1 ) {
71
+ ERROR(Errors.Fail, 'entity.fail')
72
+ }
73
+
74
+ const r1 = Bcs.getInstance().de_ent(Uint8Array.from(res!.results![0].returnValues![0][0]));
75
+ const a = Bcs.getInstance().de_entInfo(Uint8Array.from(r1.avatar));
76
+ var ret : EntityAnswer = {address:query.address, like:r1.like, dislike:r1.dislike, resource_object:r1.resource?.some ?? undefined,
77
+ details:{homepage:a.homepage, name:a.name, avatar:a.avatar, x:a.twitter, discord:a.discord, description:a.description},
78
+ };
79
+
80
+ if (r1.resource?.some && query.showTags) {
81
+ const res2 = await Protocol.Client().getObject({id:r1.resource?.some, options:{showContent:true, showPreviousTransaction:true, showType:true}});
82
+ ret.tags = (res2?.data?.content as any)?.fields?.tags?.map((v:any) => {
83
+ return {address:v.fields.object, nick:v.fields.nick, tags:v.fields.tags}
84
+ })
85
+
86
+ ret.lastActive_digest = res2.data?.previousTransaction ?? '';
87
+ }
88
+
89
+ if (r1.resource?.some && query.showMarks) {
90
+ const fields = await Protocol.Client().getDynamicFields({parentId:r1.resource?.some});
91
+ if (fields.data.length > 0) {
92
+ const objects = await Protocol.Client().multiGetObjects({ids:fields.data.map(v => v.objectId), options:{showContent:true}});
93
+ ret.marks = objects.map((i:any) => {
94
+ return {mark_name:i.data.content.fields.name, objects:i.data.content.fields.value}
95
+ })
96
+ }
97
+ }
98
+ return ret
99
+ }
100
+ }
@@ -0,0 +1,518 @@
1
+ /**
2
+ * Provide a JSON query interface for AI
3
+ *
4
+ */
5
+
6
+ import { Protocol } from '../protocol';
7
+ import { Treasury_WithdrawMode, Treasury_Operation } from '../treasury';
8
+ import { Repository_Type, Repository_Policy_Mode, Repository_Policy } from '../repository';
9
+ import { Service_Discount_Type, Service_Sale } from '../service';
10
+ import { Machine_Node, Machine } from '../machine';
11
+ import { Progress, History } from '../progress';
12
+ export interface ObjectBase {
13
+ object: string;
14
+ type?: string;
15
+ type_raw?: string;
16
+ owner?: any;
17
+ version?: string;
18
+ }
19
+ export interface ObjectPermission extends ObjectBase {
20
+ builder: string;
21
+ admin: string[];
22
+ description: string;
23
+ entity_count: number;
24
+ biz_permission: {id:number; name:string}[];
25
+ }
26
+
27
+ export interface PermissionTable_Entity extends ObjectBase {
28
+ entity: string;
29
+ permission: {id:number; guard?:string|null}[];
30
+ }
31
+
32
+ export interface ObjectDemand extends ObjectBase {
33
+ permission: string;
34
+ guard?: {object:string; service_id_in_guard?:number|null} | null;
35
+ description: string;
36
+ time_expire: string;
37
+ yes?: string | null;
38
+ presenter_count: number;
39
+ bounty: {object:string; balance:string; type:string}[];
40
+ }
41
+
42
+ export interface DemandTable_Presenter extends ObjectBase {
43
+ service: string;
44
+ presenter: string;
45
+ recommendation: string;
46
+ }
47
+
48
+ export interface ObjectMachine extends ObjectBase {
49
+ permission: string;
50
+ bPaused: boolean;
51
+ bPublished: boolean;
52
+ consensus_repository: string[];
53
+ description: string;
54
+ endpoint?: string | null;
55
+ node_count: number;
56
+ }
57
+
58
+ export interface MachineTable_Node extends ObjectBase {
59
+ node: Machine_Node;
60
+ }
61
+
62
+ export interface ObjectProgressHolder {
63
+ forward_name: string;
64
+ holder?: string | null;
65
+ orders: string[];
66
+ msg: string;
67
+ accomplished: boolean;
68
+ time: string;
69
+ }
70
+
71
+ export interface ObjectProgressSession {
72
+ forward: ObjectProgressHolder[];
73
+ weights: number;
74
+ threshold: number;
75
+ next_node: string;
76
+ }
77
+
78
+ export interface ObjectProgress extends ObjectBase {
79
+ machine: string;
80
+ current: string;
81
+ context_repository?: string | null;
82
+ parent?: string | null;
83
+ task?: string | null;
84
+ session: ObjectProgressSession[];
85
+ history_count: number;
86
+ namedOperator: {name:string, operator:string[]}[];
87
+ }
88
+
89
+ export interface ProgressTable_History extends ObjectBase {
90
+ history: History;
91
+ }
92
+
93
+ export interface ObjectService extends ObjectBase {
94
+ permission: string;
95
+ bPaused: boolean;
96
+ bPublished: boolean;
97
+ description: string;
98
+ arbitration: string[];
99
+ buy_guard?: string | null;
100
+ endpoint?: string | null;
101
+ extern_withdraw_treasuries: string[];
102
+ machine?: string | null;
103
+ payee: string;
104
+ repository: string[];
105
+ sales_count: number;
106
+ withdraw_guard: {guard:string, percent:number}[];
107
+ refund_guard: {guard:string, percent:number}[];
108
+ customer_required_info?: {pubkey:string; required_info:string[]};
109
+ }
110
+
111
+ export interface ServiceTable_Sale extends ObjectBase {
112
+ item: Service_Sale;
113
+ }
114
+ export interface ObjectOrder extends ObjectBase {
115
+ service: string;
116
+ amount: string;
117
+ balance: string;
118
+ payer: string;
119
+ arb: string[];
120
+ agent: string[];
121
+ progress?: string | null;
122
+ discount?: string | null;
123
+ required_info?: {pubkey:string; msg_encrypted:string};
124
+ item: Service_Sale[];
125
+ }
126
+
127
+ export interface ObjectTreasury extends ObjectBase {
128
+ permission: string;
129
+ description: string;
130
+ inflow: string;
131
+ outflow: string;
132
+ withdraw_mode: Treasury_WithdrawMode;
133
+ withdraw_guard: {guard:string, percent:number}[];
134
+ deposit_guard?: string | null;
135
+ balance: string;
136
+ history_count: number;
137
+ }
138
+ export interface TreasuryTable_History extends ObjectBase {
139
+ id: number,
140
+ operation: Treasury_Operation,
141
+ signer: string,
142
+ payment: string,
143
+ amount: string,
144
+ time: string,
145
+ }
146
+ export interface ObjectArbitration extends ObjectBase {
147
+ permission: string;
148
+ description: string;
149
+ bPaused: boolean;
150
+ endpoint?: string | null;
151
+ fee: string;
152
+ fee_treasury: string;
153
+ usage_guard?: string | null;
154
+ voting_guard: {guard:string, weights:number}[];
155
+ }
156
+
157
+ export interface ObjectArb extends ObjectBase {
158
+ arbitration: string;
159
+ order: string;
160
+ description: string;
161
+ bWithdrawn: boolean;
162
+ fee: string;
163
+ feedback: string;
164
+ indemnity?: string | null;
165
+ proposition: {proposition:string, votes:string};
166
+ voted_count: number;
167
+ }
168
+ export interface ArbTable_Vote extends ObjectBase {
169
+ singer: string;
170
+ vote: number[];
171
+ weight: string;
172
+ time: string;
173
+ }
174
+ export interface ObjectRepository extends ObjectBase {
175
+ permission: string;
176
+ description: string;
177
+ policy_mode: Repository_Policy_Mode;
178
+ rep_type: Repository_Type;
179
+ reference: string[];
180
+ policy: Repository_Policy[];
181
+ data_count: number;
182
+ }
183
+ export interface RepositoryTable_Data extends ObjectBase {
184
+ address: string;
185
+ key: string;
186
+ data: Uint8Array;
187
+ }
188
+ export interface ObjectPayment extends ObjectBase {
189
+ amount: string;
190
+ for_guard?: string | null;
191
+ for_object?: string | null;
192
+ from ?: string | null;
193
+ biz_id: string;
194
+ remark: string;
195
+ signer: string;
196
+ time: string;
197
+ record: {recipient:string; amount:string}[];
198
+ }
199
+ export interface ObjectDiscount extends ObjectBase {
200
+ service: string;
201
+ name: string;
202
+ off_type: Service_Discount_Type;
203
+ price_greater?: string | null;
204
+ off: string;
205
+ time_start: string;
206
+ time_end: string;
207
+ }
208
+
209
+ export interface ObjectGuard extends ObjectBase {
210
+ description: string;
211
+ input: Uint8Array;
212
+ identifier: {id:number; bWitness:boolean; value:Uint8Array}[];
213
+ }
214
+
215
+ export interface ObjectsQuery {
216
+ objects: string[];
217
+ showType?: boolean;
218
+ showContent?: boolean;
219
+ showOwner?: boolean;
220
+ }
221
+
222
+ export interface ObjectsAnswer {
223
+ objects?: ObjectBase[];
224
+ error?: string;
225
+ }
226
+
227
+ export interface TableQuery {
228
+ parent: string;
229
+ cursor?: string | null | undefined;
230
+ limit?: number | null | undefined;
231
+ }
232
+
233
+ export interface TableAnswer {
234
+ items: TableItem[];
235
+ nextCursor: string | null;
236
+ hasNextPage: boolean;
237
+ }
238
+
239
+ export interface TableItemQuery {
240
+ parent: string;
241
+ name: {type:string; value:string};
242
+ }
243
+ export interface TableItemAnwser {
244
+ object: string;
245
+ type?: string;
246
+ version?: string;
247
+ owner?: any;
248
+ }
249
+
250
+ export interface TableItem {
251
+ name: {type:string; value:string};
252
+ object: string;
253
+ version: string;
254
+ error?: string;
255
+ }
256
+
257
+ export const PermissionTable_Type = 'address';
258
+
259
+ export class OBJECT_QUERY {
260
+ /* json: ObjectsQuery string */
261
+ static objects_json = async (json:string) : Promise<string> => {
262
+ try {
263
+ const q : ObjectsQuery = JSON.parse(json);
264
+ return JSON.stringify(await OBJECT_QUERY.objects(q));
265
+ } catch (e) {
266
+ return JSON.stringify({error:e?.toString()})
267
+ }
268
+ }
269
+
270
+ /* json: TableQuery string */
271
+ static table_json = async (json:string) : Promise<string> => {
272
+ try {
273
+ const q : TableQuery = JSON.parse(json);
274
+ return JSON.stringify(await OBJECT_QUERY.table(q));
275
+ } catch (e) {
276
+ return JSON.stringify({error:e?.toString()})
277
+ }
278
+ }
279
+
280
+ /* json: TableQuery string*/
281
+ static tableItem_json = async (json:string) : Promise<string> => {
282
+ try {
283
+ const q : TableItemQuery = JSON.parse(json);
284
+ return JSON.stringify(await OBJECT_QUERY.tableItem(q));
285
+ } catch (e) {
286
+ return JSON.stringify({error:e?.toString()})
287
+ }
288
+ }
289
+
290
+ static objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer> => {
291
+ if (query.objects.length > 0) {
292
+ const res = await Protocol.Client().multiGetObjects({ids:query.objects,
293
+ options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
294
+ console.log(JSON.stringify(res))
295
+ return {objects:res.map(v=>this.data2object(v?.data))}
296
+ }
297
+ return {objects:[]}
298
+ }
299
+
300
+ static table = async (query:TableQuery) : Promise<TableAnswer> => {
301
+ const res = await Protocol.Client().getDynamicFields({parentId:query.parent, cursor:query.cursor, limit:query.limit});
302
+ return {items:res?.data?.map(v=>{
303
+ return {object:v.objectId, type:v.type, version:v.version, name:{
304
+ type:v.name.type, value:v.name.value?.toString() ?? ''
305
+ }}
306
+ }), nextCursor:res.nextCursor, hasNextPage:res.hasNextPage}
307
+ }
308
+
309
+ static tableItem = async (query:TableItemQuery) : Promise<TableItemAnwser> => {
310
+ const res = await Protocol.Client().getDynamicFieldObject({parentId:query.parent, name:{type:query.name.type, value:query.name.value}});
311
+ return {object:res.data?.objectId ??'', version:res.data?.version, owner:res.data?.owner}
312
+ }
313
+
314
+ private static data2object = (data?:any) : ObjectBase => {
315
+ const content = (data?.content as any)?.fields;
316
+ const id = data?.objectId ?? (content?.id?.id ?? undefined);
317
+ const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
318
+ const version = data?.version ?? undefined;
319
+ const owner = data?.owner ?? undefined;
320
+ const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
321
+
322
+ if (type) {
323
+ switch(type) {
324
+ case 'Permission':
325
+ return {object:id, type:type, type_raw:type_raw, owner:owner, version:version,
326
+ builder: content?.builder ??'', admin:content?.admin, description:content?.description??'',
327
+ entity_count: parseInt(content?.table?.fields?.size),
328
+ biz_permission:content?.user_define?.fields?.contents?.map((v:any) => {
329
+ return {id:parseInt(v?.fields?.key), name:v?.fields?.value}
330
+ })
331
+ } as ObjectPermission;
332
+ case 'Demand':
333
+ return {
334
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
335
+ permission: content?.permission, description:content?.description,
336
+ guard:content?.guard ? {object:content?.guard, service_id_in_guard:content?.service_identifier}:undefined,
337
+ time_expire:content?.time_expire, yes:content?.yes,
338
+ presenter_count:parseInt(content?.presenters?.fields?.size),
339
+ bounty: content?.bounty?.map((v:any) => {
340
+ return {type:v?.fields?.type, object:v?.fields?.id?.id, balance:v?.fields?.balance}
341
+ })
342
+ } as ObjectDemand;
343
+ case 'Machine':
344
+ return {
345
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
346
+ permission: content?.permission ?? '', description:content?.description??'',
347
+ bPaused: content?.bPaused, bPublished:content?.bPublished, endpoint:content?.endpoint,
348
+ consensus_repository:content?.consensus_repositories, node_count:parseInt(content?.nodes?.fields?.size),
349
+ } as ObjectMachine;
350
+ case 'Progress':
351
+ return {
352
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
353
+ machine: content?.machine, current: content?.current, task:content?.task,
354
+ parent:content?.parent, history_count:parseInt(content?.history?.fields?.contents?.fields?.size),
355
+ namedOperator:content?.namedOperator?.fields?.contents?.map((v:any) => {
356
+ return {name:v?.fields?.key, operator:v?.fields?.value}
357
+ }),
358
+ session:content?.session?.fields?.contents?.map((v:any) => {
359
+ return {weights:v?.fields?.value?.fields?.weight, threshold:v?.fields?.value?.fields?.threshold,
360
+ next_node:v?.fields?.key, forward: v?.fields?.value?.fields?.forwards?.fields?.contents?.map((i:any) => {
361
+ return {forward_name:i?.fields?.key, accomplished:i?.fields?.value?.fields?.accomplished,
362
+ msg:i?.fields?.value?.fields?.msg, orders:i?.fields?.value?.fields?.orders,
363
+ time:i?.fields?.value?.fields?.time, holder:i?.fields?.value?.fields?.who
364
+ }
365
+ })
366
+ }
367
+ })
368
+ } as ObjectProgress;
369
+ case 'Order':
370
+ return {
371
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
372
+ service:content?.service, amount: content?.amount, agent:content?.agent, arb:content?.dispute,
373
+ payer:content?.payer, progress:content?.progress, discount:content?.discount, balance:content?.payed,
374
+ required_info: content?.required_info ?
375
+ {pubkey:content?.required_info?.fields?.customer_pub, msg_encrypted:content?.required_info?.fields?.info}
376
+ : undefined,
377
+ item : content?.items?.map((v:any) => {
378
+ return {name:v?.fields?.name, price:v?.fields?.price, stock:v?.fields?.stock, endpoint:v?.fields?.endpoint}
379
+ }),
380
+ } as ObjectOrder;
381
+ case 'Service':
382
+ return {
383
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
384
+ machine:content?.machine, permission:content?.permission, description:content?.description,
385
+ arbitration:content?.arbitrations, bPaused:content?.bPaused, bPublished:content?.bPublished,
386
+ buy_guard:content?.buy_guard, endpoint:content?.endpoint, payee:content?.payee, repository:content?.repositories,
387
+ withdraw_guard:content?.withdraw_guard?.fields?.contents?.map((v:any) => {
388
+ return {object:v?.fields?.key, percent:v?.fields?.value}
389
+ }),
390
+ refund_guard:content?.refund_guard?.fields?.contents?.map((v:any) => {
391
+ return {object:v?.fields?.key, percent:v?.fields?.value}
392
+ }),
393
+ sales_count:parseInt(content?.sales?.fields?.size), extern_withdraw_treasuries:content?.extern_withdraw_treasuries,
394
+ customer_required_info:content?.customer_required ?
395
+ {pubkey:content?.customer_required?.fields?.service_pubkey, required_info:content?.customer_required?.fields?.customer_required_info}
396
+ :undefined,
397
+ } as ObjectService;
398
+ case 'Treasury':
399
+ return {
400
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
401
+ permission:content?.permission, description:content?.description, withdraw_mode:content?.withdraw_mode,
402
+ history_count:parseInt(content?.history?.fields?.contents?.fields?.size), balance: content?.balance,
403
+ deposit_guard:content?.deposit_guard, withdraw_guard:content?.withdraw_guard?.fields?.contents?.map((v:any) => {
404
+ return {object:v?.fields?.key, percent:v?.fields?.value}
405
+ })
406
+ } as ObjectTreasury;
407
+ case 'Arbitration':
408
+ return {
409
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
410
+ permission:content?.permission, description:content?.description, fee:content?.fee,
411
+ fee_treasury:content?.fee_treasury, usage_guard:content?.usage_guard,
412
+ endpoint:content?.endpoint, bPaused:content?.bPaused, voting_guard:content?.voting_guard?.fields?.contents?.map((v:any) => {
413
+ return {object:v?.fields?.key, weights:v?.fields?.value}
414
+ })
415
+ } as ObjectArbitration;
416
+ case 'Arb':
417
+ return {
418
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
419
+ arbitration:content?.arbitration, description:content?.description, fee:content?.fee,
420
+ feedback:content?.feedback, indemnity:content?.indemnity, order:content?.order,
421
+ voted_count:parseInt(content?.voted?.fields?.size),
422
+ proposition:content?.proposition?.fields?.contents?.map((v:any) => {
423
+ return {proposition:v?.fields?.key, votes:v?.fields?.value}
424
+ })
425
+ } as ObjectArb;
426
+ case 'Repository':
427
+ return {
428
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
429
+ permission:content?.permission, description:content?.description, policy_mode:content?.policy_mode,
430
+ data_count:parseInt(content?.data?.fields?.size), reference:content?.reference, rep_type:content?.type,
431
+ policy:content?.policies?.fields?.contents?.map((v:any) => {
432
+ return {key:v?.fields?.key, description:v?.fields?.value?.fields?.description,
433
+ permissionIndex:v?.fields?.value?.fields?.permission_index, dataType:v?.fields?.value?.fields?.value_type}
434
+ })
435
+ } as ObjectRepository;
436
+ case 'Payment':
437
+ return {
438
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
439
+ signer:content?.signer, time:content?.time, remark:content?.remark, from: content?.from,
440
+ biz_id:content?.index, for_guard:content?.for_guard, for_object:content?.for_object,
441
+ amount:content?.amount, record:content?.record?.map((v:any) => {
442
+ return {recipient:v?.fields?.recipient, amount:v?.fields?.amount}
443
+ })
444
+ } as ObjectPayment;
445
+ case 'Discount':
446
+ return {
447
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
448
+ service:content?.service, time_start:content?.time_start, time_end:content?.time_end,
449
+ price_greater:content?.price_greater, off_type:content?.type, off:content?.off,
450
+ name:content?.name
451
+ } as ObjectDiscount;
452
+ case 'Guard':
453
+ return {
454
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
455
+ description:content?.description, input:Uint8Array.from(content?.input?.fields?.bytes),
456
+ identifier:content?.constants?.map((v:any) => {
457
+ return {id:v?.fields?.identifier, bWitness:v?.fields?.bWitness, value:Uint8Array.from(v?.fields?.value)}
458
+ })
459
+ } as ObjectGuard;
460
+ }
461
+ }
462
+
463
+ const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
464
+ if (start === 0) {
465
+ const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
466
+ if(end && Protocol.Instance().hasPackage(end)) {
467
+ if (end.includes('::demand::Tips>')) {
468
+ return {
469
+ object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
470
+ service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
471
+ } as DemandTable_Presenter;
472
+ } else if (end.includes('::machine::NodePair>>>')) {
473
+ return {
474
+ object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
475
+ node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
476
+ } as MachineTable_Node;
477
+ } else if (end.includes('::progress::History>')) {
478
+ return {
479
+ object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
480
+ history:Progress.rpc_de_history(content)
481
+ } as ProgressTable_History;
482
+ } else if (end.includes('::service::Sale>')) {
483
+ return {
484
+ object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
485
+ item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
486
+ endpoint:content?.value?.fields?.endpoint
487
+ }
488
+ } as ServiceTable_Sale;
489
+ } else if (end.includes('::treasury::Record>')) {
490
+ return {
491
+ object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
492
+ id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
493
+ operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
494
+ } as TreasuryTable_History;
495
+ } else if (end.includes('::arb::Voted>')) {
496
+ return {
497
+ object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
498
+ singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
499
+ weight:content?.value?.fields?.weight
500
+ } as ArbTable_Vote;
501
+ } else if (end.includes('::permission::Perm>>')) {
502
+ return {
503
+ object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
504
+ entity:content?.name, permission:content?.value?.map((v:any) => {
505
+ return {id:v?.fields.index, guard:v?.fields.guard}
506
+ })
507
+ } as PermissionTable_Entity;
508
+ } else if (end.includes('::repository::DataKey')) {
509
+ return {
510
+ object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
511
+ address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
512
+ } as RepositoryTable_Data;
513
+ }
514
+ }
515
+ }
516
+ return {object:id, type:type, type_raw:type_raw, owner:owner, version:version}
517
+ }
518
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Provide a JSON query interface for AI
3
+ *
4
+ */
5
+
6
+ import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
7
+ import { Protocol, } from '../protocol';
8
+ import { Bcs, IsValidAddress} from '../utils'
9
+ import { Errors, ERROR} from '../exception'
10
+ import { Permission } from '../permission';
11
+ import { BCS } from '@mysten/bcs';
12
+ import { PermissionAnswerItem, PermissionIndexType, PermissionAnswer } from '../permission';
13
+
14
+ export interface PermissionQuery {
15
+ permission_object: string;
16
+ address: string;
17
+ }
18
+
19
+ export class PERMISSION_QUERY {
20
+ /*json: PermissionQuery; return PermissionAnswer */
21
+ static permission_json = async (json:string) : Promise<string> => {
22
+ try {
23
+ const q : PermissionQuery = JSON.parse(json);
24
+ return JSON.stringify(await PERMISSION_QUERY.permission(q));
25
+ } catch (e) {
26
+ return JSON.stringify({error:e});
27
+ }
28
+ }
29
+
30
+ static permission = async (query:PermissionQuery) : Promise<PermissionAnswer> => {
31
+ if (!IsValidAddress(query.permission_object)) {
32
+ ERROR(Errors.IsValidAddress, 'permission.permission_object');
33
+ }
34
+ if (!IsValidAddress(query.address)) {
35
+ ERROR(Errors.IsValidAddress, 'permission.address')
36
+ }
37
+ const txb = new TransactionBlock();
38
+ const object = Permission.From(txb, query.permission_object);
39
+ object.query_permissions_all(query.address);
40
+
41
+
42
+ const res = await Protocol.Client().devInspectTransactionBlock({sender:query.address, transactionBlock:txb});
43
+ if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
44
+ ERROR(Errors.Fail, 'permission.retValues')
45
+ }
46
+
47
+ const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
48
+ if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
49
+ return {who:query.address, admin:true, owner:perm%2===1, items:[], object:query.permission_object}
50
+ } else {
51
+ const perms = Bcs.getInstance().de('vector<u64>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
52
+ const guards = Bcs.getInstance().de_guards(Uint8Array.from((res.results as any)[0].returnValues[2][0]));
53
+ const items: PermissionAnswerItem[] = [];
54
+ for(let i = 0; i < perms.length; ++i) {
55
+ items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
56
+ }
57
+ return {who:query.address, admin:false, owner:perm%2===1, items:items, object:query.permission_object};
58
+ }
59
+ }
60
+ }
package/src/index.ts CHANGED
@@ -14,5 +14,9 @@ export * from './resource'
14
14
  export * from './treasury'
15
15
  export * from './payment'
16
16
  export * from './arbitration'
17
+ export * from './agent_query/object'
18
+ export * from './agent_query/permission'
19
+ export * from './agent_query/entity'
20
+
17
21
  // export * from './reward'
18
22
  // export * from './vote'
package/src/machine.ts CHANGED
@@ -487,27 +487,30 @@ export class Machine {
487
487
  static rpc_de_nodes(fields: any) : Machine_Node[] {
488
488
  const machine_nodes:Machine_Node[] = [];
489
489
  fields.forEach((n:any) => {
490
- let pairs:Machine_Node_Pair[] = [];
491
- n.data.content.fields.value.fields.value.fields.contents.forEach((p:any) => {
492
- let forwards:Machine_Forward[] = [];
493
- p.fields.value.fields.forwards.fields.contents.forEach((f:any) => {
494
- let forward_name = f.fields.key;
495
- let forward_weight = f.fields.value.fields.weight;
496
- let forward_guard = f.fields.value.fields.guard;
497
- let forward_namedOperator = f.fields.value.fields.namedOperator;
498
- let forward_permission_index = f.fields.value.fields.permission_index;
499
- forwards.push({name:forward_name, namedOperator:forward_namedOperator, permission:forward_permission_index,
500
- weight:forward_weight, guard:forward_guard?forward_guard:'', suppliers:f.fields.value.fields.suppliers.fields.contents.map((v:any) => {
501
- return {object:v.fields.key, bOptional:v.fields.value, pay_token_type:''}
502
- })}); //@ NOTICE...
503
- });
504
- pairs.push({prior_node:p.fields.key, threshold:p.fields.value.fields.threshold, forwards:forwards});
505
- });
506
- machine_nodes.push({name:n.data.content.fields.name, pairs:pairs});
490
+ machine_nodes.push({name:n.data.content.fields.name, pairs:Machine.rpc_de_pair(n?.data.content.fields.value)});
507
491
  });
508
492
  return machine_nodes;
509
493
  }
510
494
 
495
+ static rpc_de_pair(data:any) : Machine_Node_Pair[] {
496
+ let pairs:Machine_Node_Pair[] = [];
497
+ data.fields.value.fields.contents.forEach((p:any) => {
498
+ let forwards:Machine_Forward[] = [];
499
+ p.fields.value.fields.forwards.fields.contents.forEach((f:any) => {
500
+ let forward_name = f.fields.key;
501
+ let forward_weight = f.fields.value.fields.weight;
502
+ let forward_guard = f.fields.value.fields.guard;
503
+ let forward_namedOperator = f.fields.value.fields.namedOperator;
504
+ let forward_permission_index = f.fields.value.fields.permission_index;
505
+ forwards.push({name:forward_name, namedOperator:forward_namedOperator, permission:forward_permission_index,
506
+ weight:forward_weight, guard:forward_guard?forward_guard:'', suppliers:f.fields.value.fields.suppliers.fields.contents.map((v:any) => {
507
+ return {object:v.fields.key, bOptional:v.fields.value, pay_token_type:''}
508
+ })}); //@ NOTICE...
509
+ });
510
+ pairs.push({prior_node:p.fields.key, threshold:p.fields.value.fields.threshold, forwards:forwards});
511
+ });
512
+ return pairs
513
+ }
511
514
  static namedOperators(nodes:Machine_Node[]) : string[] {
512
515
  let ret: string[] = [];
513
516
  nodes.forEach((v)=> {
package/src/permission.ts CHANGED
@@ -487,23 +487,6 @@ export class Permission {
487
487
  });
488
488
  }
489
489
 
490
- // query some permissions for address
491
- query_permissions(address_queried:string, permissions:PermissionIndexType[]) {
492
- if (!IsValidAddress(address_queried)) {
493
- ERROR(Errors.InvalidParam, 'query_permissions');
494
- }
495
-
496
- if (permissions.length === 0 || permissions.length > Permission.MAX_QUERY_COUNT) {
497
- ERROR(Errors.InvalidParam, 'permissions count');
498
- }
499
-
500
- this.txb.moveCall({
501
- target:Protocol.Instance().PermissionFn('query_permissions') as FnCallType,
502
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried),
503
- this.txb.pure.vector('u64', permissions)]
504
- })
505
- }
506
-
507
490
  // query all permissions for address
508
491
  query_permissions_all(address_queried:string) {
509
492
  if (!IsValidAddress(address_queried)) {
@@ -516,13 +499,9 @@ export class Permission {
516
499
  })
517
500
  }
518
501
 
519
- QueryPermissions(permission:string, address_queried:string, permissions:PermissionIndexType[]|'all', onPermissionAnswer:OnPermissionAnswer, sender?:string) {
502
+ QueryPermissions(permission:string, address_queried:string, onPermissionAnswer:OnPermissionAnswer, sender?:string) {
520
503
  //@ be the same txb
521
- if (permissions === 'all') {
522
- this.query_permissions_all(address_queried);
523
- } else {
524
- this.query_permissions(address_queried, permissions);
525
- }
504
+ this.query_permissions_all(address_queried);
526
505
 
527
506
  Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:this.txb}).then((res) => {
528
507
  if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
@@ -533,32 +512,13 @@ export class Permission {
533
512
  if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
534
513
  onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[], object:permission})
535
514
  } else {
536
- if (permissions === 'all') {
537
- const perms = Bcs.getInstance().de('vector<u64>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
538
- const guards = Bcs.getInstance().de_guards(Uint8Array.from((res.results as any)[0].returnValues[2][0]));
539
- const items: PermissionAnswerItem[] = [];
540
- for(let i = 0; i < perms.length; ++i) {
541
- items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
542
- }
543
- onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
544
- } else {
545
- const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
546
- const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
547
- if (perms.length !== permissions.length) {
548
- onPermissionAnswer({who:address_queried, object:permission});
549
- return
550
- }
551
-
552
- const items: PermissionAnswerItem[] = (permissions as PermissionIndexType[]).map((v, index) => {
553
- const p = perms[index] === Permission.PERMISSION_QUERY_NONE ? false : true;
554
- let g : any = undefined;
555
- if (p && perms[index] < guards.length) {
556
- g = '0x' + guards[perms[index] as number];
557
- }
558
- return {query:v, permission:p, guard:g}
559
- })
560
- onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
515
+ const perms = Bcs.getInstance().de('vector<u64>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
516
+ const guards = Bcs.getInstance().de_guards(Uint8Array.from((res.results as any)[0].returnValues[2][0]));
517
+ const items: PermissionAnswerItem[] = [];
518
+ for(let i = 0; i < perms.length; ++i) {
519
+ items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
561
520
  }
521
+ onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
562
522
  }
563
523
  }).catch((e) => {
564
524
  console.log(e);
@@ -586,9 +546,7 @@ export class Permission {
586
546
  static MAX_ENTITY_COUNT = 2000;
587
547
  static MAX_PERMISSION_INDEX_COUNT = 200;
588
548
  static MAX_PERSONAL_PERMISSION_COUNT = 200;
589
- static MAX_QUERY_COUNT = 250; //
590
- static PERMISSION_QUERY_NONE = 255;
591
- static PERMISSION_QUERY_HAS = 254;
549
+
592
550
  static PERMISSION_NORMAL = 0;
593
551
  static PERMISSION_OWNER = 1;
594
552
  static PERMISSION_ADMIN = 2;
package/src/progress.ts CHANGED
@@ -35,9 +35,10 @@ export interface Holder {
35
35
  who?:string;
36
36
  deliverable: Deliverable;
37
37
  accomplished:boolean;
38
+ time: string;
38
39
  }
39
40
  export interface Session {
40
- id?:number; // for parent progress's history
41
+ id?: number; // sid
41
42
  next_node: string;
42
43
  holders: Holder[];
43
44
  weights: number;
@@ -46,6 +47,13 @@ export interface Session {
46
47
  bComplete?: boolean;
47
48
  }
48
49
 
50
+ export interface History {
51
+ id: number; // sid
52
+ node: string;
53
+ next_node: string;
54
+ time: string;
55
+ sessions: Session[];
56
+ }
49
57
  export class Progress {
50
58
  protected permission ;
51
59
  protected machine;
@@ -327,9 +335,8 @@ export class Progress {
327
335
  session?.fields?.contents?.forEach((v:any) => {
328
336
  var s:Session = {next_node: v.fields.key, holders:[], weights:v.fields.value.fields.weights, threshold:v.fields.value.fields.threshold};
329
337
  v.fields.value.fields.forwards.fields.contents.forEach((i:any) => {
330
- s.holders.push({forward:i.fields.key, accomplished:i.fields.value.fields.accomplished,
331
- who:i.fields.value.fields.who, deliverable:{msg:i.fields.value.fields.msg,
332
- orders:i.fields.value.fields.orders ?? []},
338
+ s.holders.push({forward:i.fields.key, accomplished:i.fields.value.fields.accomplished, time:i.fields.value.fields.time,
339
+ who:i.fields.value.fields.who, deliverable:{msg:i.fields.value.fields.msg, orders:i.fields.value.fields.orders ?? []},
333
340
  })
334
341
  })
335
342
  sessions.push(s);
@@ -337,23 +344,16 @@ export class Progress {
337
344
  return sessions;
338
345
  }
339
346
 
340
- static rpc_de_history = (fields: any) : Session[] => {
341
- let sessions : Session[] = [];
342
- fields?.forEach((v:any) => {
343
- const next_node = v.data.content.fields.value.fields.next_node;
344
- v.data.content.fields.value.fields.session.fields.contents.forEach((i:any) => {
345
- var s:Session = {id:v.data.content.fields.name,
346
- node:v.data.content.fields.value.fields.node, next_node: i.fields.key, holders:[],
347
- weights:i.fields.value.fields.weights, threshold:i.fields.value.fields.threshold, bComplete:i.fields.key === next_node};
348
- i.fields.value.fields.forwards.fields.contents.forEach((k:any) => {
349
- s.holders.push({forward:k.fields.key, who:k.fields.value.fields.who, accomplished:k.fields.value.fields.accomplished,
350
- deliverable:{msg:k.fields.value.fields.msg,
351
- orders:k.fields.value.fields.orders ?? []}});
352
- })
353
- sessions.push(s);
354
- })
347
+ static rpc_de_histories = (fields: any) : History[] => {
348
+ return fields?.map((v:any) => {
349
+ return Progress.rpc_de_history(v?.data?.content?.fields)
355
350
  })
356
- return sessions;
351
+ }
352
+
353
+ static rpc_de_history = (data: any) : History => {
354
+ return {id:parseInt(data?.name), node:data?.value?.fields?.node, next_node:data?.value?.fields?.next_node,
355
+ sessions:Progress.rpc_de_sessions(data?.value.fields?.session), time: data?.value?.fields?.time
356
+ }
357
357
  }
358
358
 
359
359
  static MAX_NAMED_OPERATOR_COUNT = 20;
package/src/protocol.ts CHANGED
@@ -14,10 +14,8 @@ export enum MODULES {
14
14
  permission = 'permission',
15
15
  passport = 'passport',
16
16
  guard = 'guard',
17
- vote = 'vote',
18
17
  demand = 'demand',
19
18
  order = 'order',
20
- reward = 'reward',
21
19
  service = 'service',
22
20
  resource = 'resource',
23
21
  entity = 'entity',
@@ -221,15 +219,15 @@ const TESTNET = {
221
219
  }
222
220
  */
223
221
  const TESTNET = {
224
- wowok: "0x66f08884668a7b18b34ce0ae91cfb7bdab284d4dbbc28ad3fb009df50f88e11e",
225
- wowok_origin:'0x66f08884668a7b18b34ce0ae91cfb7bdab284d4dbbc28ad3fb009df50f88e11e' ,
226
- base: '0x3960658ad695c829bd62a083a8a92f94f04404ae3ea6b13bbc72e5780cfeec4c',
227
- base_origin: '0x3960658ad695c829bd62a083a8a92f94f04404ae3ea6b13bbc72e5780cfeec4c',
228
-
229
- wowok_object: '0xa51c94e11a4693e63b77cc6577a2deb0e4eed1cc6a1fbc3971b35edafc72eaed',
230
- entity_object: '0x5f45ec58ed208c7b1b5d427fa77bbc64ad2256203aa6f11961b9417a7eeca053',
231
- treasury_cap:'0xc1f614972987e8839584710c0a8b9f284745e667f2e19594c0ffa09ca5e59721',
232
- oracle_object:'0x57c89a7ba9f2aaf784a5325da111989f157939a14df15bb9698de0a46285d746',
222
+ wowok: "0x7bb3672fb818b362703a2f2e0804c4cea6b5a23dc79920217088374450300f45",
223
+ wowok_origin:'0x7bb3672fb818b362703a2f2e0804c4cea6b5a23dc79920217088374450300f45' ,
224
+ base: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
225
+ base_origin: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
226
+
227
+ wowok_object: '0x6f0b0c6d1d6b02e8589064c0c40d6aed105c5cc5ffece509111a8d308e3eb188',
228
+ entity_object: '0x42a28bf08b8373cc460b001eab9d9cd91c4285855bea0dc40116237de79870b8',
229
+ treasury_cap:'0x9f415c863f0c26103e70fc4a739fea479ff20544057a3c5665db16c0b8650f7c',
230
+ oracle_object:'0x6c7d9b8ab0e9d21291e0128ca3e0d550b30f375f1e008381f2fbeef6753e6dcf',
233
231
  }
234
232
  const MAINNET = {
235
233
  wowok: "",
@@ -334,10 +332,8 @@ export class Protocol {
334
332
  RepositoryFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.repository}::${fn}`};
335
333
  PermissionFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.permission}::${fn}`};
336
334
  PassportFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.passport}::${fn}`};
337
- VoteFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.vote}::${fn}`};
338
335
  DemandFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.demand}::${fn}`};
339
336
  OrderFn = (fn:any) => { return `${this.package.get('wowok')}::${MODULES.order}::${fn}`};
340
- RewardFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.reward}::${fn}`};
341
337
  ServiceFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.service}::${fn}`};
342
338
  ResourceFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.resource}::${fn}`};
343
339
  EntityFn = (fn: any) => { return `${this.package.get('wowok')}::${MODULES.entity}::${fn}`};
@@ -476,9 +472,9 @@ export class Protocol {
476
472
  { let i = (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; return i + capitalize(key); })
477
473
  WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
478
474
  { return (key === MODULES.guard ? this.package.get('base') : this.package.get('wowok')) + '::' + key + '::'; })
479
- private hasPackage(pack:string) : boolean {
475
+ hasPackage(pack:string) : boolean {
480
476
  for (let value of this.package.values()) {
481
- if (value === pack) {
477
+ if (pack.includes(value)) {
482
478
  return true;
483
479
  }
484
480
  } return false;
package/src/repository.ts CHANGED
@@ -10,6 +10,11 @@ export enum Repository_Policy_Mode {
10
10
  POLICY_MODE_STRICT = 1,
11
11
  }
12
12
 
13
+ export enum Repository_Type {
14
+ NORMAL = 0,
15
+ WOWOK_GRANTEE = 1,
16
+ WOWOK_ORACLE = 2
17
+ }
13
18
  export interface RepData {
14
19
  id: string;
15
20
  name: string;
@@ -21,8 +26,8 @@ export interface RepData {
21
26
  export type Repository_Policy = {
22
27
  key:string;
23
28
  description: string;
24
- data_type: RepositoryValueType;
25
- permission?: PermissionIndexType; // PermissionIndex like, must be geater than 1000
29
+ dataType: RepositoryValueType;
30
+ permissionIndex?: PermissionIndexType | null; // PermissionIndex like, must be geater than 1000
26
31
  }
27
32
  export type Repository_Policy_Data = {
28
33
  key: string;
@@ -51,7 +56,7 @@ export class Repository {
51
56
  return r
52
57
  }
53
58
  static New(txb:TransactionBlock, permission:PermissionObject, description:string,
54
- policy_mode: Repository_Policy_Mode, passport?:PassportObject) : Repository {
59
+ policy_mode: Repository_Policy_Mode=Repository_Policy_Mode.POLICY_MODE_FREE, passport?:PassportObject) : Repository {
55
60
  if (!Protocol.IsValidObjects([permission])) {
56
61
  ERROR(Errors.IsValidObjects, 'permission')
57
62
  }
@@ -213,14 +218,14 @@ export class Repository {
213
218
  }
214
219
 
215
220
  policies.forEach((policy) => {
216
- let permission_index = this.txb.pure.option('u64', policy?.permission ? policy?.permission : undefined);
221
+ let permission_index = this.txb.pure.option('u64', policy?.permissionIndex ? policy?.permissionIndex : undefined);
217
222
  if (passport) {
218
223
  this.txb.moveCall({
219
224
  target:Protocol.Instance().RepositoryFn('policy_add_with_passport') as FnCallType,
220
225
  arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
221
226
  this.txb.pure.string(policy.key),
222
227
  this.txb.pure.string(policy.description),
223
- permission_index, this.txb.pure.u8(policy.data_type),
228
+ permission_index, this.txb.pure.u8(policy.dataType),
224
229
  Protocol.TXB_OBJECT(this.txb, this.permission)]
225
230
  })
226
231
  } else {
@@ -229,7 +234,7 @@ export class Repository {
229
234
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
230
235
  this.txb.pure.string(policy.key),
231
236
  this.txb.pure.string(policy.description),
232
- permission_index, this.txb.pure.u8(policy.data_type),
237
+ permission_index, this.txb.pure.u8(policy.dataType),
233
238
  Protocol.TXB_OBJECT(this.txb, this.permission)]
234
239
  })
235
240
  }
@@ -376,15 +381,11 @@ export class Repository {
376
381
  this.permission = new_permission
377
382
  }
378
383
 
379
- static MAX_POLICY_COUNT = 200;
384
+ static MAX_POLICY_COUNT = 120;
380
385
  static MAX_KEY_LENGTH = 128;
381
386
  static MAX_VALUE_LENGTH = 204800;
382
387
  static MAX_REFERENCE_COUNT = 100;
383
388
 
384
- static TYPE_NORMAL = 0;
385
- static TYPE_WOWOK_GRANTEE = 1;
386
- static TYPE_WOWOK_ORACLE = 2;
387
-
388
389
  static IsValidName = (key:string) => {
389
390
  return key.length <= Repository.MAX_KEY_LENGTH && key.length != 0;
390
391
  }
package/src/service.ts CHANGED
@@ -18,10 +18,10 @@ export type Service_Guard_Percent = {
18
18
  percent: number;
19
19
  }
20
20
  export type Service_Sale = {
21
- item:string;
22
- price:bigint;
23
- stock:bigint;
24
- endpoint?:string;
21
+ item: string;
22
+ price: string;
23
+ stock: string;
24
+ endpoint?:string | null;
25
25
  }
26
26
  export enum Service_Discount_Type {
27
27
  ratio = 0, // -off%
@@ -581,7 +581,7 @@ export class Service {
581
581
  ERROR(Errors.InvalidParam, 'add_sales')
582
582
  }
583
583
 
584
- let names: string[] = []; let price: bigint[] = []; let stock: bigint[] = []; let endpoint: string[] = [];
584
+ let names: string[] = []; let price: string[] = []; let stock: string[] = []; let endpoint: string[] = [];
585
585
  sales.forEach((s) => {
586
586
  if (s.endpoint && !IsValidEndpoint(s.endpoint)) {
587
587
  ERROR(Errors.IsValidEndpoint, 'add_sales')
package/src/treasury.ts CHANGED
@@ -4,13 +4,17 @@ import { FnCallType, Protocol, PassportObject, PermissionObject, TreasuryAddress
4
4
  import { IsValidDesription, IsValidU64, IsValidAddress, IsValidArgType, IsValidArray, parseObjectType} from './utils'
5
5
  import { Errors, ERROR} from './exception'
6
6
 
7
- export enum WithdrawMode {
7
+ export enum Treasury_WithdrawMode {
8
8
  PERMISSION = 0,
9
9
  GUARD_ONLY_AND_IMMUTABLE = 1,
10
10
  BOTH_PERMISSION_AND_GUARD = 2,
11
11
  }
12
12
 
13
-
13
+ export enum Treasury_Operation {
14
+ WITHDRAW = 1,
15
+ DEPOSIT = 2,
16
+ RECEIVE = 4,
17
+ }
14
18
  export interface DepositParam {
15
19
  coin: CoinObject,
16
20
  index: bigint,
@@ -315,7 +319,7 @@ export class Treasury {
315
319
  }
316
320
  }
317
321
 
318
- set_withdraw_mode(mode: WithdrawMode, passport?: PassportObject) {
322
+ set_withdraw_mode(mode: Treasury_WithdrawMode, passport?: PassportObject) {
319
323
  if (passport) {
320
324
  this.txb.moveCall({
321
325
  target:Protocol.Instance().TreasuryFn('withdraw_mode_set_with_passport') as FnCallType,
@@ -414,10 +418,6 @@ export class Treasury {
414
418
  static parseObjectType = (chain_type:string) : string => {
415
419
  return parseObjectType(chain_type, 'treasury::Treasury<')
416
420
  }
417
-
418
- static OP_WITHDRAW = 1;
419
- static OP_DEPOSIT = 2;
420
- static OP_RECEIVE = 4;
421
421
 
422
422
  static MAX_WITHDRAW_GUARD_COUNT = 16;
423
423
  }