wowok 1.7.13 → 1.7.16

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.
Files changed (48) hide show
  1. package/dist/arbitration.d.ts.map +1 -1
  2. package/dist/arbitration.js +21 -32
  3. package/dist/arbitration.js.map +1 -1
  4. package/dist/entity.d.ts +1 -0
  5. package/dist/entity.d.ts.map +1 -1
  6. package/dist/entity.js +12 -6
  7. package/dist/entity.js.map +1 -1
  8. package/dist/exception.d.ts +2 -1
  9. package/dist/exception.d.ts.map +1 -1
  10. package/dist/exception.js +1 -0
  11. package/dist/exception.js.map +1 -1
  12. package/dist/guard.d.ts.map +1 -1
  13. package/dist/guard.js +8 -4
  14. package/dist/guard.js.map +1 -1
  15. package/dist/payment.d.ts +2 -2
  16. package/dist/payment.d.ts.map +1 -1
  17. package/dist/payment.js +2 -2
  18. package/dist/payment.js.map +1 -1
  19. package/dist/protocol.d.ts +21 -19
  20. package/dist/protocol.d.ts.map +1 -1
  21. package/dist/protocol.js +211 -58
  22. package/dist/protocol.js.map +1 -1
  23. package/dist/service.d.ts +2 -2
  24. package/dist/service.d.ts.map +1 -1
  25. package/dist/service.js +5 -6
  26. package/dist/service.js.map +1 -1
  27. package/package.json +5 -2
  28. package/src/arbitration.ts +0 -551
  29. package/src/demand.ts +0 -300
  30. package/src/entity.ts +0 -171
  31. package/src/exception.ts +0 -37
  32. package/src/guard.ts +0 -810
  33. package/src/index.ts +0 -40
  34. package/src/machine.ts +0 -542
  35. package/src/passport.ts +0 -777
  36. package/src/payment.ts +0 -94
  37. package/src/permission.ts +0 -550
  38. package/src/progress.ts +0 -367
  39. package/src/protocol.ts +0 -549
  40. package/src/repository.ts +0 -680
  41. package/src/resource.ts +0 -155
  42. package/src/service.ts +0 -1349
  43. package/src/treasury.ts +0 -425
  44. package/src/utils.ts +0 -660
  45. package/src/wowok.ts +0 -70
  46. package/tsconfig.json +0 -30
  47. package/tsconfig.tsbuildinfo +0 -1
  48. package/webpack.config.cjs +0 -23
package/src/progress.ts DELETED
@@ -1,367 +0,0 @@
1
-
2
- import { FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject,
3
- ProgressObject, ProgressAddress, Protocol, TxbObject,
4
- OrderObject} from './protocol.js';
5
- import { Machine } from './machine.js';
6
- import { Bcs, array_unique,IsValidName, IsValidAddress, IsValidArray, IsValidInt, IsValidDesription, IsValidTokenType } from './utils.js'
7
- import { ERROR, Errors } from './exception.js';
8
- import { type TransactionResult, Transaction as TransactionBlock, } from '@mysten/sui/transactions';
9
- import { bcs } from '@mysten/sui/bcs'
10
-
11
- export interface OrderWrap {
12
- object: OrderObject;
13
- pay_token_type: string;
14
- }
15
-
16
- export interface Deliverable {
17
- msg: string;
18
- orders: OrderWrap[];
19
- }
20
-
21
- export type ProgressNext = {
22
- next_node_name: string;
23
- forward: string;
24
- }
25
-
26
- export type ParentProgress = {
27
- parent_id: string;
28
- parent_session_id: number;
29
- operation: ProgressNext;
30
- }
31
-
32
- export type CurrentSessionId = TransactionResult;
33
- export interface Holder {
34
- forward: string;
35
- who?:string;
36
- deliverable: Deliverable;
37
- accomplished:boolean;
38
- time: string;
39
- }
40
- export interface Session {
41
- id?: number; // sid
42
- next_node: string;
43
- holders: Holder[];
44
- weights: number;
45
- threshold: number;
46
- node?:string;
47
- bComplete?: boolean;
48
- }
49
-
50
- export interface History {
51
- id: number; // sid
52
- node: string;
53
- next_node: string;
54
- time: string;
55
- sessions: Session[];
56
- }
57
- export class Progress {
58
- protected permission ;
59
- protected machine;
60
- protected object : TxbObject;
61
- protected txb;
62
-
63
- get_object() { return this.object }
64
- private constructor(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject) {
65
- this.permission = permission;
66
- this.txb = txb;
67
- this.machine = machine;
68
- this.object = '';
69
- }
70
- static From(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, object:TxbObject) : Progress{
71
- let p = new Progress(txb, machine, permission)
72
- p.object = Protocol.TXB_OBJECT(txb, object);
73
- return p
74
- }
75
- static New(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, task?:string | null, passport?:PassportObject) : Progress {
76
- if (!Protocol.IsValidObjects([machine, permission])) {
77
- ERROR(Errors.IsValidObjects, 'machine & permission')
78
- }
79
-
80
- let p = new Progress(txb, machine, permission);
81
- let t = txb.pure.option('address', task ? task : undefined);
82
-
83
- if (passport) {
84
- p.object = txb.moveCall({
85
- target:Protocol.Instance().progressFn('new_with_passport') as FnCallType,
86
- arguments: [passport, t, Protocol.TXB_OBJECT(txb, machine), Protocol.TXB_OBJECT(txb, permission)],
87
- })
88
- } else {
89
- p.object = txb.moveCall({
90
- target:Protocol.Instance().progressFn('new') as FnCallType,
91
- arguments: [t, Protocol.TXB_OBJECT(txb, machine), Protocol.TXB_OBJECT(txb, permission)],
92
- })
93
- }
94
- return p
95
- }
96
-
97
- launch() : ProgressAddress {
98
- return this.txb.moveCall({
99
- target:Protocol.Instance().progressFn('create') as FnCallType,
100
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
101
- })
102
- }
103
-
104
- set_namedOperator(name:string, addresses:string[], passport?:PassportObject) {
105
- if (!IsValidName(name)) {
106
- ERROR(Errors.IsValidName, 'name')
107
- }
108
- if (name === Machine.OPERATOR_ORDER_PAYER) {
109
- ERROR(Errors.InvalidParam, 'name cannot be '+Machine.OPERATOR_ORDER_PAYER);
110
- }
111
- if (addresses.length > Progress.MAX_NAMED_OPERATOR_COUNT || !IsValidArray(addresses, IsValidAddress)) {
112
- ERROR(Errors.InvalidParam, 'addresses')
113
- }
114
-
115
- if (passport) {
116
- this.txb.moveCall({
117
- target:Protocol.Instance().progressFn('namedOperator_set_with_passport') as FnCallType,
118
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
119
- this.txb.pure.vector('address', array_unique(addresses)),
120
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
121
- })
122
- } else {
123
- this.txb.moveCall({
124
- target:Protocol.Instance().progressFn('namedOperator_set') as FnCallType,
125
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
126
- this.txb.pure.vector('address', array_unique(addresses)),
127
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
128
- })
129
- }
130
- }
131
-
132
- bind_task(task_address:string, passport?:PassportObject) {
133
- if (!IsValidAddress(task_address)) {
134
- ERROR(Errors.IsValidAddress)
135
- }
136
-
137
- if (passport) {
138
- this.txb.moveCall({
139
- target:Protocol.Instance().progressFn('task_set_with_passport') as FnCallType,
140
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
141
- this.txb.pure.address(task_address), Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
142
- })
143
- } else {
144
- this.txb.moveCall({
145
- target:Protocol.Instance().progressFn('task_set') as FnCallType,
146
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(task_address),
147
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
148
- })
149
- }
150
- }
151
- set_context_repository(repository?:RepositoryObject, passport?:PassportObject) {
152
- if (repository && !Protocol.IsValidObjects([repository])) {
153
- ERROR(Errors.IsValidObjects, 'repository')
154
- }
155
-
156
- if (passport) {
157
- if (repository) {
158
- this.txb.moveCall({
159
- target:Protocol.Instance().progressFn('context_repository_set_with_passport') as FnCallType,
160
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository),
161
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
162
- })
163
- } else {
164
- this.txb.moveCall({
165
- target:Protocol.Instance().progressFn('context_repository_none_with_passport') as FnCallType,
166
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
167
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
168
- })
169
- }
170
- } else {
171
- if (repository) {
172
- this.txb.moveCall({
173
- target:Protocol.Instance().progressFn('context_repository_set') as FnCallType,
174
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository),
175
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
176
- })
177
- } else {
178
- this.txb.moveCall({
179
- target:Protocol.Instance().progressFn('context_repository_none') as FnCallType,
180
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
181
- })
182
- }
183
- }
184
- }
185
- unhold(next:ProgressNext, passport?:PassportObject) {
186
- if (!Progress.IsValidProgressNext(next)) {
187
- ERROR(Errors.InvalidParam, 'unhold')
188
- }
189
-
190
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
191
-
192
- if (passport) {
193
- this.txb.moveCall({
194
- target:Protocol.Instance().progressFn('unhold_with_passport') as FnCallType,
195
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
196
- Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
197
- this.txb.pure.string(next.forward), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
198
- })
199
- } else {
200
- this.txb.moveCall({
201
- target:Protocol.Instance().progressFn('unhold') as FnCallType,
202
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
203
- this.txb.pure.string(next.next_node_name), this.txb.pure.string(next.forward),
204
- Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
205
- })
206
- }
207
- }
208
- parent_none(passport?:PassportObject) {
209
- if (passport) {
210
- this.txb.moveCall({
211
- target:Protocol.Instance().progressFn('parent_none_with_passport') as FnCallType,
212
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object),
213
- Protocol.TXB_OBJECT(this.txb, this.machine), Protocol.TXB_OBJECT(this.txb, this.permission)],
214
- })
215
- } else {
216
- this.txb.moveCall({
217
- target:Protocol.Instance().progressFn('parent_none') as FnCallType,
218
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
219
- Protocol.TXB_OBJECT(this.txb, this.permission)],
220
- })
221
- }
222
- }
223
-
224
- parent(parent:ParentProgress, passport?:PassportObject) {
225
- if (!IsValidAddress(parent.parent_id) || !IsValidInt(parent.parent_session_id)) {
226
- ERROR(Errors.InvalidParam, 'parent')
227
- }
228
- if (!parent.operation.next_node_name || !parent.operation.forward) {
229
- ERROR(Errors.InvalidParam, 'parent')
230
- }
231
-
232
- if (passport) {
233
- this.txb.moveCall({
234
- target:Protocol.Instance().progressFn('parent_set_with_passport') as FnCallType,
235
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
236
- this.txb.object(parent.parent_id),
237
- this.txb.pure.u64(parent.parent_session_id),
238
- this.txb.pure.string(parent.operation.next_node_name),
239
- this.txb.pure.string(parent.operation.forward),
240
- Protocol.TXB_OBJECT(this.txb, this.permission)],
241
- })
242
- } else {
243
- this.txb.moveCall({
244
- target:Protocol.Instance().progressFn('parent_set') as FnCallType,
245
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
246
- this.txb.object(parent.parent_id),
247
- this.txb.pure.u64(parent.parent_session_id),
248
- this.txb.pure.string(parent.operation.next_node_name),
249
- this.txb.pure.string(parent.operation.forward),
250
- Protocol.TXB_OBJECT(this.txb, this.permission)],
251
- })
252
- }
253
- }
254
-
255
- private deliverable(deliverable:Deliverable) : TransactionResult {
256
- if (!IsValidDesription(deliverable.msg)) {
257
- ERROR(Errors.IsValidDesription, 'deliverable.msg')
258
- }
259
- if (deliverable.orders.length > 0 && !Protocol.IsValidObjects(deliverable.orders.map(v=>v.object))) {
260
- ERROR(Errors.IsValidObjects, 'deliverable.orders')
261
- }
262
-
263
- const d = this.txb.moveCall({
264
- target:Protocol.Instance().progressFn('deliverable_new') as FnCallType,
265
- arguments: [this.txb.pure.string(deliverable.msg)],
266
- })
267
- deliverable.orders.forEach(v => {
268
- if (!IsValidTokenType(v.pay_token_type)) {
269
- ERROR(Errors.IsValidTokenType, 'deliverable.orders:' + v.object)
270
- }
271
- this.txb.moveCall({
272
- target:Protocol.Instance().orderFn('as_deliverable') as FnCallType,
273
- arguments: [Protocol.TXB_OBJECT(this.txb, v.object), d],
274
- typeArguments:[v.pay_token_type]
275
- })
276
- })
277
- return d
278
- }
279
-
280
- next(next:ProgressNext, deliverable:Deliverable, passport?:PassportObject) : CurrentSessionId {
281
- if (!Progress.IsValidProgressNext(next)) {
282
- ERROR(Errors.InvalidParam, 'next')
283
- }
284
-
285
- const d = this.deliverable(deliverable);
286
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
287
-
288
- if (passport) {
289
- return this.txb.moveCall({
290
- target:Protocol.Instance().progressFn('next_with_passport') as FnCallType,
291
- arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
292
- this.txb.pure.string(next.next_node_name),
293
- this.txb.pure.string(next.forward), d,
294
- Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
295
- })
296
- } else {
297
- return this.txb.moveCall({
298
- target:Protocol.Instance().progressFn('next') as FnCallType,
299
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
300
- this.txb.pure.string(next.forward), d, Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
301
- })
302
- }
303
- }
304
-
305
- hold(next:ProgressNext, hold:boolean) : CurrentSessionId {
306
- if (!Progress.IsValidProgressNext(next)) {
307
- ERROR(Errors.InvalidParam, 'hold')
308
- }
309
- const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
310
- return this.txb.moveCall({
311
- target:Protocol.Instance().progressFn('hold') as FnCallType,
312
- arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine), this.txb.pure.string(next.next_node_name),
313
- this.txb.pure.string(next.forward), this.txb.pure.bool(hold), Protocol.TXB_OBJECT(this.txb, this.permission), this.txb.object(clock)],
314
- })
315
- }
316
- static QueryForwardGuard = async (progress:ProgressObject, machine:MachineObject, sender:string, next_node:string, forward:string): Promise<string | undefined> => {
317
- if (!progress || !machine || !next_node || !forward) { // prior_node maybe ''
318
- ERROR(Errors.InvalidParam, 'QueryForwardGuard');
319
- return ;
320
- }
321
-
322
- const txb = new TransactionBlock();
323
- txb.moveCall({
324
- target:Protocol.Instance().progressFn('query_guard') as FnCallType,
325
- arguments:[Protocol.TXB_OBJECT(txb, progress), Protocol.TXB_OBJECT(txb, machine),
326
- txb.pure.string(next_node), txb.pure.string(forward)],
327
- });
328
-
329
- const res = await Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:txb});
330
- if (res.results?.length === 1 && res.results[0].returnValues?.length === 1) {
331
- const guard = bcs.option(bcs.Address).parse(Uint8Array.from(res.results[0].returnValues[0][0]));
332
- return guard?? undefined;
333
- }
334
- }
335
-
336
- static DeSessions = (session: any) : Session[] => {
337
- let sessions : Session[] = [];
338
- session?.fields?.contents?.forEach((v:any) => {
339
- var s:Session = {next_node: v.fields.key, holders:[], weights:v.fields.value.fields.weights, threshold:v.fields.value.fields.threshold};
340
- v.fields.value.fields.forwards.fields.contents.forEach((i:any) => {
341
- s.holders.push({forward:i.fields.key, accomplished:i.fields.value.fields.accomplished, time:i.fields.value.fields.time,
342
- who:i.fields.value.fields.who, deliverable:{msg:i.fields.value.fields.msg, orders:i.fields.value.fields.orders ?? []},
343
- })
344
- })
345
- sessions.push(s);
346
- })
347
- return sessions;
348
- }
349
-
350
- static DeHistories = (fields: any) : History[] => {
351
- return fields?.map((v:any) => {
352
- return Progress.DeHistory(v?.data?.content?.fields)
353
- })
354
- }
355
-
356
- static DeHistory = (data: any) : History => {
357
- return {id:parseInt(data?.name), node:data?.value?.fields?.node, next_node:data?.value?.fields?.next_node,
358
- sessions:Progress.DeSessions(data?.value.fields?.session), time: data?.value?.fields?.time
359
- }
360
- }
361
-
362
- static MAX_NAMED_OPERATOR_COUNT = 20;
363
- static MAX_DELEVERABLE_ORDER_COUNT = 20;
364
- static IsValidProgressNext = (next:ProgressNext) => {
365
- return IsValidName(next.forward) && IsValidName(next.next_node_name);
366
- }
367
- }