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,31 +1,32 @@
1
1
  import { TransactionBlock, IsValidArgType, PassportObject, Errors, ERROR, Permission, PermissionIndex,
2
- PermissionIndexType, Treasury, Arbitration, VotingGuard, WithdrawFee, ArbObject,
2
+ PermissionIndexType, Treasury, Arbitration, VotingGuard, ArbObject, Service,
3
+ PermissionObject,
3
4
  } from 'wowok';
4
- import { ObjectArbitration, } from '../query/objects.js';
5
- import { CallBase, CallResult, Namedbject} from "./base.js";
5
+ import { ObjectArbitration, query_objects, } from '../query/objects.js';
6
+ import { CallBase, CallResult, GetObjectExisted, GetObjectMain, GetObjectParam, Namedbject,
7
+ ObjectParam, ObjectTypedMain, SetWithdrawFee, TypeNamedObjectWithPermission, WithdrawParam } from "./base.js";
6
8
  import { Account } from '../local/account.js';
7
9
  import { LocalMark } from '../local/local.js';
8
10
  export interface DisputeData {
9
11
  order: string,
10
- order_token_type: string,
11
12
  description: string,
12
13
  votable_proposition: string[],
13
- fee: string | number,
14
+ max_fee: string | number,
14
15
  }
15
16
 
17
+
16
18
  /// The execution priority is determined by the order in which the object attributes are arranged
17
19
  export interface CallArbitration_Data {
18
- type_parameter: string;
19
- object?: {address:string} | {namedNew?: Namedbject}; // undefined or {named_new...} for creating a new object
20
- permission?: {address:string} | {namedNew?: Namedbject, description?:string};
20
+ object: ObjectTypedMain;
21
+ arb_new?: {data: DisputeData; namedNew?: Namedbject}; // dispute an order, and a Arb object will be created.
22
+ arb_withdraw_fee?: {arb:string; data:WithdrawParam};
23
+ arb_vote?: {arb?: string; voting_guard?: string; agrees: number[]};
24
+ arb_arbitration?: {arb?:string; feedback:string; indemnity?:string|number};
25
+
21
26
  description?: string;
22
27
  endpoint?: string;
23
28
  fee?: string | number;
24
- fee_treasury?: {address:string} | {namedNew?: Namedbject, description?:string};
25
- arb_new?: {data: DisputeData; guard?:string; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
26
- arb_withdraw_fee?: {arb?:string; data:WithdrawFee};
27
- arb_vote?: {arb?: string; voting_guard?: string; agrees: number[]};
28
- arb_arbitration?: {arb?:string; feedback:string; indemnity?:string|number};
29
+ fee_treasury?: ObjectParam;
29
30
  guard?: string;
30
31
  voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
31
32
  bPaused?: boolean;
@@ -33,40 +34,44 @@ export interface CallArbitration_Data {
33
34
 
34
35
  export class CallArbitration extends CallBase {
35
36
  data: CallArbitration_Data;
37
+ object_address: string | undefined = undefined;
38
+ permission_address: string | undefined = undefined;
39
+ type_parameter: string | undefined = undefined; // type of the object, e.g. '00x2::sui::SUI'
36
40
 
37
41
  constructor (data: CallArbitration_Data) {
38
42
  super();
39
43
  this.data = data;
40
44
  }
41
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
+
42
65
  async call(account?:string) : Promise<CallResult> {
43
66
  var checkOwner = false; const guards : string[] = [];
44
67
  const perms : PermissionIndexType[] = [];
45
- var [permission_address, object_address, treasury_address] =
46
- await LocalMark.Instance().get_many_address(
47
- [(this.data?.permission as any)?.address,
48
- (this.data?.object as any)?.address,
49
- (this.data?.fee_treasury as any)?.address]);
50
-
51
- if (object_address) {
52
- if (!this.data.type_parameter || !permission_address) {
53
- await this.update_content(object_address, 'Arbitration');
54
- if (this.content) {
55
- permission_address = (this.content as ObjectArbitration).permission;
56
- this.data.type_parameter = this.content.type_raw!;
57
- }
58
- }
59
- } else {
60
- if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
61
- ERROR(Errors.IsValidArgType, 'CallArbitration_Data.data.type_parameter')
62
- }
63
- }
64
68
 
65
- if (permission_address) {
69
+ await this.prepare();
70
+ if (this.permission_address) {
66
71
  if (!this.data?.object) {
67
72
  perms.push(PermissionIndex.arbitration)
68
73
  }
69
- if (this.data?.description !== undefined && object_address) {
74
+ if (this.data?.description !== undefined && this.object_address) {
70
75
  perms.push(PermissionIndex.arbitration_description)
71
76
  }
72
77
  if (this.data?.bPaused !== undefined) {
@@ -75,10 +80,10 @@ export class CallArbitration extends CallBase {
75
80
  if (this.data?.endpoint == undefined) { // publish is an irreversible one-time operation
76
81
  perms.push(PermissionIndex.arbitration_endpoint)
77
82
  }
78
- if (this.data?.fee !== undefined && object_address) {
83
+ if (this.data?.fee !== undefined && this.object_address) {
79
84
  perms.push(PermissionIndex.arbitration_fee)
80
85
  }
81
- if (treasury_address !== undefined && object_address) {
86
+ if (this.data.fee_treasury !== undefined && this.object_address) {
82
87
  perms.push(PermissionIndex.arbitration_treasury)
83
88
  }
84
89
  if (this.data?.guard !== undefined) {
@@ -90,27 +95,15 @@ export class CallArbitration extends CallBase {
90
95
  if (this.data?.arb_arbitration !== undefined) {
91
96
  perms.push(PermissionIndex.arbitration_arbitration)
92
97
  }
93
- if (this.data?.arb_new?.guard !== undefined) {
94
- if (this.data?.arb_new?.guard) {
95
- const guard = await LocalMark.Instance().get_address(this.data?.arb_new?.guard);
96
- if (guard) {
97
- guards.push(guard)
98
- }
99
- } else {
100
- if (!object_address) { // new
101
- const guard = await LocalMark.Instance().get_address(this.data.guard);
102
- if (guard) {
103
- guards.push(guard);
104
- }
105
- } else {
106
- await this.update_content(object_address, 'Arbitration');
107
-
108
- if ((this.content as ObjectArbitration)?.usage_guard) {
109
- guards.push((this.content as ObjectArbitration).usage_guard!)
110
- }
111
- }
98
+
99
+ if (this.data?.arb_new !== undefined) { // new arb with guard and permission
100
+ if (this.object_address) {
101
+ if ((this.content as ObjectArbitration)?.usage_guard) {
102
+ guards.push((this.content as ObjectArbitration).usage_guard!)
103
+ }
112
104
  }
113
105
  }
106
+
114
107
  if (this.data?.arb_vote !== undefined) {
115
108
  perms.push(PermissionIndex.arbitration_vote);
116
109
 
@@ -120,135 +113,159 @@ export class CallArbitration extends CallBase {
120
113
  }
121
114
  }
122
115
 
123
- return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
116
+ return await this.check_permission_and_call(this.permission_address, perms, guards, checkOwner, undefined, account)
124
117
  }
125
118
  return await this.exec(account);
126
119
  }
127
120
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
128
- let obj : Arbitration | undefined ; let permission: any; let withdraw_treasury:any;
129
- var [permission_address, object_address] = this?.content ?
130
- [(this.content as ObjectArbitration).permission, this.content.object] :
131
- await LocalMark.Instance().get_many_address(
132
- [(this.data?.permission as any)?.address,
133
- (this.data?.object as any)?.address]);
134
- const treasury_address = await LocalMark.Instance().get_address((this.data?.fee_treasury as any)?.address);
135
-
136
- if (!object_address) {
137
- if (!permission_address) {
138
- const d = (this.data?.permission as any)?.description ?? '';
139
- permission = Permission.New(txb, d);
121
+ let obj : Arbitration | undefined ; let perm: Permission | undefined;
122
+ let permission : PermissionObject | undefined;
123
+ let withdraw_treasury:Treasury | undefined;
124
+
125
+ if (this.object_address) {
126
+ obj = Arbitration.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
127
+ permission = this.permission_address;
128
+ } else {
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();
140
134
  }
135
+ const treasury_address = await LocalMark.Instance().get_address(GetObjectExisted(this.data.fee_treasury));
141
136
  if (!treasury_address) {
142
- const d = (this.data?.fee_treasury as any)?.description ?? '';
143
- withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
144
- d, permission?undefined:passport);
145
- }
146
- obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
147
- BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
148
- } else {
149
- if (this.data.type_parameter && permission_address) {
150
- obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
151
- } else {
152
- ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.type_parameter or permission')
137
+ withdraw_treasury = Treasury.New(txb, this.type_parameter!, permission,
138
+ GetObjectParam(this.data.fee_treasury)?.description ?? '', perm?undefined:passport);
153
139
  }
140
+ const t = withdraw_treasury ? withdraw_treasury.get_object() : treasury_address;
141
+ if (!t) {
142
+ ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.fee_treasury')
143
+ }
144
+ obj = Arbitration.New(txb, this.type_parameter!, permission, this.data?.description??'',
145
+ BigInt(this.data?.fee ?? 0), t, perm?undefined:passport);
154
146
  }
155
147
 
156
- if (obj) {
157
- const pst = permission?undefined:passport;
158
- if (this.data?.description !== undefined && object_address) {
159
- obj?.set_description(this.data.description, pst);
160
- }
161
- if (this.data?.endpoint !== undefined) {
162
- obj?.set_endpoint(this.data.endpoint, pst)
163
- }
164
- if (this.data?.fee !== undefined && object_address) {
165
- obj?.set_fee(BigInt(this.data.fee), pst)
166
- }
167
- if (treasury_address !== undefined && object_address) {
168
- obj?.set_withdrawTreasury(treasury_address, pst)
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');
169
162
  }
170
- var arb_new : ArbObject | undefined;
171
- if (this.data?.arb_new !== undefined) {
172
- const d = this.data?.arb_new.data;
173
- const order = await LocalMark.Instance().get_address(d.order);
174
- if (order) {
175
- const b = BigInt(d.fee);
176
- arb_new = obj?.arb({order:d.order, order_token_type:d.order_token_type, description:d.description, votable_proposition:d.votable_proposition,
177
- fee: b>BigInt(0) ? await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter) : undefined
178
- }, pst);
179
- }
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');
180
166
  }
181
167
 
182
- if (this.data?.arb_arbitration !== undefined) {
183
- const a = await LocalMark.Instance().get_address(this.data.arb_arbitration.arb) ?? arb_new;
184
- if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_arbitration.arb');
168
+ if (fee > max_fee) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_new.fee > max_fee');
185
169
 
186
- obj?.arbitration({arb:a!, feedback:this.data.arb_arbitration.feedback, indemnity:this.data.arb_arbitration.indemnity}, pst)
187
- }
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
+ }
188
175
 
189
- if (this.data?.arb_vote !== undefined) {
190
- const a = await LocalMark.Instance().get_address(this.data.arb_vote.arb) ?? arb_new;
191
- if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_vote.arb');
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');
192
179
 
193
- obj?.vote({arb:a!, voting_guard:this.data.arb_vote.voting_guard, agrees:this.data.arb_vote.agrees}, pst)
194
- }
180
+ obj?.arbitration({arb:a!, feedback:this.data.arb_arbitration.feedback, indemnity:this.data.arb_arbitration.indemnity}, pst)
181
+ }
195
182
 
196
- if (this.data?.arb_withdraw_fee !== undefined) {
197
- const a = await LocalMark.Instance().get_address(this.data.arb_withdraw_fee.arb) ?? arb_new;
198
- if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_withdraw_fee.arb');
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');
199
186
 
200
- obj?.withdraw_fee(a!, this.data.arb_withdraw_fee.data, pst)
201
- }
187
+ obj?.vote({arb:a!, voting_guard:this.data.arb_vote.voting_guard, agrees:this.data.arb_vote.agrees}, pst)
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
+ }
196
+
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
+ }
202
200
 
203
- if (arb_new) {
204
- await this.new_with_mark('Arb', txb, obj?.arb_launch(arb_new), (this.data?.arb_new as any)?.namedNew, account);
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);
205
215
  }
206
-
207
- if (this.data?.voting_guard !== undefined) {
208
- switch (this.data.voting_guard.op) {
209
- case 'add':
210
- case 'set':
211
- for (let i = 0; i < this.data.voting_guard.data.length; ++ i) {
212
- const v = this.data.voting_guard.data[i];
213
- if (typeof(v.guard) === 'string') {
214
- const g = await LocalMark.Instance().get_address(v.guard);
215
- if (!g) {
216
- ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.voting_guard')
217
- }
218
- v.guard = g;
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
+ }
227
+
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')
219
238
  }
220
- }
221
- if (this.data.voting_guard.op === 'set') {
222
- obj?.remove_voting_guard([], true, pst)
223
- }
224
- obj?.add_voting_guard(this.data.voting_guard.data, pst);
225
- break;
226
- case 'remove':
227
- obj?.remove_voting_guard(await LocalMark.Instance().get_many_address2(this.data.voting_guard.guards), false, pst)
228
- break;
229
- case 'removeall':
239
+ v.guard = g;
240
+ }
241
+ }
242
+ if (this.data.voting_guard.op === 'set') {
230
243
  obj?.remove_voting_guard([], true, pst)
231
- break;
232
- }
233
- }
234
- const guard = await LocalMark.Instance().get_address(this.data.guard);
235
- if (guard) {
236
- obj?.set_guard(guard, pst)
237
- }
238
-
239
- if (this.data?.bPaused !== undefined) {
240
- obj?.pause(this.data.bPaused, pst);
241
- }
242
- if (withdraw_treasury) {
243
- await this.new_with_mark('Treasury', txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
244
- }
245
- if (permission) {
246
- await this.new_with_mark('Permission', txb, permission.launch(), (this.data?.permission as any)?.namedNew, 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;
247
253
  }
254
+ }
248
255
 
249
- if (!object_address) {
250
- await this.new_with_mark('Arbitration', txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
251
- }
256
+ if (this.data?.bPaused !== undefined) {
257
+ obj?.pause(this.data.bPaused, pst);
252
258
  }
259
+ if (withdraw_treasury) {
260
+ await this.new_with_mark('Treasury', txb, withdraw_treasury.launch(), GetObjectParam(this.data?.fee_treasury), account);
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
+ }
253
270
  }
254
271
  }
package/src/call/base.ts CHANGED
@@ -1,21 +1,95 @@
1
1
 
2
2
 
3
3
  import { Entity, Resource, TxbAddress, array_unique, TagName, ResourceObject, PassportObject, Errors, ERROR, Permission,
4
- PermissionIndexType, GuardParser, Passport, WitnessFill, CallResponse, TransactionBlock
4
+ PermissionIndexType, GuardParser, Passport, WitnessFill, CallResponse, TransactionBlock,
5
+ WithdrawFee, TreasuryObject
5
6
  } from 'wowok';
6
7
  import { query_permission } from '../query/permission.js';
7
8
  import { Account } from '../local/account.js';
8
- import { ObjectArbitration, ObjectBase, ObjectBaseType, query_objects, query_personal, raw2type} from '../query/objects.js';
9
+ import { ObjectBase, ObjectBaseType, query_objects, query_personal, raw2type} from '../query/objects.js';
9
10
  import { LocalMark } from '../local/local.js';
10
11
 
11
12
  export interface Namedbject {
12
- name?: string;
13
- tags?: string[];
13
+ name?: string; // name of the object, if not defined, the object will be created without name
14
+ tags?: string[]; // tags of the object, if not defined, the object will be created without tags
14
15
  // true: use address as the name if the name exist; otherwise, use this name and change the original name to its address
15
16
  useAddressIfNameExist?: boolean;
16
- onChain?: boolean; // true: onchain, false: local(default)
17
+ onChain?: boolean; // true: onchain mark, false: local mark(default)
18
+ }
19
+
20
+ export interface NamedObjectWithDescription extends Namedbject {
21
+ description?:string; // description of the new object, if not defined, the object will be created with no description.
22
+ }
23
+
24
+ export interface NamedObjectWithPermission extends Namedbject {
25
+ // permission object, undefined or {named_new...} for creating a new object; if defined, the permission object must exist.
26
+ permission?: ObjectParam;
27
+ }
28
+
29
+ export interface TypeNamedObjectWithPermission extends NamedObjectWithPermission {
30
+ // type of the object, e.g. '0x2::coin::Coin<0x2::sui::SUI>'
31
+ type_parameter: string;
32
+ };
33
+
34
+ /// object address or namedNew for creating a new object
35
+ export type ObjectTypedMain = string | TypeNamedObjectWithPermission ;
36
+ export type ObjectMain = string | NamedObjectWithPermission ;
37
+ export type ObjectPermissionMain = string | Namedbject;
38
+ export type ObjectParam = string | NamedObjectWithDescription;
39
+
40
+ export const GetObjectExisted = (object: ObjectMain | ObjectTypedMain | ObjectParam | ObjectPermissionMain | undefined) : string | undefined => {
41
+ return (typeof object === 'string' ) ? object : undefined;
42
+ }
43
+
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
+ }
52
+ }
53
+
54
+ export const GetObjectParam = (object: ObjectParam | undefined) : NamedObjectWithDescription | undefined => {
55
+ return (typeof object === 'object' && object!== null && 'description' in object)? (object as NamedObjectWithDescription) : undefined;
17
56
  }
18
57
 
58
+ // address from local Account or local Mark.
59
+ export type AccountOrMark_Address = {account?: string} | {name_or_address: string};
60
+
61
+ export const GetAccountOrMark_Address = async (entity?: AccountOrMark_Address) : Promise<string | undefined> => {
62
+ if (typeof((entity as any)?.name_or_address) === 'string') {
63
+ return await LocalMark.Instance().get_address((entity as any).name_or_address);
64
+ } else {
65
+ const acc = await Account.Instance().get((entity as any)?.account);
66
+ return acc?.address;
67
+ }
68
+ }
69
+
70
+ export const GetManyAccountOrMark_Address = async (entities: AccountOrMark_Address[]) : Promise<(string | undefined)[]> => {
71
+ const res = [];
72
+ for (let i = 0; i < entities.length; ++i) {
73
+ const addr = await GetAccountOrMark_Address(entities[i]);
74
+ if (addr) res.push(addr);
75
+ }
76
+ return res;
77
+ }
78
+
79
+ export interface WithdrawParam {
80
+ index: bigint | string | number,
81
+ remark: string,
82
+ for_object?: string,
83
+ for_guard?: string,
84
+ }
85
+
86
+ export const SetWithdrawFee = async (param: WithdrawParam, treasury?:TreasuryObject) : Promise<WithdrawFee> => {
87
+ if (!treasury) {
88
+ ERROR(Errors.InvalidParam, 'WithdrawFee: treasury_address invalid');
89
+ }
90
+ const [object, guard] = await LocalMark.Instance().get_many_address([param.for_object, param.for_guard]);
91
+ return {index:BigInt(param.index), remark:param.remark, for_object:object, for_guard:guard, treasury:treasury};
92
+ }
19
93
  export interface AddressMark {
20
94
  address: TxbAddress;
21
95
  name?: string;
@@ -53,6 +127,7 @@ export class CallBase {
53
127
  content: ObjectBase | undefined = undefined;
54
128
 
55
129
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
130
+ protected async prepare() {};
56
131
  constructor () {}
57
132
  // return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
58
133
  // return ResponseData when the call has completed;
@@ -67,6 +142,7 @@ export class CallBase {
67
142
  if (query) {
68
143
  const txb = new TransactionBlock();
69
144
  const passport = new Passport(txb, query!);
145
+ await this.prepare();
70
146
  await this.operate(txb, passport?.get_object(), account)
71
147
  passport.destroy();
72
148
 
@@ -99,7 +175,6 @@ export class CallBase {
99
175
  if (guards_needed.length > 0) {
100
176
  guards = guards.concat(guards_needed);
101
177
  }
102
-
103
178
  if (guards.length > 0) { // prepare passport
104
179
  const p: GuardParser | undefined = await GuardParser.Create([...guards]);
105
180
  const futures = p ? p.future_fills() : [];
@@ -156,10 +231,10 @@ export class CallBase {
156
231
  }
157
232
  }
158
233
 
159
- protected async update_content(object:string, type:ObjectBaseType) {
160
- if (this.content) return ;
234
+ protected async update_content(type:ObjectBaseType, object?:string) {
235
+ if (this.content || !object) return ;
161
236
 
162
- const r = await query_objects({objects:[object]});
237
+ const r = await query_objects({objects:[object], no_cache:true});
163
238
  if (r?.objects?.length !== 1 || r?.objects[0]?.type !== type) {
164
239
  ERROR(Errors.Fail, `Fetch ${type} object ${object} failed`)
165
240
  }
@@ -173,7 +248,6 @@ export class CallBase {
173
248
  this.resouceObject = undefined;
174
249
  }
175
250
  const r = await Account.Instance().sign_and_commit(txb, account);
176
-
177
251
  if (!r) {
178
252
  ERROR(Errors.Fail, 'sign and commit failed');
179
253
  }
package/src/call/call.ts CHANGED
@@ -20,27 +20,32 @@ export interface CallDemandObject {
20
20
  data: CallDemand_Data;
21
21
  account?: string | null;
22
22
  witness?: GuardInfo_forCall | null;
23
+ no_cache?: boolean;
23
24
  }
24
25
 
25
26
  export interface CallServiceObject {
26
27
  data: CallService_Data;
27
28
  account?: string | null;
28
29
  witness?: GuardInfo_forCall | null;
30
+ no_cache?: boolean;
29
31
  }
30
32
  export interface CallMachineObject {
31
33
  data: CallMachine_Data;
32
34
  account?: string | null;
33
35
  witness?: GuardInfo_forCall | null;
36
+ no_cache?: boolean; // true: no cache to query the machine, false: use cache if exist
34
37
  }
35
38
  export interface CallTreasuryObject {
36
39
  data: CallTreasury_Data;
37
40
  account?: string | null;
38
41
  witness?: GuardInfo_forCall | null;
42
+ no_cache?: boolean;
39
43
  }
40
44
  export interface CallArbitrationObject {
41
45
  data: CallArbitration_Data;
42
46
  account?: string | null;
43
47
  witness?: GuardInfo_forCall | null;
48
+ no_cache?: boolean;
44
49
  }
45
50
  export interface CallGuardObject {
46
51
  data: CallGuard_Data;
@@ -50,6 +55,7 @@ export interface CallRepositoryObject {
50
55
  data: CallRepository_Data;
51
56
  account?: string | null;
52
57
  witness?: GuardInfo_forCall | null;
58
+ no_cache?: boolean;
53
59
  }
54
60
  export interface CallPersonalObject {
55
61
  data: CallPersonal_Data;