wowok 1.2.10 → 1.2.12
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/package.json +3 -3
- package/src/demand.ts +85 -98
- package/src/entity.ts +35 -35
- package/src/guard.ts +15 -15
- package/src/machine.ts +150 -174
- package/src/passport.ts +34 -38
- package/src/permission.ts +157 -89
- package/src/progress.ts +118 -118
- package/src/protocol.ts +28 -31
- package/src/repository.ts +147 -160
- package/src/resource.ts +43 -45
- package/src/reward.ts +108 -119
- package/src/service.ts +338 -364
- package/src/utils.ts +9 -5
- package/src/vote.ts +139 -157
- package/src/wowok.ts +19 -23
package/src/repository.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
|
|
3
3
|
import { PermissionIndexType, Permission } from './permission'
|
|
4
|
-
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray,
|
|
4
|
+
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert} from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
6
|
import { MAX_U8, MAX_U128, MAX_U256, MAX_U64 } from './utils';
|
|
7
|
+
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
7
8
|
|
|
8
9
|
export enum Repository_Policy_Mode {
|
|
9
10
|
POLICY_MODE_FREE = 0,
|
|
@@ -37,20 +38,20 @@ export type Repository_Value = {
|
|
|
37
38
|
export class Repository {
|
|
38
39
|
protected permission ;
|
|
39
40
|
protected object:TxbObject;
|
|
40
|
-
protected
|
|
41
|
+
protected txb;
|
|
41
42
|
|
|
42
43
|
get_object() { return this.object }
|
|
43
|
-
private constructor(
|
|
44
|
-
this.
|
|
44
|
+
private constructor(txb:TransactionBlock, permission:PermissionObject) {
|
|
45
|
+
this.txb = txb;
|
|
45
46
|
this.permission = permission;
|
|
46
47
|
this.object = '';
|
|
47
48
|
}
|
|
48
|
-
static From(
|
|
49
|
-
let r = new Repository(
|
|
50
|
-
r.object = Protocol.TXB_OBJECT(
|
|
49
|
+
static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Repository {
|
|
50
|
+
let r = new Repository(txb, permission);
|
|
51
|
+
r.object = Protocol.TXB_OBJECT(txb, object);
|
|
51
52
|
return r
|
|
52
53
|
}
|
|
53
|
-
static New(
|
|
54
|
+
static New(txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
54
55
|
policy_mode: Repository_Policy_Mode, passport?:PassportObject) : Repository {
|
|
55
56
|
if (!Protocol.IsValidObjects([permission])) {
|
|
56
57
|
ERROR(Errors.IsValidObjects, 'permission')
|
|
@@ -59,36 +60,34 @@ export class Repository {
|
|
|
59
60
|
ERROR(Errors.IsValidDesription)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
let r = new Repository(
|
|
63
|
-
let txb = protocol.CurrentSession();
|
|
63
|
+
let r = new Repository(txb, permission);
|
|
64
64
|
|
|
65
65
|
if (passport) {
|
|
66
66
|
r.object = txb.moveCall({
|
|
67
|
-
target:
|
|
68
|
-
arguments:[passport, txb.pure(description), txb.pure(policy_mode
|
|
67
|
+
target:Protocol.Instance().RepositoryFn('new_with_passport') as FnCallType,
|
|
68
|
+
arguments:[passport, txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
|
|
69
69
|
})
|
|
70
70
|
} else {
|
|
71
71
|
r.object = txb.moveCall({
|
|
72
|
-
target:
|
|
73
|
-
arguments:[txb.pure(description), txb.pure(policy_mode
|
|
72
|
+
target:Protocol.Instance().RepositoryFn('new') as FnCallType,
|
|
73
|
+
arguments:[txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
76
|
return r
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
launch() : RepositoryAddress {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object)],
|
|
80
|
+
return this.txb.moveCall({
|
|
81
|
+
target:Protocol.Instance().RepositoryFn('create') as FnCallType,
|
|
82
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
84
83
|
})
|
|
85
84
|
}
|
|
85
|
+
|
|
86
86
|
destroy() {
|
|
87
87
|
if (!Protocol.IsValidObjects([this.object])) return false;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
88
|
+
this.txb.moveCall({
|
|
89
|
+
target:Protocol.Instance().RepositoryFn('destroy') as FnCallType,
|
|
90
|
+
arguments: [Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
92
91
|
})
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -105,27 +104,26 @@ export class Repository {
|
|
|
105
104
|
if (!bValid) {
|
|
106
105
|
ERROR(Errors.InvalidParam)
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
txb.pure(
|
|
115
|
-
txb.pure(data.
|
|
116
|
-
txb.pure(
|
|
117
|
-
|
|
118
|
-
Protocol.TXB_OBJECT(txb, this.permission),
|
|
107
|
+
|
|
108
|
+
if (data?.value_type !== undefined) {
|
|
109
|
+
data.data.forEach((d) => this.txb.moveCall({
|
|
110
|
+
target:Protocol.Instance().RepositoryFn('add') as FnCallType,
|
|
111
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
112
|
+
this.txb.pure.address(d.address),
|
|
113
|
+
this.txb.pure.string(data.key),
|
|
114
|
+
this.txb.pure.u8(data.value_type!),
|
|
115
|
+
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
116
|
+
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
119
117
|
],
|
|
120
118
|
}))
|
|
121
119
|
} else {
|
|
122
|
-
data.data.forEach((d) => txb.moveCall({
|
|
123
|
-
target:
|
|
124
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
125
|
-
txb.pure(d.address
|
|
126
|
-
txb.pure(data.key),
|
|
127
|
-
txb.pure([...d.bcsBytes]
|
|
128
|
-
Protocol.TXB_OBJECT(txb, this.permission),
|
|
120
|
+
data.data.forEach((d) => this.txb.moveCall({
|
|
121
|
+
target:Protocol.Instance().RepositoryFn('add_typed_data') as FnCallType,
|
|
122
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
123
|
+
this.txb.pure.address(d.address),
|
|
124
|
+
this.txb.pure.string(data.key),
|
|
125
|
+
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
126
|
+
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
129
127
|
],
|
|
130
128
|
}))
|
|
131
129
|
}
|
|
@@ -138,14 +136,13 @@ export class Repository {
|
|
|
138
136
|
if (!IsValidAddress(address)) {
|
|
139
137
|
ERROR(Errors.IsValidAddress)
|
|
140
138
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
txb.pure(
|
|
147
|
-
txb.
|
|
148
|
-
Protocol.TXB_OBJECT(txb, this.permission),
|
|
139
|
+
|
|
140
|
+
this.txb.moveCall({
|
|
141
|
+
target:Protocol.Instance().RepositoryFn('remove') as FnCallType,
|
|
142
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
143
|
+
this.txb.pure.address(address),
|
|
144
|
+
this.txb.pure.string(key),
|
|
145
|
+
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
149
146
|
],
|
|
150
147
|
})
|
|
151
148
|
}
|
|
@@ -154,21 +151,20 @@ export class Repository {
|
|
|
154
151
|
if (!IsValidArray(references, IsValidAddress)) {
|
|
155
152
|
ERROR(Errors.IsValidArray, 'add_reference')
|
|
156
153
|
}
|
|
157
|
-
|
|
158
|
-
let txb = this.protocol.CurrentSession();
|
|
154
|
+
|
|
159
155
|
if (passport) {
|
|
160
|
-
txb.moveCall({
|
|
161
|
-
target:
|
|
162
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
163
|
-
txb.pure(array_unique(references)
|
|
164
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
156
|
+
this.txb.moveCall({
|
|
157
|
+
target:Protocol.Instance().RepositoryFn('reference_add_with_passport') as FnCallType,
|
|
158
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
159
|
+
this.txb.pure.vector('address', array_unique(references)),
|
|
160
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
165
161
|
})
|
|
166
162
|
} else {
|
|
167
|
-
txb.moveCall({
|
|
168
|
-
target:
|
|
169
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
170
|
-
txb.pure(array_unique(references)
|
|
171
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
163
|
+
this.txb.moveCall({
|
|
164
|
+
target:Protocol.Instance().RepositoryFn('reference_add') as FnCallType,
|
|
165
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
166
|
+
this.txb.pure.vector('address', array_unique(references)),
|
|
167
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
172
168
|
})
|
|
173
169
|
}
|
|
174
170
|
}
|
|
@@ -178,36 +174,35 @@ export class Repository {
|
|
|
178
174
|
if (!IsValidArray(references, IsValidAddress)) {
|
|
179
175
|
ERROR(Errors.IsValidArray, 'remove_reference')
|
|
180
176
|
}
|
|
181
|
-
|
|
182
|
-
let txb = this.protocol.CurrentSession();
|
|
177
|
+
|
|
183
178
|
if (removeall) {
|
|
184
179
|
if (passport) {
|
|
185
|
-
txb.moveCall({
|
|
186
|
-
target:
|
|
187
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
188
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
180
|
+
this.txb.moveCall({
|
|
181
|
+
target:Protocol.Instance().RepositoryFn('reference_removeall_with_passport') as FnCallType,
|
|
182
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
183
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
189
184
|
})
|
|
190
185
|
} else {
|
|
191
|
-
txb.moveCall({
|
|
192
|
-
target:
|
|
193
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
194
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
186
|
+
this.txb.moveCall({
|
|
187
|
+
target:Protocol.Instance().RepositoryFn('reference_removeall') as FnCallType,
|
|
188
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
189
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
195
190
|
})
|
|
196
191
|
}
|
|
197
192
|
} else {
|
|
198
193
|
if (passport) {
|
|
199
|
-
txb.moveCall({
|
|
200
|
-
target:
|
|
201
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
202
|
-
txb.pure(array_unique(references)
|
|
203
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
194
|
+
this.txb.moveCall({
|
|
195
|
+
target:Protocol.Instance().RepositoryFn('reference_remove_with_passport') as FnCallType,
|
|
196
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
197
|
+
this.txb.pure.vector('address', array_unique(references)),
|
|
198
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
204
199
|
})
|
|
205
200
|
} else {
|
|
206
|
-
txb.moveCall({
|
|
207
|
-
target:
|
|
208
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
209
|
-
txb.pure(array_unique(references)
|
|
210
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
201
|
+
this.txb.moveCall({
|
|
202
|
+
target:Protocol.Instance().RepositoryFn('reference_remove') as FnCallType,
|
|
203
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
204
|
+
this.txb.pure.vector('address', array_unique(references)),
|
|
205
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
211
206
|
})
|
|
212
207
|
}
|
|
213
208
|
}
|
|
@@ -226,26 +221,25 @@ export class Repository {
|
|
|
226
221
|
ERROR(Errors.InvalidParam, 'policies')
|
|
227
222
|
}
|
|
228
223
|
|
|
229
|
-
let txb = this.protocol.CurrentSession();
|
|
230
224
|
policies.forEach((policy) => {
|
|
231
|
-
let permission_index =
|
|
225
|
+
let permission_index = this.txb.pure.option('u64', policy?.permission);
|
|
232
226
|
if (passport) {
|
|
233
|
-
txb.moveCall({
|
|
234
|
-
target:
|
|
235
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
236
|
-
txb.pure(policy.key),
|
|
237
|
-
txb.pure(policy.description),
|
|
238
|
-
permission_index, txb.pure(policy.data_type
|
|
239
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
227
|
+
this.txb.moveCall({
|
|
228
|
+
target:Protocol.Instance().RepositoryFn('policy_add_with_passport') as FnCallType,
|
|
229
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
230
|
+
this.txb.pure.string(policy.key),
|
|
231
|
+
this.txb.pure.string(policy.description),
|
|
232
|
+
permission_index, this.txb.pure.u8(policy.data_type),
|
|
233
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
240
234
|
})
|
|
241
235
|
} else {
|
|
242
|
-
txb.moveCall({
|
|
243
|
-
target:
|
|
244
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
245
|
-
txb.pure(policy.key),
|
|
246
|
-
txb.pure(policy.description),
|
|
247
|
-
permission_index, txb.pure(policy.data_type
|
|
248
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
236
|
+
this.txb.moveCall({
|
|
237
|
+
target:Protocol.Instance().RepositoryFn('policy_add') as FnCallType,
|
|
238
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
239
|
+
this.txb.pure.string(policy.key),
|
|
240
|
+
this.txb.pure.string(policy.description),
|
|
241
|
+
permission_index, this.txb.pure.u8(policy.data_type),
|
|
242
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
249
243
|
})
|
|
250
244
|
}
|
|
251
245
|
});
|
|
@@ -256,21 +250,20 @@ export class Repository {
|
|
|
256
250
|
if (!IsValidArray(policy_keys, Repository.IsValidName)){
|
|
257
251
|
ERROR(Errors.InvalidParam, 'policy_keys')
|
|
258
252
|
}
|
|
259
|
-
|
|
260
|
-
let txb = this.protocol.CurrentSession();
|
|
253
|
+
|
|
261
254
|
if (passport) {
|
|
262
|
-
txb.moveCall({
|
|
263
|
-
target:
|
|
264
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
265
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
266
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
255
|
+
this.txb.moveCall({
|
|
256
|
+
target:Protocol.Instance().RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
257
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
258
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
259
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
267
260
|
})
|
|
268
261
|
} else {
|
|
269
|
-
txb.moveCall({
|
|
270
|
-
target:
|
|
271
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
272
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
273
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
262
|
+
this.txb.moveCall({
|
|
263
|
+
target:Protocol.Instance().RepositoryFn('policy_remove') as FnCallType,
|
|
264
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
265
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
266
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
274
267
|
})
|
|
275
268
|
}
|
|
276
269
|
}
|
|
@@ -278,21 +271,20 @@ export class Repository {
|
|
|
278
271
|
if (!IsValidName(policy_key) || !IsValidName(new_policy_key)) {
|
|
279
272
|
ERROR(Errors.IsValidName, 'change_policy')
|
|
280
273
|
}
|
|
281
|
-
|
|
282
|
-
let txb = this.protocol.CurrentSession();
|
|
274
|
+
|
|
283
275
|
if (passport) {
|
|
284
|
-
txb.moveCall({
|
|
285
|
-
target:
|
|
286
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
287
|
-
txb.pure(policy_key), txb.pure(new_policy_key),
|
|
288
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
276
|
+
this.txb.moveCall({
|
|
277
|
+
target:Protocol.Instance().RepositoryFn('policy_rename_with_passport') as FnCallType,
|
|
278
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
279
|
+
this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
|
|
280
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
289
281
|
})
|
|
290
282
|
} else {
|
|
291
|
-
txb.moveCall({
|
|
292
|
-
target:
|
|
293
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
294
|
-
txb.pure(policy_key), txb.pure(new_policy_key),
|
|
295
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
283
|
+
this.txb.moveCall({
|
|
284
|
+
target:Protocol.Instance().RepositoryFn('policy_rename') as FnCallType,
|
|
285
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
286
|
+
this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
|
|
287
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
296
288
|
})
|
|
297
289
|
}
|
|
298
290
|
}
|
|
@@ -302,33 +294,31 @@ export class Repository {
|
|
|
302
294
|
if (!IsValidDesription(description)){
|
|
303
295
|
ERROR(Errors.IsValidDesription)
|
|
304
296
|
}
|
|
305
|
-
|
|
306
|
-
let txb = this.protocol.CurrentSession();
|
|
297
|
+
|
|
307
298
|
if (passport) {
|
|
308
|
-
txb.moveCall({
|
|
309
|
-
target:
|
|
310
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
299
|
+
this.txb.moveCall({
|
|
300
|
+
target:Protocol.Instance().RepositoryFn('description_set_with_passport') as FnCallType,
|
|
301
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
311
302
|
})
|
|
312
303
|
} else {
|
|
313
|
-
txb.moveCall({
|
|
314
|
-
target:
|
|
315
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
304
|
+
this.txb.moveCall({
|
|
305
|
+
target:Protocol.Instance().RepositoryFn('description_set') as FnCallType,
|
|
306
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
316
307
|
})
|
|
317
308
|
}
|
|
318
309
|
|
|
319
310
|
}
|
|
320
311
|
|
|
321
312
|
set_policy_mode(policy_mode:Repository_Policy_Mode, passport?:PassportObject) {
|
|
322
|
-
let txb = this.protocol.CurrentSession();
|
|
323
313
|
if (passport) {
|
|
324
|
-
txb.moveCall({
|
|
325
|
-
target:
|
|
326
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy_mode), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
314
|
+
this.txb.moveCall({
|
|
315
|
+
target:Protocol.Instance().RepositoryFn('policy_mode_set_with_passport') as FnCallType,
|
|
316
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
327
317
|
})
|
|
328
318
|
} else {
|
|
329
|
-
txb.moveCall({
|
|
330
|
-
target:
|
|
331
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy_mode), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
319
|
+
this.txb.moveCall({
|
|
320
|
+
target:Protocol.Instance().RepositoryFn('policy_mode_set') as FnCallType,
|
|
321
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
332
322
|
})
|
|
333
323
|
}
|
|
334
324
|
}
|
|
@@ -340,19 +330,18 @@ export class Repository {
|
|
|
340
330
|
if (!IsValidDesription(description)) {
|
|
341
331
|
ERROR(Errors.IsValidDesription)
|
|
342
332
|
}
|
|
343
|
-
|
|
344
|
-
let txb = this.protocol.CurrentSession();
|
|
333
|
+
|
|
345
334
|
if (passport) {
|
|
346
|
-
txb.moveCall({
|
|
347
|
-
target:
|
|
348
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy), txb.pure(description),
|
|
349
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
335
|
+
this.txb.moveCall({
|
|
336
|
+
target:Protocol.Instance().RepositoryFn('policy_description_set_with_passport') as FnCallType,
|
|
337
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
|
|
338
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
350
339
|
})
|
|
351
340
|
} else {
|
|
352
|
-
txb.moveCall({
|
|
353
|
-
target:
|
|
354
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(policy), txb.pure(description),
|
|
355
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
341
|
+
this.txb.moveCall({
|
|
342
|
+
target:Protocol.Instance().RepositoryFn('policy_description_set') as FnCallType,
|
|
343
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
|
|
344
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
356
345
|
})
|
|
357
346
|
}
|
|
358
347
|
}
|
|
@@ -362,25 +351,23 @@ export class Repository {
|
|
|
362
351
|
ERROR(Errors.IsValidName, 'policy')
|
|
363
352
|
}
|
|
364
353
|
|
|
365
|
-
let
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (permission_index) {
|
|
354
|
+
let index = this.txb.pure.option('u64', undefined);
|
|
355
|
+
if (permission_index !== undefined) {
|
|
369
356
|
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
370
357
|
ERROR(Errors.IsValidPermissionIndex)
|
|
371
358
|
}
|
|
372
|
-
index = txb.pure
|
|
359
|
+
index = this.txb.pure.option('u64', permission_index);
|
|
373
360
|
}
|
|
374
361
|
|
|
375
362
|
if (passport) {
|
|
376
|
-
txb.moveCall({
|
|
377
|
-
target:
|
|
378
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), index, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
363
|
+
this.txb.moveCall({
|
|
364
|
+
target:Protocol.Instance().RepositoryFn('policy_permission_set_with_passport') as FnCallType,
|
|
365
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
379
366
|
})
|
|
380
367
|
} else {
|
|
381
|
-
txb.moveCall({
|
|
382
|
-
target:
|
|
383
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), index, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
368
|
+
this.txb.moveCall({
|
|
369
|
+
target:Protocol.Instance().RepositoryFn('policy_permission_set') as FnCallType,
|
|
370
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
384
371
|
})
|
|
385
372
|
}
|
|
386
373
|
}
|
|
@@ -389,10 +376,10 @@ export class Repository {
|
|
|
389
376
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
390
377
|
ERROR(Errors.IsValidObjects)
|
|
391
378
|
}
|
|
392
|
-
|
|
393
|
-
txb.moveCall({
|
|
394
|
-
target:
|
|
395
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
|
|
379
|
+
|
|
380
|
+
this.txb.moveCall({
|
|
381
|
+
target:Protocol.Instance().RepositoryFn('permission_set') as FnCallType,
|
|
382
|
+
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
396
383
|
typeArguments:[]
|
|
397
384
|
})
|
|
398
385
|
this.permission = new_permission
|
package/src/resource.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { BCS } from '@mysten/bcs';
|
|
|
2
2
|
import { Protocol, FnCallType, TxbObject, ResourceAddress} from './protocol';
|
|
3
3
|
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
+
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
6
|
+
|
|
5
7
|
export interface Tags {
|
|
6
8
|
address: string;
|
|
7
9
|
nick: string;
|
|
@@ -22,36 +24,35 @@ export class Resource {
|
|
|
22
24
|
static FavorName = "favor";
|
|
23
25
|
|
|
24
26
|
protected object:TxbObject;
|
|
25
|
-
protected
|
|
27
|
+
protected txb;
|
|
26
28
|
|
|
27
29
|
get_object() { return this.object }
|
|
28
|
-
private constructor(
|
|
29
|
-
this.
|
|
30
|
+
private constructor(txb:TransactionBlock) {
|
|
31
|
+
this.txb = txb;
|
|
30
32
|
this.object = '';
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
static From(
|
|
34
|
-
let r = new Resource(
|
|
35
|
-
r.object = Protocol.TXB_OBJECT(
|
|
35
|
+
static From(txb:TransactionBlock, object:TxbObject) : Resource {
|
|
36
|
+
let r = new Resource(txb);
|
|
37
|
+
r.object = Protocol.TXB_OBJECT(txb, object);
|
|
36
38
|
return r
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
launch() {
|
|
40
42
|
if (!this.object) ERROR(Errors.Fail, 'launch object Invalid');
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
43
|
+
this.txb.moveCall({
|
|
44
|
+
target:Protocol.Instance().ResourceFn('create') as FnCallType,
|
|
45
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
add(name:string, object:string[]) {
|
|
48
49
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
|
|
49
50
|
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
this.txb.moveCall({
|
|
53
|
+
target:Protocol.Instance().ResourceFn('add') as FnCallType,
|
|
54
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
55
|
+
this.txb.pure.vector('address', object)]
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -60,10 +61,10 @@ export class Resource {
|
|
|
60
61
|
if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2');
|
|
61
62
|
if (!name) return
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
this.txb.moveCall({
|
|
65
|
+
target:Protocol.Instance().ResourceFn('add2') as FnCallType,
|
|
66
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
|
|
67
|
+
this.txb.pure.vector('string', name)]
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -71,18 +72,18 @@ export class Resource {
|
|
|
71
72
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
72
73
|
if (object.length===0 && !removeall) return;
|
|
73
74
|
|
|
74
|
-
let txb = this.protocol.CurrentSession();
|
|
75
75
|
if (removeall) {
|
|
76
|
-
txb.moveCall({
|
|
77
|
-
target:
|
|
78
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name)]
|
|
76
|
+
this.txb.moveCall({
|
|
77
|
+
target:Protocol.Instance().ResourceFn('remove_all') as FnCallType,
|
|
78
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name)]
|
|
79
79
|
});
|
|
80
80
|
} else if(object) {
|
|
81
81
|
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
82
82
|
|
|
83
|
-
txb.moveCall({
|
|
84
|
-
target:
|
|
85
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name),
|
|
83
|
+
this.txb.moveCall({
|
|
84
|
+
target:Protocol.Instance().ResourceFn('remove') as FnCallType,
|
|
85
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
86
|
+
this.txb.pure.vector('address', object)]
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
89
|
}
|
|
@@ -92,20 +93,20 @@ export class Resource {
|
|
|
92
93
|
if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
|
|
93
94
|
if (!name) return
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
this.txb.moveCall({
|
|
97
|
+
target:Protocol.Instance().ResourceFn('remove2') as FnCallType,
|
|
98
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
|
|
99
|
+
this.txb.pure.vector('string', name)]
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
rename(old_name:string, new_name:string) {
|
|
103
104
|
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
this.txb.moveCall({
|
|
107
|
+
target:Protocol.Instance().ResourceFn('rename') as FnCallType,
|
|
108
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(old_name),
|
|
109
|
+
this.txb.pure.string(new_name)]
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
|
|
@@ -116,25 +117,22 @@ export class Resource {
|
|
|
116
117
|
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
|
|
117
118
|
if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
|
|
118
119
|
|
|
119
|
-
const txb = this.protocol.CurrentSession();
|
|
120
120
|
const encode = new TextEncoder();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
txb.pure(
|
|
126
|
-
txb.pure(tags, 'vector<string>')
|
|
121
|
+
this.txb.moveCall({
|
|
122
|
+
target:Protocol.Instance().ResourceFn('tags_add') as FnCallType,
|
|
123
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object),
|
|
124
|
+
this.txb.pure.string(nick),
|
|
125
|
+
this.txb.pure.vector('string', tags)
|
|
127
126
|
]
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
remove_tags(object:string) {
|
|
132
131
|
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS)]
|
|
132
|
+
|
|
133
|
+
this.txb.moveCall({
|
|
134
|
+
target:Protocol.Instance().ResourceFn('tags_remove') as FnCallType,
|
|
135
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(object)]
|
|
138
136
|
});
|
|
139
137
|
}
|
|
140
138
|
}
|