wowok_agent 1.3.47 → 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 +1 -0
- package/dist/call/arbitration.d.ts.map +1 -1
- package/dist/call/arbitration.js +137 -131
- package/dist/call/arbitration.js.map +1 -1
- package/dist/call/base.d.ts +4 -2
- package/dist/call/base.d.ts.map +1 -1
- package/dist/call/base.js +12 -4
- package/dist/call/base.js.map +1 -1
- package/dist/call/demand.d.ts +1 -0
- package/dist/call/demand.d.ts.map +1 -1
- package/dist/call/demand.js +86 -80
- package/dist/call/demand.js.map +1 -1
- package/dist/call/machine.d.ts +1 -0
- package/dist/call/machine.d.ts.map +1 -1
- package/dist/call/machine.js +156 -146
- package/dist/call/machine.js.map +1 -1
- package/dist/call/permission.d.ts +3 -2
- package/dist/call/permission.d.ts.map +1 -1
- package/dist/call/permission.js +90 -85
- package/dist/call/permission.js.map +1 -1
- package/dist/call/repository.d.ts +1 -0
- package/dist/call/repository.d.ts.map +1 -1
- package/dist/call/repository.js +102 -92
- package/dist/call/repository.js.map +1 -1
- package/dist/call/service.d.ts +1 -0
- package/dist/call/service.d.ts.map +1 -1
- package/dist/call/service.js +272 -262
- package/dist/call/service.js.map +1 -1
- package/dist/call/treasury.d.ts +1 -0
- package/dist/call/treasury.d.ts.map +1 -1
- package/dist/call/treasury.js +108 -97
- package/dist/call/treasury.js.map +1 -1
- package/package.json +1 -1
- package/src/call/arbitration.ts +140 -135
- package/src/call/base.ts +12 -6
- package/src/call/demand.ts +89 -81
- package/src/call/machine.ts +153 -141
- package/src/call/permission.ts +93 -85
- package/src/call/repository.ts +104 -92
- package/src/call/service.ts +272 -261
- package/src/call/treasury.ts +108 -96
- package/tsconfig.tsbuildinfo +1 -1
package/src/call/arbitration.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TransactionBlock, IsValidArgType, PassportObject, Errors, ERROR, Permission, PermissionIndex,
|
|
2
2
|
PermissionIndexType, Treasury, Arbitration, VotingGuard, ArbObject, Service,
|
|
3
|
+
PermissionObject,
|
|
3
4
|
} from 'wowok';
|
|
4
5
|
import { ObjectArbitration, query_objects, } from '../query/objects.js';
|
|
5
6
|
import { CallBase, CallResult, GetObjectExisted, GetObjectMain, GetObjectParam, Namedbject,
|
|
@@ -42,24 +43,30 @@ export class CallArbitration extends CallBase {
|
|
|
42
43
|
this.data = data;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
protected async prepare() {
|
|
47
|
+
if (!this.object_address) {
|
|
48
|
+
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
49
|
+
if (this.object_address) {
|
|
50
|
+
await this.update_content('Arbitration', this.object_address);
|
|
51
|
+
if (!this.content) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object:' + this.data.object);
|
|
52
|
+
this.permission_address = (this.content as ObjectArbitration).permission;
|
|
53
|
+
this.type_parameter = Arbitration.parseObjectType(this.content.type_raw);
|
|
54
|
+
} else {
|
|
55
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
56
|
+
if (!IsValidArgType(n?.type_parameter)) {
|
|
57
|
+
ERROR(Errors.IsValidArgType, 'CallArbitration_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
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
async call(account?:string) : Promise<CallResult> {
|
|
46
66
|
var checkOwner = false; const guards : string[] = [];
|
|
47
67
|
const perms : PermissionIndexType[] = [];
|
|
48
|
-
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
49
|
-
if (this.object_address) {
|
|
50
|
-
await this.update_content('Arbitration', this.object_address);
|
|
51
|
-
if (!this.content) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object:' + this.data.object);
|
|
52
|
-
this.permission_address = (this.content as ObjectArbitration).permission;
|
|
53
|
-
this.type_parameter = Arbitration.parseObjectType(this.content.type_raw);
|
|
54
|
-
} else {
|
|
55
|
-
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
56
|
-
if (!n?.type_parameter || !IsValidArgType(n.type_parameter)) {
|
|
57
|
-
ERROR(Errors.IsValidArgType, 'CallArbitration_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
|
-
}
|
|
62
68
|
|
|
69
|
+
await this.prepare();
|
|
63
70
|
if (this.permission_address) {
|
|
64
71
|
if (!this.data?.object) {
|
|
65
72
|
perms.push(PermissionIndex.arbitration)
|
|
@@ -94,12 +101,7 @@ export class CallArbitration extends CallBase {
|
|
|
94
101
|
if ((this.content as ObjectArbitration)?.usage_guard) {
|
|
95
102
|
guards.push((this.content as ObjectArbitration).usage_guard!)
|
|
96
103
|
}
|
|
97
|
-
}
|
|
98
|
-
const guard = await LocalMark.Instance().get_address(this.data.guard);
|
|
99
|
-
if (guard) {
|
|
100
|
-
guards.push(guard);
|
|
101
|
-
}
|
|
102
|
-
}*/
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
if (this.data?.arb_vote !== undefined) {
|
|
@@ -116,151 +118,154 @@ export class CallArbitration extends CallBase {
|
|
|
116
118
|
return await this.exec(account);
|
|
117
119
|
}
|
|
118
120
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
119
|
-
let obj : Arbitration | undefined ;
|
|
120
|
-
let permission:
|
|
121
|
+
let obj : Arbitration | undefined ; let perm: Permission | undefined;
|
|
122
|
+
let permission : PermissionObject | undefined;
|
|
121
123
|
let withdraw_treasury:Treasury | undefined;
|
|
122
124
|
|
|
123
125
|
if (this.object_address) {
|
|
124
126
|
obj = Arbitration.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
|
|
127
|
+
permission = this.permission_address;
|
|
125
128
|
} else {
|
|
126
|
-
const n = GetObjectMain(this.data
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
|
|
130
|
+
permission = await LocalMark.Instance().get_address(GetObjectExisted(n?.permission));
|
|
131
|
+
if (!permission) {
|
|
132
|
+
perm = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
|
|
133
|
+
permission = perm.get_object();
|
|
129
134
|
}
|
|
130
135
|
const treasury_address = await LocalMark.Instance().get_address(GetObjectExisted(this.data.fee_treasury));
|
|
131
136
|
if (!treasury_address) {
|
|
132
|
-
withdraw_treasury = Treasury.New(txb, this.type_parameter!, permission
|
|
133
|
-
GetObjectParam(this.data.fee_treasury)?.description ?? '',
|
|
137
|
+
withdraw_treasury = Treasury.New(txb, this.type_parameter!, permission,
|
|
138
|
+
GetObjectParam(this.data.fee_treasury)?.description ?? '', perm?undefined:passport);
|
|
134
139
|
}
|
|
135
140
|
const t = withdraw_treasury ? withdraw_treasury.get_object() : treasury_address;
|
|
136
141
|
if (!t) {
|
|
137
142
|
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.fee_treasury')
|
|
138
143
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
BigInt(this.data?.fee ?? 0), t, permission?undefined:passport);
|
|
144
|
+
obj = Arbitration.New(txb, this.type_parameter!, permission, this.data?.description??'',
|
|
145
|
+
BigInt(this.data?.fee ?? 0), t, perm?undefined:passport);
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
if (obj)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
148
|
+
if (!obj) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object');
|
|
149
|
+
if (!permission) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object.permission');
|
|
150
|
+
|
|
151
|
+
const pst = perm?undefined:passport;
|
|
152
|
+
var arb_new : ArbObject | undefined;
|
|
153
|
+
if (this.data?.arb_new !== undefined) {
|
|
154
|
+
const d = this.data?.arb_new.data;
|
|
155
|
+
const order = await LocalMark.Instance().get_address(d.order);
|
|
156
|
+
const fee = BigInt((this.object_address ? (this.content as ObjectArbitration)?.fee : this.data?.fee) ?? 0);
|
|
157
|
+
const max_fee = BigInt(d.max_fee);
|
|
158
|
+
if (!order) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_new.order');
|
|
159
|
+
const r = await query_objects({objects:[order]});
|
|
160
|
+
if (r?.objects?.length !== 1 || r?.objects[0]?.type !== 'Order') {
|
|
161
|
+
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_new.order is not an Order object');
|
|
162
|
+
}
|
|
163
|
+
const order_type = Service.parseOrderObjectType(r.objects[0].type_raw);
|
|
164
|
+
if (!order_type) {
|
|
165
|
+
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_new.order type invalid');
|
|
166
|
+
}
|
|
161
167
|
|
|
162
|
-
|
|
168
|
+
if (fee > max_fee) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_new.fee > max_fee');
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
arb_new = obj?.arb({order:d.order, order_token_type:order_type, description:d.description, votable_proposition:d.votable_proposition,
|
|
171
|
+
fee: fee>BigInt(0) ? await Account.Instance().get_coin_object(txb, fee, account, this.type_parameter) : undefined
|
|
172
|
+
}, pst);
|
|
173
|
+
|
|
174
|
+
}
|
|
169
175
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
if (this.data?.arb_arbitration !== undefined) {
|
|
177
|
+
const a = await LocalMark.Instance().get_address(this.data.arb_arbitration.arb) ?? arb_new;
|
|
178
|
+
if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_arbitration.arb');
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
obj?.arbitration({arb:a!, feedback:this.data.arb_arbitration.feedback, indemnity:this.data.arb_arbitration.indemnity}, pst)
|
|
181
|
+
}
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
if (this.data?.arb_vote !== undefined) {
|
|
184
|
+
const a = await LocalMark.Instance().get_address(this.data.arb_vote.arb) ?? arb_new;
|
|
185
|
+
if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_vote.arb');
|
|
180
186
|
|
|
181
|
-
|
|
182
|
-
|
|
187
|
+
obj?.vote({arb:a!, voting_guard:this.data.arb_vote.voting_guard, agrees:this.data.arb_vote.agrees}, pst)
|
|
188
|
+
}
|
|
183
189
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
if (this.data?.arb_withdraw_fee !== undefined) {
|
|
191
|
+
const a = await LocalMark.Instance().get_address(this.data.arb_withdraw_fee.arb);
|
|
192
|
+
if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_withdraw_fee.arb');
|
|
193
|
+
|
|
194
|
+
obj?.withdraw_fee(a!, await SetWithdrawFee(this.data.arb_withdraw_fee.data, (this.content as ObjectArbitration).fee_treasury), pst);
|
|
195
|
+
}
|
|
190
196
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
if (arb_new) {
|
|
198
|
+
await this.new_with_mark('Arb', txb, obj?.arb_launch(arb_new), (this.data?.arb_new as any)?.namedNew, account);
|
|
199
|
+
}
|
|
194
200
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
const t = withdraw_treasury ? withdraw_treasury.get_object() : treasury_address;
|
|
211
|
-
if (!t) {
|
|
212
|
-
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.fee_treasury')
|
|
213
|
-
}
|
|
214
|
-
obj?.set_withdrawTreasury(t, pst)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const guard = await LocalMark.Instance().get_address(this.data.guard);
|
|
218
|
-
if (guard) {
|
|
219
|
-
obj?.set_guard(guard, pst)
|
|
201
|
+
if (this.data?.description !== undefined && this.object_address) {
|
|
202
|
+
obj?.set_description(this.data.description, pst);
|
|
203
|
+
}
|
|
204
|
+
if (this.data?.endpoint !== undefined) {
|
|
205
|
+
obj?.set_endpoint(this.data.endpoint, pst)
|
|
206
|
+
}
|
|
207
|
+
if (this.data?.fee !== undefined && this.object_address) {
|
|
208
|
+
obj?.set_fee(BigInt(this.data.fee), pst)
|
|
209
|
+
}
|
|
210
|
+
if (this.data?.fee_treasury !== undefined && this.object_address) {
|
|
211
|
+
const treasury_address = await LocalMark.Instance().get_address(GetObjectExisted(this.data.fee_treasury));
|
|
212
|
+
if (!treasury_address) {
|
|
213
|
+
withdraw_treasury = Treasury.New(txb, this.type_parameter!, permission,
|
|
214
|
+
GetObjectParam(this.data.fee_treasury)?.description ?? '', pst);
|
|
220
215
|
}
|
|
216
|
+
const t = withdraw_treasury ? withdraw_treasury.get_object() : treasury_address;
|
|
217
|
+
if (!t) {
|
|
218
|
+
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.fee_treasury')
|
|
219
|
+
}
|
|
220
|
+
obj?.set_withdrawTreasury(t, pst)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const guard = await LocalMark.Instance().get_address(this.data.guard);
|
|
224
|
+
if (guard) {
|
|
225
|
+
obj?.set_guard(guard, pst)
|
|
226
|
+
}
|
|
221
227
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
v.guard = g;
|
|
228
|
+
if (this.data?.voting_guard !== undefined) {
|
|
229
|
+
switch (this.data.voting_guard.op) {
|
|
230
|
+
case 'add':
|
|
231
|
+
case 'set':
|
|
232
|
+
for (let i = 0; i < this.data.voting_guard.data.length; ++ i) {
|
|
233
|
+
const v = this.data.voting_guard.data[i];
|
|
234
|
+
if (typeof(v.guard) === 'string') {
|
|
235
|
+
const g = await LocalMark.Instance().get_address(v.guard);
|
|
236
|
+
if (!g) {
|
|
237
|
+
ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.voting_guard')
|
|
234
238
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
obj?.add_voting_guard(this.data.voting_guard.data, pst);
|
|
240
|
-
break;
|
|
241
|
-
case 'remove':
|
|
242
|
-
obj?.remove_voting_guard(await LocalMark.Instance().get_many_address2(this.data.voting_guard.guards), false, pst)
|
|
243
|
-
break;
|
|
244
|
-
case 'removeall':
|
|
239
|
+
v.guard = g;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (this.data.voting_guard.op === 'set') {
|
|
245
243
|
obj?.remove_voting_guard([], true, pst)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
if (permission) {
|
|
257
|
-
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
258
|
-
await this.new_with_mark('Permission', txb, permission.launch(), GetObjectParam(n?.permission), account);
|
|
244
|
+
}
|
|
245
|
+
obj?.add_voting_guard(this.data.voting_guard.data, pst);
|
|
246
|
+
break;
|
|
247
|
+
case 'remove':
|
|
248
|
+
obj?.remove_voting_guard(await LocalMark.Instance().get_many_address2(this.data.voting_guard.guards), false, pst)
|
|
249
|
+
break;
|
|
250
|
+
case 'removeall':
|
|
251
|
+
obj?.remove_voting_guard([], true, pst)
|
|
252
|
+
break;
|
|
259
253
|
}
|
|
254
|
+
}
|
|
260
255
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
256
|
+
if (this.data?.bPaused !== undefined) {
|
|
257
|
+
obj?.pause(this.data.bPaused, pst);
|
|
258
|
+
}
|
|
259
|
+
if (withdraw_treasury) {
|
|
260
|
+
await this.new_with_mark('Treasury', txb, withdraw_treasury.launch(), GetObjectParam(this.data?.fee_treasury), account);
|
|
264
261
|
}
|
|
262
|
+
if (perm) {
|
|
263
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
264
|
+
await this.new_with_mark('Permission', txb, perm.launch(), GetObjectParam(n?.permission), account);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (!this.object_address) {
|
|
268
|
+
await this.new_with_mark('Arbitration', txb, obj.launch(), GetObjectMain(this.data?.object), account);
|
|
269
|
+
}
|
|
265
270
|
}
|
|
266
271
|
}
|
package/src/call/base.ts
CHANGED
|
@@ -34,17 +34,21 @@ export interface TypeNamedObjectWithPermission extends NamedObjectWithPermission
|
|
|
34
34
|
/// object address or namedNew for creating a new object
|
|
35
35
|
export type ObjectTypedMain = string | TypeNamedObjectWithPermission ;
|
|
36
36
|
export type ObjectMain = string | NamedObjectWithPermission ;
|
|
37
|
+
export type ObjectPermissionMain = string | Namedbject;
|
|
37
38
|
export type ObjectParam = string | NamedObjectWithDescription;
|
|
38
39
|
|
|
39
|
-
export const GetObjectExisted = (object: ObjectMain | ObjectTypedMain | ObjectParam | undefined) : string | undefined => {
|
|
40
|
+
export const GetObjectExisted = (object: ObjectMain | ObjectTypedMain | ObjectParam | ObjectPermissionMain | undefined) : string | undefined => {
|
|
40
41
|
return (typeof object === 'string' ) ? object : undefined;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export const GetObjectMain = (object: ObjectMain | ObjectTypedMain | undefined) : NamedObjectWithPermission | TypeNamedObjectWithPermission | undefined => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
export const GetObjectMain = (object: ObjectMain | ObjectTypedMain | ObjectPermissionMain | undefined) : NamedObjectWithPermission | TypeNamedObjectWithPermission | Namedbject | undefined => {
|
|
45
|
+
if (typeof object === 'object' && object !== null && 'type_parameter' in object) {
|
|
46
|
+
return (object as TypeNamedObjectWithPermission);
|
|
47
|
+
} else if (typeof object === 'object' && object !== null && 'permission' in object) {
|
|
48
|
+
return (object as NamedObjectWithPermission);
|
|
49
|
+
} else if (typeof object === 'object') {
|
|
50
|
+
return (object as Namedbject);
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
export const GetObjectParam = (object: ObjectParam | undefined) : NamedObjectWithDescription | undefined => {
|
|
@@ -123,6 +127,7 @@ export class CallBase {
|
|
|
123
127
|
content: ObjectBase | undefined = undefined;
|
|
124
128
|
|
|
125
129
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
|
|
130
|
+
protected async prepare() {};
|
|
126
131
|
constructor () {}
|
|
127
132
|
// return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
|
|
128
133
|
// return ResponseData when the call has completed;
|
|
@@ -137,6 +142,7 @@ export class CallBase {
|
|
|
137
142
|
if (query) {
|
|
138
143
|
const txb = new TransactionBlock();
|
|
139
144
|
const passport = new Passport(txb, query!);
|
|
145
|
+
await this.prepare();
|
|
140
146
|
await this.operate(txb, passport?.get_object(), account)
|
|
141
147
|
passport.destroy();
|
|
142
148
|
|
package/src/call/demand.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TransactionBlock, IsValidArgType, Service, PassportObject, Errors, ERROR, Permission, PermissionIndex,
|
|
2
|
-
PermissionIndexType, Demand,
|
|
2
|
+
PermissionIndexType, Demand,
|
|
3
|
+
PermissionObject, } from 'wowok';
|
|
3
4
|
import { ObjectDemand, query_objects } from '../query/objects.js';
|
|
4
5
|
import { CallBase, CallResult, GetObjectExisted, GetObjectMain, GetObjectParam, ObjectTypedMain, TypeNamedObjectWithPermission } from "./base.js";
|
|
5
6
|
import { Account } from '../local/account.js';
|
|
6
7
|
import { LocalMark } from '../local/local.js';
|
|
8
|
+
import { off } from 'process';
|
|
7
9
|
|
|
8
10
|
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
9
11
|
export interface CallDemand_Data {
|
|
@@ -30,24 +32,30 @@ export class CallDemand extends CallBase {
|
|
|
30
32
|
super();
|
|
31
33
|
this.data = data;
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
protected async prepare(): Promise<void> {
|
|
37
|
+
if (!this.object_address) {
|
|
38
|
+
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
39
|
+
if (this.object_address) {
|
|
40
|
+
await this.update_content('Demand', this.object_address);
|
|
41
|
+
if (!this.content) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object:' + this.object_address);
|
|
42
|
+
this.permission_address = (this.content as ObjectDemand).permission;
|
|
43
|
+
this.type_parameter = Demand.parseObjectType(this.content.type_raw);
|
|
44
|
+
} else {
|
|
45
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
46
|
+
if (!IsValidArgType(n?.type_parameter)) {
|
|
47
|
+
ERROR(Errors.IsValidArgType, 'CallDemand_Data.data.object.type_parameter');
|
|
48
|
+
}
|
|
49
|
+
this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
|
|
50
|
+
this.type_parameter = n.type_parameter;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
33
54
|
async call(account?:string) : Promise<CallResult> {
|
|
34
55
|
var checkOwner = false; const guards : string[] = [];
|
|
35
56
|
const perms : PermissionIndexType[] = [];
|
|
36
|
-
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
37
|
-
if (this.object_address) {
|
|
38
|
-
await this.update_content('Demand', this.object_address);
|
|
39
|
-
if (!this.content) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object:' + this.object_address);
|
|
40
|
-
this.permission_address = (this.content as ObjectDemand).permission;
|
|
41
|
-
this.type_parameter = Demand.parseObjectType(this.content.type_raw);
|
|
42
|
-
} else {
|
|
43
|
-
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
44
|
-
if (!n?.type_parameter || !IsValidArgType(n.type_parameter)) {
|
|
45
|
-
ERROR(Errors.IsValidArgType, 'CallDemand_Data.data.object.type_parameter');
|
|
46
|
-
}
|
|
47
|
-
this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
|
|
48
|
-
this.type_parameter = n.type_parameter;
|
|
49
|
-
}
|
|
50
57
|
|
|
58
|
+
await this.prepare();
|
|
51
59
|
if (this.permission_address) {
|
|
52
60
|
if (!this.data?.object) {
|
|
53
61
|
perms.push(PermissionIndex.demand)
|
|
@@ -72,98 +80,98 @@ export class CallDemand extends CallBase {
|
|
|
72
80
|
if ((this.content as ObjectDemand)?.guard?.object) {
|
|
73
81
|
guards.push((this.content as ObjectDemand).guard?.object!);
|
|
74
82
|
}
|
|
75
|
-
}
|
|
76
|
-
const guard = await LocalMark.Instance().get_address(this.data?.guard?.address);
|
|
77
|
-
if (guard) {
|
|
78
|
-
guards.push(guard)
|
|
79
|
-
}
|
|
80
|
-
}*/
|
|
83
|
+
}
|
|
81
84
|
}
|
|
82
85
|
return await this.check_permission_and_call(this.permission_address, perms, guards, checkOwner, undefined, account)
|
|
83
86
|
}
|
|
84
87
|
return await this.exec(account);
|
|
85
88
|
}
|
|
86
89
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
87
|
-
let obj : Demand | undefined ; let
|
|
90
|
+
let obj : Demand | undefined ; let perm: Permission | undefined;
|
|
91
|
+
let permission : PermissionObject | undefined;
|
|
88
92
|
|
|
89
93
|
if (this.object_address) {
|
|
90
|
-
obj = Demand.From(txb, this.type_parameter!, this.permission_address!, this.object_address)
|
|
94
|
+
obj = Demand.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
|
|
95
|
+
permission = this.permission_address;
|
|
91
96
|
} else {
|
|
92
97
|
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
permission = await LocalMark.Instance().get_address(GetObjectExisted(n?.permission));
|
|
99
|
+
if (!permission) {
|
|
100
|
+
perm = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
|
|
101
|
+
permission = perm.get_object();
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
if (this.data.time_expire !== undefined) {
|
|
98
105
|
obj = Demand.New(txb, this.type_parameter!, this.data.time_expire?.op === 'duration' ? true : false,
|
|
99
106
|
this.data.time_expire?.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire?.time,
|
|
100
|
-
permission
|
|
107
|
+
permission, this.data?.description??'', perm?undefined:passport)
|
|
101
108
|
} else {
|
|
102
109
|
obj = Demand.New(txb, this.type_parameter!, true, 30*24*60, // 30days default
|
|
103
|
-
permission
|
|
110
|
+
permission, this.data?.description??'', perm?undefined:passport)
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
|
|
107
|
-
if (obj)
|
|
108
|
-
|
|
109
|
-
if (this.data?.present !== undefined) {
|
|
110
|
-
if ((this.content as ObjectDemand)?.guard?.service_id_in_guard !== undefined && (this.content as ObjectDemand)?.guard?.service_id_in_guard !== null) {
|
|
111
|
-
obj?.present((this.content as ObjectDemand)!.guard!.service_id_in_guard!, undefined, this.data.present.recommend_words, pst);
|
|
112
|
-
} else {
|
|
113
|
-
const service_address = await LocalMark.Instance().get_address(this.data.present.service);
|
|
114
|
-
if (!service_address) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service');
|
|
115
|
-
const r = await query_objects({objects:[service_address]});
|
|
116
|
-
if (r?.objects?.length !== 1 || r?.objects[0]?.type !== 'Service') {
|
|
117
|
-
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service: ' + service_address);
|
|
118
|
-
}
|
|
119
|
-
const service_type = Service.parseOrderObjectType(r.objects[0].type_raw);
|
|
120
|
-
if (!service_type) {
|
|
121
|
-
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service: ' + service_address);
|
|
122
|
-
}
|
|
114
|
+
if (!obj) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object');
|
|
115
|
+
if (!permission) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object.permission');
|
|
123
116
|
|
|
124
|
-
|
|
117
|
+
const pst = perm?undefined:passport;
|
|
118
|
+
if (this.data?.present !== undefined) {
|
|
119
|
+
if ((this.content as ObjectDemand)?.guard?.service_id_in_guard !== undefined && (this.content as ObjectDemand)?.guard?.service_id_in_guard !== null) {
|
|
120
|
+
obj?.present((this.content as ObjectDemand)!.guard!.service_id_in_guard!, undefined, this.data.present.recommend_words, pst);
|
|
121
|
+
} else {
|
|
122
|
+
const service_address = await LocalMark.Instance().get_address(this.data.present.service);
|
|
123
|
+
if (!service_address) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service');
|
|
124
|
+
const r = await query_objects({objects:[service_address]});
|
|
125
|
+
if (r?.objects?.length !== 1 || r?.objects[0]?.type !== 'Service') {
|
|
126
|
+
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service: ' + service_address);
|
|
127
|
+
}
|
|
128
|
+
const service_type = Service.parseOrderObjectType(r.objects[0].type_raw);
|
|
129
|
+
if (!service_type) {
|
|
130
|
+
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service: ' + service_address);
|
|
125
131
|
}
|
|
126
|
-
}
|
|
127
132
|
|
|
128
|
-
|
|
129
|
-
obj?.set_description(this.data.description, pst);
|
|
133
|
+
obj?.present(service_address, service_type, this.data.present.recommend_words, pst);
|
|
130
134
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
obj
|
|
148
|
-
} else if (this.data.bounty.op === 'refund') {
|
|
149
|
-
obj?.refund(pst);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (this.data?.guard !== undefined) {
|
|
154
|
-
const guard = await LocalMark.Instance().get_address(this.data?.guard.address);
|
|
155
|
-
if (!guard) {
|
|
156
|
-
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.guard.address')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (this.data?.description !== undefined && this.object_address) {
|
|
138
|
+
obj?.set_description(this.data.description, pst);
|
|
139
|
+
}
|
|
140
|
+
if (this.data?.time_expire !== undefined && this.object_address) {
|
|
141
|
+
obj?.expand_time(this.data.time_expire.op === 'duration' ? true : false,
|
|
142
|
+
this.data.time_expire.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire.time, pst)
|
|
143
|
+
}
|
|
144
|
+
if (this.data?.bounty !== undefined) {
|
|
145
|
+
if (this.data.bounty.op === 'add') {
|
|
146
|
+
const bounty = await LocalMark.Instance().get_address((this.data.bounty.object as any)?.address)
|
|
147
|
+
if (bounty) {
|
|
148
|
+
obj.deposit(bounty)
|
|
149
|
+
} else if ((this.data.bounty.object as any)?.balance !== undefined){
|
|
150
|
+
const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.type_parameter);
|
|
151
|
+
if (r) obj.deposit(r)
|
|
157
152
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
} else if (this.data.bounty.op === 'reward') {
|
|
154
|
+
const service = await localStorage.Instance().get_address(this.data.bounty.service);
|
|
155
|
+
if (!service) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.bounty.service');
|
|
156
|
+
obj?.yes(service, pst);
|
|
157
|
+
} else if (this.data.bounty.op === 'refund') {
|
|
158
|
+
obj?.refund(pst);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.data?.guard !== undefined) {
|
|
163
|
+
const guard = await LocalMark.Instance().get_address(this.data?.guard.address);
|
|
164
|
+
if (!guard) {
|
|
165
|
+
ERROR(Errors.InvalidParam, 'CallDemand_Data.data.guard.address')
|
|
166
166
|
}
|
|
167
|
+
obj?.set_guard(guard, this.data.guard?.service_id_in_guard ?? undefined, pst);
|
|
168
|
+
}
|
|
169
|
+
if (perm) {
|
|
170
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
171
|
+
await this.new_with_mark('Permission', txb, perm.launch(), GetObjectParam(n?.permission), account);
|
|
172
|
+
}
|
|
173
|
+
if (!this.data.object) {
|
|
174
|
+
await this.new_with_mark('Demand', txb, obj.launch(), GetObjectMain(this.data?.object), account);
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
}
|