wowok_agent 1.2.37 → 1.2.40

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 (104) hide show
  1. package/dist/call/arbitration.d.ts +69 -0
  2. package/dist/call/arbitration.d.ts.map +1 -0
  3. package/dist/call/arbitration.js +210 -0
  4. package/dist/call/arbitration.js.map +1 -0
  5. package/dist/call/base.d.ts +37 -0
  6. package/dist/call/base.d.ts.map +1 -0
  7. package/dist/call/base.js +157 -0
  8. package/dist/call/base.js.map +1 -0
  9. package/dist/call/call.d.ts +84 -0
  10. package/dist/call/call.d.ts.map +1 -0
  11. package/dist/call/call.js +156 -0
  12. package/dist/call/call.js.map +1 -0
  13. package/dist/call/demand.d.ts +57 -0
  14. package/dist/call/demand.d.ts.map +1 -0
  15. package/dist/call/demand.js +160 -0
  16. package/dist/call/demand.js.map +1 -0
  17. package/dist/call/guard.d.ts +42 -0
  18. package/dist/call/guard.d.ts.map +1 -0
  19. package/dist/call/guard.js +264 -0
  20. package/dist/call/guard.js.map +1 -0
  21. package/dist/call/machine.d.ts +109 -0
  22. package/dist/call/machine.d.ts.map +1 -0
  23. package/dist/call/machine.js +250 -0
  24. package/dist/call/machine.js.map +1 -0
  25. package/dist/call/object_permission.d.ts +14 -0
  26. package/dist/call/object_permission.d.ts.map +1 -0
  27. package/dist/call/object_permission.js +52 -0
  28. package/dist/call/object_permission.js.map +1 -0
  29. package/dist/call/permission.d.ts +50 -0
  30. package/dist/call/permission.d.ts.map +1 -0
  31. package/dist/call/permission.js +127 -0
  32. package/dist/call/permission.js.map +1 -0
  33. package/dist/call/personal.d.ts +42 -0
  34. package/dist/call/personal.d.ts.map +1 -0
  35. package/dist/call/personal.js +88 -0
  36. package/dist/call/personal.js.map +1 -0
  37. package/dist/call/repository.d.ts +52 -0
  38. package/dist/call/repository.d.ts.map +1 -0
  39. package/dist/call/repository.js +135 -0
  40. package/dist/call/repository.js.map +1 -0
  41. package/dist/call/service.d.ts +134 -0
  42. package/dist/call/service.d.ts.map +1 -0
  43. package/dist/call/service.js +416 -0
  44. package/dist/call/service.js.map +1 -0
  45. package/dist/call/treasury.d.ts +53 -0
  46. package/dist/call/treasury.d.ts.map +1 -0
  47. package/dist/call/treasury.js +175 -0
  48. package/dist/call/treasury.js.map +1 -0
  49. package/dist/common.d.ts +3 -0
  50. package/dist/common.d.ts.map +1 -0
  51. package/dist/common.js +13 -0
  52. package/dist/common.js.map +1 -0
  53. package/dist/index.d.ts +22 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +22 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/local/account.d.ts +24 -0
  58. package/dist/local/account.d.ts.map +1 -0
  59. package/dist/local/account.js +188 -0
  60. package/dist/local/account.js.map +1 -0
  61. package/dist/local/cache.d.ts +32 -0
  62. package/dist/local/cache.d.ts.map +1 -0
  63. package/dist/local/cache.js +71 -0
  64. package/dist/local/cache.js.map +1 -0
  65. package/dist/local/index.d.ts +83 -0
  66. package/dist/local/index.d.ts.map +1 -0
  67. package/dist/local/index.js +98 -0
  68. package/dist/local/index.js.map +1 -0
  69. package/dist/local/local.d.ts +56 -0
  70. package/dist/local/local.d.ts.map +1 -0
  71. package/dist/local/local.js +245 -0
  72. package/dist/local/local.js.map +1 -0
  73. package/dist/query/events.d.ts +63 -0
  74. package/dist/query/events.d.ts.map +1 -0
  75. package/dist/query/events.js +78 -0
  76. package/dist/query/events.js.map +1 -0
  77. package/dist/query/objects.d.ts +323 -0
  78. package/dist/query/objects.d.ts.map +1 -0
  79. package/dist/query/objects.js +453 -0
  80. package/dist/query/objects.js.map +1 -0
  81. package/dist/query/permission.d.ts +12 -0
  82. package/dist/query/permission.d.ts.map +1 -0
  83. package/dist/query/permission.js +41 -0
  84. package/dist/query/permission.js.map +1 -0
  85. package/package.json +2 -2
  86. package/src/call/arbitration.ts +85 -54
  87. package/src/call/base.ts +22 -12
  88. package/src/call/call.ts +24 -21
  89. package/src/call/demand.ts +60 -30
  90. package/src/call/guard.ts +25 -16
  91. package/src/call/machine.ts +79 -40
  92. package/src/call/object_permission.ts +12 -8
  93. package/src/call/permission.ts +44 -18
  94. package/src/call/personal.ts +39 -13
  95. package/src/call/repository.ts +27 -13
  96. package/src/call/service.ts +150 -73
  97. package/src/call/treasury.ts +68 -50
  98. package/src/common.ts +9 -0
  99. package/src/index.ts +1 -0
  100. package/src/local/account.ts +3 -3
  101. package/src/local/index.ts +54 -50
  102. package/src/local/local.ts +48 -8
  103. package/src/query/objects.ts +14 -6
  104. package/tsconfig.tsbuildinfo +1 -1
@@ -1,9 +1,10 @@
1
- import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
2
- PermissionIndexType, Treasury, Arbitration, VotingGuard, WithdrawFee, ArbObject,
1
+ import { TransactionBlock, IsValidArgType, PassportObject, Errors, ERROR, Permission, PermissionIndex,
2
+ PermissionIndexType, Treasury, Arbitration, VotingGuard, WithdrawFee, ArbObject,
3
3
  } from 'wowok';
4
- import { query_objects, ObjectArbitration, } from '../query/objects.js';
4
+ import { ObjectArbitration, } from '../query/objects.js';
5
5
  import { CallBase, CallResult, Namedbject} from "./base.js";
6
6
  import { Account } from '../local/account.js';
7
+ import { LocalMark } from '../local/local.js';
7
8
  export interface DisputeData {
8
9
  order: string,
9
10
  order_token_type: string,
@@ -21,7 +22,7 @@ export interface CallArbitration_Data {
21
22
  endpoint?: string;
22
23
  fee?: string | number;
23
24
  fee_treasury?: {address:string} | {namedNew?: Namedbject, description?:string};
24
- arb_new?: {data: DisputeData; guard?:string | 'fetch'; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
25
+ arb_new?: {data: DisputeData; guard?:string; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
25
26
  arb_withdraw_fee?: {arb?:string; data:WithdrawFee};
26
27
  arb_vote?: {arb?: string; voting_guard?: string; agrees: number[]};
27
28
  arb_arbitration?: {arb?:string; feedback:string; indemnity?:string|number};
@@ -32,23 +33,36 @@ export interface CallArbitration_Data {
32
33
 
33
34
  export class CallArbitration extends CallBase {
34
35
  data: CallArbitration_Data;
36
+
35
37
  constructor (data: CallArbitration_Data) {
36
38
  super();
37
39
  this.data = data;
38
40
  }
39
41
 
40
42
  async call(account?:string) : Promise<CallResult> {
41
- if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
42
- ERROR(Errors.IsValidArgType, 'arbitration.type_parameter')
43
- }
44
-
45
43
  var checkOwner = false; const guards : string[] = [];
46
- const perms : PermissionIndexType[] = []; var obj: ObjectArbitration | undefined ;
47
- const permission_address = (this.data?.permission as any)?.address;
48
- const object_address = (this.data?.object as any)?.address;
49
- const treasury_address = (this.data?.fee_treasury as any)?.address;
44
+ 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
+ }
50
64
 
51
- if (permission_address && IsValidAddress(permission_address)) {
65
+ if (permission_address) {
52
66
  if (!this.data?.object) {
53
67
  perms.push(PermissionIndex.arbitration)
54
68
  }
@@ -77,32 +91,31 @@ export class CallArbitration extends CallBase {
77
91
  perms.push(PermissionIndex.arbitration_arbitration)
78
92
  }
79
93
  if (this.data?.arb_new?.guard !== undefined) {
80
- if (IsValidAddress(this.data.arb_new.guard)) {
81
- guards.push(this.data.arb_new.guard)
94
+ const guard = await LocalMark.Instance().get_address(this.data?.arb_new?.guard);
95
+ if (guard) {
96
+ guards.push(guard)
82
97
  } else {
83
98
  if (!object_address) { // new
84
- if (this.data?.guard && IsValidAddress(this.data?.guard)) {
85
- guards.push(this.data.guard)
99
+ const guard = await LocalMark.Instance().get_address(this.data.guard);
100
+ if (guard) {
101
+ guards.push(guard);
86
102
  }
87
103
  } else {
88
- if (!obj) {
89
- const r = await query_objects({objects:[object_address]});
90
- if (r?.objects && r.objects[0].type === 'Arbitration') {
91
- obj = r.objects[0] as ObjectArbitration;
92
- }
93
- }
104
+ await this.update_content(object_address, 'Arbitration');
94
105
 
95
- if (obj?.usage_guard) {
96
- guards.push(obj.usage_guard)
106
+ if ((this.content as ObjectArbitration)?.usage_guard) {
107
+ guards.push((this.content as ObjectArbitration).usage_guard!)
97
108
  }
98
109
  }
99
110
  }
100
111
  }
101
112
  if (this.data?.arb_vote !== undefined) {
102
- perms.push(PermissionIndex.treasury_receive)
103
- }
104
- if (typeof(this.data?.arb_vote?.voting_guard) === 'string' && IsValidAddress(this.data?.arb_vote?.voting_guard)) {
105
- guards.push(this.data?.arb_vote?.voting_guard)
113
+ perms.push(PermissionIndex.arbitration_vote);
114
+
115
+ const voting_guard = await LocalMark.Instance().get_address(this.data?.arb_vote?.voting_guard);
116
+ if (voting_guard) {
117
+ guards.push(voting_guard)
118
+ }
106
119
  }
107
120
 
108
121
  return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
@@ -111,16 +124,19 @@ export class CallArbitration extends CallBase {
111
124
  }
112
125
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
113
126
  let obj : Arbitration | undefined ; let permission: any; let withdraw_treasury:any;
114
- const permission_address = (this.data?.permission as any)?.address;
115
- const object_address = (this.data?.object as any)?.address;
116
- const treasury_address = (this.data?.fee_treasury as any)?.address;
127
+ var [permission_address, object_address] = this?.content ?
128
+ [(this.content as ObjectArbitration).permission, this.content.object] :
129
+ await LocalMark.Instance().get_many_address(
130
+ [(this.data?.permission as any)?.address,
131
+ (this.data?.object as any)?.address]);
132
+ const treasury_address = await LocalMark.Instance().get_address((this.data?.fee_treasury as any)?.address);
117
133
 
118
134
  if (!object_address) {
119
- if (!permission_address || !IsValidAddress(permission_address)) {
135
+ if (!permission_address) {
120
136
  const d = (this.data?.permission as any)?.description ?? '';
121
137
  permission = Permission.New(txb, d);
122
138
  }
123
- if (!treasury_address || !IsValidAddress(treasury_address)) {
139
+ if (!treasury_address) {
124
140
  const d = (this.data?.fee_treasury as any)?.description ?? '';
125
141
  withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
126
142
  d, permission?undefined:passport);
@@ -128,10 +144,10 @@ export class CallArbitration extends CallBase {
128
144
  obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
129
145
  BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
130
146
  } else {
131
- if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
147
+ if (this.data.type_parameter && permission_address) {
132
148
  obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
133
149
  } else {
134
- ERROR(Errors.InvalidParam, 'object or permission address invalid.')
150
+ ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.type_parameter or permission')
135
151
  }
136
152
  }
137
153
 
@@ -151,30 +167,33 @@ export class CallArbitration extends CallBase {
151
167
  }
152
168
  var arb_new : ArbObject | undefined;
153
169
  if (this.data?.arb_new !== undefined) {
154
- const b = BigInt(this.data.arb_new.data.fee);
155
170
  const d = this.data?.arb_new.data;
156
- arb_new = obj?.arb({order:d.order, order_token_type:d.order_token_type, description:d.description, votable_proposition:d.votable_proposition,
157
- fee: b>BigInt(0) ? await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter) : undefined
158
- }, pst);
171
+ const order = await LocalMark.Instance().get_address(d.order);
172
+ if (order) {
173
+ const b = BigInt(d.fee);
174
+ arb_new = obj?.arb({order:d.order, order_token_type:d.order_token_type, description:d.description, votable_proposition:d.votable_proposition,
175
+ fee: b>BigInt(0) ? await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter) : undefined
176
+ }, pst);
177
+ }
159
178
  }
160
179
 
161
180
  if (this.data?.arb_arbitration !== undefined) {
162
- const a = this.data.arb_arbitration.arb ?? arb_new;
163
- if (!a) ERROR(Errors.Fail, 'arb invalid: arb_arbitration');
181
+ const a = await LocalMark.Instance().get_address(this.data.arb_arbitration.arb) ?? arb_new;
182
+ if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_arbitration.arb');
164
183
 
165
184
  obj?.arbitration({arb:a!, feedback:this.data.arb_arbitration.feedback, indemnity:this.data.arb_arbitration.indemnity}, pst)
166
185
  }
167
186
 
168
187
  if (this.data?.arb_vote !== undefined) {
169
- const a = this.data.arb_vote.arb ?? arb_new;
170
- if (!a) ERROR(Errors.Fail, 'arb invalid: arb_vote');
188
+ const a = await LocalMark.Instance().get_address(this.data.arb_vote.arb) ?? arb_new;
189
+ if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_vote.arb');
171
190
 
172
191
  obj?.vote({arb:a!, voting_guard:this.data.arb_vote.voting_guard, agrees:this.data.arb_vote.agrees}, pst)
173
192
  }
174
193
 
175
194
  if (this.data?.arb_withdraw_fee !== undefined) {
176
- const a = this.data.arb_withdraw_fee.arb ?? arb_new;
177
- if (!a) ERROR(Errors.Fail, 'arb invalid: arb_withdraw_fee');
195
+ const a = await LocalMark.Instance().get_address(this.data.arb_withdraw_fee.arb) ?? arb_new;
196
+ if (!a) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.arb_withdraw_fee.arb');
178
197
 
179
198
  obj?.withdraw_fee(a!, this.data.arb_withdraw_fee.data, pst)
180
199
  }
@@ -186,23 +205,35 @@ export class CallArbitration extends CallBase {
186
205
  if (this.data?.voting_guard !== undefined) {
187
206
  switch (this.data.voting_guard.op) {
188
207
  case 'add':
189
- obj?.add_voting_guard(this.data.voting_guard.data, pst)
208
+ case 'set':
209
+ for (let i = 0; i < this.data.voting_guard.data.length; ++ i) {
210
+ const v = this.data.voting_guard.data[i];
211
+ if (typeof(v.guard) === 'string') {
212
+ const g = await LocalMark.Instance().get_address(v.guard);
213
+ if (!g) {
214
+ ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.voting_guard')
215
+ }
216
+ v.guard = g;
217
+ }
218
+ }
219
+ if (this.data.voting_guard.op === 'set') {
220
+ obj?.remove_voting_guard([], true, pst)
221
+ }
222
+ obj?.add_voting_guard(this.data.voting_guard.data, pst);
190
223
  break;
191
224
  case 'remove':
192
- obj?.remove_voting_guard(this.data.voting_guard.guards, false, pst)
193
- break;
194
- case 'set':
195
- obj?.remove_voting_guard([], true, pst)
196
- obj?.add_voting_guard(this.data.voting_guard.data, pst)
225
+ obj?.remove_voting_guard(await LocalMark.Instance().get_many_address2(this.data.voting_guard.guards), false, pst)
197
226
  break;
198
227
  case 'removeall':
199
228
  obj?.remove_voting_guard([], true, pst)
200
229
  break;
201
230
  }
202
231
  }
203
- if (this.data.guard !== undefined) {
204
- obj?.set_guard(this.data.guard, pst)
232
+ const guard = await LocalMark.Instance().get_address(this.data.guard);
233
+ if (guard) {
234
+ obj?.set_guard(guard, pst)
205
235
  }
236
+
206
237
  if (this.data?.bPaused !== undefined) {
207
238
  obj?.pause(this.data.bPaused, pst);
208
239
  }
package/src/call/base.ts CHANGED
@@ -5,7 +5,7 @@ import { Entity, Resource, TxbAddress, array_unique, TagName, ResourceObject, Pa
5
5
  } from 'wowok';
6
6
  import { query_permission } from '../query/permission.js';
7
7
  import { Account } from '../local/account.js';
8
- import { ObjectBase, ObjectBaseType, query_personal, raw2type} from '../query/objects.js';
8
+ import { ObjectArbitration, ObjectBase, ObjectBaseType, query_objects, query_personal, raw2type} from '../query/objects.js';
9
9
  import { LocalMark } from '../local/local.js';
10
10
 
11
11
  export interface Namedbject {
@@ -50,6 +50,7 @@ export class CallBase {
50
50
  // operation implementation for a call
51
51
  private resouceObject:ResourceObject | undefined;
52
52
  private traceMarkNew = new Map<ObjectBaseType, Namedbject>();
53
+ content: ObjectBase | undefined = undefined;
53
54
 
54
55
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
55
56
  constructor () {}
@@ -128,13 +129,12 @@ export class CallBase {
128
129
 
129
130
  protected async new_with_mark(type:ObjectBaseType, txb:TransactionBlock, object:TxbAddress, named_new?:Namedbject, account?:string, innerTags:string[]=[TagName.Launch]) {
130
131
  const tags = named_new?.tags ? array_unique([...named_new.tags, ...innerTags]) : array_unique([...innerTags]);
131
- if (!named_new?.onChain) {
132
- if (named_new) {
133
- named_new.tags = tags;
134
- this.traceMarkNew.set(type, named_new)
135
- }
136
- return ;
137
- } ;
132
+ if (named_new) {
133
+ named_new.tags = tags;
134
+ this.traceMarkNew.set(type, named_new)
135
+ }
136
+
137
+ if (!named_new?.onChain) return ;
138
138
 
139
139
  // onchain mark
140
140
  if (!this.resouceObject) {
@@ -154,7 +154,17 @@ export class CallBase {
154
154
  } else {
155
155
  Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
156
156
  }
157
-
157
+ }
158
+
159
+ protected async update_content(object:string, type:ObjectBaseType) {
160
+ if (this.content) return ;
161
+
162
+ const r = await query_objects({objects:[object]});
163
+ if (r?.objects?.length !== 1 || r?.objects[0]?.type !== type) {
164
+ ERROR(Errors.Fail, `Fetch ${type} object ${object} failed`)
165
+ }
166
+
167
+ this.content = r?.objects[0];
158
168
  }
159
169
 
160
170
  protected async sign_and_commit(txb: TransactionBlock, address?: string) : Promise<CallResponse> {
@@ -162,8 +172,8 @@ export class CallBase {
162
172
  Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
163
173
  this.resouceObject = undefined;
164
174
  }
165
-
166
- const r = await Account.Instance().sign_and_commit(txb, address);
175
+ const addr = address !== undefined ? await LocalMark.Instance().get_address(address) : undefined;
176
+ const r = await Account.Instance().sign_and_commit(txb, addr);
167
177
  if (!r) {
168
178
  ERROR(Errors.Fail, 'sign and commit failed');
169
179
  }
@@ -175,7 +185,7 @@ export class CallBase {
175
185
  const namedNew = this.traceMarkNew.get(v.type);
176
186
  if (namedNew) {
177
187
  LocalMark.Instance().put(namedNew.name,
178
- {object:v.object, tags:namedNew?.tags},
188
+ {object:v.object, tags:namedNew?.tags ? [...namedNew?.tags, v.type] : [v.type]},
179
189
  namedNew?.useAddressIfNameExist);
180
190
  }
181
191
  }
package/src/call/call.ts CHANGED
@@ -18,53 +18,53 @@ import { CallObjectPermission, CallObjectPermission_Data } from "./object_permis
18
18
 
19
19
  export interface CallDemandObject {
20
20
  data: CallDemand_Data;
21
- account?: string;
22
- witness?: GuardInfo_forCall;
21
+ account?: string | null;
22
+ witness?: GuardInfo_forCall | null;
23
23
  }
24
24
 
25
25
  export interface CallServiceObject {
26
26
  data: CallService_Data;
27
- account?: string;
28
- witness?: GuardInfo_forCall;
27
+ account?: string | null;
28
+ witness?: GuardInfo_forCall | null;
29
29
  }
30
30
  export interface CallMachineObject {
31
31
  data: CallMachine_Data;
32
- account?: string;
33
- witness?: GuardInfo_forCall;
32
+ account?: string | null;
33
+ witness?: GuardInfo_forCall | null;
34
34
  }
35
35
  export interface CallTreasuryObject {
36
36
  data: CallTreasury_Data;
37
- account?: string;
38
- witness?: GuardInfo_forCall;
37
+ account?: string | null;
38
+ witness?: GuardInfo_forCall | null;
39
39
  }
40
40
  export interface CallArbitrationObject {
41
41
  data: CallArbitration_Data;
42
- account?: string;
43
- witness?: GuardInfo_forCall;
42
+ account?: string | null;
43
+ witness?: GuardInfo_forCall | null;
44
44
  }
45
45
  export interface CallGuardObject {
46
46
  data: CallGuard_Data;
47
- account?: string;
47
+ account?: string | null;
48
48
  }
49
49
  export interface CallRepositoryObject {
50
50
  data: CallRepository_Data;
51
- account?: string;
52
- witness?: GuardInfo_forCall;
51
+ account?: string | null;
52
+ witness?: GuardInfo_forCall | null;
53
53
  }
54
54
  export interface CallPersonalObject {
55
55
  data: CallPersonal_Data;
56
- account?: string;
56
+ account?: string | null;
57
57
  }
58
58
  export interface CallPermissionObject {
59
59
  data: CallPermission_Data;
60
- account?: string;
61
- witness?: GuardInfo_forCall;
60
+ account?: string | null;
61
+ witness?: GuardInfo_forCall | null;
62
62
  }
63
63
 
64
64
  export interface CallTransferPermissionObject {
65
65
  data: CallObjectPermission_Data;
66
- account?: string;
67
- witness?: GuardInfo_forCall;
66
+ account?: string | null;
67
+ witness?: GuardInfo_forCall | null;
68
68
  }
69
69
 
70
70
  export const call_demand_json = async (json: string) : Promise<string> => {
@@ -101,10 +101,13 @@ export const call_repository_json = async (json: string) : Promise<string> => {
101
101
  }
102
102
  }
103
103
  export const call_permission_json = async (json: string) : Promise<string> => {
104
+ console.log(1)
104
105
  try {
105
106
  const c : CallPermissionObject = JSON.parse(json);
107
+ console.log(c)
106
108
  return JSON.stringify({data:await call_permission(c)});
107
109
  } catch (e) {
110
+ console.log(e)
108
111
  return JSON.stringify({error:e?.toString()})
109
112
  }
110
113
  }
@@ -190,10 +193,10 @@ export const call_arbitration = async (call:CallArbitrationObject) : Promise<Cal
190
193
  return call_object(obj, call.account, call.witness)
191
194
  }
192
195
 
193
- const call_object = async (object: CallBase, account?: string, witness?: GuardInfo_forCall) : Promise<CallResult> => {
196
+ const call_object = async (object: CallBase, account?: string | null, witness?: GuardInfo_forCall | null) : Promise<CallResult> => {
194
197
  if (witness) {
195
- return object.call_with_witness(witness, account);
198
+ return object.call_with_witness(witness, account ?? undefined);
196
199
  } else {
197
- return object.call(account);
200
+ return object.call(account ?? undefined);
198
201
  }
199
202
  }
@@ -4,6 +4,7 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIn
4
4
  import { query_objects, ObjectDemand } from '../query/objects.js';
5
5
  import { CallBase, CallResult, Namedbject } from "./base.js";
6
6
  import { Account } from '../local/account.js';
7
+ import { LocalMark } from '../local/local.js';
7
8
 
8
9
  /// The execution priority is determined by the order in which the object attributes are arranged
9
10
  export interface CallDemand_Data {
@@ -13,27 +14,41 @@ export interface CallDemand_Data {
13
14
  description?: string;
14
15
  time_expire?: {op: 'duration'; minutes:number} | {op:'time'; time:number};
15
16
  bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'reward'; service:string} | {op:'refund'} ;
16
- present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string | 'fetch'}; // guard is the present guard of Demand
17
+ present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string}; // guard is the present guard of Demand
17
18
  guard?: {address:string; service_id_in_guard?:number};
18
19
  }
19
20
 
20
21
  export class CallDemand extends CallBase {
21
- data: CallDemand_Data;
22
+ data: CallDemand_Data;
23
+ content: ObjectDemand | undefined = undefined;
24
+
22
25
  constructor(data: CallDemand_Data) {
23
26
  super();
24
27
  this.data = data;
25
28
  }
26
29
  async call(account?:string) : Promise<CallResult> {
27
- if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
28
- ERROR(Errors.IsValidArgType, 'demand.type_parameter')
29
- }
30
-
31
30
  var checkOwner = false; const guards : string[] = [];
32
31
  const perms : PermissionIndexType[] = [];
33
- const permission_address = (this.data?.permission as any)?.address;
34
- const object_address = (this.data?.object as any)?.address;
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
+ }
35
50
 
36
- if (permission_address && IsValidAddress(permission_address)) {
51
+ if (permission_address) {
37
52
  if (!this.data?.object) {
38
53
  perms.push(PermissionIndex.demand)
39
54
  }
@@ -53,21 +68,21 @@ export class CallDemand extends CallBase {
53
68
  perms.push(PermissionIndex.demand_refund)
54
69
  }
55
70
  if (this.data?.present?.guard !== undefined) {
56
- if (IsValidAddress(this.data.present.guard)) {
57
- guards.push(this.data.present.guard)
71
+ const guard = await LocalMark.Instance().get_address(this.data.present.guard)
72
+ if (guard) {
73
+ guards.push(guard)
58
74
  } else {
59
75
  if (!object_address) { // new
60
- if (this.data?.guard?.address && IsValidAddress(this.data?.guard.address)) {
61
- guards.push(this.data.guard.address)
76
+ const guard = await LocalMark.Instance().get_address(this.data?.guard?.address);
77
+ if (guard) {
78
+ guards.push(guard)
62
79
  }
63
80
  } else {
64
- const r = await query_objects({objects:[object_address]});
65
- if (r?.objects && r?.objects[0]?.type === 'Demand') {
66
- const obj = (r?.objects[0] as ObjectDemand);
67
- if (obj?.guard) {
68
- guards.push(obj?.guard.object);
69
- }
70
- }
81
+ await this.update_content(object_address, 'Demand');
82
+
83
+ if ((this.content as ObjectDemand)?.guard?.object) {
84
+ guards.push((this.content as ObjectDemand).guard?.object!)
85
+ }
71
86
  }
72
87
  }
73
88
  }
@@ -77,11 +92,14 @@ export class CallDemand extends CallBase {
77
92
  }
78
93
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
79
94
  let obj : Demand | undefined ; let permission: any;
80
- const permission_address = (this.data?.permission as any)?.address;
81
- const object_address = (this.data?.object as any)?.address;
95
+ var [permission_address, object_address] = this?.content ?
96
+ [(this.content as ObjectDemand).permission, this.content.object] :
97
+ await LocalMark.Instance().get_many_address(
98
+ [(this.data?.permission as any)?.address,
99
+ (this.data?.object as any)?.address]);
82
100
 
83
101
  if (!object_address) {
84
- if (!permission_address || !IsValidAddress(permission_address)) {
102
+ if (!permission_address) {
85
103
  const d = (this.data?.permission as any)?.description ?? '';
86
104
  permission = Permission.New(txb, d);
87
105
  }
@@ -95,10 +113,10 @@ export class CallDemand extends CallBase {
95
113
  permission ? permission.get_object(): permission_address, this.data?.description??'', permission?undefined:passport)
96
114
  }
97
115
  } else {
98
- if (IsValidAddress(object_address) && this.data.type_parameter && this.data.permission && IsValidAddress(permission_address)) {
116
+ if (this.data.type_parameter && permission_address) {
99
117
  obj = Demand.From(txb, this.data.type_parameter, permission_address, object_address)
100
118
  } else {
101
- ERROR(Errors.InvalidParam, 'object or permission address invalid.')
119
+ ERROR(Errors.InvalidParam, 'CallDemand_Data.data.type_parameter or permission')
102
120
  }
103
121
  }
104
122
 
@@ -113,27 +131,39 @@ export class CallDemand extends CallBase {
113
131
  }
114
132
  if (this.data?.bounty !== undefined) {
115
133
  if (this.data.bounty.op === 'add') {
116
- if (IsValidAddress((this.data.bounty.object as any)?.address)) {
134
+ const bounty = await LocalMark.Instance().get_address((this.data.bounty.object as any)?.address)
135
+ if (bounty) {
117
136
  obj.deposit((this.data.bounty.object as any)?.address)
118
137
  } else if ((this.data.bounty.object as any)?.balance !== undefined){
119
138
  if (!IsValidCoinType(this.data.type_parameter)) {
120
- ERROR(Errors.IsValidCoinType, 'demand bounty')
139
+ ERROR(Errors.IsValidCoinType, 'CallDemand_Data.data.type_parameter')
121
140
  }
122
141
  const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.data.type_parameter);
123
142
  if (r) obj.deposit(r)
124
143
  }
125
144
  } else if (this.data.bounty.op === 'reward') {
126
- obj?.yes(this.data.bounty.service, pst);
145
+ const service = await localStorage.Instance().get_address(this.data.bounty.service);
146
+ if (!service) ERROR(Errors.InvalidParam, 'CallDemand_Data.data.bounty.service');
147
+ obj?.yes(service, pst);
127
148
  } else if (this.data.bounty.op === 'refund') {
128
149
  obj?.refund(pst);
129
150
  }
130
151
  }
131
152
  if (this.data?.present !== undefined) {
132
153
  //@ demand guard and its pst, if set
133
- obj?.present(this.data.present.service, this.data.present.service_pay_type, this.data.present.recommend_words, pst);
154
+ const service = typeof(this.data.present.service) === 'string' ? await LocalMark.Instance().get_account(this.data.present.service) : this.data.present.service;
155
+ if (service === undefined) {
156
+ ERROR(Errors.InvalidParam, 'CallDemand_Data.data.present.service')
157
+ }
158
+ 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);
134
159
  }
160
+
135
161
  if (this.data?.guard !== undefined) {
136
- obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined, pst)
162
+ const guard = await LocalMark.Instance().get_address(this.data?.guard.address);
163
+ if (!guard) {
164
+ ERROR(Errors.InvalidParam, 'CallDemand_Data.data.guard.address')
165
+ }
166
+ obj?.set_guard(guard, this.data.guard?.service_id_in_guard ?? undefined, pst);
137
167
  }
138
168
  if (permission) {
139
169
  await this.new_with_mark('Permission', txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
package/src/call/guard.ts CHANGED
@@ -5,9 +5,10 @@
5
5
 
6
6
  import { Bcs, ContextType, ERROR, Errors, IsValidU8, OperatorType, ValueType, GUARD_QUERIES, IsValidAddress,
7
7
  concatenate, TransactionBlock, Protocol, FnCallType, hasDuplicates, insertAtHead,
8
- IsValidDesription, PassportObject, IsValidGuardIdentifier, GuardQuery
8
+ IsValidDesription, PassportObject, IsValidGuardIdentifier, GuardQuery,
9
9
  } from "wowok";
10
10
  import { CallBase, CallResult, Namedbject } from "./base.js";
11
+ import { LocalMark } from "../local/local.js";
11
12
 
12
13
  export interface GuardConst {
13
14
  identifier: number; // 1-255, the same identifier to represent the same data in different nodes
@@ -71,22 +72,30 @@ export class CallGuard extends CallBase {
71
72
  target: Protocol.Instance().guardFn('new') as FnCallType,
72
73
  arguments: [txb.pure.string(this.data.description ?? ''), txb.pure.vector('u8', [].slice.call(bytes.reverse()))],
73
74
  });
74
- this.data?.table?.forEach((v) => {
75
- if (v.bWitness) {
76
- const n = new Uint8Array(1); n.set([v.value_type], 0);
77
- txb.moveCall({
78
- target:Protocol.Instance().guardFn("constant_add") as FnCallType,
79
- arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(true), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
80
- })
81
- } else {
82
- const tmp = Uint8Array.from(Bcs.getInstance().ser(v.value_type, v.value));
83
- const n = insertAtHead(tmp, v.value_type);
84
- txb.moveCall({
85
- target:Protocol.Instance().guardFn("constant_add") as FnCallType,
86
- arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(false), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
87
- })
75
+ if (this.data.table) {
76
+ for (let i = 0; i < this.data?.table?.length; ++ i) {
77
+ const v = this.data.table[i];
78
+ if (v.bWitness) {
79
+ const n = new Uint8Array(1); n.set([v.value_type], 0);
80
+ txb.moveCall({
81
+ target:Protocol.Instance().guardFn("constant_add") as FnCallType,
82
+ arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(true), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
83
+ })
84
+ } else {
85
+ if (v.value_type === ValueType.TYPE_ADDRESS) {
86
+ v.value = await LocalMark.Instance().get_address(v.value);
87
+ if (!v.value) { ERROR(Errors.InvalidParam, `CallGuard_Data.data.table address`)}
88
+ };
89
+ const tmp = Uint8Array.from(Bcs.getInstance().ser(v.value_type, v.value));
90
+ const n = insertAtHead(tmp, v.value_type);
91
+ txb.moveCall({
92
+ target:Protocol.Instance().guardFn("constant_add") as FnCallType,
93
+ arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(false), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
94
+ })
95
+ }
88
96
  }
89
- })
97
+ }
98
+
90
99
  const addr = txb.moveCall({
91
100
  target:Protocol.Instance().guardFn("create") as FnCallType,
92
101
  arguments:[txb.object(obj)]