wowok 1.6.59 → 1.6.60
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 +1 -1
- package/src/agent_call/{agent_call.ts → call.ts} +17 -12
- package/src/agent_query/events.ts +100 -0
- package/src/agent_query/{object.ts → objects.ts} +155 -65
- package/src/agent_query/permission.ts +7 -7
- package/src/index.ts +2 -2
- package/src/protocol.ts +7 -6
- package/src/utils.ts +1 -1
- package/src/agent_query/entity.ts +0 -100
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provide a
|
|
2
|
+
* Provide a call interface for AI
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
|
|
7
|
-
import { Protocol, } from '../protocol';
|
|
7
|
+
import { DemandObject, PermissionObject, Protocol, ServiceObject, } from '../protocol';
|
|
8
8
|
import { Bcs, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType, IsValidU8 } from '../utils'
|
|
9
9
|
import { Errors, ERROR} from '../exception'
|
|
10
10
|
import { MultiGetObjectsParams } from '@mysten/sui/client';
|
|
@@ -13,22 +13,27 @@ import { BCS } from '@mysten/bcs';
|
|
|
13
13
|
import { PermissionAnswerItem, PermissionIndexType } from '../permission';
|
|
14
14
|
import { Entity } from '../entity';
|
|
15
15
|
import { Repository_Policy_Mode } from '../repository';
|
|
16
|
+
import { LargeNumberLike } from 'crypto';
|
|
17
|
+
|
|
18
|
+
export type FUNC_TYPE = string | number | boolean | 'DemandObject' | 'PermissionObject';
|
|
16
19
|
export interface AgentFuncParameter {
|
|
17
|
-
type: 'string' | 'number' | 'boolean' | 'struct' ;
|
|
18
20
|
name: string;
|
|
19
|
-
description
|
|
21
|
+
description?: string;
|
|
20
22
|
required: boolean;
|
|
23
|
+
type: FUNC_TYPE;
|
|
24
|
+
value?: FUNC_TYPE;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export interface AgentFuncReturn {
|
|
24
|
-
type:
|
|
28
|
+
type: DemandObject ;
|
|
25
29
|
name: string;
|
|
26
30
|
description: string;
|
|
27
31
|
}
|
|
32
|
+
|
|
28
33
|
export interface AgentFunc {
|
|
29
34
|
name: string;
|
|
30
|
-
description
|
|
31
|
-
module
|
|
35
|
+
description?: string;
|
|
36
|
+
module?: string;
|
|
32
37
|
permissionIndex: number;
|
|
33
38
|
parameter: AgentFuncParameter[];
|
|
34
39
|
return?: AgentFuncReturn;
|
|
@@ -36,12 +41,12 @@ export interface AgentFunc {
|
|
|
36
41
|
|
|
37
42
|
export const AGENT_FUNC: AgentFunc[] = [
|
|
38
43
|
{permissionIndex:PermissionIndex.repository, name:'Repository', description:'Launch new Repository', module: 'repository', parameter:[
|
|
39
|
-
{type:'
|
|
40
|
-
{type:'
|
|
44
|
+
{type: 'PermissionObject' , name:'permission', description:'Permission address or object', required:true},
|
|
45
|
+
{type: '"Relax mode" or "Strict mode"', name:'mode', description:'Relax mode: Allows entry of data other than policy. Used for informal, non-consensus situations.\nStrict mode: Prohibits entry of data beyond policy. Used in formal, fully consensus contexts.', required:false},
|
|
41
46
|
]},
|
|
42
47
|
{permissionIndex:PermissionIndex.repository_description, name:'Description', description:'Set Repository description', module: 'repository', parameter:[
|
|
43
|
-
{type:'
|
|
44
|
-
{type:'string', name:'description', description:'description', required:true},
|
|
48
|
+
{type:'DemandObject', name:'demand', description:'Demand address or object', required:true},
|
|
49
|
+
{type:'string', name:'description', description:'Demand description', required:true},
|
|
45
50
|
]},
|
|
46
51
|
{permissionIndex:PermissionIndex.repository_policy_mode, name:'Policy mode', description:'Set Repository policy mode', module: 'repository', parameter:[]},
|
|
47
52
|
{permissionIndex:PermissionIndex.repository_policies, name:'Policy', description:'Add/Remove/Edit Repository policy', module: 'repository', parameter:[]},
|
|
@@ -115,6 +120,6 @@ export const AGENT_FUNC: AgentFunc[] = [
|
|
|
115
120
|
{permissionIndex:PermissionIndex.arbitration_withdraw, name: 'Withdraw', description:'Withdraw the arbitration fee', module: 'arbitration', parameter:[]},
|
|
116
121
|
{permissionIndex:PermissionIndex.arbitration_treasury, name: 'Withdraw', description:'Set Treasury that fees was collected at the time of withdrawal', module: 'arbitration', parameter:[]},
|
|
117
122
|
]
|
|
118
|
-
export
|
|
123
|
+
export namespace Call {
|
|
119
124
|
|
|
120
125
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Provide AI with Basic WoWok event queries:
|
|
4
|
+
* for real-time detail tracking.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Protocol } from '../protocol';
|
|
8
|
+
|
|
9
|
+
export interface EventQueryOption {
|
|
10
|
+
/** optional paging cursor */
|
|
11
|
+
cursor?: {eventSeq: string; txDigest: string} | null | undefined;
|
|
12
|
+
/** maximum number of items per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified. */
|
|
13
|
+
limit?: number | null | undefined;
|
|
14
|
+
/** query result ordering, default to false (ascending order), oldest record first. */
|
|
15
|
+
order?: 'ascending' | 'descending' | null | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface EventBase {
|
|
19
|
+
id: {eventSeq: string; txDigest: string};
|
|
20
|
+
sender: string;
|
|
21
|
+
type: string | 'NewArbEvent' | 'NewOrderEvent' | 'NewProgressEvent' | 'PresentServiceEvent';
|
|
22
|
+
type_raw: string;
|
|
23
|
+
time: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NewArbEvent extends EventBase {
|
|
27
|
+
arb: string,
|
|
28
|
+
arbitration: string,
|
|
29
|
+
order: string,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NewOrderEvent extends EventBase {
|
|
33
|
+
order: string,
|
|
34
|
+
service: string,
|
|
35
|
+
progress?: string | null,
|
|
36
|
+
amount: string,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface NewProgressEvent extends EventBase {
|
|
40
|
+
progress: string,
|
|
41
|
+
machine: string,
|
|
42
|
+
task?: string | null,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PresentServiceEvent extends EventBase {
|
|
46
|
+
demand: string,
|
|
47
|
+
service: string,
|
|
48
|
+
recommendation: string,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface EventAnswer {
|
|
52
|
+
data: EventBase[];
|
|
53
|
+
hasNextPage: boolean;
|
|
54
|
+
nextCursor?: {eventSeq: string; txDigest: string} | null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export namespace EVENT_QUERY {
|
|
58
|
+
export const newArbEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
59
|
+
return await queryEvents(Protocol.Instance().Package('wowok') + '::arb::NewArbEvent', option)
|
|
60
|
+
}
|
|
61
|
+
export const presentServiceEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
62
|
+
return await queryEvents(Protocol.Instance().Package('wowok') + '::demand::PresentEvent', option)
|
|
63
|
+
}
|
|
64
|
+
export const newProgressEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
65
|
+
return await queryEvents(Protocol.Instance().Package('wowok') + '::progress::NewProgressEvent', option)
|
|
66
|
+
}
|
|
67
|
+
export const newOrderEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
68
|
+
return await queryEvents(Protocol.Instance().Package('wowok') + '::order::NewOrderEvent', option)
|
|
69
|
+
}
|
|
70
|
+
const queryEvents = async(type:string, option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
71
|
+
const res = await Protocol.Client().queryEvents({query:{MoveEventType:type}, cursor:option?.cursor, limit:option?.limit, order:option?.order});
|
|
72
|
+
const data = res?.data?.map((v:any) => {
|
|
73
|
+
if (v?.packageId === Protocol.Instance().Package('wowok')) {
|
|
74
|
+
if (v?.type?.includes('::order::NewOrderEvent')) {
|
|
75
|
+
return {
|
|
76
|
+
id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'NewOrderEvent',
|
|
77
|
+
order: v?.parsedJson?.object, service: v?.parsedJson?.service, progress: v?.parsedJson?.progress, amount: v?.parsedJson?.amount
|
|
78
|
+
} as NewOrderEvent
|
|
79
|
+
} else if (v?.type?.includes('::demand::PresentEvent')) {
|
|
80
|
+
return {
|
|
81
|
+
id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'NewOrderEvent',
|
|
82
|
+
demand:v?.parsedJson?.object, service: v?.parsedJson?.service, recommendation:v?.parsedJson?.tips
|
|
83
|
+
} as PresentServiceEvent
|
|
84
|
+
} else if (v?.type?.includes('::progress::NewProgressEvent')) {
|
|
85
|
+
return {
|
|
86
|
+
id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'NewOrderEvent',
|
|
87
|
+
progress:v?.parsedJson?.object, machine: v?.parsedJson?.machine, task:v?.parsedJson?.task
|
|
88
|
+
} as NewProgressEvent
|
|
89
|
+
} else if (v?.type?.includes('::arb::NewArbEvent')) {
|
|
90
|
+
return {
|
|
91
|
+
id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'NewOrderEvent',
|
|
92
|
+
arb:v?.parsedJson?.object, arbitration:v?.parsedJson?.arbitration, order:v?.parsedJson?.order
|
|
93
|
+
} as NewArbEvent
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'',}
|
|
97
|
+
})
|
|
98
|
+
return {data:data, hasNextPage:res?.hasNextPage, nextCursor:res?.nextCursor}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provide a
|
|
2
|
+
* Provide a query interface for AI
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,9 +9,14 @@ import { Repository_Type, Repository_Policy_Mode, Repository_Policy } from '../r
|
|
|
9
9
|
import { Service_Discount_Type, Service_Sale } from '../service';
|
|
10
10
|
import { Machine_Node, Machine } from '../machine';
|
|
11
11
|
import { Progress, History } from '../progress';
|
|
12
|
+
import { ERROR, Errors } from '../exception';
|
|
13
|
+
import { IsValidAddress, Bcs } from '../utils';
|
|
12
14
|
export interface ObjectBase {
|
|
13
15
|
object: string;
|
|
14
|
-
type?: string
|
|
16
|
+
type?: string | 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' |
|
|
17
|
+
'Entity' | 'Permission' | 'Resource' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
|
|
18
|
+
'TableItem_DemandPresenter' | 'TableItem_MachineNode' | 'TableItem_ServiceSale' | 'TableItem_TreasuryHistory' | 'TableItem_ArbVote' |
|
|
19
|
+
'TableItem_RepositoryData' | 'TableItem_ResourceMark';
|
|
15
20
|
type_raw?: string;
|
|
16
21
|
owner?: any;
|
|
17
22
|
version?: string;
|
|
@@ -24,7 +29,7 @@ export interface ObjectPermission extends ObjectBase {
|
|
|
24
29
|
biz_permission: {id:number; name:string}[];
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
export interface
|
|
32
|
+
export interface TableItem_PermissionEntity extends ObjectBase {
|
|
28
33
|
entity: string;
|
|
29
34
|
permission: {id:number; guard?:string|null}[];
|
|
30
35
|
}
|
|
@@ -39,7 +44,7 @@ export interface ObjectDemand extends ObjectBase {
|
|
|
39
44
|
bounty: {object:string; balance:string; type:string}[];
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
export interface
|
|
47
|
+
export interface TableItem_DemandPresenter extends ObjectBase {
|
|
43
48
|
service: string;
|
|
44
49
|
presenter: string;
|
|
45
50
|
recommendation: string;
|
|
@@ -55,7 +60,7 @@ export interface ObjectMachine extends ObjectBase {
|
|
|
55
60
|
node_count: number;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
export interface
|
|
63
|
+
export interface TableItem_MachineNode extends ObjectBase {
|
|
59
64
|
node: Machine_Node;
|
|
60
65
|
}
|
|
61
66
|
|
|
@@ -86,7 +91,7 @@ export interface ObjectProgress extends ObjectBase {
|
|
|
86
91
|
namedOperator: {name:string, operator:string[]}[];
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
export interface
|
|
94
|
+
export interface TableItem_ProgressHistory extends ObjectBase {
|
|
90
95
|
history: History;
|
|
91
96
|
}
|
|
92
97
|
|
|
@@ -108,7 +113,7 @@ export interface ObjectService extends ObjectBase {
|
|
|
108
113
|
customer_required_info?: {pubkey:string; required_info:string[]};
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
export interface
|
|
116
|
+
export interface TableItem_ServiceSale extends ObjectBase {
|
|
112
117
|
item: Service_Sale;
|
|
113
118
|
}
|
|
114
119
|
export interface ObjectOrder extends ObjectBase {
|
|
@@ -135,7 +140,7 @@ export interface ObjectTreasury extends ObjectBase {
|
|
|
135
140
|
balance: string;
|
|
136
141
|
history_count: number;
|
|
137
142
|
}
|
|
138
|
-
export interface
|
|
143
|
+
export interface TableItem_TreasuryHistory extends ObjectBase {
|
|
139
144
|
id: number,
|
|
140
145
|
operation: Treasury_Operation,
|
|
141
146
|
signer: string,
|
|
@@ -165,7 +170,7 @@ export interface ObjectArb extends ObjectBase {
|
|
|
165
170
|
proposition: {proposition:string, votes:string};
|
|
166
171
|
voted_count: number;
|
|
167
172
|
}
|
|
168
|
-
export interface
|
|
173
|
+
export interface TableItem_ArbVote extends ObjectBase {
|
|
169
174
|
singer: string;
|
|
170
175
|
vote: number[];
|
|
171
176
|
weight: string;
|
|
@@ -180,7 +185,7 @@ export interface ObjectRepository extends ObjectBase {
|
|
|
180
185
|
policy: Repository_Policy[];
|
|
181
186
|
data_count: number;
|
|
182
187
|
}
|
|
183
|
-
export interface
|
|
188
|
+
export interface TableItem_RepositoryData extends ObjectBase {
|
|
184
189
|
address: string;
|
|
185
190
|
key: string;
|
|
186
191
|
data: Uint8Array;
|
|
@@ -211,6 +216,37 @@ export interface ObjectGuard extends ObjectBase {
|
|
|
211
216
|
input: Uint8Array;
|
|
212
217
|
identifier: {id:number; bWitness:boolean; value:Uint8Array}[];
|
|
213
218
|
}
|
|
219
|
+
export interface ObjectEntity extends ObjectBase {
|
|
220
|
+
address: string;
|
|
221
|
+
like: number;
|
|
222
|
+
dislike: number;
|
|
223
|
+
|
|
224
|
+
name?: string;
|
|
225
|
+
description?: string;
|
|
226
|
+
avatar?: string;
|
|
227
|
+
x?: string;
|
|
228
|
+
discord?: string;
|
|
229
|
+
|
|
230
|
+
homepage?: string;
|
|
231
|
+
resource_object?: string | null;
|
|
232
|
+
lastActive_digest?: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface ObjectResouorce_Tag {
|
|
236
|
+
object: string;
|
|
237
|
+
nick_name: string;
|
|
238
|
+
tags: string[];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface ObjectResouorce extends ObjectBase {
|
|
242
|
+
marks_count: number;
|
|
243
|
+
tags: ObjectResouorce_Tag[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface TableItem_ResourceMark extends ObjectBase {
|
|
247
|
+
mark_name: string;
|
|
248
|
+
objects: string[];
|
|
249
|
+
}
|
|
214
250
|
|
|
215
251
|
export interface ObjectsQuery {
|
|
216
252
|
objects: string[];
|
|
@@ -218,7 +254,6 @@ export interface ObjectsQuery {
|
|
|
218
254
|
showContent?: boolean;
|
|
219
255
|
showOwner?: boolean;
|
|
220
256
|
}
|
|
221
|
-
|
|
222
257
|
export interface ObjectsAnswer {
|
|
223
258
|
objects?: ObjectBase[];
|
|
224
259
|
error?: string;
|
|
@@ -229,89 +264,122 @@ export interface TableQuery {
|
|
|
229
264
|
cursor?: string | null | undefined;
|
|
230
265
|
limit?: number | null | undefined;
|
|
231
266
|
}
|
|
232
|
-
|
|
267
|
+
export interface TableAnswerItem {
|
|
268
|
+
key: {type:string; value:unknown};
|
|
269
|
+
object: string;
|
|
270
|
+
version: string;
|
|
271
|
+
}
|
|
233
272
|
export interface TableAnswer {
|
|
234
|
-
items:
|
|
273
|
+
items: TableAnswerItem[];
|
|
235
274
|
nextCursor: string | null;
|
|
236
275
|
hasNextPage: boolean;
|
|
237
276
|
}
|
|
238
277
|
|
|
239
|
-
|
|
278
|
+
interface TableItemQuery {
|
|
240
279
|
parent: string;
|
|
241
|
-
|
|
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;
|
|
280
|
+
key: {type:string, value:unknown};
|
|
255
281
|
}
|
|
256
282
|
|
|
257
|
-
export
|
|
258
|
-
|
|
259
|
-
export class OBJECT_QUERY {
|
|
283
|
+
export namespace OBJECT_QUERY {
|
|
260
284
|
/* json: ObjectsQuery string */
|
|
261
|
-
|
|
285
|
+
export const objects_json = async (json:string) : Promise<string> => {
|
|
262
286
|
try {
|
|
263
287
|
const q : ObjectsQuery = JSON.parse(json);
|
|
264
|
-
return JSON.stringify(await
|
|
288
|
+
return JSON.stringify({data:await objects(q)});
|
|
265
289
|
} catch (e) {
|
|
266
290
|
return JSON.stringify({error:e?.toString()})
|
|
267
291
|
}
|
|
268
292
|
}
|
|
269
293
|
|
|
270
294
|
/* json: TableQuery string */
|
|
271
|
-
|
|
295
|
+
export const table_json = async (json:string) : Promise<string> => {
|
|
272
296
|
try {
|
|
273
297
|
const q : TableQuery = JSON.parse(json);
|
|
274
|
-
return JSON.stringify(await
|
|
298
|
+
return JSON.stringify({data:await table(q)});
|
|
275
299
|
} catch (e) {
|
|
276
300
|
return JSON.stringify({error:e?.toString()})
|
|
277
301
|
}
|
|
278
302
|
}
|
|
279
303
|
|
|
280
|
-
|
|
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> => {
|
|
304
|
+
export const objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer> => {
|
|
291
305
|
if (query.objects.length > 0) {
|
|
292
306
|
const res = await Protocol.Client().multiGetObjects({ids:query.objects,
|
|
293
307
|
options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
|
|
294
308
|
console.log(JSON.stringify(res))
|
|
295
|
-
return {objects:res.map(v=>
|
|
309
|
+
return {objects:res.map(v=>data2object(v?.data))}
|
|
296
310
|
}
|
|
297
311
|
return {objects:[]}
|
|
298
312
|
}
|
|
313
|
+
export const entity = async (address:string) : Promise<ObjectEntity> => {
|
|
314
|
+
if (!IsValidAddress(address)) ERROR(Errors.IsValidAddress, 'entity.address')
|
|
315
|
+
const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().EntityObject(), name:{type:'address', value:address}});
|
|
316
|
+
return data2object(res?.data) as ObjectEntity
|
|
317
|
+
}
|
|
299
318
|
|
|
300
|
-
|
|
319
|
+
export const table = async (query:TableQuery) : Promise<TableAnswer> => {
|
|
301
320
|
const res = await Protocol.Client().getDynamicFields({parentId:query.parent, cursor:query.cursor, limit:query.limit});
|
|
302
321
|
return {items:res?.data?.map(v=>{
|
|
303
|
-
return {object:v.objectId, type:v.type, version:v.version,
|
|
304
|
-
type:v.name.type, value:v.name.value
|
|
322
|
+
return {object:v.objectId, type:v.type, version:v.version, key:{
|
|
323
|
+
type:v.name.type, value:v.name.value
|
|
305
324
|
}}
|
|
306
325
|
}), nextCursor:res.nextCursor, hasNextPage:res.hasNextPage}
|
|
307
326
|
}
|
|
308
327
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
328
|
+
export const queryTableItem_DemandPresenter = async (demand_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
329
|
+
return await tableItem(tableItemQuery_byAddress(demand_object, address))
|
|
330
|
+
}
|
|
331
|
+
export const queryTableItem_PermissionEntity = async (permission_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
332
|
+
return await tableItem(tableItemQuery_byAddress(permission_object, address))
|
|
333
|
+
}
|
|
334
|
+
export const queryTableItem_ArbVote = async (arb_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
335
|
+
return await tableItem(tableItemQuery_byAddress(arb_object, address))
|
|
336
|
+
}
|
|
337
|
+
export const tableItemQuery_MachineNode = async (machine_object:string | ObjectMachine, name:string) : Promise<ObjectBase> => {
|
|
338
|
+
return await tableItem(tableItemQuery_byString(machine_object, name))
|
|
339
|
+
}
|
|
340
|
+
export const tableItemQuery_ServiceSale = async (service_object:string | ObjectService, name:string) : Promise<ObjectBase> => {
|
|
341
|
+
return await tableItem(tableItemQuery_byString(service_object, name))
|
|
342
|
+
}
|
|
343
|
+
export const tableItemQuery_ProgressHistory = async (progress_object:string | ObjectProgress, index:BigInt) : Promise<ObjectBase> => {
|
|
344
|
+
return await tableItem(tableItemQuery_byU64(progress_object, index))
|
|
345
|
+
}
|
|
346
|
+
export const tableItemQuery_TreasuryHistory = async (treasury_object:string | ObjectTreasury, index:BigInt) : Promise<ObjectBase> => {
|
|
347
|
+
return await tableItem(tableItemQuery_byU64(treasury_object, index))
|
|
348
|
+
}
|
|
349
|
+
export const tableItemQuery_RepositoryData = async (repository_object:string | ObjectRepository, address:string, name:string) : Promise<ObjectBase> => {
|
|
350
|
+
if (typeof(repository_object) !== 'string') {
|
|
351
|
+
repository_object = repository_object.object;
|
|
352
|
+
}
|
|
353
|
+
return await tableItem({parent:repository_object, key:{type:Protocol.Instance().Package('wowok')+'::repository::DataKey', value:{id:address, key:name}}})
|
|
354
|
+
}
|
|
355
|
+
export const tableItemQuery_ResourceMark = async (resource_object:string | ObjectResouorce, name:string) : Promise<ObjectBase> => {
|
|
356
|
+
return await tableItem(tableItemQuery_byString(resource_object, name))
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function tableItemQuery_byAddress(parent:string | ObjectDemand | ObjectPermission | ObjectArb, address:string) : TableItemQuery {
|
|
360
|
+
if (typeof(parent) !== 'string') {
|
|
361
|
+
parent = parent.object;
|
|
362
|
+
}
|
|
363
|
+
return {parent:parent, key:{type:'address', value:address}};
|
|
364
|
+
}
|
|
365
|
+
function tableItemQuery_byString(parent:string | ObjectMachine | ObjectService | ObjectResouorce, name:string) : TableItemQuery {
|
|
366
|
+
if (typeof(parent) !== 'string') {
|
|
367
|
+
parent = parent.object;
|
|
368
|
+
}
|
|
369
|
+
return {parent:parent, key:{type:'0x1::string::String', value:name}};
|
|
370
|
+
}
|
|
371
|
+
function tableItemQuery_byU64 (parent:string | ObjectProgress | ObjectTreasury, index:BigInt) : TableItemQuery {
|
|
372
|
+
if (typeof(parent) !== 'string') {
|
|
373
|
+
parent = parent.object;
|
|
374
|
+
}
|
|
375
|
+
return {parent:parent, key:{type:'u64', value:index}};
|
|
376
|
+
}
|
|
377
|
+
const tableItem = async (query:TableItemQuery) : Promise<ObjectBase> => {
|
|
378
|
+
const res = await Protocol.Client().getDynamicFieldObject({parentId:query.parent, name:{type:query.key.type, value:query.key.value}});
|
|
379
|
+
return data2object(res?.data)
|
|
312
380
|
}
|
|
313
381
|
|
|
314
|
-
|
|
382
|
+
function data2object(data?:any) : ObjectBase {
|
|
315
383
|
const content = (data?.content as any)?.fields;
|
|
316
384
|
const id = data?.objectId ?? (content?.id?.id ?? undefined);
|
|
317
385
|
const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
|
|
@@ -456,7 +524,15 @@ export class OBJECT_QUERY {
|
|
|
456
524
|
identifier:content?.constants?.map((v:any) => {
|
|
457
525
|
return {id:v?.fields?.identifier, bWitness:v?.fields?.bWitness, value:Uint8Array.from(v?.fields?.value)}
|
|
458
526
|
})
|
|
459
|
-
} as ObjectGuard;
|
|
527
|
+
} as ObjectGuard;
|
|
528
|
+
case 'Resource' :
|
|
529
|
+
return {
|
|
530
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
531
|
+
marks_count:parseInt(content?.marks?.fields?.size),
|
|
532
|
+
tags:content?.tags?.map((v:any) => {
|
|
533
|
+
return {object:v?.fields?.object, nick_name:v?.fields?.nick, tags:v?.fields?.tags}
|
|
534
|
+
})
|
|
535
|
+
} as ObjectResouorce;
|
|
460
536
|
}
|
|
461
537
|
}
|
|
462
538
|
|
|
@@ -468,48 +544,62 @@ export class OBJECT_QUERY {
|
|
|
468
544
|
return {
|
|
469
545
|
object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
|
|
470
546
|
service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
|
|
471
|
-
} as
|
|
547
|
+
} as TableItem_DemandPresenter;
|
|
472
548
|
} else if (end.includes('::machine::NodePair>>>')) {
|
|
473
549
|
return {
|
|
474
550
|
object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
|
|
475
551
|
node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
|
|
476
|
-
} as
|
|
552
|
+
} as TableItem_MachineNode;
|
|
477
553
|
} else if (end.includes('::progress::History>')) {
|
|
478
554
|
return {
|
|
479
555
|
object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
480
556
|
history:Progress.rpc_de_history(content)
|
|
481
|
-
} as
|
|
557
|
+
} as TableItem_ProgressHistory;
|
|
482
558
|
} else if (end.includes('::service::Sale>')) {
|
|
483
559
|
return {
|
|
484
560
|
object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
|
|
485
561
|
item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
|
|
486
562
|
endpoint:content?.value?.fields?.endpoint
|
|
487
563
|
}
|
|
488
|
-
} as
|
|
564
|
+
} as TableItem_ServiceSale;
|
|
489
565
|
} else if (end.includes('::treasury::Record>')) {
|
|
490
566
|
return {
|
|
491
567
|
object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
492
568
|
id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
|
|
493
569
|
operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
|
|
494
|
-
} as
|
|
570
|
+
} as TableItem_TreasuryHistory;
|
|
495
571
|
} else if (end.includes('::arb::Voted>')) {
|
|
496
572
|
return {
|
|
497
573
|
object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
|
|
498
574
|
singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
|
|
499
575
|
weight:content?.value?.fields?.weight
|
|
500
|
-
} as
|
|
576
|
+
} as TableItem_ArbVote;
|
|
501
577
|
} else if (end.includes('::permission::Perm>>')) {
|
|
502
578
|
return {
|
|
503
|
-
object:id, type:'
|
|
579
|
+
object:id, type:'TableItem_PermissionEntity', type_raw:type_raw, owner:owner, version:version,
|
|
504
580
|
entity:content?.name, permission:content?.value?.map((v:any) => {
|
|
505
581
|
return {id:v?.fields.index, guard:v?.fields.guard}
|
|
506
582
|
})
|
|
507
|
-
} as
|
|
583
|
+
} as TableItem_PermissionEntity;
|
|
508
584
|
} else if (end.includes('::repository::DataKey')) {
|
|
509
585
|
return {
|
|
510
|
-
object:id, type:'
|
|
586
|
+
object:id, type:'TableItem_RepositoryData', type_raw:type_raw, owner:owner, version:version,
|
|
511
587
|
address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
|
|
512
|
-
} as
|
|
588
|
+
} as TableItem_RepositoryData;
|
|
589
|
+
} else if (end.includes('::entity::Ent>')) {
|
|
590
|
+
const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
|
|
591
|
+
return {
|
|
592
|
+
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
593
|
+
address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
|
|
594
|
+
resource_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
|
|
595
|
+
homepage:info?.homepage, name:info?.name, avatar:info?.avatar, x:info?.twitter, discord:info?.discord,
|
|
596
|
+
description:info?.description
|
|
597
|
+
} as ObjectEntity;
|
|
598
|
+
} else if (end.includes('::resource::Addresses>')) {
|
|
599
|
+
return {
|
|
600
|
+
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
601
|
+
mark_name:content?.name, objects:content?.value?.fields?.addresses
|
|
602
|
+
} as TableItem_ResourceMark;
|
|
513
603
|
}
|
|
514
604
|
}
|
|
515
605
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Provides permission lookup for an address:
|
|
3
|
+
* not only the permission table, but also the administrator or Builder identity.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
|
|
@@ -9,25 +9,25 @@ import { Bcs, IsValidAddress} from '../utils'
|
|
|
9
9
|
import { Errors, ERROR} from '../exception'
|
|
10
10
|
import { Permission } from '../permission';
|
|
11
11
|
import { BCS } from '@mysten/bcs';
|
|
12
|
-
import { PermissionAnswerItem,
|
|
12
|
+
import { PermissionAnswerItem, PermissionAnswer } from '../permission';
|
|
13
13
|
|
|
14
14
|
export interface PermissionQuery {
|
|
15
15
|
permission_object: string;
|
|
16
16
|
address: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export namespace PERMISSION_QUERY {
|
|
20
20
|
/*json: PermissionQuery; return PermissionAnswer */
|
|
21
|
-
|
|
21
|
+
export const permission_json = async (json:string) : Promise<string> => {
|
|
22
22
|
try {
|
|
23
23
|
const q : PermissionQuery = JSON.parse(json);
|
|
24
|
-
return JSON.stringify(await
|
|
24
|
+
return JSON.stringify({data:await permission(q)});
|
|
25
25
|
} catch (e) {
|
|
26
26
|
return JSON.stringify({error:e});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
export const permission = async (query:PermissionQuery) : Promise<PermissionAnswer> => {
|
|
31
31
|
if (!IsValidAddress(query.permission_object)) {
|
|
32
32
|
ERROR(Errors.IsValidAddress, 'permission.permission_object');
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,9 +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/
|
|
17
|
+
export * from './agent_query/objects'
|
|
18
18
|
export * from './agent_query/permission'
|
|
19
|
-
export * from './agent_query/
|
|
19
|
+
export * from './agent_query/events'
|
|
20
20
|
|
|
21
21
|
// export * from './reward'
|
|
22
22
|
// export * from './vote'
|
package/src/protocol.ts
CHANGED
|
@@ -163,7 +163,7 @@ export enum ContextType {
|
|
|
163
163
|
TYPE_SIGNER = 60,
|
|
164
164
|
TYPE_CLOCK = 61,
|
|
165
165
|
TYPE_GUARD = 62, // current guard address
|
|
166
|
-
TYPE_STACK_ADDRESS = 63, // object queried from current stack top
|
|
166
|
+
//TYPE_STACK_ADDRESS = 63, // object queried from current stack top
|
|
167
167
|
TYPE_CONSTANT = 80,
|
|
168
168
|
}
|
|
169
169
|
interface ValueTypeString {
|
|
@@ -219,13 +219,13 @@ const TESTNET = {
|
|
|
219
219
|
}
|
|
220
220
|
*/
|
|
221
221
|
const TESTNET = {
|
|
222
|
-
wowok: "
|
|
223
|
-
wowok_origin:'
|
|
222
|
+
wowok: "0x5091944f647fdcd1a5a90016933a9eac13b2c1dc41291d1ce31ed7a0cd664a02",
|
|
223
|
+
wowok_origin:'0x5091944f647fdcd1a5a90016933a9eac13b2c1dc41291d1ce31ed7a0cd664a02' ,
|
|
224
224
|
base: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
|
|
225
225
|
base_origin: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
|
|
226
226
|
|
|
227
|
-
wowok_object: '
|
|
228
|
-
entity_object: '
|
|
227
|
+
wowok_object: '0x6cfe6ee9f53b33eed11a6d4d1e09fb43278f222ced15aef7246243ecadf3c00f',
|
|
228
|
+
entity_object: '0x5469d38103ab78f91222338b489b512f9de86932edde064f7d2d77a6e78cf7a9',
|
|
229
229
|
treasury_cap:'0x9f415c863f0c26103e70fc4a739fea479ff20544057a3c5665db16c0b8650f7c',
|
|
230
230
|
oracle_object:'0x6c7d9b8ab0e9d21291e0128ca3e0d550b30f375f1e008381f2fbeef6753e6dcf',
|
|
231
231
|
}
|
|
@@ -272,7 +272,8 @@ export class Protocol {
|
|
|
272
272
|
static Client() : SuiClient {
|
|
273
273
|
return new SuiClient({ url: Protocol.Instance().NetworkUrl() });
|
|
274
274
|
}
|
|
275
|
-
|
|
275
|
+
|
|
276
|
+
client() { return new SuiClient({url: this.NetworkUrl() })}
|
|
276
277
|
UseNetwork(network:ENTRYPOINT=ENTRYPOINT.testnet) {
|
|
277
278
|
this.network = network;
|
|
278
279
|
switch(network) {
|
package/src/utils.ts
CHANGED
|
@@ -323,7 +323,7 @@ export class Bcs {
|
|
|
323
323
|
return this.bcs.de('EntStruct', Uint8Array.from(struct_vec));
|
|
324
324
|
}
|
|
325
325
|
de_entInfo(data:Uint8Array | undefined) : any {
|
|
326
|
-
if (!data || data.length === 0) return
|
|
326
|
+
if (!data || data.length === 0) return undefined
|
|
327
327
|
let r = this.bcs.de('PersonalInfo', data);
|
|
328
328
|
r.name = new TextDecoder().decode(Uint8Array.from(r.name));
|
|
329
329
|
r.description = new TextDecoder().decode(Uint8Array.from(r.description));
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
}
|