wowok_agent 1.2.45 → 1.3.48

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