wowok_agent 1.2.44 → 1.3.47

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 (75) hide show
  1. package/dist/call/arbitration.d.ts +13 -28
  2. package/dist/call/arbitration.d.ts.map +1 -1
  3. package/dist/call/arbitration.js +91 -84
  4. package/dist/call/arbitration.js.map +1 -1
  5. package/dist/call/base.d.ts +31 -2
  6. package/dist/call/base.d.ts.map +1 -1
  7. package/dist/call/base.js +41 -3
  8. package/dist/call/base.js.map +1 -1
  9. package/dist/call/call.d.ts +6 -0
  10. package/dist/call/call.d.ts.map +1 -1
  11. package/dist/call/call.js.map +1 -1
  12. package/dist/call/demand.d.ts +9 -22
  13. package/dist/call/demand.d.ts.map +1 -1
  14. package/dist/call/demand.js +70 -78
  15. package/dist/call/demand.js.map +1 -1
  16. package/dist/call/machine.d.ts +35 -44
  17. package/dist/call/machine.d.ts.map +1 -1
  18. package/dist/call/machine.js +105 -115
  19. package/dist/call/machine.js.map +1 -1
  20. package/dist/call/object_permission.d.ts.map +1 -1
  21. package/dist/call/object_permission.js.map +1 -1
  22. package/dist/call/permission.d.ts +30 -18
  23. package/dist/call/permission.d.ts.map +1 -1
  24. package/dist/call/permission.js +39 -38
  25. package/dist/call/permission.js.map +1 -1
  26. package/dist/call/personal.d.ts +6 -6
  27. package/dist/call/personal.d.ts.map +1 -1
  28. package/dist/call/personal.js +11 -13
  29. package/dist/call/personal.js.map +1 -1
  30. package/dist/call/repository.d.ts +4 -12
  31. package/dist/call/repository.d.ts.map +1 -1
  32. package/dist/call/repository.js +49 -37
  33. package/dist/call/repository.js.map +1 -1
  34. package/dist/call/service.d.ts +50 -70
  35. package/dist/call/service.d.ts.map +1 -1
  36. package/dist/call/service.js +187 -164
  37. package/dist/call/service.js.map +1 -1
  38. package/dist/call/treasury.d.ts +22 -26
  39. package/dist/call/treasury.d.ts.map +1 -1
  40. package/dist/call/treasury.js +74 -73
  41. package/dist/call/treasury.js.map +1 -1
  42. package/dist/common.d.ts +1 -0
  43. package/dist/common.d.ts.map +1 -1
  44. package/dist/common.js +6 -0
  45. package/dist/common.js.map +1 -1
  46. package/dist/local/local.d.ts +1 -1
  47. package/dist/local/local.d.ts.map +1 -1
  48. package/dist/local/local.js +4 -1
  49. package/dist/local/local.js.map +1 -1
  50. package/dist/query/events.d.ts +1 -1
  51. package/dist/query/events.d.ts.map +1 -1
  52. package/dist/query/events.js +15 -9
  53. package/dist/query/events.js.map +1 -1
  54. package/dist/query/objects.d.ts +7 -2
  55. package/dist/query/objects.d.ts.map +1 -1
  56. package/dist/query/objects.js +8 -1
  57. package/dist/query/objects.js.map +1 -1
  58. package/package.json +4 -2
  59. package/src/call/arbitration.ts +117 -105
  60. package/src/call/base.ts +78 -10
  61. package/src/call/call.ts +6 -0
  62. package/src/call/demand.ts +77 -86
  63. package/src/call/machine.ts +119 -132
  64. package/src/call/object_permission.ts +1 -1
  65. package/src/call/permission.ts +68 -45
  66. package/src/call/personal.ts +18 -20
  67. package/src/call/repository.ts +54 -47
  68. package/src/call/service.ts +236 -197
  69. package/src/call/treasury.ts +96 -86
  70. package/src/common.ts +7 -1
  71. package/src/local/account.ts +1 -1
  72. package/src/local/local.ts +6 -2
  73. package/src/query/events.ts +12 -10
  74. package/src/query/objects.ts +18 -4
  75. package/tsconfig.tsbuildinfo +1 -1
@@ -1,42 +1,54 @@
1
- import { TransactionBlock, IsValidArgType, TxbAddress, TagName, PassportObject, IsValidAddress, Errors, ERROR, Permission,
2
- PermissionIndex, PermissionIndexType, BuyRequiredEnum, Customer_RequiredInfo, DicountDispatch, Service, Service_Buy,
3
- Service_Guard_Percent, Service_Sale, WithdrawPayee, Treasury, OrderResult,
1
+ import { TransactionBlock, IsValidArgType, TxbAddress, TagName, PassportObject, Errors, ERROR, Permission,
2
+ PermissionIndex, PermissionIndexType, BuyRequiredEnum, Customer_RequiredInfo, Service, Service_Buy,
3
+ Service_Guard_Percent, Service_Sale, Treasury, OrderResult, DicountDispatch as WowokDiscountDispatch,
4
+ ProgressObject, Arbitration, Service_Discount,
5
+ ServiceObject,
4
6
  } from 'wowok';
5
- import { query_objects, ObjectService } from '../query/objects.js';
6
- import { CallBase, CallResult, Namedbject } from "./base.js";
7
+ import { ObjectOrder, ObjectService, query_objects } from '../query/objects.js';
8
+ import { AccountOrMark_Address, CallBase, CallResult, GetAccountOrMark_Address, GetManyAccountOrMark_Address,
9
+ GetObjectExisted, GetObjectMain, GetObjectParam, Namedbject, ObjectParam, ObjectTypedMain,
10
+ TypeNamedObjectWithPermission, WithdrawParam } from "./base.js";
7
11
  import { Account } from '../local/account.js';
8
12
  import { LocalMark } from '../local/local.js';
9
- import { get_object_address } from '../common.js';
13
+ import { crypto_string } from '../common.js';
14
+ import { machine } from 'os';
15
+
16
+ export interface ServiceWithdraw extends WithdrawParam {
17
+ withdraw_guard: string;
18
+ }
19
+
20
+ export interface DicountDispatch {
21
+ receiver: AccountOrMark_Address;
22
+ discount: Service_Discount;
23
+ count?: number;
24
+ }
10
25
 
11
26
  /// The execution priority is determined by the order in which the object attributes are arranged
12
27
  export interface CallService_Data {
13
- type_parameter: string;
14
- object?: {address:string} | {namedNew?: Namedbject}; // undefined or {named_new...} for creating a new object
15
- permission?: {address:string} | {namedNew?: Namedbject, description?:string};
28
+ object: ObjectTypedMain;
29
+ order_new?: {buy_items:Service_Buy[], discount_object?:string, customer_info_required?: string,
30
+ namedNewOrder?: Namedbject, namedNewProgress?:Namedbject}
31
+ order_agent?: {order?:string; agents: AccountOrMark_Address[];};
32
+ order_required_info?: {order:string; customer_info_required?:string};
33
+ order_refund?: {order:string; } | {order:string; arb:string;};
34
+ order_withdrawl?: {order:string; data:ServiceWithdraw}; // guard address
35
+ order_payer?: {order?:string; payer_new:AccountOrMark_Address; }; // transfer the order payer permission to someaddress
36
+
16
37
  description?: string;
17
38
  endpoint?: string;
18
- payee_treasury?:{address:string} | {namedNew?: Namedbject, description?:string};
39
+ payee_treasury?:ObjectParam;
19
40
  gen_discount?: DicountDispatch[];
20
41
  repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
21
- extern_withdraw_treasury?: {op:'set' | 'add'; treasuries:{address:string, token_type:string}[]}
22
- | {op:'removeall'} | {op:'remove', addresses:string[]};
42
+ extern_withdraw_treasury?: {op:'set' | 'add' | 'remove'; treasuries:string[]} | {op:'removeall'} ;
23
43
  machine?: string;
24
- arbitration?: {op:'set' | 'add'; arbitrations:{address:string, token_type:string}[]}
25
- | {op:'removeall'} | {op:'remove', addresses:string[]};
44
+ arbitration?: {op:'set' | 'add' | 'remove'; arbitrations:string[]} | {op:'removeall'};
26
45
  customer_required_info?: {pubkey:string; required_info:(string | BuyRequiredEnum)[]};
27
46
  sales?: {op:'add', sales:Service_Sale[]} | {op:'remove'; sales_name:string[]}
28
47
  withdraw_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
29
- | {op:'removeall'} | {op:'remove', addresses:string[]};
48
+ | {op:'removeall'} | {op:'remove', guards:string[]};
30
49
  refund_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
31
- | {op:'removeall'} | {op:'remove', addresses:string[]};
50
+ | {op:'removeall'} | {op:'remove', guards:string[]};
32
51
  bPublished?: boolean;
33
- order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string,
34
- namedNewOrder?: Namedbject, namedNewProgress?:Namedbject}
35
- order_agent?: {order?:string; agents: string[]; progress?:string};
36
- order_required_info?: {order?:string; info?:Customer_RequiredInfo};
37
- order_refund?: {order?:string; guard?:string;} | {order?:string; arb:string; arb_token_type:string}; // guard address
38
- order_withdrawl?: {order?:string; data:WithdrawPayee}; // guard address
39
- order_payer?: {order?:string; payer_new:string; progress?:string}; // transfer the order payer permission to someaddress
40
52
  buy_guard?: string;
41
53
  bPaused?: boolean;
42
54
  clone_new?: {token_type_new?:string; namedNew?: Namedbject};
@@ -44,42 +56,37 @@ export interface CallService_Data {
44
56
 
45
57
  export class CallService extends CallBase {
46
58
  data: CallService_Data;
59
+ object_address: string | undefined = undefined;
60
+ permission_address: string | undefined = undefined;
61
+ type_parameter: string | undefined = undefined;
62
+
47
63
  constructor(data: CallService_Data) {
48
64
  super();
49
65
  this.data = data;
50
66
  }
51
67
  async call(account?:string) : Promise<CallResult> {
52
- if (!this.data.type_parameter || !IsValidArgType(this.data.type_parameter)) {
53
- ERROR(Errors.IsValidArgType, 'service.type_parameter');
54
- }
55
-
56
68
  var checkOwner = false; const guards : string[] = [];
57
- const perms : PermissionIndexType[] = []; var obj: ObjectService | undefined;
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]);
63
-
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
- }
69
+ const perms : PermissionIndexType[] = [];
70
+ this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
71
+ if (this.object_address) {
72
+ await this.update_content('Service', this.object_address);
73
+ if (!this.content) ERROR(Errors.InvalidParam, 'CallService_Data.data.object:' + this.object_address);
74
+ this.permission_address = (this.content as ObjectService).permission;
75
+ this.type_parameter = Service.parseObjectType(this.content.type_raw);
72
76
  } else {
73
- if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
74
- ERROR(Errors.IsValidArgType, 'CallService_Data.data.type_parameter')
75
- }
76
- }
77
+ const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
78
+ if (!IsValidArgType(n?.type_parameter)) {
79
+ ERROR(Errors.IsValidArgType, 'CallService_Data.data.object.type_parameter');
80
+ }
81
+ this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
82
+ this.type_parameter = n.type_parameter;
83
+ }
77
84
 
78
- if (permission_address) {
85
+ if (this.permission_address) {
79
86
  if (!this.data?.object) {
80
87
  perms.push(PermissionIndex.service)
81
88
  }
82
- if (this.data?.description !== undefined && object_address) {
89
+ if (this.data?.description !== undefined && this.object_address) {
83
90
  perms.push(PermissionIndex.service_description)
84
91
  }
85
92
  if (this.data?.bPaused !== undefined) {
@@ -115,7 +122,7 @@ export class CallService extends CallBase {
115
122
  if (this.data?.machine !== undefined) {
116
123
  perms.push(PermissionIndex.service_machine)
117
124
  }
118
- if (treasury_address !== undefined && object_address) {
125
+ if (this.data?.payee_treasury !== undefined && this.object_address) {
119
126
  perms.push(PermissionIndex.service_payee)
120
127
  }
121
128
  if (this.data?.withdraw_guard !== undefined) {
@@ -131,24 +138,10 @@ export class CallService extends CallBase {
131
138
  perms.push(PermissionIndex.service_sales)
132
139
  }
133
140
  if (this.data?.order_new !== undefined) {
134
- if (this.data.order_new.guard) {
135
- const guard = await LocalMark.Instance().get_address(this.data.order_new.guard);
136
- if (guard) {
137
- guards.push(guard)
138
- }
139
- } else {
140
- if (!object_address) {
141
- const buy_guard = await LocalMark.Instance().get_address(this.data?.buy_guard);
142
- if (buy_guard) {
143
- guards.push(buy_guard)
144
- }
145
- } else {
146
- await this.update_content(object_address, 'Service');
147
-
148
- if ((this.content as ObjectService)?.buy_guard) {
149
- guards.push((this.content as ObjectService).buy_guard!)
150
- }
151
- }
141
+ if (this.object_address) {
142
+ if ((this.content as ObjectService)?.buy_guard) {
143
+ guards.push((this.content as ObjectService).buy_guard!)
144
+ }
152
145
  }
153
146
  }
154
147
  if (this.data.order_refund !== undefined) {
@@ -165,59 +158,167 @@ export class CallService extends CallBase {
165
158
  if (guard) guards.push(guard);
166
159
  }
167
160
 
168
- return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
161
+ return await this.check_permission_and_call(this.permission_address, perms, guards, checkOwner, undefined, account)
169
162
  }
170
163
  return await this.exec(account);
171
164
  }
165
+
166
+ private order_allowed() : boolean {
167
+ if ((this.content as ObjectService)?.bPaused) {
168
+ ERROR(Errors.InvalidParam, 'Service is paused');
169
+ return false;
170
+ }
171
+ if (((this.content as ObjectService)?.bPublished !== true)) {
172
+ ERROR(Errors.InvalidParam, 'Service is not published');
173
+ return false;
174
+ }
175
+ return true
176
+ }
177
+
178
+ private order_progress = async (order?: string, order_new?:OrderResult) : Promise<ProgressObject> => {
179
+ if (order) {
180
+ const r = await query_objects({objects:[order]});
181
+ if (r?.objects?.length !== 1 || r?.objects[0]?.type !== 'Order') {
182
+ ERROR(Errors.InvalidParam, 'order_progress:' + order);
183
+ }
184
+ return (r.objects[0] as ObjectOrder).progress! as ProgressObject;
185
+ } else if (order_new) {
186
+ return order_new.progress as ProgressObject;
187
+ } else {
188
+ ERROR(Errors.InvalidParam, 'order_progress');
189
+ }
190
+ }
191
+
172
192
  protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
173
- let obj : Service | undefined ; let permission: any; let payee: any;
174
- var [permission_address, object_address] = this?.content ?
175
- [(this.content as ObjectService).permission, this.content.object] :
176
- await LocalMark.Instance().get_many_address(
177
- [(this.data?.permission as any)?.address,
178
- (this.data?.object as any)?.address]);
179
- const treasury_address = await LocalMark.Instance().get_address((this.data?.payee_treasury as any)?.address);
193
+ let obj : Service | undefined ;
194
+ let permission: any; let payee: any;
180
195
 
181
- if (!object_address) {
182
- if (!permission_address || !IsValidAddress(permission_address)) {
183
- const d = (this.data?.permission as any)?.description ?? '';
184
- permission = Permission.New(txb, d);
185
- }
186
- if (!treasury_address || !IsValidAddress(treasury_address)) {
187
- const d = (this.data?.payee_treasury as any)?.description ?? '';
188
- payee = Treasury.New(txb, this.data?.type_parameter!, permission ?? permission_address, d, permission?undefined:passport);
189
- }
190
- obj = Service.New(txb, this.data.type_parameter!, permission?permission.get_object():permission_address,
191
- this.data?.description??'', payee?payee.get_object():treasury_address, permission?undefined:passport)
196
+ if (this.object_address) {
197
+ obj = Service.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
192
198
  } else {
193
- if (this.data.type_parameter && permission_address) {
194
- obj = Service.From(txb, this.data.type_parameter, permission_address, object_address)
195
- } else {
196
- ERROR(Errors.InvalidParam, 'CallService_Data.data.type_parameter or permission')
197
- }
199
+ const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
200
+ if (!this.permission_address) {
201
+ permission = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
202
+ }
203
+ const treasury_address = await LocalMark.Instance().get_address(GetObjectExisted(this.data.payee_treasury));
204
+ if (!treasury_address) {
205
+ payee = Treasury.New(txb, this.type_parameter!, permission ? permission.get_object() : this.permission_address,
206
+ GetObjectParam(this.data.payee_treasury)?.description ?? '', permission?undefined:passport);
207
+ }
208
+ const t = payee ? payee.get_object() : treasury_address;
209
+ if (!t) {
210
+ ERROR(Errors.InvalidParam, 'CallService_Data.payee_treasury:' + (this.data.payee_treasury as any).address);
211
+ }
212
+
213
+ obj = Service.New(txb, this.type_parameter!, permission ? permission.get_object() : this.permission_address,
214
+ this.data?.description??'', t, permission?undefined:passport);
198
215
  }
199
216
 
200
217
  if (obj) {
201
218
  //const perm = permission ? permission.get_object() : permission_address;
202
219
  const pst = permission?undefined:passport;
220
+ var order_new : OrderResult | undefined;
221
+ if (this.data?.order_new !== undefined && this.order_allowed()) {
222
+ let b = BigInt(0); let coin : any;
223
+ this.data.order_new.buy_items.forEach(v => {
224
+ b += BigInt(v.max_price) * BigInt(v.count)
225
+ });
226
+
227
+ coin = await Account.Instance().get_coin_object(txb, b, account, this.type_parameter);
228
+ if (coin) {
229
+ order_new = obj.order(this.data.order_new.buy_items, coin,
230
+ await LocalMark.Instance().get_address(this.data.order_new.discount_object),
231
+ (this?.content as ObjectService).machine!,
232
+ await this.info_crypto(this.data.order_new.customer_info_required), pst);
233
+ }
234
+ }
235
+
236
+ if (this.data?.order_agent !== undefined) {
237
+ const o = this.data.order_agent.order ? await LocalMark.Instance().get_address(this.data.order_agent.order) : order_new?.order;
238
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_agent.order}`);
239
+
240
+ const p = await this.order_progress(this.data.order_agent.order, order_new);
241
+ const agents = await GetManyAccountOrMark_Address(this.data.order_agent.agents);
242
+ obj?.set_order_agent(o, agents.filter((v):v is string =>v!==undefined), p);
243
+ }
244
+ if (this.data?.order_required_info?.customer_info_required) {
245
+ const o = await LocalMark.Instance().get_address(this.data.order_required_info.order);
246
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_required_info.order:${this.data.order_required_info.order}`);
247
+ const crypto = await this.info_crypto(this.object_address, this.data.order_required_info.customer_info_required);
248
+ if (crypto) {
249
+ obj?.update_order_required_info(o, crypto);
250
+ }
251
+ }
252
+ if (this.data?.order_refund !== undefined) {
253
+ const o = await LocalMark.Instance().get_address(this.data.order_refund.order);
254
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_refund.order}`);
255
+
256
+ if ((this.data?.order_refund as any)?.arb) {
257
+ const r = await query_objects({objects:[(this.data?.order_refund as any)?.arb]});
258
+ if (r?.objects?.length!== 1 || r?.objects[0]?.type!== 'Arb') {
259
+ ERROR(Errors.InvalidParam, 'order_refund.arb:' + (this.data?.order_refund as any)?.arb);
260
+ }
261
+ obj?.refund_withArb(o!, r?.objects[0].object, Arbitration.parseArbObjectType(r.objects[0].type_raw)!);
262
+ } else {
263
+ const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
264
+ if (guard) obj?.refund(o!, guard, pst)
265
+ }
266
+ }
267
+ if (this.data?.order_withdrawl !== undefined && pst) { //@ need withdrawal pst
268
+ const n = this.data?.order_withdrawl;
269
+ const o = await LocalMark.Instance().get_address(n.order);
270
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_withdrawl.order}`);
271
+
272
+ const [for_guard, for_object, withdrawGuard] = await LocalMark.Instance().get_many_address(
273
+ [n.data.for_guard, n.data.for_object, n.data.withdraw_guard]);
274
+ if (!withdrawGuard) ERROR(Errors.InvalidParam, `CallService_Data.data.order_withdrawl.data.withdraw_guard:${this.data.order_withdrawl.data.withdraw_guard}`);
275
+
276
+ obj?.withdraw(o!, {withdraw_guard:withdrawGuard, treasury:(this.content as ObjectService).payee_treasury!,
277
+ index: n.data.index, for_guard:for_guard, for_object:for_object, remark:n.data.remark}, pst);
278
+ }
279
+
280
+ if (this.data?.order_payer !== undefined) {
281
+ const o = this.data.order_payer.order ? await LocalMark.Instance().get_address(this.data.order_payer.order) : order_new?.order;
282
+ if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_payer.order}`);
283
+
284
+ const p = await this.order_progress(this.data.order_payer.order, order_new);
285
+ const payer = await GetAccountOrMark_Address(this.data.order_payer.payer_new);
286
+ if (payer) obj?.change_order_payer(o, payer, p)
287
+ }
288
+
289
+ if (order_new && this?.data?.order_new) {
290
+ const buy = obj.order_launch(order_new);
291
+ await this.new_with_mark('Order', txb, buy.order, (this.data?.order_new as any)?.namedNewOrder, account, [TagName.Launch, TagName.Order]);
292
+ if (buy?.progress) {
293
+ await this.new_with_mark('Progress', txb, buy.progress, (this.data?.order_new as any)?.namedNewProgress, account, [TagName.Launch, 'progress']);
294
+ }
295
+ }
203
296
 
204
- if (this.data?.description !== undefined && object_address) {
297
+ if (this.data?.description !== undefined && this.object_address) {
205
298
  obj?.set_description(this.data.description, pst);
206
299
  }
207
300
  if (this.data?.endpoint !== undefined) {
208
301
  obj?.set_endpoint(this.data.endpoint, pst)
209
302
  }
210
- if (treasury_address !== undefined && object_address) {
211
- obj?.set_payee(treasury_address, pst);
303
+ if (this.data?.payee_treasury !== undefined && this.object_address) {
304
+ const treasury_address = await LocalMark.Instance().get_address(GetObjectExisted(this.data.payee_treasury));
305
+ if (!treasury_address) {
306
+ payee = Treasury.New(txb, this.type_parameter!, permission ? permission.get_object() : this.permission_address,
307
+ GetObjectParam(this.data.payee_treasury)?.description ?? '', permission?undefined:passport);
308
+ }
309
+ const t = payee ? payee.get_object() : treasury_address;
310
+ if (!t) {
311
+ ERROR(Errors.InvalidParam, 'CallService_Data.payee_treasury:' + (this.data.payee_treasury as any).address);
312
+ }
313
+ obj?.set_payee(t, pst);
212
314
  }
213
315
  if (this.data?.gen_discount !== undefined) {
214
- const add = [];
316
+ const add: WowokDiscountDispatch[] = [];
215
317
  for (let i = 0; i < this.data.gen_discount.length; ++ i) {
216
318
  let v = this.data.gen_discount[i];
217
- const addr = await LocalMark.Instance().get_address(v.receiver);
319
+ const addr = await GetAccountOrMark_Address(v.receiver);
218
320
  if (addr) {
219
- v.receiver = addr;
220
- add.push(v)
321
+ add.push({receiver:addr, count:v.count ?? 1, discount:v.discount})
221
322
  }
222
323
  }
223
324
  obj?.discount_transfer(add, pst)
@@ -231,7 +332,7 @@ export class CallService extends CallBase {
231
332
  let v = this.data.repository.repositories[i];
232
333
  const addr = await LocalMark.Instance().get_address(v);
233
334
  if (addr) {
234
- obj?.add_repository(v, pst)
335
+ obj?.add_repository(addr, pst)
235
336
  }
236
337
  }
237
338
  break;
@@ -248,17 +349,15 @@ export class CallService extends CallBase {
248
349
  case 'add':
249
350
  case 'set':
250
351
  if (this.data.extern_withdraw_treasury.op === 'set') obj?.remove_treasury([], true, pst);
251
-
252
- for (let i = 0; i < this.data.extern_withdraw_treasury.treasuries.length; ++ i) {
253
- let v = this.data.extern_withdraw_treasury.treasuries[i];
254
- const addr = await LocalMark.Instance().get_address(v.address);
255
- if (addr && v.token_type) {
256
- obj?.add_treasury(v.token_type, v.address, pst);
352
+ const r = await query_objects({objects:this.data.extern_withdraw_treasury.treasuries, no_cache:true});
353
+ r.objects?.forEach(v => {
354
+ if (v.type ==='Treasury') {
355
+ obj?.add_treasury(v.object, Treasury.parseObjectType(v.type_raw), pst)
257
356
  }
258
- }
357
+ });
259
358
  break;
260
359
  case 'remove':
261
- obj?.remove_treasury(await LocalMark.Instance().get_many_address2(this.data.extern_withdraw_treasury.addresses), false, pst)
360
+ obj?.remove_treasury(await LocalMark.Instance().get_many_address2(this.data.extern_withdraw_treasury.treasuries), false, pst)
262
361
  break;
263
362
  case 'removeall':
264
363
  obj?.remove_treasury([], false, pst)
@@ -274,17 +373,15 @@ export class CallService extends CallBase {
274
373
  case 'add':
275
374
  case 'set':
276
375
  if (this.data.arbitration.op === 'set') obj?.remove_arbitration([], true, pst);
277
- for (let i = 0; i < this.data.arbitration.arbitrations.length; ++ i) {
278
- let v = this.data.arbitration.arbitrations[i];
279
- const addr = await LocalMark.Instance().get_address(v.address);
280
- if (addr && v.token_type) {
281
- obj?.add_arbitration(v.address, v.token_type, pst)
376
+ const r = await query_objects({objects:this.data.arbitration.arbitrations, no_cache:true});
377
+ r.objects?.forEach(v => {
378
+ if (v.type ==='Arbitration') {
379
+ obj?.add_arbitration(v.object, Arbitration.parseObjectType(v.type_raw), pst)
282
380
  }
283
- }
284
-
381
+ });
285
382
  break;
286
383
  case 'remove':
287
- obj?.remove_arbitration(await LocalMark.Instance().get_many_address2(this.data.arbitration.addresses), false, pst)
384
+ obj?.remove_arbitration(await LocalMark.Instance().get_many_address2(this.data.arbitration.arbitrations), false, pst)
288
385
  break;
289
386
  case 'removeall':
290
387
  obj?.remove_arbitration([], false, pst)
@@ -292,7 +389,7 @@ export class CallService extends CallBase {
292
389
  }
293
390
  }
294
391
  if (this.data?.customer_required_info !== undefined) {
295
- if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
392
+ if (this.data.customer_required_info.required_info.length > 0 && this.data.customer_required_info.pubkey) {
296
393
  obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, pst);
297
394
  } else if (this.data.customer_required_info.pubkey) {
298
395
  obj?.change_required_pubkey(this.data.customer_required_info.pubkey, pst);
@@ -326,7 +423,7 @@ export class CallService extends CallBase {
326
423
  obj?.add_withdraw_guards(add, pst)
327
424
  break;
328
425
  case 'remove':
329
- obj?.remove_withdraw_guards(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.addresses), false, pst)
426
+ obj?.remove_withdraw_guards(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.guards), false, pst)
330
427
  break;
331
428
  case 'removeall':
332
429
  obj?.remove_withdraw_guards([], true, pst)
@@ -350,9 +447,8 @@ export class CallService extends CallBase {
350
447
  obj?.add_refund_guards(add, pst)
351
448
  break;
352
449
 
353
-
354
450
  case 'remove':
355
- obj?.remove_refund_guards(await LocalMark.Instance().get_many_address2(this.data.refund_guard.addresses), false, pst)
451
+ obj?.remove_refund_guards(await LocalMark.Instance().get_many_address2(this.data.refund_guard.guards), false, pst)
356
452
  break;
357
453
  case 'removeall':
358
454
  obj?.remove_refund_guards([], true, pst)
@@ -362,79 +458,6 @@ export class CallService extends CallBase {
362
458
  if (this.data?.bPublished) {
363
459
  obj?.publish(pst)
364
460
  }
365
- var order_new : OrderResult | undefined;
366
- if (this.data?.order_new !== undefined) {
367
- let b = BigInt(0); let coin : any;
368
- this.data.order_new.buy_items.forEach(v => {
369
- b += BigInt(v.max_price) * BigInt(v.count)
370
- })
371
- if (b > BigInt(0)) {
372
- coin = await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter);
373
- if (coin) {
374
- //@ crypto tools support
375
- order_new = obj.order(this.data.order_new.buy_items, coin, this.data.order_new.discount, this.data.order_new.machine,
376
- this.data.order_new.customer_info_crypto, pst);
377
- }
378
- }
379
- }
380
-
381
- if (this.data?.order_agent !== undefined) {
382
- const o = this.data.order_agent.order ? await LocalMark.Instance().get_address(this.data.order_agent.order) : order_new?.order;
383
- if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_agent.order}`);
384
-
385
- const p = this.data.order_agent.progress ? await LocalMark.Instance().get_address(this.data.order_agent.progress) : order_new?.progress;
386
- if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_agent.progress}`);
387
-
388
- obj?.set_order_agent(o, await LocalMark.Instance().get_many_address2(this.data.order_agent.agents), p)
389
- }
390
- if (this.data?.order_required_info !== undefined && this.data.order_required_info.info !== undefined) {
391
- const o = this.data.order_required_info.order ? await LocalMark.Instance().get_address(this.data.order_required_info.order) : order_new?.order;
392
- if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_required_info.order}`);
393
-
394
- obj?.update_order_required_info(o!, this.data.order_required_info.info)
395
- }
396
- if (this.data?.order_refund !== undefined) {
397
- const o = this.data.order_refund.order ? await LocalMark.Instance().get_address(this.data.order_refund.order) : order_new?.order;
398
- if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_refund.order}`);
399
-
400
-
401
- if ((this.data?.order_refund as any)?.arb && (this.data?.order_refund as any)?.arb_token_type) {
402
- const arb = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.arb);
403
- if (arb) {
404
- obj?.refund_withArb(o!, arb, (this.data?.order_refund as any)?.arb_token_type)
405
- }
406
- } else {
407
- const guard = await LocalMark.Instance().get_address((this.data?.order_refund as any)?.guard);
408
- if (guard) obj?.refund(o!, guard, pst)
409
- }
410
- }
411
- if (this.data?.order_withdrawl !== undefined && pst) { //@ need withdrawal pst
412
- const o = this.data.order_withdrawl.order ? await LocalMark.Instance().get_address(this.data.order_withdrawl.order) : order_new?.order;
413
- if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_withdrawl.order}`);
414
- this.data.order_withdrawl.data.for_guard = await get_object_address(this.data.order_withdrawl.data.for_guard);
415
- this.data.order_withdrawl.data.for_object = await get_object_address(this.data.order_withdrawl.data.for_object);
416
- this.data.order_withdrawl.data.treasury = await get_object_address(this.data.order_withdrawl.data.treasury);
417
- this.data.order_withdrawl.data.withdraw_guard = await get_object_address(this.data.order_withdrawl.data.withdraw_guard);
418
- obj?.withdraw(o!, this.data.order_withdrawl.data, pst)
419
- }
420
-
421
- if (this.data?.order_payer !== undefined && obj) {
422
- const o = this.data.order_payer.order ? await LocalMark.Instance().get_address(this.data.order_payer.order) : order_new?.order;
423
- if (!o) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.order:${this.data.order_payer.order}`);
424
- const p = this.data.order_payer.progress ? await LocalMark.Instance().get_address(this.data.order_payer.progress) : order_new?.progress;
425
- if (!p) ERROR(Errors.InvalidParam, `CallService_Data.data.order_agent.progress:${this.data.order_payer.progress}`);
426
-
427
- const payer = await LocalMark.Instance().get_address(this.data.order_payer.payer_new);
428
- if (payer) obj?.change_order_payer(o, payer, p)
429
- }
430
-
431
- if (order_new && this?.data?.order_new) {
432
- const buy = obj.order_launch(order_new);
433
- await this.new_with_mark('Order', txb, buy.order, (this.data?.order_new as any)?.namedNewOrder, account, [TagName.Launch, TagName.Order]);
434
- if (buy?.progress) {
435
- await this.new_with_mark('Progress', txb, buy.progress, (this.data?.order_new as any)?.namedNewProgress, account, [TagName.Launch]);
436
- }
437
- }
438
461
 
439
462
  if (this.data?.buy_guard !== undefined) {
440
463
  obj?.set_buy_guard(this.data.buy_guard, pst)
@@ -442,18 +465,34 @@ export class CallService extends CallBase {
442
465
  if (this.data?.bPaused !== undefined) {
443
466
  obj?.pause(this.data.bPaused, pst)
444
467
  }
445
- if (this.data?.clone_new !== undefined && object_address) {
468
+ if (this.data?.clone_new !== undefined) {
446
469
  await this.new_with_mark('Service', txb, obj.clone(this.data.clone_new?.token_type_new, true, pst) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
447
470
  }
448
471
  if (payee) {
449
- await this.new_with_mark('Treasury', txb, payee.launch(), (this.data?.payee_treasury as any)?.namedNew, account);
472
+ await this.new_with_mark('Treasury', txb, payee.launch(), GetObjectParam(this.data?.payee_treasury), account);
450
473
  }
451
474
  if (permission) {
452
- await this.new_with_mark('Permission', txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
475
+ const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
476
+ await this.new_with_mark('Permission', txb, permission.launch(), GetObjectParam(n?.permission), account);
453
477
  }
454
- if (!object_address) {
455
- await this.new_with_mark('Service', txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
478
+ if (!this.object_address) {
479
+ await this.new_with_mark('Service', txb, obj.launch(), GetObjectMain(this.data?.object), account);
456
480
  }
457
481
  }
458
482
  }
483
+
484
+ private info_crypto = async (object?:string, info?: string) : Promise<Customer_RequiredInfo | undefined>=> {
485
+ if (!this.content && info && object) {
486
+ await this.update_content('Service', object);
487
+ }
488
+ const pubkey = (this.content as ObjectService).customer_required_info?.pubkey ?? '';
489
+ var info_crypto: Customer_RequiredInfo | undefined ;
490
+ if (pubkey && info) {
491
+ info_crypto = {
492
+ customer_pubkey: pubkey,
493
+ customer_info_crypt: crypto_string(info, pubkey)
494
+ }
495
+ }
496
+ return info_crypto
497
+ }
459
498
  }