wowok_agent 1.2.37 → 1.2.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/call/arbitration.d.ts +69 -0
- package/dist/call/arbitration.d.ts.map +1 -0
- package/dist/call/arbitration.js +210 -0
- package/dist/call/arbitration.js.map +1 -0
- package/dist/call/base.d.ts +37 -0
- package/dist/call/base.d.ts.map +1 -0
- package/dist/call/base.js +157 -0
- package/dist/call/base.js.map +1 -0
- package/dist/call/call.d.ts +84 -0
- package/dist/call/call.d.ts.map +1 -0
- package/dist/call/call.js +156 -0
- package/dist/call/call.js.map +1 -0
- package/dist/call/demand.d.ts +57 -0
- package/dist/call/demand.d.ts.map +1 -0
- package/dist/call/demand.js +160 -0
- package/dist/call/demand.js.map +1 -0
- package/dist/call/guard.d.ts +42 -0
- package/dist/call/guard.d.ts.map +1 -0
- package/dist/call/guard.js +264 -0
- package/dist/call/guard.js.map +1 -0
- package/dist/call/machine.d.ts +109 -0
- package/dist/call/machine.d.ts.map +1 -0
- package/dist/call/machine.js +250 -0
- package/dist/call/machine.js.map +1 -0
- package/dist/call/object_permission.d.ts +14 -0
- package/dist/call/object_permission.d.ts.map +1 -0
- package/dist/call/object_permission.js +52 -0
- package/dist/call/object_permission.js.map +1 -0
- package/dist/call/permission.d.ts +50 -0
- package/dist/call/permission.d.ts.map +1 -0
- package/dist/call/permission.js +127 -0
- package/dist/call/permission.js.map +1 -0
- package/dist/call/personal.d.ts +42 -0
- package/dist/call/personal.d.ts.map +1 -0
- package/dist/call/personal.js +88 -0
- package/dist/call/personal.js.map +1 -0
- package/dist/call/repository.d.ts +52 -0
- package/dist/call/repository.d.ts.map +1 -0
- package/dist/call/repository.js +135 -0
- package/dist/call/repository.js.map +1 -0
- package/dist/call/service.d.ts +134 -0
- package/dist/call/service.d.ts.map +1 -0
- package/dist/call/service.js +416 -0
- package/dist/call/service.js.map +1 -0
- package/dist/call/treasury.d.ts +53 -0
- package/dist/call/treasury.d.ts.map +1 -0
- package/dist/call/treasury.js +175 -0
- package/dist/call/treasury.js.map +1 -0
- package/dist/common.d.ts +3 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +13 -0
- package/dist/common.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/local/account.d.ts +24 -0
- package/dist/local/account.d.ts.map +1 -0
- package/dist/local/account.js +188 -0
- package/dist/local/account.js.map +1 -0
- package/dist/local/cache.d.ts +32 -0
- package/dist/local/cache.d.ts.map +1 -0
- package/dist/local/cache.js +71 -0
- package/dist/local/cache.js.map +1 -0
- package/dist/local/index.d.ts +83 -0
- package/dist/local/index.d.ts.map +1 -0
- package/dist/local/index.js +98 -0
- package/dist/local/index.js.map +1 -0
- package/dist/local/local.d.ts +56 -0
- package/dist/local/local.d.ts.map +1 -0
- package/dist/local/local.js +245 -0
- package/dist/local/local.js.map +1 -0
- package/dist/query/events.d.ts +63 -0
- package/dist/query/events.d.ts.map +1 -0
- package/dist/query/events.js +78 -0
- package/dist/query/events.js.map +1 -0
- package/dist/query/objects.d.ts +323 -0
- package/dist/query/objects.d.ts.map +1 -0
- package/dist/query/objects.js +453 -0
- package/dist/query/objects.js.map +1 -0
- package/dist/query/permission.d.ts +12 -0
- package/dist/query/permission.d.ts.map +1 -0
- package/dist/query/permission.js +41 -0
- package/dist/query/permission.js.map +1 -0
- package/package.json +2 -2
- package/src/call/arbitration.ts +85 -54
- package/src/call/base.ts +22 -12
- package/src/call/call.ts +24 -21
- package/src/call/demand.ts +60 -30
- package/src/call/guard.ts +25 -16
- package/src/call/machine.ts +79 -40
- package/src/call/object_permission.ts +12 -8
- package/src/call/permission.ts +44 -18
- package/src/call/personal.ts +39 -13
- package/src/call/repository.ts +27 -13
- package/src/call/service.ts +150 -73
- package/src/call/treasury.ts +68 -50
- package/src/common.ts +9 -0
- package/src/index.ts +1 -0
- package/src/local/account.ts +3 -3
- package/src/local/index.ts +54 -50
- package/src/local/local.ts +48 -8
- package/src/query/objects.ts +14 -6
- package/tsconfig.tsbuildinfo +1 -1
package/src/call/service.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { TransactionBlock, IsValidArgType, TxbAddress, TagName, PassportObject,
|
|
|
5
5
|
import { query_objects, ObjectService } from '../query/objects.js';
|
|
6
6
|
import { CallBase, CallResult, Namedbject } from "./base.js";
|
|
7
7
|
import { Account } from '../local/account.js';
|
|
8
|
+
import { LocalMark } from '../local/local.js';
|
|
9
|
+
import { get_object_address } from '../common.js';
|
|
8
10
|
|
|
9
11
|
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
10
12
|
export interface CallService_Data {
|
|
@@ -28,7 +30,7 @@ export interface CallService_Data {
|
|
|
28
30
|
refund_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
|
|
29
31
|
| {op:'removeall'} | {op:'remove', addresses:string[]};
|
|
30
32
|
bPublished?: boolean;
|
|
31
|
-
order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string
|
|
33
|
+
order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string,
|
|
32
34
|
namedNewOrder?: Namedbject, namedNewProgress?:Namedbject}
|
|
33
35
|
order_agent?: {order?:string; agents: string[]; progress?:string};
|
|
34
36
|
order_required_info?: {order?:string; info?:Customer_RequiredInfo};
|
|
@@ -53,11 +55,27 @@ export class CallService extends CallBase {
|
|
|
53
55
|
|
|
54
56
|
var checkOwner = false; const guards : string[] = [];
|
|
55
57
|
const perms : PermissionIndexType[] = []; var obj: ObjectService | undefined;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
var [permission_address, object_address, treasury_address] =
|
|
59
|
+
await LocalMark.Instance().get_many_address(
|
|
60
|
+
[(this.data?.permission as any)?.address,
|
|
61
|
+
(this.data?.object as any)?.address,
|
|
62
|
+
(this.data?.payee_treasury as any)?.address]);
|
|
59
63
|
|
|
60
|
-
if (
|
|
64
|
+
if (object_address) {
|
|
65
|
+
if (!this.data.type_parameter || !permission_address) {
|
|
66
|
+
await this.update_content(object_address, 'Service');
|
|
67
|
+
if (this.content) {
|
|
68
|
+
permission_address = (this.content as ObjectService).permission;
|
|
69
|
+
this.data.type_parameter = this.content.type_raw!;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
|
|
74
|
+
ERROR(Errors.IsValidArgType, 'CallService_Data.data.type_parameter')
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (permission_address) {
|
|
61
79
|
if (!this.data?.object) {
|
|
62
80
|
perms.push(PermissionIndex.service)
|
|
63
81
|
}
|
|
@@ -112,36 +130,37 @@ export class CallService extends CallBase {
|
|
|
112
130
|
if (this.data?.sales !== undefined) {
|
|
113
131
|
perms.push(PermissionIndex.service_sales)
|
|
114
132
|
}
|
|
115
|
-
if (this.data?.order_new
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
if (this.data?.order_new !== undefined) {
|
|
134
|
+
const guard = await LocalMark.Instance().get_address(this.data.order_new.guard);
|
|
135
|
+
if (guard) {
|
|
136
|
+
guards.push(guard)
|
|
118
137
|
} else {
|
|
119
|
-
if (!
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
if (!object_address) {
|
|
139
|
+
const buy_guard = await LocalMark.Instance().get_address(this.data?.buy_guard);
|
|
140
|
+
if (buy_guard) {
|
|
141
|
+
guards.push(buy_guard)
|
|
122
142
|
}
|
|
123
143
|
} else {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
if (obj?.buy_guard) {
|
|
131
|
-
guards.push(obj?.buy_guard)
|
|
132
|
-
}
|
|
144
|
+
await this.update_content(object_address, 'Service');
|
|
145
|
+
|
|
146
|
+
if ((this.content as ObjectService)?.buy_guard) {
|
|
147
|
+
guards.push((this.content as ObjectService).buy_guard!)
|
|
148
|
+
}
|
|
133
149
|
}
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
|
-
if (
|
|
137
|
-
|
|
152
|
+
if (this.data.order_refund !== undefined) {
|
|
153
|
+
const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
|
|
154
|
+
if (guard) guards.push(guard);
|
|
138
155
|
}
|
|
156
|
+
|
|
139
157
|
if (this.data.order_withdrawl !== undefined) { // permission(may be guard) + withdraw_guard
|
|
140
158
|
perms.push(PermissionIndex.service_withdraw)
|
|
141
159
|
}
|
|
142
160
|
|
|
143
|
-
if (typeof(this.data?.order_withdrawl?.data?.withdraw_guard) === 'string'
|
|
144
|
-
|
|
161
|
+
if (typeof(this.data?.order_withdrawl?.data?.withdraw_guard) === 'string') {
|
|
162
|
+
const guard = await LocalMark.Instance().get_address(this.data?.order_withdrawl?.data?.withdraw_guard);
|
|
163
|
+
if (guard) guards.push(guard);
|
|
145
164
|
}
|
|
146
165
|
|
|
147
166
|
return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
|
|
@@ -150,9 +169,12 @@ export class CallService extends CallBase {
|
|
|
150
169
|
}
|
|
151
170
|
protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
152
171
|
let obj : Service | undefined ; let permission: any; let payee: any;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
var [permission_address, object_address] = this?.content ?
|
|
173
|
+
[(this.content as ObjectService).permission, this.content.object] :
|
|
174
|
+
await LocalMark.Instance().get_many_address(
|
|
175
|
+
[(this.data?.permission as any)?.address,
|
|
176
|
+
(this.data?.object as any)?.address]);
|
|
177
|
+
const treasury_address = await LocalMark.Instance().get_address((this.data?.payee_treasury as any)?.address);
|
|
156
178
|
|
|
157
179
|
if (!object_address) {
|
|
158
180
|
if (!permission_address || !IsValidAddress(permission_address)) {
|
|
@@ -166,10 +188,10 @@ export class CallService extends CallBase {
|
|
|
166
188
|
obj = Service.New(txb, this.data.type_parameter!, permission?permission.get_object():permission_address,
|
|
167
189
|
this.data?.description??'', payee?payee.get_object():treasury_address, permission?undefined:passport)
|
|
168
190
|
} else {
|
|
169
|
-
if (
|
|
191
|
+
if (this.data.type_parameter && permission_address) {
|
|
170
192
|
obj = Service.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
171
193
|
} else {
|
|
172
|
-
ERROR(Errors.InvalidParam, '
|
|
194
|
+
ERROR(Errors.InvalidParam, 'CallService_Data.data.type_parameter or permission')
|
|
173
195
|
}
|
|
174
196
|
}
|
|
175
197
|
|
|
@@ -183,23 +205,36 @@ export class CallService extends CallBase {
|
|
|
183
205
|
if (this.data?.endpoint !== undefined) {
|
|
184
206
|
obj?.set_endpoint(this.data.endpoint, pst)
|
|
185
207
|
}
|
|
186
|
-
if (
|
|
208
|
+
if (treasury_address !== undefined && object_address) {
|
|
187
209
|
obj?.set_payee(treasury_address, pst);
|
|
188
210
|
}
|
|
189
211
|
if (this.data?.gen_discount !== undefined) {
|
|
190
|
-
|
|
212
|
+
const add = [];
|
|
213
|
+
for (let i = 0; i < this.data.gen_discount.length; ++ i) {
|
|
214
|
+
let v = this.data.gen_discount[i];
|
|
215
|
+
const addr = await LocalMark.Instance().get_address(v.receiver);
|
|
216
|
+
if (addr) {
|
|
217
|
+
v.receiver = addr;
|
|
218
|
+
add.push(v)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
obj?.discount_transfer(add, pst)
|
|
191
222
|
}
|
|
192
223
|
if (this.data?.repository !== undefined) {
|
|
193
224
|
switch (this.data.repository.op) {
|
|
194
225
|
case 'add':
|
|
195
|
-
|
|
226
|
+
case 'set':
|
|
227
|
+
if (this.data.repository.op === 'set') obj?.remove_repository([], true, pst);
|
|
228
|
+
for (let i = 0; i < this.data.repository.repositories.length; ++ i) {
|
|
229
|
+
let v = this.data.repository.repositories[i];
|
|
230
|
+
const addr = await LocalMark.Instance().get_address(v);
|
|
231
|
+
if (addr) {
|
|
232
|
+
obj?.add_repository(v, pst)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
196
235
|
break;
|
|
197
236
|
case 'remove':
|
|
198
|
-
obj?.remove_repository(this.data.repository.repositories, false, pst)
|
|
199
|
-
break;
|
|
200
|
-
case 'set':
|
|
201
|
-
obj?.remove_repository([], true, pst)
|
|
202
|
-
this.data.repository.repositories.forEach(v => obj?.add_repository(v, pst))
|
|
237
|
+
obj?.remove_repository(await LocalMark.Instance().get_many_address2(this.data.repository.repositories), false, pst)
|
|
203
238
|
break;
|
|
204
239
|
case 'removeall':
|
|
205
240
|
obj?.remove_repository([], true, pst)
|
|
@@ -209,14 +244,19 @@ export class CallService extends CallBase {
|
|
|
209
244
|
if (this.data?.extern_withdraw_treasury !== undefined) {
|
|
210
245
|
switch(this.data.extern_withdraw_treasury.op) {
|
|
211
246
|
case 'add':
|
|
212
|
-
this.data.extern_withdraw_treasury.treasuries.forEach(v=>obj?.add_treasury(v.token_type, v.address, pst))
|
|
213
|
-
break;
|
|
214
247
|
case 'set':
|
|
215
|
-
obj?.remove_treasury([], true, pst)
|
|
216
|
-
|
|
248
|
+
if (this.data.extern_withdraw_treasury.op === 'set') obj?.remove_treasury([], true, pst);
|
|
249
|
+
|
|
250
|
+
for (let i = 0; i < this.data.extern_withdraw_treasury.treasuries.length; ++ i) {
|
|
251
|
+
let v = this.data.extern_withdraw_treasury.treasuries[i];
|
|
252
|
+
const addr = await LocalMark.Instance().get_address(v.address);
|
|
253
|
+
if (addr && v.token_type) {
|
|
254
|
+
obj?.add_treasury(v.token_type, v.address, pst);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
217
257
|
break;
|
|
218
258
|
case 'remove':
|
|
219
|
-
obj?.remove_treasury(this.data.extern_withdraw_treasury.addresses, false, pst)
|
|
259
|
+
obj?.remove_treasury(await LocalMark.Instance().get_many_address2(this.data.extern_withdraw_treasury.addresses), false, pst)
|
|
220
260
|
break;
|
|
221
261
|
case 'removeall':
|
|
222
262
|
obj?.remove_treasury([], false, pst)
|
|
@@ -224,19 +264,25 @@ export class CallService extends CallBase {
|
|
|
224
264
|
}
|
|
225
265
|
}
|
|
226
266
|
if (this.data?.machine !== undefined) {
|
|
227
|
-
|
|
267
|
+
const machine = await LocalMark.Instance().get_address(this.data.machine);
|
|
268
|
+
obj?.set_machine(machine, pst)
|
|
228
269
|
}
|
|
229
270
|
if (this.data?.arbitration !== undefined) {
|
|
230
271
|
switch(this.data.arbitration.op) {
|
|
231
272
|
case 'add':
|
|
232
|
-
this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.token_type, pst))
|
|
233
|
-
break;
|
|
234
273
|
case 'set':
|
|
235
|
-
obj?.remove_arbitration([], true, pst)
|
|
236
|
-
this.data.arbitration.arbitrations.
|
|
274
|
+
if (this.data.arbitration.op === 'set') obj?.remove_arbitration([], true, pst);
|
|
275
|
+
for (let i = 0; i < this.data.arbitration.arbitrations.length; ++ i) {
|
|
276
|
+
let v = this.data.arbitration.arbitrations[i];
|
|
277
|
+
const addr = await LocalMark.Instance().get_address(v.address);
|
|
278
|
+
if (addr && v.token_type) {
|
|
279
|
+
obj?.add_arbitration(v.address, v.token_type, pst)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
237
283
|
break;
|
|
238
284
|
case 'remove':
|
|
239
|
-
obj?.remove_arbitration(this.data.arbitration.addresses, false, pst)
|
|
285
|
+
obj?.remove_arbitration(await LocalMark.Instance().get_many_address2(this.data.arbitration.addresses), false, pst)
|
|
240
286
|
break;
|
|
241
287
|
case 'removeall':
|
|
242
288
|
obj?.remove_arbitration([], false, pst)
|
|
@@ -263,14 +309,22 @@ export class CallService extends CallBase {
|
|
|
263
309
|
if (this.data?.withdraw_guard !== undefined) {
|
|
264
310
|
switch(this.data.withdraw_guard.op) {
|
|
265
311
|
case 'add':
|
|
266
|
-
obj?.add_withdraw_guards(this.data.withdraw_guard.guards, pst)
|
|
267
|
-
break;
|
|
268
312
|
case 'set':
|
|
269
|
-
obj?.remove_withdraw_guards([], true, pst)
|
|
270
|
-
|
|
313
|
+
if (this.data.withdraw_guard.op === 'set') obj?.remove_withdraw_guards([], true, pst);
|
|
314
|
+
|
|
315
|
+
const add = []
|
|
316
|
+
for (let i = 0; i < this.data.withdraw_guard.guards.length; ++ i) {
|
|
317
|
+
let v = this.data.withdraw_guard.guards[i];
|
|
318
|
+
const addr = typeof(v.guard) === 'string' ? await LocalMark.Instance().get_address(v.guard as string) : v.guard;
|
|
319
|
+
if (addr) {
|
|
320
|
+
v.guard = addr;
|
|
321
|
+
add.push(v)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
obj?.add_withdraw_guards(add, pst)
|
|
271
325
|
break;
|
|
272
326
|
case 'remove':
|
|
273
|
-
obj?.remove_withdraw_guards(this.data.withdraw_guard.addresses, false, pst)
|
|
327
|
+
obj?.remove_withdraw_guards(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.addresses), false, pst)
|
|
274
328
|
break;
|
|
275
329
|
case 'removeall':
|
|
276
330
|
obj?.remove_withdraw_guards([], true, pst)
|
|
@@ -280,14 +334,23 @@ export class CallService extends CallBase {
|
|
|
280
334
|
if (this.data?.refund_guard !== undefined) {
|
|
281
335
|
switch(this.data.refund_guard.op) {
|
|
282
336
|
case 'add':
|
|
283
|
-
obj?.add_refund_guards(this.data.refund_guard.guards, pst)
|
|
284
|
-
break;
|
|
285
337
|
case 'set':
|
|
286
|
-
obj?.remove_refund_guards([], true, pst)
|
|
287
|
-
|
|
338
|
+
if (this.data.refund_guard.op === 'set') obj?.remove_refund_guards([], true, pst);
|
|
339
|
+
const add = []
|
|
340
|
+
for (let i = 0; i < this.data.refund_guard.guards.length; ++ i) {
|
|
341
|
+
let v = this.data.refund_guard.guards[i];
|
|
342
|
+
const addr = typeof(v.guard) === 'string' ? await LocalMark.Instance().get_address(v.guard as string) : v.guard;
|
|
343
|
+
if (addr) {
|
|
344
|
+
v.guard = addr;
|
|
345
|
+
add.push(v)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
obj?.add_refund_guards(add, pst)
|
|
288
349
|
break;
|
|
350
|
+
|
|
351
|
+
|
|
289
352
|
case 'remove':
|
|
290
|
-
obj?.remove_refund_guards(this.data.refund_guard.addresses, false, pst)
|
|
353
|
+
obj?.remove_refund_guards(await LocalMark.Instance().get_many_address2(this.data.refund_guard.addresses), false, pst)
|
|
291
354
|
break;
|
|
292
355
|
case 'removeall':
|
|
293
356
|
obj?.remove_refund_guards([], true, pst)
|
|
@@ -314,39 +377,53 @@ export class CallService extends CallBase {
|
|
|
314
377
|
}
|
|
315
378
|
|
|
316
379
|
if (this.data?.order_agent !== undefined) {
|
|
317
|
-
const o = this.data.order_agent.order
|
|
318
|
-
if (!o) ERROR(Errors.
|
|
380
|
+
const o = this.data.order_agent.order ? await LocalMark.Instance().get_address(this.data.order_agent.order) : order_new?.order;
|
|
381
|
+
if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_agent.order}`);
|
|
319
382
|
|
|
320
|
-
|
|
383
|
+
const p = this.data.order_agent.progress ? await LocalMark.Instance().get_address(this.data.order_agent.progress) : order_new?.progress;
|
|
384
|
+
if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_agent.progress}`);
|
|
385
|
+
|
|
386
|
+
obj?.set_order_agent(o, await LocalMark.Instance().get_many_address2(this.data.order_agent.agents), p)
|
|
321
387
|
}
|
|
322
388
|
if (this.data?.order_required_info !== undefined && this.data.order_required_info.info !== undefined) {
|
|
323
|
-
const o = this.data.order_required_info.order
|
|
324
|
-
if (!o) ERROR(Errors.
|
|
389
|
+
const o = this.data.order_required_info.order ? await LocalMark.Instance().get_address(this.data.order_required_info.order) : order_new?.order;
|
|
390
|
+
if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_required_info.order}`);
|
|
325
391
|
|
|
326
392
|
obj?.update_order_required_info(o!, this.data.order_required_info.info)
|
|
327
393
|
}
|
|
328
394
|
if (this.data?.order_refund !== undefined) {
|
|
329
|
-
const o = this.data.order_refund.order
|
|
330
|
-
if (!o) ERROR(Errors.
|
|
395
|
+
const o = this.data.order_refund.order ? await LocalMark.Instance().get_address(this.data.order_refund.order) : order_new?.order;
|
|
396
|
+
if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_refund.order}`);
|
|
397
|
+
|
|
331
398
|
|
|
332
399
|
if ((this.data?.order_refund as any)?.arb && (this.data?.order_refund as any)?.arb_token_type) {
|
|
333
|
-
|
|
400
|
+
const arb = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.arb);
|
|
401
|
+
if (arb) {
|
|
402
|
+
obj?.refund_withArb(o!, arb, (this.data?.order_refund as any)?.arb_token_type)
|
|
403
|
+
}
|
|
334
404
|
} else {
|
|
335
|
-
|
|
405
|
+
const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
|
|
406
|
+
if (guard) obj?.refund(o!, guard, pst)
|
|
336
407
|
}
|
|
337
408
|
}
|
|
338
409
|
if (this.data?.order_withdrawl !== undefined && pst) { //@ need withdrawal pst
|
|
339
|
-
const o = this.data.order_withdrawl.order
|
|
340
|
-
if (!o) ERROR(Errors.
|
|
341
|
-
|
|
410
|
+
const o = this.data.order_withdrawl.order ? await LocalMark.Instance().get_address(this.data.order_withdrawl.order) : order_new?.order;
|
|
411
|
+
if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_withdrawl.order}`);
|
|
412
|
+
this.data.order_withdrawl.data.for_guard = await get_object_address(this.data.order_withdrawl.data.for_guard);
|
|
413
|
+
this.data.order_withdrawl.data.for_object = await get_object_address(this.data.order_withdrawl.data.for_object);
|
|
414
|
+
this.data.order_withdrawl.data.treasury = await get_object_address(this.data.order_withdrawl.data.treasury);
|
|
415
|
+
this.data.order_withdrawl.data.withdraw_guard = await get_object_address(this.data.order_withdrawl.data.withdraw_guard);
|
|
342
416
|
obj?.withdraw(o!, this.data.order_withdrawl.data, pst)
|
|
343
417
|
}
|
|
344
418
|
|
|
345
419
|
if (this.data?.order_payer !== undefined && obj) {
|
|
346
|
-
const o = this.data.order_payer.order
|
|
347
|
-
if (!o) ERROR(Errors.
|
|
420
|
+
const o = this.data.order_payer.order ? await LocalMark.Instance().get_address(this.data.order_payer.order) : order_new?.order;
|
|
421
|
+
if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_payer.order}`);
|
|
422
|
+
const p = this.data.order_payer.progress ? await LocalMark.Instance().get_address(this.data.order_payer.progress) : order_new?.progress;
|
|
423
|
+
if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_payer.progress}`);
|
|
348
424
|
|
|
349
|
-
|
|
425
|
+
const payer = await LocalMark.Instance().get_address(this.data.order_payer.payer_new);
|
|
426
|
+
if (payer) obj?.change_order_payer(o, payer, p)
|
|
350
427
|
}
|
|
351
428
|
|
|
352
429
|
if (order_new && this?.data?.order_new) {
|
package/src/call/treasury.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Error
|
|
|
4
4
|
import { query_objects, ObjectTreasury } from '../query/objects.js';
|
|
5
5
|
import { CallBase, CallResult, Namedbject } from "./base.js";
|
|
6
6
|
import { Account } from '../local/account.js';
|
|
7
|
+
import { LocalMark } from '../local/local.js';
|
|
8
|
+
import { get_object_address } from '../common.js';
|
|
7
9
|
|
|
8
10
|
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
9
11
|
export interface CallTreasury_Data {
|
|
@@ -11,7 +13,7 @@ export interface CallTreasury_Data {
|
|
|
11
13
|
object?: {address:string} | {namedNew?: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
12
14
|
permission?: {address:string} | {namedNew?: Namedbject, description?:string};
|
|
13
15
|
description?: string;
|
|
14
|
-
deposit?: {data:{balance:string|number; index?:number|string; remark?:string; for_object?:string; for_guard?:string}; guard?:string
|
|
16
|
+
deposit?: {data:{balance:string|number; index?:number|string; remark?:string; for_object?:string; for_guard?:string}; guard?:string};
|
|
15
17
|
receive?: {payment:string; received_object:string};
|
|
16
18
|
withdraw?: WithdrawParam;
|
|
17
19
|
deposit_guard?: string;
|
|
@@ -32,10 +34,26 @@ export class CallTreasury extends CallBase {
|
|
|
32
34
|
|
|
33
35
|
var checkOwner = false; const guards : string[] = [];
|
|
34
36
|
const perms : PermissionIndexType[] = []; var obj: ObjectTreasury | undefined ;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
var [permission_address, object_address, treasury_address] =
|
|
38
|
+
await LocalMark.Instance().get_many_address(
|
|
39
|
+
[(this.data?.permission as any)?.address,
|
|
40
|
+
(this.data?.object as any)?.address]);
|
|
37
41
|
|
|
38
|
-
if (
|
|
42
|
+
if (object_address) {
|
|
43
|
+
if (!this.data.type_parameter || !permission_address) {
|
|
44
|
+
await this.update_content(object_address, 'Treasury');
|
|
45
|
+
if (this.content) {
|
|
46
|
+
permission_address = (this.content as ObjectTreasury).permission;
|
|
47
|
+
this.data.type_parameter = this.content.type_raw!;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
|
|
52
|
+
ERROR(Errors.IsValidArgType, 'CallTreasury_Data.data.type_parameter')
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (permission_address) {
|
|
39
57
|
if (!this.data?.object) {
|
|
40
58
|
perms.push(PermissionIndex.treasury)
|
|
41
59
|
}
|
|
@@ -54,46 +72,34 @@ export class CallTreasury extends CallBase {
|
|
|
54
72
|
if (this.data?.deposit_guard !== undefined) {
|
|
55
73
|
perms.push(PermissionIndex.treasury_deposit_guard)
|
|
56
74
|
}
|
|
57
|
-
if (this.data?.deposit
|
|
58
|
-
|
|
59
|
-
|
|
75
|
+
if (this.data?.deposit !== undefined) {
|
|
76
|
+
const guard = await LocalMark.Instance().get_address(this.data?.deposit?.guard);
|
|
77
|
+
if (guard) {
|
|
78
|
+
guards.push(guard)
|
|
60
79
|
} else {
|
|
61
|
-
if (!
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
if (!object_address) {
|
|
81
|
+
const guard = await LocalMark.Instance().get_address(this.data.deposit_guard);
|
|
82
|
+
if (guard) {
|
|
83
|
+
guards.push(guard);
|
|
64
84
|
}
|
|
65
85
|
} else {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
if (obj?.deposit_guard) {
|
|
73
|
-
guards.push(obj?.deposit_guard)
|
|
74
|
-
}
|
|
86
|
+
await this.update_content(object_address, 'Treasury');
|
|
87
|
+
|
|
88
|
+
if ((this.content as ObjectTreasury)?.deposit_guard) {
|
|
89
|
+
guards.push((this.content as ObjectTreasury).deposit_guard!)
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
|
-
|
|
77
92
|
}
|
|
78
93
|
}
|
|
79
94
|
if (this.data?.receive !== undefined) {
|
|
80
95
|
perms.push(PermissionIndex.treasury_receive)
|
|
81
96
|
}
|
|
82
|
-
if (this.data?.withdraw?.withdraw_guard !== undefined) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (r?.objects && r.objects[0].type === 'Treasury') {
|
|
89
|
-
obj = r.objects[0] as ObjectTreasury;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (typeof(obj?.withdraw_guard) === 'string') {
|
|
93
|
-
guards.push(obj?.withdraw_guard)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
+
if (this.data?.withdraw?.withdraw_guard !== undefined) { // withdraw with guard
|
|
98
|
+
const guard = await get_object_address(this.data.withdraw.withdraw_guard);
|
|
99
|
+
if (guard) {
|
|
100
|
+
guards.push(guard)
|
|
101
|
+
}
|
|
102
|
+
} else { // withdraw with permission
|
|
97
103
|
perms.push(PermissionIndex.treasury_withdraw)
|
|
98
104
|
}
|
|
99
105
|
return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
|
|
@@ -102,20 +108,23 @@ export class CallTreasury extends CallBase {
|
|
|
102
108
|
}
|
|
103
109
|
protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
104
110
|
let obj : Treasury | undefined ; let permission: any;
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
var [permission_address, object_address] = this?.content ?
|
|
112
|
+
[(this.content as ObjectTreasury).permission, this.content.object] :
|
|
113
|
+
await LocalMark.Instance().get_many_address(
|
|
114
|
+
[(this.data?.permission as any)?.address,
|
|
115
|
+
(this.data?.object as any)?.address]);
|
|
107
116
|
|
|
108
117
|
if (!object_address) {
|
|
109
|
-
if (!permission_address
|
|
118
|
+
if (!permission_address) {
|
|
110
119
|
const d = (this.data?.permission as any)?.description ?? '';
|
|
111
120
|
permission = Permission.New(txb, d);
|
|
112
121
|
}
|
|
113
122
|
obj = Treasury.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'', permission?undefined:passport)
|
|
114
123
|
} else {
|
|
115
|
-
if (
|
|
124
|
+
if (this.data.type_parameter && permission_address) {
|
|
116
125
|
obj = Treasury.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
117
126
|
} else {
|
|
118
|
-
ERROR(Errors.InvalidParam, '
|
|
127
|
+
ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.type_parameter or permission')
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
130
|
|
|
@@ -129,33 +138,42 @@ export class CallTreasury extends CallBase {
|
|
|
129
138
|
if (coin) {
|
|
130
139
|
const index = this.data.deposit.data?.index ?? 0;
|
|
131
140
|
obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
|
|
132
|
-
for_guard:this.data.deposit.data?.for_guard,
|
|
133
|
-
for_object: this.data.deposit.data?.for_object
|
|
141
|
+
for_guard:await get_object_address(this.data.deposit.data?.for_guard),
|
|
142
|
+
for_object:await get_object_address(this.data.deposit.data?.for_object)
|
|
134
143
|
})
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
if (this.data?.receive !== undefined) {
|
|
138
|
-
|
|
147
|
+
const [payment, receive] = await LocalMark.Instance().get_many_address([this.data.receive.payment, this.data.receive.received_object])
|
|
148
|
+
if (payment && receive) obj?.receive(payment, receive, pst);
|
|
139
149
|
}
|
|
150
|
+
|
|
140
151
|
if (this.data?.withdraw !== undefined) {
|
|
152
|
+
this.data.withdraw.for_guard = await get_object_address(this.data.withdraw.for_guard);
|
|
153
|
+
this.data.withdraw.for_object = await get_object_address(this.data.withdraw.for_object);
|
|
154
|
+
this.data.withdraw.withdraw_guard = await get_object_address(this.data.withdraw.withdraw_guard);
|
|
141
155
|
obj?.withdraw(this.data.withdraw, pst)
|
|
142
156
|
}
|
|
143
157
|
|
|
144
158
|
if (this.data?.deposit_guard !== undefined) {
|
|
145
|
-
|
|
159
|
+
const guard = await LocalMark.Instance().get_address(this.data?.deposit_guard);
|
|
160
|
+
obj?.set_deposit_guard(guard, pst);
|
|
146
161
|
}
|
|
147
162
|
if (this.data?.withdraw_guard !== undefined) {
|
|
148
163
|
switch (this.data.withdraw_guard.op) {
|
|
149
164
|
case 'add':
|
|
150
|
-
|
|
165
|
+
case 'set':
|
|
166
|
+
if (this.data.withdraw_guard.op === 'set') obj?.remove_withdraw_guard([], true, pst);
|
|
167
|
+
for (let i = 0; i < this.data.withdraw_guard.data.length; ++ i) {
|
|
168
|
+
let v = this.data.withdraw_guard.data[i];
|
|
169
|
+
const guard = await LocalMark.Instance().get_address(v.guard);
|
|
170
|
+
if (guard) obj?.add_withdraw_guard(guard, BigInt(v.amount), pst);
|
|
171
|
+
}
|
|
151
172
|
break;
|
|
152
173
|
case 'remove':
|
|
153
|
-
obj?.remove_withdraw_guard(this.data.withdraw_guard.guards, false, pst)
|
|
154
|
-
break;
|
|
155
|
-
case 'set':
|
|
156
|
-
obj?.remove_withdraw_guard([], true, pst)
|
|
157
|
-
this.data.withdraw_guard.data.forEach(v => obj?.add_withdraw_guard(v.guard, BigInt(v.amount), pst))
|
|
174
|
+
obj?.remove_withdraw_guard(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.guards), false, pst)
|
|
158
175
|
break;
|
|
176
|
+
|
|
159
177
|
case 'removeall':
|
|
160
178
|
obj?.remove_withdraw_guard([], true, pst)
|
|
161
179
|
break;
|
package/src/common.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { LocalMark } from "./local/local.js";
|
|
1
2
|
|
|
2
3
|
|
|
3
4
|
export const isBrowser = () => {
|
|
4
5
|
return typeof window !== 'undefined' && typeof indexedDB !== 'undefined';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const get_object_address = async (object: any) => {
|
|
9
|
+
if (typeof(object) === 'string') {
|
|
10
|
+
return await LocalMark.Instance().get_address(object)
|
|
11
|
+
} else {
|
|
12
|
+
return object
|
|
13
|
+
}
|
|
5
14
|
}
|
package/src/index.ts
CHANGED
package/src/local/account.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey, Protocol, TransactionBlock, IsValidAddress,
|
|
6
6
|
getFaucetHost, requestSuiFromFaucetV0, requestSuiFromFaucetV1, CoinBalance, CoinStruct, TransactionArgument, TransactionResult,
|
|
7
|
-
CallResponse} from 'wowok';
|
|
7
|
+
CallResponse, TransactionObjectArgument} from 'wowok';
|
|
8
8
|
import { isBrowser } from '../common.js';
|
|
9
9
|
import path from 'path';
|
|
10
10
|
import os from 'os';
|
|
@@ -169,7 +169,7 @@ export class Account {
|
|
|
169
169
|
const txb = new TransactionBlock();
|
|
170
170
|
const coin = await this.get_coin_object(txb, amount, from, token_type);
|
|
171
171
|
if (coin) {
|
|
172
|
-
txb.transferObjects([
|
|
172
|
+
txb.transferObjects([coin as TransactionObjectArgument], to)
|
|
173
173
|
const r = await Protocol.Client().signAndExecuteTransaction({
|
|
174
174
|
transaction: txb,
|
|
175
175
|
signer: pair,
|
|
@@ -194,7 +194,7 @@ export class Account {
|
|
|
194
194
|
const txb = new TransactionBlock();
|
|
195
195
|
const res = await this.get_coin_object(txb, balance_required, address, token_type);
|
|
196
196
|
if (res) {
|
|
197
|
-
txb.transferObjects([
|
|
197
|
+
txb.transferObjects([res as TransactionObjectArgument], address)
|
|
198
198
|
const r = await Protocol.Client().signAndExecuteTransaction({
|
|
199
199
|
transaction: txb,
|
|
200
200
|
signer: pair,
|