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