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,178 +1,177 @@
1
- import { TransactionBlock, IsValidArgType, IsValidCoinType, Resource, ResourceObject } from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
- PermissionIndexType, Demand, } from 'wowok';
4
- import { query_objects, ObjectDemand } from '../query/objects.js';
5
- import { CallBase, CallResult, Namedbject } from "./base.js";
1
+ import { TransactionBlock, IsValidArgType, Service, PassportObject, Errors, ERROR, Permission, PermissionIndex,
2
+ PermissionIndexType, Demand,
3
+ PermissionObject, } from 'wowok';
4
+ import { ObjectDemand, query_objects } from '../query/objects.js';
5
+ import { CallBase, CallResult, GetObjectExisted, GetObjectMain, GetObjectParam, ObjectTypedMain, TypeNamedObjectWithPermission } from "./base.js";
6
6
  import { Account } from '../local/account.js';
7
7
  import { LocalMark } from '../local/local.js';
8
+ import { off } from 'process';
8
9
 
9
10
  /// The execution priority is determined by the order in which the object attributes are arranged
10
11
  export interface CallDemand_Data {
11
- type_parameter: string;
12
- object?: {address:string} | {namedNew?: Namedbject}; // undefined or {named_new...} for creating a new object
13
- permission?: {address:string} | {namedNew?: Namedbject, description?:string};
12
+ object: ObjectTypedMain;
13
+ // service to present.
14
+ // If Demand.guard.service_id_in_guard is set, the service address must be provided as the service_id_in_guard identifier while Guard verification is performed.
15
+ // Otherwise, the service address is used to present the service to the Demand.
16
+ present?: {service?: string; recommend_words:string;};
17
+
14
18
  description?: string;
15
19
  time_expire?: {op: 'duration'; minutes:number} | {op:'time'; time:number};
16
20
  bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'reward'; service:string} | {op:'refund'} ;
17
- present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string}; // guard is the present guard of Demand
21
+ // If service_id_in_guard is set, the service address must be provided as the service_id_in_guard identifier while Guard verification is performed.
18
22
  guard?: {address:string; service_id_in_guard?:number};
19
23
  }
20
24
 
21
25
  export class CallDemand extends CallBase {
22
26
  data: CallDemand_Data;
23
- content: ObjectDemand | undefined = undefined;
27
+ object_address: string | undefined = undefined;
28
+ permission_address: string | undefined = undefined;
29
+ type_parameter: string | undefined = undefined;
24
30
 
25
31
  constructor(data: CallDemand_Data) {
26
32
  super();
27
33
  this.data = data;
28
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
+ }
29
54
  async call(account?:string) : Promise<CallResult> {
30
55
  var checkOwner = false; const guards : string[] = [];
31
56
  const perms : PermissionIndexType[] = [];
32
- var [permission_address, object_address] =
33
- await LocalMark.Instance().get_many_address(
34
- [(this.data?.permission as any)?.address,
35
- (this.data?.object as any)?.address]);
36
-
37
- if (object_address) {
38
- if (!this.data.type_parameter || !permission_address) {
39
- await this.update_content(object_address, 'Demand');
40
- if (this.content) {
41
- permission_address = (this.content as ObjectDemand).permission;
42
- this.data.type_parameter = this.content.type_raw!;
43
- }
44
- }
45
- } else {
46
- if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
47
- ERROR(Errors.IsValidArgType, 'CallDemand_Data.data.type_parameter')
48
- }
49
- }
50
57
 
51
- if (permission_address) {
58
+ await this.prepare();
59
+ if (this.permission_address) {
52
60
  if (!this.data?.object) {
53
61
  perms.push(PermissionIndex.demand)
54
62
  }
55
- if (this.data?.description !== undefined && object_address) {
63
+ if (this.data?.description !== undefined && this.object_address) {
56
64
  perms.push(PermissionIndex.demand_description)
57
65
  }
58
- if (this.data?.time_expire !== undefined && object_address) {
66
+ if (this.data?.time_expire !== undefined && this.object_address) {
59
67
  perms.push(PermissionIndex.demand_expand_time)
60
68
  }
61
- if (this.data?.guard !== undefined) {
62
- perms.push(PermissionIndex.demand_guard)
63
- }
64
69
  if (this.data?.bounty?.op === 'reward') {
65
70
  perms.push(PermissionIndex.demand_yes)
66
71
  }
67
72
  if (this.data?.bounty?.op === 'refund') {
68
73
  perms.push(PermissionIndex.demand_refund)
69
74
  }
70
- if (this.data?.present?.guard !== undefined) {
71
- if (this.data.present.guard) {
72
- const guard = await LocalMark.Instance().get_address(this.data.present.guard)
73
- if (guard) {
74
- guards.push(guard)
75
- }
76
- } else {
77
- if (!object_address) { // new
78
- const guard = await LocalMark.Instance().get_address(this.data?.guard?.address);
79
- if (guard) {
80
- guards.push(guard)
81
- }
82
- } else {
83
- await this.update_content(object_address, 'Demand');
84
-
85
- if ((this.content as ObjectDemand)?.guard?.object) {
86
- guards.push((this.content as ObjectDemand).guard?.object!)
87
- }
75
+ if (this.data?.guard !== undefined) {
76
+ perms.push(PermissionIndex.demand_guard)
77
+ }
78
+ if (this.data?.present !== undefined) {
79
+ if (this.object_address) {
80
+ if ((this.content as ObjectDemand)?.guard?.object) {
81
+ guards.push((this.content as ObjectDemand).guard?.object!);
88
82
  }
89
- }
83
+ }
90
84
  }
91
- return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
85
+ return await this.check_permission_and_call(this.permission_address, perms, guards, checkOwner, undefined, account)
92
86
  }
93
87
  return await this.exec(account);
94
88
  }
95
89
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
96
- let obj : Demand | undefined ; let permission: any;
97
- var [permission_address, object_address] = this?.content ?
98
- [(this.content as ObjectDemand).permission, this.content.object] :
99
- await LocalMark.Instance().get_many_address(
100
- [(this.data?.permission as any)?.address,
101
- (this.data?.object as any)?.address]);
90
+ let obj : Demand | undefined ; let perm: Permission | undefined;
91
+ let permission : PermissionObject | undefined;
102
92
 
103
- if (!object_address) {
104
- if (!permission_address) {
105
- const d = (this.data?.permission as any)?.description ?? '';
106
- permission = Permission.New(txb, d);
93
+ if (this.object_address) {
94
+ obj = Demand.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
95
+ permission = this.permission_address;
96
+ } else {
97
+ const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
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();
107
102
  }
108
103
 
109
104
  if (this.data.time_expire !== undefined) {
110
- obj = Demand.New(txb, this.data.type_parameter!, this.data.time_expire?.op === 'duration' ? true : false,
105
+ obj = Demand.New(txb, this.type_parameter!, this.data.time_expire?.op === 'duration' ? true : false,
111
106
  this.data.time_expire?.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire?.time,
112
- permission ? permission.get_object(): permission_address, this.data?.description??'', permission?undefined:passport)
113
- } else {
114
- obj = Demand.New(txb, this.data.type_parameter!, true, 30*24*60, // 30days default
115
- permission ? permission.get_object(): permission_address, this.data?.description??'', permission?undefined:passport)
116
- }
117
- } else {
118
- if (this.data.type_parameter && permission_address) {
119
- obj = Demand.From(txb, this.data.type_parameter, permission_address, object_address)
107
+ permission, this.data?.description??'', perm?undefined:passport)
120
108
  } else {
121
- ERROR(Errors.InvalidParam, 'CallDemand_Data.data.type_parameter or permission')
109
+ obj = Demand.New(txb, this.type_parameter!, true, 30*24*60, // 30days default
110
+ permission, this.data?.description??'', perm?undefined:passport)
122
111
  }
123
112
  }
124
113
 
125
- if (obj) {
126
- const pst = permission?undefined:passport;
127
- if (this.data?.description !== undefined && object_address) {
128
- obj?.set_description(this.data.description, pst);
129
- }
130
- if (this.data?.time_expire !== undefined && object_address) {
131
- obj?.expand_time(this.data.time_expire.op === 'duration' ? true : false,
132
- this.data.time_expire.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire.time, pst)
133
- }
134
- if (this.data?.bounty !== undefined) {
135
- if (this.data.bounty.op === 'add') {
136
- const bounty = await LocalMark.Instance().get_address((this.data.bounty.object as any)?.address)
137
- if (bounty) {
138
- obj.deposit((this.data.bounty.object as any)?.address)
139
- } else if ((this.data.bounty.object as any)?.balance !== undefined){
140
- if (!IsValidCoinType(this.data.type_parameter)) {
141
- ERROR(Errors.IsValidCoinType, 'CallDemand_Data.data.type_parameter')
142
- }
143
- const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.data.type_parameter);
144
- if (r) obj.deposit(r)
145
- }
146
- } else if (this.data.bounty.op === 'reward') {
147
- const service = await localStorage.Instance().get_address(this.data.bounty.service);
148
- if (!service) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.bounty.service');
149
- obj?.yes(service, pst);
150
- } else if (this.data.bounty.op === 'refund') {
151
- obj?.refund(pst);
152
- }
153
- }
154
- if (this.data?.present !== undefined) {
155
- //@ demand guard and its pst, if set
156
- const service = typeof(this.data.present.service) === 'string' ? (await LocalMark.Instance().get_address(this.data.present.service)): this.data.present.service;
157
- if (service === undefined) {
158
- ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service')
114
+ if (!obj) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object');
115
+ if (!permission) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.object.permission');
116
+
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);
159
127
  }
160
- obj?.present(typeof(this.data.present.service) === 'string' ? service : this.data.present.service, this.data.present.service_pay_type, this.data.present.recommend_words, pst);
161
- }
162
-
163
- if (this.data?.guard !== undefined) {
164
- const guard = await LocalMark.Instance().get_address(this.data?.guard.address);
165
- if (!guard) {
166
- ERROR(Errors.InvalidParam, 'CallDemand_Data.data.guard.address')
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);
167
131
  }
168
- obj?.set_guard(guard, this.data.guard?.service_id_in_guard ?? undefined, pst);
169
- }
170
- if (permission) {
171
- await this.new_with_mark('Permission', txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
132
+
133
+ obj?.present(service_address, service_type, this.data.present.recommend_words, pst);
172
134
  }
173
- if (!this.data.object) {
174
- await this.new_with_mark('Demand', txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
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)
152
+ }
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')
175
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);
176
175
  }
177
176
  }
178
177
  }