wowok_agent 1.2.38 → 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 (87) hide show
  1. package/dist/call/arbitration.d.ts +1 -1
  2. package/dist/call/arbitration.d.ts.map +1 -1
  3. package/dist/call/arbitration.js +74 -50
  4. package/dist/call/arbitration.js.map +1 -1
  5. package/dist/call/base.d.ts +2 -0
  6. package/dist/call/base.d.ts.map +1 -1
  7. package/dist/call/base.js +19 -10
  8. package/dist/call/base.js.map +1 -1
  9. package/dist/call/call.d.ts +18 -18
  10. package/dist/call/call.d.ts.map +1 -1
  11. package/dist/call/call.js +5 -2
  12. package/dist/call/call.js.map +1 -1
  13. package/dist/call/demand.d.ts +3 -1
  14. package/dist/call/demand.d.ts.map +1 -1
  15. package/dist/call/demand.js +53 -28
  16. package/dist/call/demand.js.map +1 -1
  17. package/dist/call/guard.d.ts.map +1 -1
  18. package/dist/call/guard.js +29 -18
  19. package/dist/call/guard.js.map +1 -1
  20. package/dist/call/machine.d.ts +1 -1
  21. package/dist/call/machine.d.ts.map +1 -1
  22. package/dist/call/machine.js +73 -36
  23. package/dist/call/machine.js.map +1 -1
  24. package/dist/call/object_permission.d.ts +1 -0
  25. package/dist/call/object_permission.d.ts.map +1 -1
  26. package/dist/call/object_permission.js +12 -9
  27. package/dist/call/object_permission.js.map +1 -1
  28. package/dist/call/permission.d.ts +1 -0
  29. package/dist/call/permission.d.ts.map +1 -1
  30. package/dist/call/permission.js +47 -18
  31. package/dist/call/permission.js.map +1 -1
  32. package/dist/call/personal.d.ts +1 -1
  33. package/dist/call/personal.d.ts.map +1 -1
  34. package/dist/call/personal.js +40 -13
  35. package/dist/call/personal.js.map +1 -1
  36. package/dist/call/repository.d.ts.map +1 -1
  37. package/dist/call/repository.js +24 -14
  38. package/dist/call/repository.js.map +1 -1
  39. package/dist/call/service.d.ts +1 -1
  40. package/dist/call/service.d.ts.map +1 -1
  41. package/dist/call/service.js +147 -71
  42. package/dist/call/service.js.map +1 -1
  43. package/dist/call/treasury.d.ts +1 -1
  44. package/dist/call/treasury.d.ts.map +1 -1
  45. package/dist/call/treasury.js +63 -49
  46. package/dist/call/treasury.js.map +1 -1
  47. package/dist/common.d.ts +1 -0
  48. package/dist/common.d.ts.map +1 -1
  49. package/dist/common.js +9 -0
  50. package/dist/common.js.map +1 -1
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/local/account.d.ts.map +1 -1
  56. package/dist/local/account.js.map +1 -1
  57. package/dist/local/index.d.ts +31 -17
  58. package/dist/local/index.d.ts.map +1 -1
  59. package/dist/local/index.js +41 -37
  60. package/dist/local/index.js.map +1 -1
  61. package/dist/local/local.d.ts +4 -1
  62. package/dist/local/local.d.ts.map +1 -1
  63. package/dist/local/local.js +41 -7
  64. package/dist/local/local.js.map +1 -1
  65. package/dist/query/objects.d.ts.map +1 -1
  66. package/dist/query/objects.js +15 -7
  67. package/dist/query/objects.js.map +1 -1
  68. package/package.json +2 -2
  69. package/src/call/arbitration.ts +85 -54
  70. package/src/call/base.ts +22 -12
  71. package/src/call/call.ts +24 -21
  72. package/src/call/demand.ts +60 -30
  73. package/src/call/guard.ts +25 -16
  74. package/src/call/machine.ts +79 -40
  75. package/src/call/object_permission.ts +12 -8
  76. package/src/call/permission.ts +44 -18
  77. package/src/call/personal.ts +39 -13
  78. package/src/call/repository.ts +27 -13
  79. package/src/call/service.ts +150 -73
  80. package/src/call/treasury.ts +68 -50
  81. package/src/common.ts +9 -0
  82. package/src/index.ts +1 -0
  83. package/src/local/account.ts +3 -3
  84. package/src/local/index.ts +54 -50
  85. package/src/local/local.ts +48 -8
  86. package/src/query/objects.ts +14 -6
  87. package/tsconfig.tsbuildinfo +1 -1
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)]
@@ -4,6 +4,8 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIn
4
4
  } from 'wowok';
5
5
  import { CallBase, CallResult, Namedbject } from "./base.js";
6
6
  import { Account } from '../local/account.js';
7
+ import { ObjectMachine } from '../query/objects.js';
8
+ import { LocalMark } from '../local/local.js';
7
9
 
8
10
  /// The execution priority is determined by the order in which the object attributes are arranged
9
11
  export interface CallMachine_Data {
@@ -24,7 +26,7 @@ export interface CallMachine_Data {
24
26
  progress_parent?: {progress?:string, parent?:ParentProgress};
25
27
  progress_task?: {progress?:string; task:string};
26
28
  progress_hold?: {progress?:string; operation:ProgressNext; bHold:boolean; adminUnhold?:boolean};
27
- progress_next?: {progress:string; operation:ProgressNext; deliverable:Deliverable; guard?:string | 'fetch'};
29
+ progress_next?: {progress:string; operation:ProgressNext; deliverable:Deliverable; guard?:string};
28
30
  bPaused?: boolean;
29
31
  clone_new?: {namedNew?: Namedbject/*, description?:string*/};
30
32
  }
@@ -37,10 +39,21 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
37
39
  async call(account?:string) : Promise<CallResult> {
38
40
  var checkOwner = false; const guards : string[] = [];
39
41
  const perms : PermissionIndexType[] = [];
40
- const permission_address = (this.data?.permission as any)?.address;
41
- const object_address = (this.data?.object as any)?.address;
42
+ var [permission_address, object_address] =
43
+ await LocalMark.Instance().get_many_address(
44
+ [(this.data?.permission as any)?.address,
45
+ (this.data?.object as any)?.address]);
42
46
 
43
- if (permission_address && IsValidAddress(permission_address)) {
47
+ if (object_address) {
48
+ if (!permission_address) {
49
+ await this.update_content(object_address, 'Machine');
50
+ if (this.content) {
51
+ permission_address = (this.content as ObjectMachine).permission;
52
+ }
53
+ }
54
+ }
55
+
56
+ if (permission_address) {
44
57
  if (!this.data?.object) {
45
58
  perms.push(PermissionIndex.machine)
46
59
  }
@@ -82,15 +95,19 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
82
95
  if (this.data?.bPaused !== undefined) {
83
96
  perms.push(PermissionIndex.machine_pause)
84
97
  }
85
- if (this.data?.progress_next?.guard !== undefined) {
86
- if (IsValidAddress(this.data?.progress_next?.guard)) {
87
- guards.push(this.data?.progress_next?.guard)
88
- } else if (this.data?.object && IsValidAddress(object_address)) { // fetch guard
89
- const guard = await Progress.QueryForwardGuard(this.data?.progress_next.progress, object_address,
90
- await Account.Instance().default() ?? '0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f',
91
- this.data.progress_next.operation.next_node_name, this.data.progress_next.operation.forward);
92
- if (guard) {
93
- guards.push(guard)
98
+ if (this.data?.progress_next !== undefined) {
99
+ const guard = await LocalMark.Instance().get_address(this.data?.progress_next?.guard);
100
+ if (guard) {
101
+ guards.push(guard)
102
+ } else if (object_address) { // fetch guard
103
+ const p = await LocalMark.Instance().get_address(this.data?.progress_next.progress);
104
+ if (p) {
105
+ const guard = await Progress.QueryForwardGuard(this.data?.progress_next.progress, object_address,
106
+ await Account.Instance().default() ?? '0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f',
107
+ this.data.progress_next.operation.next_node_name, this.data.progress_next.operation.forward);
108
+ if (guard) {
109
+ guards.push(guard)
110
+ }
94
111
  }
95
112
  }
96
113
  }
@@ -102,20 +119,23 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
102
119
 
103
120
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
104
121
  let obj : Machine | undefined ; let permission: any;
105
- const permission_address = (this.data?.permission as any)?.address;
106
- const object_address = (this.data?.object as any)?.address;
122
+ var [permission_address, object_address] = this?.content ?
123
+ [(this.content as ObjectMachine).permission, this.content.object] :
124
+ await LocalMark.Instance().get_many_address(
125
+ [(this.data?.permission as any)?.address,
126
+ (this.data?.object as any)?.address]);
107
127
 
108
128
  if (!object_address) {
109
- if (!permission_address || !IsValidAddress(permission_address)) {
129
+ if (!permission_address) {
110
130
  const d = (this.data?.permission as any)?.description ?? '';
111
131
  permission = Permission.New(txb, d);
112
132
  }
113
133
  obj = Machine.New(txb, permission ? permission.get_object() : permission_address, this.data?.description??'', this.data?.endpoint ?? '', permission?undefined:passport);
114
134
  } else {
115
- if (IsValidAddress(object_address) &&permission_address && IsValidAddress(permission_address)) {
135
+ if (permission_address) {
116
136
  obj = Machine.From(txb, permission_address, object_address)
117
137
  } else {
118
- ERROR(Errors.InvalidParam, 'object or permission address invalid.')
138
+ ERROR(Errors.InvalidParam, 'CallMachine_Data.data.permission')
119
139
  }
120
140
  }
121
141
 
@@ -133,18 +153,22 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
133
153
  if (this.data?.consensus_repository !== undefined) {
134
154
  switch (this.data.consensus_repository.op) {
135
155
  case 'add':
136
- this.data.consensus_repository.repositories.forEach(v=>obj?.add_repository(v, pst)) ;
156
+ case 'set':
157
+ if (this.data.consensus_repository.op === 'set') {
158
+ obj?.remove_repository([], true, pst);
159
+ }
160
+ var reps = await LocalMark.Instance().get_many_address2(this.data.consensus_repository.repositories);
161
+ reps.forEach(v=>obj?.add_repository(v, pst)) ;
137
162
  break;
138
163
  case 'remove':
139
- obj?.remove_repository(this.data.consensus_repository.repositories, false, pst);
164
+ var reps = await LocalMark.Instance().get_many_address2(this.data.consensus_repository.repositories);
165
+ if (reps.length > 0) {
166
+ obj?.remove_repository(reps, false, pst);
167
+ }
140
168
  break;
141
169
  case 'removeall':
142
170
  obj?.remove_repository([], true, pst);
143
171
  break;
144
- case 'set':
145
- obj?.remove_repository([], true, pst);
146
- this.data.consensus_repository.repositories.forEach(v=>obj?.add_repository(v, pst)) ;
147
- break;
148
172
  }
149
173
  }
150
174
  if (this.data?.nodes !== undefined) {
@@ -177,40 +201,55 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
177
201
  }
178
202
  var new_progress : Progress | undefined;
179
203
  if (this.data?.progress_new !== undefined) {
180
- new_progress = Progress?.New(txb, obj?.get_object(), perm, this.data?.progress_new.task_address, pst);
204
+ const task = await LocalMark.Instance().get_address(this.data?.progress_new.task_address);
205
+ new_progress = Progress?.New(txb, obj?.get_object(), perm, task, pst);
181
206
  }
182
207
  if (this.data?.progress_context_repository !== undefined) {
183
- const p = this.data?.progress_context_repository.progress ?? new_progress?.get_object();
184
- if (!p) ERROR(Errors.Fail, 'progress invalid: progress_context_repository');
185
-
186
- Progress.From(txb, obj?.get_object(), perm, p!).set_context_repository(this.data?.progress_context_repository.repository, pst)
208
+ const p = this.data?.progress_context_repository.progress
209
+ ? await LocalMark.Instance().get_address(this.data?.progress_context_repository.progress)
210
+ : new_progress?.get_object();
211
+ if (!p) ERROR(Errors.InvalidParam, 'CallMachine_Data.data.progress_context_repository.progress');
212
+ const rep = await LocalMark.Instance().get_address(this.data?.progress_context_repository.repository);
213
+ Progress.From(txb, obj?.get_object(), perm, p!).set_context_repository(rep, pst)
187
214
  }
188
215
  if (this.data?.progress_namedOperator !== undefined) {
189
- const p = this.data?.progress_namedOperator.progress ?? new_progress?.get_object();
190
- if (!p) ERROR(Errors.Fail, 'progress invalid: progress_namedOperator');
216
+ const p = this.data?.progress_namedOperator.progress
217
+ ? await LocalMark.Instance().get_address(this.data?.progress_namedOperator.progress)
218
+ : new_progress?.get_object();
219
+ if (!p) ERROR(Errors.InvalidParam, 'CallMachine_Data.data.progress_namedOperator.progress');
191
220
 
192
221
  let pp = Progress.From(txb, obj?.get_object(), perm, p!);
193
222
  this.data.progress_namedOperator.data.forEach(v => pp.set_namedOperator(v.name, v.operators, pst));
194
223
  }
195
224
  if (this.data?.progress_parent !== undefined) {
196
- const p = this.data?.progress_parent.progress ?? new_progress?.get_object();
197
- if (!p) ERROR(Errors.Fail, 'progress invalid: progress_parent');
225
+ const p = this.data?.progress_parent.progress
226
+ ? await LocalMark.Instance().get_address(this.data?.progress_parent.progress)
227
+ : new_progress?.get_object();
228
+ if (!p) ERROR(Errors.InvalidParam, 'CallMachine_Data.data.progress_parent.progress');
198
229
 
199
230
  if (this.data.progress_parent.parent) {
200
- Progress.From(txb, obj?.get_object(), perm, p!).parent(this.data.progress_parent.parent);
231
+ const parent = await LocalMark.Instance().get_address(this.data.progress_parent.parent.parent_id);
232
+ if (parent) {
233
+ this.data.progress_parent.parent.parent_id = parent;
234
+ Progress.From(txb, obj?.get_object(), perm, p!).parent(this.data.progress_parent.parent);
235
+ }
201
236
  } else {
202
237
  Progress.From(txb, obj?.get_object(), perm, p!).parent_none();
203
238
  }
204
239
  }
205
240
  if (this.data?.progress_task !== undefined) {
206
- const p = this.data?.progress_task.progress ?? new_progress?.get_object();
207
- if (!p) ERROR(Errors.Fail, 'progress invalid: progress_task');
208
-
209
- Progress.From(txb, obj?.get_object(), perm, p!).bind_task(this.data.progress_task.task, pst)
241
+ const p = this.data?.progress_task.progress
242
+ ? await LocalMark.Instance().get_address(this.data?.progress_task.progress)
243
+ : new_progress?.get_object();
244
+ if (!p) ERROR(Errors.InvalidParam, 'CallMachine_Data.data.progress_task.progress');
245
+ const task = await LocalMark.Instance().get_address(this.data.progress_task.task);
246
+ if (task) Progress.From(txb, obj?.get_object(), perm, p!).bind_task(task, pst);
210
247
  }
211
248
  if (this.data?.progress_hold !== undefined) {
212
- const p = this.data?.progress_hold.progress ?? new_progress?.get_object();
213
- if (!p) ERROR(Errors.Fail, 'progress invalid: progress_hold');
249
+ const p = this.data?.progress_hold.progress
250
+ ? await LocalMark.Instance().get_address(this.data?.progress_hold.progress)
251
+ : new_progress?.get_object();
252
+ if (!p) ERROR(Errors.InvalidParam, 'CallMachine_Data.data.progress_hold.progress');
214
253
 
215
254
  if (this.data?.progress_hold.adminUnhold) {
216
255
  Progress.From(txb, obj?.get_object(), perm, p!).unhold(this.data.progress_hold.operation, pst)