wowok 1.2.11 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/machine.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
2
- import { BCS } from '@mysten/bcs';
1
+ import { Transaction as TransactionBlock, TransactionObjectArgument, type TransactionResult } from '@mysten/sui/transactions';
3
2
  import { Protocol, FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject, MachineAddress, GuardObject, TxbObject} from './protocol';
4
3
  import { IsValidInt, Bcs, array_unique, IsValidArray, IsValidAddress, IsValidName, IsValidName_AllowEmpty,
5
- IsValidEndpoint, OptionNone, IsValidDesription,
6
- IsValidUintLarge} from './utils'
4
+ IsValidEndpoint, IsValidDesription,
5
+ IsValidUintLarge,
6
+ IsValidU64} from './utils'
7
7
  import { Permission, PermissionIndexType } from './permission';
8
8
  import { Errors, ERROR} from './exception'
9
9
  import { ValueType } from './protocol';
@@ -26,25 +26,33 @@ export interface Machine_Node {
26
26
  pairs: Machine_Node_Pair[];
27
27
  }
28
28
 
29
+ export interface QueryGuardParam {
30
+ node: string;
31
+ prior_node: string;
32
+ forward: string;
33
+ txb: TransactionBlock;
34
+ guard: string | null;
35
+ }
36
+ export type OnQueryGuard = (param: QueryGuardParam) => void;
29
37
  export class Machine {
30
- protected protocol;
38
+ protected txb;
31
39
  protected object : TxbObject;
32
- protected permission;
40
+ protected permission: TxbObject;
33
41
 
34
42
  get_object() { return this.object }
35
43
 
36
- static From(protocol:Protocol, permission:PermissionObject, object:TxbObject) : Machine {
37
- let d = new Machine(protocol, permission)
38
- d.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object)
44
+ static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Machine {
45
+ let d = new Machine(txb, permission)
46
+ d.object = Protocol.TXB_OBJECT(txb, object)
39
47
  return d
40
48
  }
41
49
 
42
- private constructor(protocol:Protocol, permission:PermissionObject) {
43
- this.protocol = protocol;
50
+ private constructor(txb:TransactionBlock, permission:PermissionObject) {
51
+ this.txb = txb;
44
52
  this.permission = permission;
45
53
  this.object = '';
46
54
  }
47
- static New(protocol:Protocol, permission:PermissionObject, description:string, endpoint?:string|null, passport?:PassportObject) : Machine {
55
+ static New(txb:TransactionBlock, permission:PermissionObject, description:string, endpoint?:string|null|undefined, passport?:PassportObject) : Machine {
48
56
  if (!Protocol.IsValidObjects([permission])) {
49
57
  ERROR(Errors.IsValidObjects, 'permission')
50
58
  }
@@ -55,19 +63,18 @@ export class Machine {
55
63
  ERROR(Errors.IsValidEndpoint)
56
64
  }
57
65
 
58
- let m = new Machine(protocol, permission);
59
- let txb = protocol.CurrentSession();
60
- let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
66
+ let m = new Machine(txb, permission);
67
+ let ep = txb.pure.option('string', endpoint ? endpoint : undefined);
61
68
 
62
69
  if (passport) {
63
70
  m.object = txb.moveCall({
64
- target:protocol.MachineFn('new_with_passport') as FnCallType,
65
- arguments:[passport, txb.pure(description), ep, Protocol.TXB_OBJECT(txb, permission)],
71
+ target:Protocol.Instance().MachineFn('new_with_passport') as FnCallType,
72
+ arguments:[passport, txb.pure.string(description), ep, Protocol.TXB_OBJECT(txb, permission)],
66
73
  })
67
74
  } else {
68
75
  m.object = txb.moveCall({
69
- target:protocol.MachineFn('new') as FnCallType,
70
- arguments:[txb.pure(description), ep, Protocol.TXB_OBJECT(txb, permission)],
76
+ target:Protocol.Instance().MachineFn('new') as FnCallType,
77
+ arguments:[txb.pure.string(description), ep, Protocol.TXB_OBJECT(txb, permission)],
71
78
  })
72
79
  }
73
80
  return m
@@ -84,7 +91,7 @@ export class Machine {
84
91
  if (!IsValidName_AllowEmpty(p.prior_node)) { bValid = false; }
85
92
  if (p?.threshold && !IsValidInt(p.threshold)) { bValid = false; }
86
93
  p.forwards.forEach((f) => {
87
- if (!Machine.isValidForward(f)) bValid = false;
94
+ if (Machine.checkValidForward(f) !== '') bValid = false;
88
95
  })
89
96
  })
90
97
  })
@@ -93,25 +100,24 @@ export class Machine {
93
100
  }
94
101
 
95
102
  let new_nodes: TxbObject[] = [];
96
- let txb = this.protocol.CurrentSession();
97
103
  nodes.forEach((node) => {
98
- let n = txb.moveCall({
99
- target:this.protocol.MachineFn('node_new') as FnCallType,
100
- arguments:[txb.pure(node.name)]
104
+ let n = this.txb.moveCall({
105
+ target:Protocol.Instance().MachineFn('node_new') as FnCallType,
106
+ arguments:[this.txb.pure.string(node.name)]
101
107
  });
102
108
  node.pairs.forEach((pair) => {
103
- let threshold = pair?.threshold ? txb.pure(Bcs.getInstance().ser_option_u32(pair.threshold)) : OptionNone(txb);
109
+ let threshold = this.txb.pure.option('u32', pair?.threshold);
104
110
 
105
111
  pair.forwards.forEach((forward) => {
106
- txb.moveCall({ // add forward
107
- target:this.protocol.MachineFn('forward_add') as FnCallType,
108
- arguments:[n, txb.pure(pair.prior_node), txb.pure(forward.name), threshold, this.forward(forward)]
112
+ this.txb.moveCall({ // add forward
113
+ target:Protocol.Instance().MachineFn('forward_add') as FnCallType,
114
+ arguments:[n, this.txb.pure.string(pair.prior_node), this.txb.pure.string(forward.name), threshold, this.forward(forward)]
109
115
  });
110
116
  });
111
117
  if (pair.forwards.length === 0) {
112
- txb.moveCall({ // add forward
113
- target:this.protocol.MachineFn('forward_add_none') as FnCallType,
114
- arguments:[n, txb.pure(pair.prior_node), threshold]
118
+ this.txb.moveCall({ // add forward
119
+ target:Protocol.Instance().MachineFn('forward_add_none') as FnCallType,
120
+ arguments:[n, this.txb.pure.string(pair.prior_node), threshold]
115
121
  });
116
122
  }
117
123
  });
@@ -121,45 +127,47 @@ export class Machine {
121
127
  }
122
128
 
123
129
  forward(forward:Machine_Forward) : TransactionResult {
124
- const txb = this.protocol.CurrentSession();
125
-
126
130
  let weight = forward?.weight ? forward.weight : 1;
127
- let perm = forward?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, forward.permission)) : OptionNone(txb);
128
- let namedOperator = forward?.namedOperator ? txb.pure(forward.namedOperator) : txb.pure('');
129
131
  let f:any;
130
132
 
131
- if (forward?.guard) {
132
- f = txb.moveCall({
133
- target:this.protocol.MachineFn('forward') as FnCallType,
134
- arguments:[namedOperator, txb.pure(weight), txb.object(Protocol.TXB_OBJECT(txb, forward.guard)), perm]
135
- });
133
+ // namedOperator first.
134
+ if (forward?.namedOperator && IsValidName(forward.namedOperator)) {
135
+ if (forward?.guard) {
136
+ f = this.txb.moveCall({
137
+ target:Protocol.Instance().MachineFn('forward') as FnCallType,
138
+ arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight), this.txb.object(Protocol.TXB_OBJECT(this.txb, forward.guard))]
139
+ });
140
+ } else {
141
+ f = this.txb.moveCall({
142
+ target:Protocol.Instance().MachineFn('forward2') as FnCallType,
143
+ arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight)]
144
+ });
145
+ }
146
+ } else if (forward?.permission !== undefined && IsValidU64(forward.permission)) {
147
+ f = this.txb.moveCall({
148
+ target:Protocol.Instance().MachineFn('forward3') as FnCallType,
149
+ arguments:[this.txb.pure.u64(forward.permission), this.txb.pure.u16(weight)]
150
+ });
136
151
  } else {
137
- f = txb.moveCall({
138
- target:this.protocol.MachineFn('forward2') as FnCallType,
139
- arguments:[namedOperator, txb.pure(weight), perm]
140
- });
152
+ ERROR(Errors.InvalidParam, 'forward')
141
153
  }
154
+
142
155
  return f
143
156
  }
144
157
 
145
158
  // move MachineNodeObject to the machine from signer-owned MachineNode object
146
159
  add_node2(nodes:TxbObject[], passport?:PassportObject) {
147
- if (nodes.length === 0) {
148
- ERROR(Errors.InvalidParam, 'add_node2');
149
- }
150
-
151
- let txb = this.protocol.CurrentSession();
152
- let n: TransactionResult[] = nodes.map((v)=>Protocol.TXB_OBJECT(txb, v));
153
-
160
+ if (nodes.length === 0) return;
161
+ let n: TransactionObjectArgument[] = nodes.map((v)=>Protocol.TXB_OBJECT(this.txb, v));
154
162
  if (passport) {
155
- txb.moveCall({ // add node
156
- target:this.protocol.MachineFn('node_add_with_passport') as FnCallType,
157
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.makeMoveVec({objects:n}), Protocol.TXB_OBJECT(txb, this.permission)]
163
+ this.txb.moveCall({ // add node
164
+ target:Protocol.Instance().MachineFn('node_add_with_passport') as FnCallType,
165
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:n}), Protocol.TXB_OBJECT(this.txb, this.permission)]
158
166
  });
159
167
  } else {
160
- txb.moveCall({ // add node
161
- target:this.protocol.MachineFn('node_add') as FnCallType,
162
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.makeMoveVec({objects:n}), Protocol.TXB_OBJECT(txb, this.permission)]
168
+ this.txb.moveCall({ // add node
169
+ target:Protocol.Instance().MachineFn('node_add') as FnCallType,
170
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:n}), Protocol.TXB_OBJECT(this.txb, this.permission)]
163
171
  });
164
172
  }
165
173
  }
@@ -168,17 +176,17 @@ export class Machine {
168
176
  if (!IsValidName(node_name)) {
169
177
  ERROR(Errors.IsValidName, 'fetch_node');
170
178
  }
171
- let txb = this.protocol.CurrentSession();
179
+
172
180
  if (passport) {
173
- return txb.moveCall({
174
- target:this.protocol.MachineFn('node_fetch_with_passport') as FnCallType,
175
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name),
176
- Protocol.TXB_OBJECT(txb, this.permission)],
181
+ return this.txb.moveCall({
182
+ target:Protocol.Instance().MachineFn('node_fetch_with_passport') as FnCallType,
183
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name),
184
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
177
185
  });
178
186
  } else {
179
- return txb.moveCall({
180
- target:this.protocol.MachineFn('node_fetch') as FnCallType,
181
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name), Protocol.TXB_OBJECT(txb, this.permission)],
187
+ return this.txb.moveCall({
188
+ target:Protocol.Instance().MachineFn('node_fetch') as FnCallType,
189
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
182
190
  });
183
191
  }
184
192
  }
@@ -187,21 +195,19 @@ export class Machine {
187
195
  if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'rename_node');
188
196
  if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'rename_node');
189
197
 
190
- let txb = this.protocol.CurrentSession();
191
-
192
198
  if (passport) {
193
- txb.moveCall({
194
- target:this.protocol.MachineFn('node_rename_with_passport') as FnCallType,
195
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
196
- txb.pure(node_name), txb.pure(new_name),
197
- Protocol.TXB_OBJECT(txb, this.permission)],
199
+ this.txb.moveCall({
200
+ target:Protocol.Instance().MachineFn('node_rename_with_passport') as FnCallType,
201
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
202
+ this.txb.pure.string(node_name), this.txb.pure.string(new_name),
203
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
198
204
  });
199
205
  } else {
200
- txb.moveCall({
201
- target:this.protocol.MachineFn('node_rename') as FnCallType,
202
- arguments:[Protocol.TXB_OBJECT(txb, this.object),
203
- txb.pure(node_name), txb.pure(new_name),
204
- Protocol.TXB_OBJECT(txb, this.permission)],
206
+ this.txb.moveCall({
207
+ target:Protocol.Instance().MachineFn('node_rename') as FnCallType,
208
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
209
+ this.txb.pure.string(node_name), this.txb.pure.string(new_name),
210
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
205
211
  });
206
212
  }
207
213
  }
@@ -213,35 +219,33 @@ export class Machine {
213
219
  if (!IsValidArray(nodes_name, IsValidName)) {
214
220
  ERROR(Errors.IsValidArray, 'nodes_name')
215
221
  }
216
-
217
- let txb = this.protocol.CurrentSession();
222
+
218
223
  if (passport) {
219
- txb.moveCall({
220
- target:this.protocol.MachineFn('node_remove_with_passport') as FnCallType,
221
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
222
- txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
224
+ this.txb.moveCall({
225
+ target:Protocol.Instance().MachineFn('node_remove_with_passport') as FnCallType,
226
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
227
+ this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
223
228
  });
224
229
  } else {
225
- txb.moveCall({
226
- target:this.protocol.MachineFn('node_remove') as FnCallType,
227
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)), txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
230
+ this.txb.moveCall({
231
+ target:Protocol.Instance().MachineFn('node_remove') as FnCallType,
232
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
233
+ this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
228
234
  });
229
235
  }
230
236
  }
231
237
 
232
238
  destroy() {
233
- let txb = this.protocol.CurrentSession();
234
- txb.moveCall({
235
- target:this.protocol.MachineFn('destroy') as FnCallType,
236
- arguments: [Protocol.TXB_OBJECT(txb, this.object)],
239
+ this.txb.moveCall({
240
+ target:Protocol.Instance().MachineFn('destroy') as FnCallType,
241
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
237
242
  })
238
243
  }
239
244
 
240
245
  launch() : MachineAddress {
241
- let txb = this.protocol.CurrentSession();
242
- return txb.moveCall({
243
- target:this.protocol.MachineFn('create') as FnCallType,
244
- arguments:[Protocol.TXB_OBJECT(txb, this.object)],
246
+ return this.txb.moveCall({
247
+ target:Protocol.Instance().MachineFn('create') as FnCallType,
248
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
245
249
  })
246
250
  }
247
251
 
@@ -250,30 +254,28 @@ export class Machine {
250
254
  ERROR(Errors.IsValidDesription)
251
255
  }
252
256
 
253
- let txb = this.protocol.CurrentSession();
254
257
  if (passport) {
255
- txb.moveCall({
256
- target:this.protocol.MachineFn('description_set_with_passport') as FnCallType,
257
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)],
258
+ this.txb.moveCall({
259
+ target:Protocol.Instance().MachineFn('description_set_with_passport') as FnCallType,
260
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
258
261
  })
259
262
  } else {
260
- txb.moveCall({
261
- target:this.protocol.MachineFn('description_set') as FnCallType,
262
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)],
263
+ this.txb.moveCall({
264
+ target:Protocol.Instance().MachineFn('description_set') as FnCallType,
265
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
263
266
  })
264
267
  }
265
268
  }
266
269
  add_repository(repository:RepositoryObject, passport?:PassportObject) {
267
- let txb = this.protocol.CurrentSession();
268
270
  if (passport) {
269
- txb.moveCall({
270
- target:this.protocol.MachineFn('repository_add_with_passport') as FnCallType,
271
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, repository), Protocol.TXB_OBJECT(txb, this.permission)],
271
+ this.txb.moveCall({
272
+ target:Protocol.Instance().MachineFn('repository_add_with_passport') as FnCallType,
273
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository), Protocol.TXB_OBJECT(this.txb, this.permission)],
272
274
  })
273
275
  } else {
274
- txb.moveCall({
275
- target:this.protocol.MachineFn('repository_add') as FnCallType,
276
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, repository), Protocol.TXB_OBJECT(txb, this.permission)],
276
+ this.txb.moveCall({
277
+ target:Protocol.Instance().MachineFn('repository_add') as FnCallType,
278
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository), Protocol.TXB_OBJECT(this.txb, this.permission)],
277
279
  })
278
280
  }
279
281
  }
@@ -286,97 +288,91 @@ export class Machine {
286
288
  if (!IsValidArray(repositories, IsValidAddress)){
287
289
  ERROR(Errors.IsValidArray, 'remove_repository')
288
290
  }
289
-
290
- let txb = this.protocol.CurrentSession();
291
+
291
292
  if (passport) {
292
293
  if (removeall) {
293
- txb.moveCall({
294
- target:this.protocol.MachineFn('repository_remove_all_with_passport') as FnCallType,
295
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.object)],
294
+ this.txb.moveCall({
295
+ target:Protocol.Instance().MachineFn('repository_remove_all_with_passport') as FnCallType,
296
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.object)],
296
297
  })
297
298
  } else {
298
- txb.moveCall({
299
- target:this.protocol.MachineFn('repository_remove_with_passport') as FnCallType,
300
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
301
- Protocol.TXB_OBJECT(txb, this.permission)],
299
+ this.txb.moveCall({
300
+ target:Protocol.Instance().MachineFn('repository_remove_with_passport') as FnCallType,
301
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(repositories)),
302
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
302
303
  })
303
304
  }
304
305
  } else {
305
306
  if (removeall) {
306
- txb.moveCall({
307
- target:this.protocol.MachineFn('repository_remove_all') as FnCallType,
308
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
307
+ this.txb.moveCall({
308
+ target:Protocol.Instance().MachineFn('repository_remove_all') as FnCallType,
309
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
309
310
  })
310
311
  } else {
311
- txb.moveCall({
312
- target:this.protocol.MachineFn('repository_remove') as FnCallType,
313
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
314
- Protocol.TXB_OBJECT(txb, this.permission)],
312
+ this.txb.moveCall({
313
+ target:Protocol.Instance().MachineFn('repository_remove') as FnCallType,
314
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(repositories)),
315
+ Protocol.TXB_OBJECT(this.txb, this.permission)],
315
316
  })
316
317
  }
317
318
  }
318
319
  }
319
320
 
320
321
  clone(passport?:PassportObject) : MachineObject {
321
- let txb = this.protocol.CurrentSession();
322
322
  if (passport) {
323
- return txb.moveCall({
324
- target:this.protocol.MachineFn('clone_with_passport') as FnCallType,
325
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
323
+ return this.txb.moveCall({
324
+ target:Protocol.Instance().MachineFn('clone_with_passport') as FnCallType,
325
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
326
326
  })
327
327
  } else {
328
- return txb.moveCall({
329
- target:this.protocol.MachineFn('clone') as FnCallType,
330
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
328
+ return this.txb.moveCall({
329
+ target:Protocol.Instance().MachineFn('clone') as FnCallType,
330
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
331
331
  })
332
332
  }
333
333
  }
334
334
 
335
- set_endpoint(endpoint?:string|null, passport?:PassportObject) {
335
+ set_endpoint(endpoint?:string|null|undefined, passport?:PassportObject) {
336
336
  if (endpoint && !IsValidEndpoint(endpoint)) {
337
337
  ERROR(Errors.IsValidEndpoint)
338
338
  }
339
339
 
340
- let txb = this.protocol.CurrentSession();
341
- let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
342
-
340
+ let ep = this.txb.pure.option('string', endpoint ? endpoint : undefined) ;
343
341
  if (passport) {
344
- txb.moveCall({
345
- target:this.protocol.MachineFn('endpoint_set_with_passport') as FnCallType,
346
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), ep, Protocol.TXB_OBJECT(txb, this.permission)],
342
+ this.txb.moveCall({
343
+ target:Protocol.Instance().MachineFn('endpoint_set_with_passport') as FnCallType,
344
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), ep, Protocol.TXB_OBJECT(this.txb, this.permission)],
347
345
  })
348
346
  } else {
349
- txb.moveCall({
350
- target:this.protocol.MachineFn('endpoint_set') as FnCallType,
351
- arguments:[Protocol.TXB_OBJECT(txb, this.object), ep, Protocol.TXB_OBJECT(txb, this.permission)],
347
+ this.txb.moveCall({
348
+ target:Protocol.Instance().MachineFn('endpoint_set') as FnCallType,
349
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), ep, Protocol.TXB_OBJECT(this.txb, this.permission)],
352
350
  })
353
351
  }
354
352
  }
355
353
  pause(bPaused:boolean, passport?:PassportObject) {
356
- let txb = this.protocol.CurrentSession();
357
354
  if (passport) {
358
- txb.moveCall({
359
- target:this.protocol.MachineFn('pause_with_passport') as FnCallType,
360
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(bPaused), Protocol.TXB_OBJECT(txb, this.permission)],
355
+ this.txb.moveCall({
356
+ target:Protocol.Instance().MachineFn('pause_with_passport') as FnCallType,
357
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bPaused), Protocol.TXB_OBJECT(this.txb, this.permission)],
361
358
  })
362
359
  } else {
363
- txb.moveCall({
364
- target:this.protocol.MachineFn('pause') as FnCallType,
365
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(bPaused), Protocol.TXB_OBJECT(txb, this.permission)],
360
+ this.txb.moveCall({
361
+ target:Protocol.Instance().MachineFn('pause') as FnCallType,
362
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bPaused), Protocol.TXB_OBJECT(this.txb, this.permission)],
366
363
  })
367
364
  }
368
365
  }
369
366
  publish(passport?:PassportObject) {
370
- let txb = this.protocol.CurrentSession();
371
367
  if (passport) {
372
- txb.moveCall({
373
- target:this.protocol.MachineFn('publish_with_passport') as FnCallType,
374
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
368
+ this.txb.moveCall({
369
+ target:Protocol.Instance().MachineFn('publish_with_passport') as FnCallType,
370
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
375
371
  })
376
372
  } else {
377
- txb.moveCall({
378
- target:this.protocol.MachineFn('publish') as FnCallType,
379
- arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
373
+ this.txb.moveCall({
374
+ target:Protocol.Instance().MachineFn('publish') as FnCallType,
375
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
380
376
  })
381
377
  }
382
378
  }
@@ -386,64 +382,70 @@ export class Machine {
386
382
  ERROR(Errors.IsValidObjects, 'new_permission')
387
383
  }
388
384
 
389
- let txb = this.protocol.CurrentSession();
390
- txb.moveCall({
391
- target:this.protocol.MachineFn('permission_set') as FnCallType,
392
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
385
+ this.txb.moveCall({
386
+ target:Protocol.Instance().MachineFn('permission_set') as FnCallType,
387
+ arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
393
388
  typeArguments:[]
394
389
  })
395
390
  this.permission = new_permission;
396
391
  }
397
392
 
398
- add_forward(node_prior:string, node_name:string, foward: Machine_Forward, threshold?:number, passport?:PassportObject) {
393
+ add_forward(node_prior:string, node_name:string, foward: Machine_Forward, threshold?:number, old_forward_name?:string, passport?:PassportObject) {
399
394
  if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'add_forward');
400
395
  if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'add_forward');
401
- if (!Machine.isValidForward(foward)) ERROR(Errors.InvalidParam, 'add_forward');
396
+ const err = Machine.checkValidForward(foward); if (err) ERROR(Errors.InvalidParam, err);
402
397
 
403
- let txb = this.protocol.CurrentSession();
404
398
  let n : any;
405
399
  if (passport) {
406
- n = txb.moveCall({
407
- target:this.protocol.MachineFn('node_fetch_with_passport') as FnCallType,
408
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name), Protocol.TXB_OBJECT(txb, this.permission)],
400
+ n = this.txb.moveCall({
401
+ target:Protocol.Instance().MachineFn('node_fetch_with_passport') as FnCallType,
402
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
409
403
  })
410
404
 
411
405
  } else {
412
- n = txb.moveCall({
413
- target:this.protocol.MachineFn('node_fetch') as FnCallType,
414
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name), Protocol.TXB_OBJECT(txb, this.permission)],
406
+ n = this.txb.moveCall({
407
+ target:Protocol.Instance().MachineFn('node_fetch') as FnCallType,
408
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
415
409
  })
416
410
  }
417
411
  const f = this.forward(foward);
418
- const t = threshold ? txb.pure(Bcs.getInstance().ser_option_u32(threshold)) : OptionNone(txb);
419
- txb.moveCall({
420
- target:this.protocol.MachineFn('forward_add') as FnCallType,
421
- arguments:[n, txb.pure(node_prior), txb.pure(foward.name), t, f],
412
+ const t = this.txb.pure.option('u32', threshold);
413
+ this.txb.moveCall({
414
+ target:Protocol.Instance().MachineFn('forward_add') as FnCallType,
415
+ arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward.name), t, f],
422
416
  })
417
+
418
+ if (old_forward_name && old_forward_name !== foward.name) {
419
+ this.txb.moveCall({
420
+ target:Protocol.Instance().MachineFn('forward_remove') as FnCallType,
421
+ arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(old_forward_name)],
422
+ })
423
+ }
424
+ this.add_node2([n], passport);
423
425
  }
424
426
 
425
427
  remove_forward(node_prior:string, node_name:string, foward_name: string, passport?:PassportObject) {
426
428
  if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'add_forward');
427
429
  if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'add_forward');
428
430
 
429
- let txb = this.protocol.CurrentSession();
430
431
  let n : any;
431
432
  if (passport) {
432
- n = txb.moveCall({
433
- target:this.protocol.MachineFn('node_fetch_with_passport') as FnCallType,
434
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name), Protocol.TXB_OBJECT(txb, this.permission)],
433
+ n = this.txb.moveCall({
434
+ target:Protocol.Instance().MachineFn('node_fetch_with_passport') as FnCallType,
435
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
435
436
  })
436
437
 
437
438
  } else {
438
- n = txb.moveCall({
439
- target:this.protocol.MachineFn('node_fetch') as FnCallType,
440
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(node_name), Protocol.TXB_OBJECT(txb, this.permission)],
439
+ n = this.txb.moveCall({
440
+ target:Protocol.Instance().MachineFn('node_fetch') as FnCallType,
441
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
441
442
  })
442
443
  }
443
- txb.moveCall({
444
- target:this.protocol.MachineFn('forward_remove') as FnCallType,
445
- arguments:[n, txb.pure(node_prior), txb.pure(foward_name)],
444
+ this.txb.moveCall({
445
+ target:Protocol.Instance().MachineFn('forward_remove') as FnCallType,
446
+ arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward_name)],
446
447
  })
448
+ this.add_node2([n], passport);
447
449
  }
448
450
 
449
451
  static rpc_de_nodes(fields: any) : Machine_Node[] {
@@ -482,15 +484,37 @@ export class Machine {
482
484
  return ret;
483
485
  }
484
486
 
485
- static isValidForward(forward:Machine_Forward) {
486
- if (!IsValidName(forward.name)) return false
487
- if (forward?.namedOperator && !IsValidName_AllowEmpty(forward?.namedOperator)) return false;
488
- if (forward?.permission && !Permission.IsValidPermissionIndex(forward?.permission)) return false;
489
- if (!forward?.permission && !forward?.namedOperator) return false;
490
- if (forward?.weight && !IsValidUintLarge(forward.weight)) return false;
491
- return true
487
+ static checkValidForward(forward:Machine_Forward) : string {
488
+ if (!IsValidName(forward.name)) return 'Forward name invalid'
489
+ if (forward?.namedOperator && !IsValidName_AllowEmpty(forward?.namedOperator)) return 'Progress Operator invalid';
490
+ if (forward?.permission && !Permission.IsValidPermissionIndex(forward?.permission)) return 'Permission index invalid';
491
+ if (!forward?.permission && !forward?.namedOperator) return 'Both Permission index and Progress Operator empty';
492
+ if (forward?.weight && !IsValidUintLarge(forward.weight)) return 'Weight invalid';
493
+ return ''
492
494
  }
493
495
 
496
+
497
+ QueryForwardGuard(sender:string, node:string, prior_node:string, forward:string, onGuard:OnQueryGuard) {
498
+ if (!node || !forward) { // prior_node maybe ''
499
+ ERROR(Errors.InvalidParam, 'QueryForwardGuard');
500
+ return ;
501
+ }
502
+
503
+ this.txb.moveCall({
504
+ target:Protocol.Instance().MachineFn('query_guard') as FnCallType,
505
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node),
506
+ this.txb.pure.string(prior_node), this.txb.pure.string(forward)],
507
+ });
508
+
509
+ Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:this.txb}).then((res) => {
510
+ if (res.results?.length === 1 && res.results[0].returnValues?.length === 1) {
511
+ const guard = Bcs.getInstance().de('Option<address>', Uint8Array.from(res.results[0].returnValues[0][0]));
512
+ onGuard({node:node, prior_node:prior_node, forward:forward, guard:guard?.some?('0x'+guard?.some):'', txb:this.txb});
513
+ }
514
+ }).catch(e=>{
515
+ console.log(e);
516
+ })
517
+ }
494
518
  static INITIAL_NODE_NAME = '';
495
519
  /* static NODE_NAME_RESERVED = 'origin';
496
520
  static IsNodeNameReserved = (name:string) => {