wowok 1.0.3 → 1.0.5

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/permission.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
2
2
  import { BCS } from '@mysten/bcs';
3
- import { description_data, FnCallType, PROTOCOL, TxbObject, GuardObject, TXB_OBJECT} from './protocol';
3
+ import { FnCallType, PROTOCOL, TxbObject, PermissionObject, PermissionAddress, TXB_OBJECT, IsValidDesription,
4
+ IsValidObjects, IsValidAddress, IsValidArray, GuardObject, IsValidUint} from './protocol';
4
5
  import { array_unique } from './util';
5
6
 
6
7
 
7
8
  export const MAX_ADMIN_COUNT = 64;
8
- export const MAX_ENTITY_COUNT = 1024;
9
- export const MAX_PERMISSION_INDEX_COUNT = 512;
9
+ export const MAX_ENTITY_COUNT = 2000;
10
+ export const MAX_PERMISSION_INDEX_COUNT = 200;
10
11
 
11
12
  export enum PermissionIndex {
12
13
  repository = 100,
@@ -84,34 +85,70 @@ export enum PermissionIndex {
84
85
  progress_bind_task = 652,
85
86
  progress_set_context_repository = 653,
86
87
  progress_unhold = 654,
88
+ user_defined_start = 10000,
87
89
  }
90
+
91
+ export type PermissionIndexType = PermissionIndex | number;
92
+ export const IsValidUserDefinedIndex = (index:number) : boolean => {
93
+ return index >= PermissionIndex.user_defined_start && IsValidUint(index)
94
+ }
95
+ export const IsValidPermissionIndex = (index:PermissionIndexType) : boolean => {
96
+ //console.log(index)
97
+ if (Object.values(PermissionIndex).includes(index)) {
98
+ return true
99
+ }
100
+ //console.log(Object.keys(PermissionIndex))
101
+ return IsValidUserDefinedIndex(index);
102
+ }
103
+
88
104
  export type Permission_Index = {
89
- index:PermissionIndex;
105
+ index: PermissionIndexType;
90
106
  guard?: TxbObject;
91
107
  }
108
+
92
109
  export type Permission_Entity = {
93
- who:string;
110
+ entity_address:string;
94
111
  permissions:Permission_Index[];
95
112
  }
96
113
 
97
- export type PermissionAddress = TransactionResult;
98
- export type PermissionObject = TransactionResult;
114
+ export function permission(txb:TransactionBlock, description:string) : PermissionObject | boolean {
115
+ if (!IsValidDesription(description)) return false;
99
116
 
100
- export function permission(txb:TransactionBlock, description:string) : PermissionObject {
101
117
  return txb.moveCall({
102
118
  target: PROTOCOL.PermissionFn('new') as FnCallType,
103
- arguments: [txb.pure(description_data(description))]
119
+ arguments: [txb.pure(description)]
104
120
  });
105
121
  }
106
122
 
107
- export function launch(txb:TransactionBlock, permission:PermissionObject) : PermissionAddress {
123
+ export function launch(txb:TransactionBlock, permission:PermissionObject) : PermissionAddress | boolean {
124
+ if (!IsValidObjects([permission])) return false;
108
125
  return txb.moveCall({ // address returned
109
126
  target:PROTOCOL.PermissionFn('create') as FnCallType,
110
- arguments:[ permission ]
127
+ arguments:[ TXB_OBJECT(txb, permission) ]
111
128
  })
112
129
  }
130
+ export function destroy(txb:TransactionBlock, permission:PermissionObject) : boolean {
131
+ if (!IsValidObjects([permission])) return false;
132
+ txb.moveCall({
133
+ target:PROTOCOL.PermissionFn('destroy') as FnCallType,
134
+ arguments: [TXB_OBJECT(txb, permission)],
135
+ })
136
+ return true
137
+ }
138
+ export function add_entity(txb:TransactionBlock, permission:PermissionObject, entities:Permission_Entity[]) : boolean {
139
+ if (!IsValidObjects([permission])) return false;
140
+ if (!entities) return false;
141
+
142
+ let bValid = true;
143
+ let e = entities.forEach((v) => {
144
+ if (!IsValidAddress(v.entity_address)) bValid = false;
145
+ v.permissions.forEach((p) => {
146
+ if (!IsValidPermissionIndex(p.index)) bValid = false;
147
+ if (p?.guard && !IsValidObjects([p.guard])) bValid = false;
148
+ })
149
+ });
150
+ if (!bValid) return false;
113
151
 
114
- export function add_entity(txb:TransactionBlock, permission:PermissionObject, entities:Permission_Entity[]) {
115
152
  let guards:any[] = [];
116
153
  for (let i = 0; i < entities.length; i++) {
117
154
  let entity = entities[i];
@@ -119,106 +156,125 @@ export function add_entity(txb:TransactionBlock, permission:PermissionObject, en
119
156
 
120
157
  for (let j = 0; j < entity.permissions.length; j++) {
121
158
  let index = entity.permissions[j];
122
- if (index?.guard) {
123
- guards.push({who:entity.who, index:index.index, guard:index.guard});
159
+ if (!IsValidPermissionIndex(index.index)) {
160
+ continue;
124
161
  }
125
162
 
126
163
  if (!indexes.includes(index.index)) {
127
164
  indexes.push(index.index);
165
+ if (index?.guard) {
166
+ guards.push({entity_address:entity.entity_address, index:index.index, guard:index.guard});
167
+ }
128
168
  }
129
169
  }
130
170
  if (indexes.length > 0) {
131
171
  txb.moveCall({
132
172
  target:PROTOCOL.PermissionFn('add_batch') as FnCallType,
133
- arguments:[permission, txb.pure(entity.who, BCS.ADDRESS), txb.pure(indexes, 'vector<u64>')]
173
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(entity.entity_address, BCS.ADDRESS), txb.pure(indexes, 'vector<u64>')]
134
174
  })
135
175
  }
136
176
  }
137
177
  // set guards
138
- guards.forEach(({who, index, guard}) => {
178
+ guards.forEach(({entity_address, index, guard}) => {
139
179
  txb.moveCall({
140
180
  target:PROTOCOL.PermissionFn('guard_set') as FnCallType,
141
- arguments:[ permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, BCS.U64), TXB_OBJECT(txb, guard)]
181
+ arguments:[ TXB_OBJECT(txb, permission), txb.pure(entity_address, BCS.ADDRESS), txb.pure(index, BCS.U64), TXB_OBJECT(txb, guard)]
142
182
  })
143
183
  })
184
+
185
+ return true;
144
186
  }
145
187
 
146
188
  // guard: undefine to set none
147
- export function set_guard(txb:TransactionBlock, permission:PermissionObject, who:string, index:number, guard?:string | GuardObject) {
189
+ export function set_guard(txb:TransactionBlock, permission:PermissionObject, entity_address:string,
190
+ index:PermissionIndexType, guard?:GuardObject) : boolean {
191
+ if (!IsValidObjects([permission])) return false;
192
+ if (!IsValidAddress(entity_address) || !IsValidPermissionIndex(index)) return false;
193
+
148
194
  if (guard) {
149
195
  txb.moveCall({
150
196
  target:PROTOCOL.PermissionFn('guard_set') as FnCallType,
151
- arguments:[permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, BCS.U64), TXB_OBJECT(txb, guard)]
197
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(entity_address, BCS.ADDRESS), txb.pure(index, BCS.U64), TXB_OBJECT(txb, guard)]
152
198
  })
153
199
  } else {
154
200
  txb.moveCall({
155
201
  target:PROTOCOL.PermissionFn('guard_none') as FnCallType,
156
- arguments:[permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, BCS.U64)]
202
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(entity_address, BCS.ADDRESS), txb.pure(index, BCS.U64)]
157
203
  })
158
204
  }
205
+ return true;
159
206
  }
160
207
 
161
- export function add_or_modify(txb:TransactionBlock, permission:PermissionObject, who:string, index:number, modifyIfOldExist?:boolean, guard?:string | GuardObject) {
162
- if (guard) {
163
- txb.moveCall({
164
- target:PROTOCOL.PermissionFn('add_or_modify') as FnCallType,
165
- arguments:[permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, BCS.U64), TXB_OBJECT(txb, guard), txb.pure(modifyIfOldExist, BCS.BOOL)]
166
- })
167
- } else {
168
- txb.moveCall({
169
- target:PROTOCOL.PermissionFn('add_or_modify') as FnCallType,
170
- arguments:[permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, BCS.U64), txb.pure([], BCS.U8), txb.pure(modifyIfOldExist, BCS.BOOL)]
171
- })
172
- }
173
- }
174
- export function remove_index(txb:TransactionBlock, permission:PermissionObject, who:string, index:number[]) {
175
- if (index) {
176
- txb.moveCall({
177
- target:PROTOCOL.PermissionFn('remove_index') as FnCallType,
178
- arguments:[permission, txb.pure(who, BCS.ADDRESS), txb.pure(index, 'vector<u64>')]
179
- })
180
- }
208
+ export function remove_index(txb:TransactionBlock, permission:PermissionObject, entity_address:string,
209
+ index:PermissionIndexType[]) : boolean {
210
+ if (!IsValidObjects([permission])) return false;
211
+ if (!IsValidAddress(entity_address)) return false;
212
+ if (!index || !(IsValidArray(index, IsValidPermissionIndex))) return false;
213
+
214
+ txb.moveCall({
215
+ target:PROTOCOL.PermissionFn('remove_index') as FnCallType,
216
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(entity_address, BCS.ADDRESS), txb.pure(array_unique(index), 'vector<u64>')]
217
+ })
218
+ return true;
181
219
  }
182
- export function remove_entity(txb:TransactionBlock, permission:PermissionObject, who:string[]) {
183
- if (who) {
184
- txb.moveCall({
185
- target:PROTOCOL.PermissionFn('remove') as FnCallType,
186
- arguments:[permission, txb.pure(who, 'vector<address>')]
187
- })
188
- }
220
+ export function remove_entity(txb:TransactionBlock, permission:PermissionObject, entity_address:string[]) : boolean {
221
+ if (!IsValidObjects([permission])) return false;
222
+ if (!entity_address || !IsValidArray(entity_address, IsValidAddress)) return false;
223
+
224
+ txb.moveCall({
225
+ target:PROTOCOL.PermissionFn('remove') as FnCallType,
226
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(array_unique(entity_address), 'vector<address>')]
227
+ })
228
+ return true;
189
229
  }
190
- export function set_description(txb:TransactionBlock, permission:PermissionObject, description:string) {
230
+ export function set_description(txb:TransactionBlock, permission:PermissionObject, description:string) : boolean {
231
+ if (!IsValidObjects([permission])) return false;
232
+ if (!IsValidDesription(description)) return false;
233
+
191
234
  txb.moveCall({
192
235
  target:PROTOCOL.PermissionFn('description_set') as FnCallType,
193
- arguments: [permission, txb.pure(description_data(description))]
236
+ arguments: [TXB_OBJECT(txb, permission), txb.pure(description)]
194
237
  })
238
+ return true;
195
239
  }
196
240
 
197
- export function add_admin(txb:TransactionBlock, permission:PermissionObject, admin:string[]) {
198
- let n = array_unique(admin);
241
+ export function add_admin(txb:TransactionBlock, permission:PermissionObject, admin:string[]) : boolean {
242
+ if (!IsValidObjects([permission])) return false;
243
+ if (!admin || !IsValidArray(admin, IsValidAddress)) return false;
244
+
199
245
  txb.moveCall({
200
246
  target:PROTOCOL.PermissionFn('admin_add_batch') as FnCallType,
201
- arguments:[permission, txb.pure(n, 'vector<address>')]
202
- });
247
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(array_unique(admin), 'vector<address>')]
248
+ });
249
+ return true;
203
250
  }
204
251
 
205
- export function remove_admin(txb:TransactionBlock, permission:PermissionObject, admin:string[], removeall?:boolean) {
252
+ export function remove_admin(txb:TransactionBlock, permission:PermissionObject, admin:string[], removeall?:boolean) : boolean {
253
+ if (!IsValidObjects([permission])) return false;
254
+ if (!removeall && !admin) return false;
255
+ if (!IsValidArray(admin, IsValidAddress)) return false;
256
+
206
257
  if (removeall) {
207
258
  txb.moveCall({
208
259
  target:PROTOCOL.PermissionFn('admins_clear') as FnCallType,
209
- arguments:[permission]
260
+ arguments:[TXB_OBJECT(txb, permission)]
210
261
  });
211
- } else {
262
+ } else if (admin) {
212
263
  txb.moveCall({
213
264
  target:PROTOCOL.PermissionFn('admin_remove_batch') as FnCallType,
214
- arguments:[permission, txb.pure(admin, 'vector<address>')]
265
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(array_unique(admin), 'vector<address>')]
215
266
  });
216
267
  }
268
+ return true
217
269
  }
218
270
 
219
- export function change_owner(txb:TransactionBlock, permission:PermissionObject, new_owner:string) {
271
+ export function change_owner(txb:TransactionBlock, permission:PermissionObject, new_owner:string) :boolean {
272
+ if (!IsValidObjects([permission])) return false;
273
+ if (!IsValidAddress(new_owner)) return false;
274
+
220
275
  txb.moveCall({
221
276
  target:PROTOCOL.PermissionFn('builder_set') as FnCallType,
222
- arguments:[permission, txb.pure(new_owner, BCS.ADDRESS)]
277
+ arguments:[TXB_OBJECT(txb, permission), txb.pure(new_owner, BCS.ADDRESS)]
223
278
  });
279
+ return true
224
280
  }
package/src/progress.ts CHANGED
@@ -1,139 +1,225 @@
1
- import { SuiClient, getFullnodeUrl, SuiObjectResponse } from '@mysten/sui.js/client';
2
- import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
3
- import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
4
- import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
5
- import { name_data, FnCallType, PROTOCOL,} from './protocol';
6
- import { verify, PassportObject} from './passport'
7
- import { PermissionIndex, PermissionObject } from './permission'
8
- import { RepositoryObject } from './repository';
9
- import { MachineObject } from './machine';
10
-
11
- export type ProgressObject = TransactionResult;
12
- export type ProgressAddress = TransactionResult;
13
- export const MAX_NAMED_OPERATOR_COUNT = 64;
14
-
15
- export function progress(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, passport?:PassportObject) : ProgressObject {
1
+ import { TransactionBlock } from '@mysten/sui.js/transactions';
2
+ import { BCS } from '@mysten/bcs';
3
+ import { FnCallType, PROTOCOL, PermissionObject, RepositoryObject, PassportObject, MachineObject, TXB_OBJECT,
4
+ ProgressObject, ProgressAddress, IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidObjects,
5
+ IsValidInt} from './protocol';
6
+ import { BCS_CONVERT, array_unique } from './util'
7
+
8
+ export const MAX_NAMED_OPERATOR_COUNT = 100;
9
+
10
+ export function progress(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, passport?:PassportObject) : ProgressObject | boolean {
11
+ if (!IsValidObjects([machine, permission])) return false;
16
12
  if (passport) {
17
13
  return txb.moveCall({
18
14
  target:PROTOCOL.ProgressFn('new_with_passport') as FnCallType,
19
- arguments: [passport, machine, permission],
15
+ arguments: [passport, TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
20
16
  })
21
17
  } else {
22
18
  return txb.moveCall({
23
19
  target:PROTOCOL.ProgressFn('new') as FnCallType,
24
- arguments: [machine, permission],
20
+ arguments: [TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
25
21
  })
26
22
  }
27
23
  }
28
- export function launch(txb:TransactionBlock, progress:ProgressObject) : ProgressAddress {
24
+ export function launch(txb:TransactionBlock, progress:ProgressObject) : ProgressAddress | boolean {
25
+ if (!IsValidObjects([progress])) return false;
29
26
  return txb.moveCall({
30
27
  target:PROTOCOL.ProgressFn('create') as FnCallType,
31
- arguments: [progress],
28
+ arguments: [TXB_OBJECT(txb, progress)],
32
29
  })
33
30
  }
34
- export function launch_as_child(txb:TransactionBlock, progress:ProgressObject, parent:ProgressObject, parent_next:ProgressNext) : ProgressAddress {
31
+ export function launch_as_child(txb:TransactionBlock, progress:ProgressObject, parent:ProgressObject, parent_next:ProgressNext) : ProgressAddress | boolean {
32
+ if (!IsValidObjects([progress, parent])) return false;
33
+ if (!IsValidProgressNext(parent_next)) return false;
34
+
35
35
  return txb.moveCall({
36
36
  target:PROTOCOL.ProgressFn('create_as_child') as FnCallType,
37
- arguments: [progress, parent, txb.pure(parent_next.next_node_name), txb.pure(name_data(parent_next.forward))],
37
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, parent), txb.pure(parent_next.next_node_name), txb.pure(parent_next.forward)],
38
38
  })
39
39
  }
40
- export function destroy(txb:TransactionBlock, progress:ProgressObject) {
41
- return txb.moveCall({
40
+ export function destroy(txb:TransactionBlock, progress:ProgressObject) : boolean {
41
+ if (!IsValidObjects([progress])) return false;
42
+ txb.moveCall({
42
43
  target:PROTOCOL.ProgressFn('destroy') as FnCallType,
43
- arguments: [progress],
44
+ arguments: [TXB_OBJECT(txb, progress)],
44
45
  })
46
+ return true
45
47
  }
46
- export function progress_set_namedOperator(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, name:string, addresses:string[], passport?:PassportObject) {
47
- if (addresses.length == 0 || name.length == 0 || addresses.length > MAX_NAMED_OPERATOR_COUNT) return undefined;
48
+ export function progress_set_namedOperator(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject,
49
+ progress:ProgressObject, name:string, addresses:string[], passport?:PassportObject) : boolean {
50
+ if (!IsValidObjects([machine, permission, progress])) return false;
51
+ if (!IsValidName(name)) return false;
52
+ if (!addresses || addresses.length > MAX_NAMED_OPERATOR_COUNT) return false;
53
+ if (!IsValidArray(addresses, IsValidAddress)) return false;
48
54
 
49
55
  if (passport) {
50
56
  txb.moveCall({
51
57
  target:PROTOCOL.ProgressFn('namedOperator_set_with_passport') as FnCallType,
52
- arguments: [passport, progress, txb.pure(name_data(name)), txb.pure(addresses, 'vector<address>'),
53
- machine, permission],
58
+ arguments: [passport, TXB_OBJECT(txb, progress), txb.pure(name), txb.pure(array_unique(addresses), 'vector<address>'),
59
+ TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
54
60
  })
55
61
  } else {
56
62
  txb.moveCall({
57
63
  target:PROTOCOL.ProgressFn('namedOperator_set') as FnCallType,
58
- arguments: [progress, txb.pure(name_data(name)), txb.pure(addresses, 'vector<address>'),
59
- machine, permission],
64
+ arguments: [TXB_OBJECT(txb, progress), txb.pure(name), txb.pure(array_unique(addresses), 'vector<address>'),
65
+ TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
60
66
  })
61
67
  }
68
+ return true
62
69
  }
63
- export function progress_bind_task(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, task_address:string, passport?:PassportObject) {
70
+ export function progress_bind_task(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject,
71
+ progress:ProgressObject, task_address:string, passport?:PassportObject) : boolean {
72
+ if (!IsValidObjects([machine, permission, progress])) return false;
73
+ if (!IsValidAddress(task_address)) return false;
74
+
64
75
  if (passport) {
65
76
  txb.moveCall({
66
77
  target:PROTOCOL.ProgressFn('task_set_with_passport') as FnCallType,
67
- arguments: [passport, progress, txb.pure(task_address, BCS.ADDRESS), machine, permission],
78
+ arguments: [passport, TXB_OBJECT(txb, progress), txb.pure(task_address, BCS.ADDRESS), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
68
79
  })
69
80
  } else {
70
81
  txb.moveCall({
71
82
  target:PROTOCOL.ProgressFn('task_set') as FnCallType,
72
- arguments: [progress, txb.pure(task_address, BCS.ADDRESS), machine, permission],
83
+ arguments: [TXB_OBJECT(txb, progress), txb.pure(task_address, BCS.ADDRESS), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
73
84
  })
74
85
  }
86
+ return true
75
87
  }
76
- export function progress_set_context_repository(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, repository?:RepositoryObject, passport?:PassportObject) {
88
+ export function progress_set_context_repository(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject,
89
+ progress:ProgressObject, repository?:RepositoryObject, passport?:PassportObject) : boolean {
90
+ if (!IsValidObjects([machine, permission, progress])) return false;
77
91
  if (passport) {
78
92
  if (repository) {
79
93
  txb.moveCall({
80
94
  target:PROTOCOL.ProgressFn('context_repository_set_with_passport') as FnCallType,
81
- arguments: [passport, progress, repository, machine, permission],
95
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, repository), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
82
96
  })
83
97
  } else {
84
98
  txb.moveCall({
85
99
  target:PROTOCOL.ProgressFn('context_repository_none_with_passport') as FnCallType,
86
- arguments: [passport, progress, machine, permission],
100
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
87
101
  })
88
102
  }
89
103
  } else {
90
104
  if (repository) {
91
105
  txb.moveCall({
92
106
  target:PROTOCOL.ProgressFn('context_repository_set') as FnCallType,
93
- arguments: [progress, repository, machine, permission],
107
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, repository), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
94
108
  })
95
109
  } else {
96
110
  txb.moveCall({
97
111
  target:PROTOCOL.ProgressFn('context_repository_none') as FnCallType,
98
- arguments: [progress, machine, permission],
112
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
99
113
  })
100
114
  }
101
115
  }
116
+ return true
102
117
  }
103
- export function progress_unhold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, next:ProgressNext) {
104
- txb.moveCall({
105
- target:PROTOCOL.ProgressFn('unhold') as FnCallType,
106
- arguments: [progress, machine, txb.pure(next.next_node_name), txb.pure(name_data(next.forward)), permission],
107
- })
118
+ export function progress_unhold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject,
119
+ progress:ProgressObject, next:ProgressNext, passport?:PassportObject) : boolean {
120
+ if (!IsValidObjects([machine, permission, progress])) return false;
121
+ if (!IsValidProgressNext(next)) return false;
122
+
123
+ if (passport) {
124
+ txb.moveCall({
125
+ target:PROTOCOL.ProgressFn('unhold_with_passport') as FnCallType,
126
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), TXB_OBJECT(txb, permission)],
127
+ })
128
+ } else {
129
+ txb.moveCall({
130
+ target:PROTOCOL.ProgressFn('unhold') as FnCallType,
131
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), TXB_OBJECT(txb, permission)],
132
+ })
133
+ }
134
+
135
+ return true
108
136
  }
109
137
 
110
- export type ProgressNext = {
111
- next_node_name: string;
112
- forward: string;
138
+ export type ParentProgress = {
139
+ parent_progress_id: string;
140
+ parent_session_id: number;
113
141
  }
114
- export function next(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, next:ProgressNext,
115
- deliverables_address?:string, passport?:PassportObject) {
116
- let diliverable = txb.pure([], BCS.U8);
117
- if (deliverables_address) { diliverable = txb.pure(deliverables_address, BCS.ADDRESS)}
142
+ export function progress_parent(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
143
+ parent_progress?:ParentProgress, passport?:PassportObject) : boolean {
144
+ if (!IsValidObjects([machine, permission, progress])) return false;
145
+ if (parent_progress && (!IsValidAddress(parent_progress.parent_progress_id) || !IsValidInt(parent_progress.parent_session_id))) return false;
118
146
 
119
- if (passport) {
147
+ if (passport) {
148
+ if (parent_progress) {
120
149
  txb.moveCall({
121
- target:PROTOCOL.ProgressFn('run_with_passport') as FnCallType,
122
- arguments: [passport, progress, machine, txb.pure(next.next_node_name),
123
- txb.pure(name_data(next.forward)), diliverable, permission],
124
- })
150
+ target:PROTOCOL.ProgressFn('parent_set_with_passport') as FnCallType,
151
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(parent_progress.parent_progress_id, BCS.ADDRESS),
152
+ txb.pure(parent_progress.parent_session_id, BCS.U64), TXB_OBJECT(txb, permission)],
153
+ })
125
154
  } else {
126
155
  txb.moveCall({
127
- target:PROTOCOL.ProgressFn('run') as FnCallType,
128
- arguments: [progress, machine, txb.pure(next.next_node_name),
129
- txb.pure(name_data(next.forward)), diliverable, permission],
130
- })
156
+ target:PROTOCOL.ProgressFn('parent_none_with_passport') as FnCallType,
157
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
158
+ })
131
159
  }
160
+ } else {
161
+ if (parent_progress) {
162
+ txb.moveCall({
163
+ target:PROTOCOL.ProgressFn('parent_set') as FnCallType,
164
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(parent_progress.parent_progress_id, BCS.ADDRESS),
165
+ txb.pure(parent_progress.parent_session_id, BCS.U64), TXB_OBJECT(txb, permission)],
166
+ })
167
+ } else {
168
+ txb.moveCall({
169
+ target:PROTOCOL.ProgressFn('parent_none') as FnCallType,
170
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), TXB_OBJECT(txb, permission)],
171
+ })
172
+ }
173
+ }
174
+
175
+ return true
176
+ }
177
+
178
+ export type ProgressNext = {
179
+ next_node_name: string;
180
+ forward: string;
181
+ }
182
+ function IsValidProgressNext(next:ProgressNext) : boolean {
183
+ return IsValidName(next.forward) && IsValidName(next.next_node_name);
184
+ }
185
+
186
+ export function next(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
187
+ next:ProgressNext, deliverables_address?:string, sub_progress_id?:string, passport?:PassportObject) : boolean {
188
+ if (!IsValidObjects([machine, permission, progress])) return false;
189
+ if (!IsValidProgressNext(next)) return false;
190
+ if (deliverables_address && !IsValidAddress(deliverables_address)) return false;
191
+ if (sub_progress_id && !IsValidAddress(sub_progress_id)) return false;
192
+
193
+ let diliverable = deliverables_address? txb.pure(BCS_CONVERT.ser_option_address(deliverables_address)) : OptionNone(txb)
194
+ let sub = sub_progress_id? txb.pure(BCS_CONVERT.ser_option_address(sub_progress_id)) : OptionNone(txb)
195
+
196
+ if (passport) {
197
+ txb.moveCall({
198
+ target:PROTOCOL.ProgressFn('next_with_passport') as FnCallType,
199
+ arguments: [passport, TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name, BCS.STRING),
200
+ txb.pure(next.forward, BCS.STRING), diliverable, sub, TXB_OBJECT(txb, permission)],
201
+ })
202
+ } else {
203
+ txb.moveCall({
204
+ target:PROTOCOL.ProgressFn('next') as FnCallType,
205
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name, BCS.STRING),
206
+ txb.pure(next.forward, BCS.STRING), diliverable, sub, TXB_OBJECT(txb, permission)],
207
+ })
208
+ }
209
+ return true
132
210
  }
133
- export function hold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject, next:ProgressNext, hold:boolean) {
211
+
212
+ export function hold(txb:TransactionBlock, machine:MachineObject, permission:PermissionObject, progress:ProgressObject,
213
+ next:ProgressNext, hold:boolean) : boolean {
214
+ if (!IsValidObjects([machine, permission, progress])) return false;
215
+ if (!IsValidProgressNext(next)) return false;
216
+
134
217
  txb.moveCall({
135
218
  target:PROTOCOL.ProgressFn('hold') as FnCallType,
136
- arguments: [progress, machine, txb.pure(next.next_node_name),
137
- txb.pure(name_data(next.forward)), txb.pure(hold, BCS.BOOL), permission],
219
+ arguments: [TXB_OBJECT(txb, progress), TXB_OBJECT(txb, machine), txb.pure(next.next_node_name),
220
+ txb.pure(next.forward), txb.pure(hold, BCS.BOOL), TXB_OBJECT(txb, permission)],
138
221
  })
139
- }
222
+ return true
223
+ }
224
+
225
+