wowok 1.0.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/dist/community.d.ts +8 -0
- package/dist/community.js +96 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +27 -0
- package/dist/demand.js +176 -0
- package/dist/guard.js +267 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/machine.js +259 -0
- package/dist/passport.js +89 -0
- package/dist/permission.js +217 -0
- package/dist/progress.js +143 -0
- package/dist/protocol.js +177 -0
- package/dist/repository.js +206 -0
- package/dist/reward.js +192 -0
- package/dist/service.js +698 -0
- package/dist/util.js +131 -0
- package/dist/vote.js +273 -0
- package/package.json +24 -0
- package/src/demand.ts +173 -0
- package/src/guard.ts +283 -0
- package/src/index.ts +0 -0
- package/src/machine.ts +257 -0
- package/src/passport.ts +110 -0
- package/src/permission.ts +224 -0
- package/src/progress.ts +139 -0
- package/src/protocol.ts +189 -0
- package/src/repository.ts +213 -0
- package/src/reward.ts +184 -0
- package/src/service.ts +686 -0
- package/src/util.ts +134 -0
- package/src/vote.ts +251 -0
- package/tsconfig.json +110 -0
package/dist/machine.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.change_permission = exports.machine_publish = exports.machine_pause = exports.machine_set_endpoint = exports.machine_clone = exports.machine_remove_repository = exports.machine_add_repository = exports.machine_set_description = exports.launch = exports.destroy = exports.machine = exports.machine_remove_node = exports.machine_add_node2 = exports.machine_add_node = exports.is_valid_name = exports.INITIAL_NODE_NAME = void 0;
|
|
4
|
+
const bcs_1 = require("@mysten/bcs");
|
|
5
|
+
const protocol_1 = require("./protocol");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
exports.INITIAL_NODE_NAME = '';
|
|
8
|
+
// node & forward & forward permission string length validation
|
|
9
|
+
function is_valid_name(name) { return name.length > 0 && name.length < 33; }
|
|
10
|
+
exports.is_valid_name = is_valid_name;
|
|
11
|
+
// 创建新的node加入到machine
|
|
12
|
+
function machine_add_node(txb, machine, permission, nodes, passport) {
|
|
13
|
+
let new_nodes = [];
|
|
14
|
+
nodes.forEach((node) => {
|
|
15
|
+
let n = txb.moveCall({
|
|
16
|
+
target: protocol_1.PROTOCOL.NodeFn('new'),
|
|
17
|
+
arguments: [txb.pure((0, protocol_1.name_data)(node.name)), txb.pure((0, protocol_1.description_data)(node.description))]
|
|
18
|
+
});
|
|
19
|
+
node.pairs.forEach((pair) => {
|
|
20
|
+
pair.forwards.forEach((forward) => {
|
|
21
|
+
if (!forward?.namedOperator && !forward?.permission) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let weight = txb.pure(1);
|
|
25
|
+
if (forward?.weight && forward.weight > 0) {
|
|
26
|
+
weight = txb.pure(forward.weight);
|
|
27
|
+
}
|
|
28
|
+
let per = txb.pure([], bcs_1.BCS.U8);
|
|
29
|
+
if (forward?.permission) {
|
|
30
|
+
per = txb.pure(util_1.BCS_CONVERT.ser_option_u64(forward.permission));
|
|
31
|
+
}
|
|
32
|
+
;
|
|
33
|
+
let namedOperator = txb.pure('');
|
|
34
|
+
if (forward?.namedOperator) {
|
|
35
|
+
namedOperator = txb.pure(forward.namedOperator);
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
let f;
|
|
39
|
+
if (forward?.guard_address) {
|
|
40
|
+
f = txb.moveCall({
|
|
41
|
+
target: protocol_1.PROTOCOL.NodeFn('forward'),
|
|
42
|
+
arguments: [namedOperator, weight, txb.object(forward.guard_address), per]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
f = txb.moveCall({
|
|
47
|
+
target: protocol_1.PROTOCOL.NodeFn('forward2'),
|
|
48
|
+
arguments: [namedOperator, weight, per]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
txb.moveCall({
|
|
52
|
+
target: protocol_1.PROTOCOL.NodeFn('forward_add'),
|
|
53
|
+
arguments: [n, txb.pure(pair.prior_node), txb.pure((0, protocol_1.name_data)(forward.name)),
|
|
54
|
+
txb.pure(util_1.BCS_CONVERT.ser_option_u64(pair.threshold)), f]
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
new_nodes.push(n);
|
|
59
|
+
});
|
|
60
|
+
machine_add_node2(txb, machine, permission, new_nodes, passport);
|
|
61
|
+
}
|
|
62
|
+
exports.machine_add_node = machine_add_node;
|
|
63
|
+
// 把个人拥有的node加入到machine
|
|
64
|
+
function machine_add_node2(txb, machine, permission, nodes, passport) {
|
|
65
|
+
if (passport) {
|
|
66
|
+
txb.moveCall({
|
|
67
|
+
target: protocol_1.PROTOCOL.MachineFn('node_add_with_passport'),
|
|
68
|
+
arguments: [passport, machine, txb.makeMoveVec({ objects: nodes }), permission]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
txb.moveCall({
|
|
73
|
+
target: protocol_1.PROTOCOL.MachineFn('node_add'),
|
|
74
|
+
arguments: [machine, txb.makeMoveVec({ objects: nodes }), permission]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.machine_add_node2 = machine_add_node2;
|
|
79
|
+
// 从machine把node移动到个人地址
|
|
80
|
+
function machine_remove_node(txb, machine, permission, nodes_name, receive_address, passport) {
|
|
81
|
+
if (passport) {
|
|
82
|
+
txb.moveCall({
|
|
83
|
+
target: protocol_1.PROTOCOL.MachineFn('node_remove_with_passport'),
|
|
84
|
+
arguments: [passport, machine, txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
txb.moveCall({
|
|
89
|
+
target: protocol_1.PROTOCOL.MachineFn('node_remove'),
|
|
90
|
+
arguments: [machine, txb.pure(util_1.BCS_CONVERT.ser_vector_string(nodes_name)), permission],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.machine_remove_node = machine_remove_node;
|
|
95
|
+
function machine(txb, permission, description, endpoint_url, passport) {
|
|
96
|
+
if (endpoint_url && endpoint_url.length > protocol_1.MAX_ENDPOINT_LENGTH)
|
|
97
|
+
return undefined;
|
|
98
|
+
let endpoint = endpoint_url ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint_url)) : txb.pure([], bcs_1.BCS.U8);
|
|
99
|
+
if (passport) {
|
|
100
|
+
return txb.moveCall({
|
|
101
|
+
target: protocol_1.PROTOCOL.MachineFn('new_with_passport'),
|
|
102
|
+
arguments: [passport, txb.pure((0, protocol_1.description_data)(description)), endpoint, permission],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
//console.log(endpoint)
|
|
107
|
+
return txb.moveCall({
|
|
108
|
+
target: protocol_1.PROTOCOL.MachineFn('new'),
|
|
109
|
+
arguments: [txb.pure((0, protocol_1.description_data)(description)), endpoint, permission],
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.machine = machine;
|
|
114
|
+
function destroy(txb, machine) {
|
|
115
|
+
return txb.moveCall({
|
|
116
|
+
target: protocol_1.PROTOCOL.MachineFn('destroy'),
|
|
117
|
+
arguments: [machine],
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
exports.destroy = destroy;
|
|
121
|
+
function launch(txb, machine) {
|
|
122
|
+
return txb.moveCall({
|
|
123
|
+
target: protocol_1.PROTOCOL.MachineFn('create'),
|
|
124
|
+
arguments: [machine],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.launch = launch;
|
|
128
|
+
function machine_set_description(txb, machine, permission, description, passport) {
|
|
129
|
+
if (passport) {
|
|
130
|
+
txb.moveCall({
|
|
131
|
+
target: protocol_1.PROTOCOL.MachineFn('description_set_with_passport'),
|
|
132
|
+
arguments: [passport, machine, txb.pure((0, protocol_1.description_data)(description)), permission],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
txb.moveCall({
|
|
137
|
+
target: protocol_1.PROTOCOL.MachineFn('description_set'),
|
|
138
|
+
arguments: [machine, txb.pure((0, protocol_1.description_data)(description)), permission],
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.machine_set_description = machine_set_description;
|
|
143
|
+
function machine_add_repository(txb, machine, permission, repository, passport) {
|
|
144
|
+
if (passport) {
|
|
145
|
+
txb.moveCall({
|
|
146
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_add_with_passport'),
|
|
147
|
+
arguments: [passport, machine, repository, permission],
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
txb.moveCall({
|
|
152
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_add'),
|
|
153
|
+
arguments: [machine, repository, permission],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.machine_add_repository = machine_add_repository;
|
|
158
|
+
function machine_remove_repository(txb, machine, permission, repositories, removeall, passport) {
|
|
159
|
+
if (passport) {
|
|
160
|
+
if (removeall) {
|
|
161
|
+
txb.moveCall({
|
|
162
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_remove_all_with_passport'),
|
|
163
|
+
arguments: [passport, machine, permission],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
txb.moveCall({
|
|
168
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_remove_with_passport'),
|
|
169
|
+
arguments: [passport, machine, txb.pure(repositories, 'vector<address>'), permission],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
if (removeall) {
|
|
175
|
+
txb.moveCall({
|
|
176
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_remove_all'),
|
|
177
|
+
arguments: [machine, permission],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
txb.moveCall({
|
|
182
|
+
target: protocol_1.PROTOCOL.MachineFn('repository_remove'),
|
|
183
|
+
arguments: [machine, txb.pure(repositories, 'vector<address>'), permission],
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.machine_remove_repository = machine_remove_repository;
|
|
189
|
+
function machine_clone(txb, machine, permission, passport) {
|
|
190
|
+
if (passport) {
|
|
191
|
+
return txb.moveCall({
|
|
192
|
+
target: protocol_1.PROTOCOL.MachineFn('clone_with_passport'),
|
|
193
|
+
arguments: [passport, machine, permission],
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return txb.moveCall({
|
|
198
|
+
target: protocol_1.PROTOCOL.MachineFn('clone'),
|
|
199
|
+
arguments: [machine, permission],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.machine_clone = machine_clone;
|
|
204
|
+
function machine_set_endpoint(txb, machine, permission, endpoint_url, passport) {
|
|
205
|
+
if (endpoint_url && endpoint_url.length > protocol_1.MAX_ENDPOINT_LENGTH)
|
|
206
|
+
return undefined;
|
|
207
|
+
let endpoint = endpoint_url ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint_url)) : txb.pure([], bcs_1.BCS.U8);
|
|
208
|
+
if (passport) {
|
|
209
|
+
txb.moveCall({
|
|
210
|
+
target: protocol_1.PROTOCOL.MachineFn('endpoint_set_with_passport'),
|
|
211
|
+
arguments: [passport, machine, endpoint, permission],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
txb.moveCall({
|
|
216
|
+
target: protocol_1.PROTOCOL.MachineFn('endpoint_set'),
|
|
217
|
+
arguments: [machine, endpoint, permission],
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.machine_set_endpoint = machine_set_endpoint;
|
|
222
|
+
function machine_pause(txb, machine, permission, bPaused, passport) {
|
|
223
|
+
if (passport) {
|
|
224
|
+
txb.moveCall({
|
|
225
|
+
target: protocol_1.PROTOCOL.MachineFn('pause_with_passport'),
|
|
226
|
+
arguments: [passport, machine, txb.pure(bPaused), permission],
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
txb.moveCall({
|
|
231
|
+
target: protocol_1.PROTOCOL.MachineFn('pause'),
|
|
232
|
+
arguments: [machine, txb.pure(bPaused), permission],
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.machine_pause = machine_pause;
|
|
237
|
+
function machine_publish(txb, machine, permission, passport) {
|
|
238
|
+
if (passport) {
|
|
239
|
+
txb.moveCall({
|
|
240
|
+
target: protocol_1.PROTOCOL.MachineFn('publish_with_passport'),
|
|
241
|
+
arguments: [passport, machine, permission],
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
txb.moveCall({
|
|
246
|
+
target: protocol_1.PROTOCOL.MachineFn('publish'),
|
|
247
|
+
arguments: [machine, permission],
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.machine_publish = machine_publish;
|
|
252
|
+
function change_permission(txb, machine, old_permission, new_permission) {
|
|
253
|
+
txb.moveCall({
|
|
254
|
+
target: protocol_1.PROTOCOL.MachineFn('permission_set'),
|
|
255
|
+
arguments: [machine, old_permission, new_permission],
|
|
256
|
+
typeArguments: []
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
exports.change_permission = change_permission;
|
package/dist/passport.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.query_cmd_fn = exports.destroy = exports.verify = exports.passport_quries = exports.MAX_GUARD_COUNT = void 0;
|
|
4
|
+
const transactions_1 = require("@mysten/sui.js/transactions");
|
|
5
|
+
const protocol_1 = require("./protocol");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
const guard_1 = require("./guard");
|
|
8
|
+
exports.MAX_GUARD_COUNT = 4;
|
|
9
|
+
const passport_quries = async (guards) => {
|
|
10
|
+
let sense_objects = guards.map((value) => {
|
|
11
|
+
return { objectid: value, callback: guard_1.sense_objects_fn, data: [] };
|
|
12
|
+
});
|
|
13
|
+
await protocol_1.PROTOCOL.Query(sense_objects); // objects need quering in guards
|
|
14
|
+
let sense_objects_result = [];
|
|
15
|
+
sense_objects.forEach((value) => {
|
|
16
|
+
sense_objects_result = sense_objects_result.concat(value.data);
|
|
17
|
+
});
|
|
18
|
+
sense_objects_result = (0, util_1.array_unique)(sense_objects_result);
|
|
19
|
+
console.log(sense_objects_result);
|
|
20
|
+
let queries = sense_objects_result.map((value) => {
|
|
21
|
+
return { objectid: value, callback: exports.query_cmd_fn };
|
|
22
|
+
});
|
|
23
|
+
await protocol_1.PROTOCOL.Query(queries, { 'showType': true }); // queries for passport verifing
|
|
24
|
+
return queries.map((value) => {
|
|
25
|
+
return value.data;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.passport_quries = passport_quries;
|
|
29
|
+
// return passport object for using
|
|
30
|
+
function verify(txb, passport_queries) {
|
|
31
|
+
if (passport_queries.length == 0 || passport_queries.length > exports.MAX_GUARD_COUNT) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
let guard_ids = passport_queries.map((value) => value.id);
|
|
35
|
+
var passport = txb.moveCall({
|
|
36
|
+
target: protocol_1.PROTOCOL.PassportFn('new'),
|
|
37
|
+
arguments: [txb.object(guard_ids[0]), txb.object(protocol_1.CLOCK_OBJECT)]
|
|
38
|
+
});
|
|
39
|
+
// add others guards, if any
|
|
40
|
+
for (let i = 1; i < guard_ids.length; i++) {
|
|
41
|
+
txb.moveCall({
|
|
42
|
+
target: protocol_1.PROTOCOL.PassportFn('guard_add'),
|
|
43
|
+
arguments: [passport, txb.object(guard_ids[i])]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// rules: 'verify' & 'query' in turns;'verify' at final end.
|
|
47
|
+
for (let i = 0; i < passport_queries.length; i++) {
|
|
48
|
+
txb.moveCall({
|
|
49
|
+
target: protocol_1.PROTOCOL.PassportFn('passport_verify'),
|
|
50
|
+
arguments: [passport]
|
|
51
|
+
});
|
|
52
|
+
txb.moveCall({
|
|
53
|
+
target: passport_queries[i].target,
|
|
54
|
+
arguments: [txb.object(passport_queries[i].object), passport],
|
|
55
|
+
typeArguments: passport_queries[i].types,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
txb.moveCall({
|
|
59
|
+
target: protocol_1.PROTOCOL.PassportFn('passport_verify'),
|
|
60
|
+
arguments: [passport]
|
|
61
|
+
});
|
|
62
|
+
return passport;
|
|
63
|
+
}
|
|
64
|
+
exports.verify = verify;
|
|
65
|
+
function destroy(txb, passport) {
|
|
66
|
+
txb.moveCall({
|
|
67
|
+
target: protocol_1.PROTOCOL.PassportFn('destroy'),
|
|
68
|
+
arguments: [passport]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
exports.destroy = destroy;
|
|
72
|
+
// construct Guard_Query_Object of wowok objects for passport verify
|
|
73
|
+
const query_cmd_fn = (response, param, option) => {
|
|
74
|
+
if (!response.error && response.data?.objectId == param.objectid && response.data?.type) {
|
|
75
|
+
for (let k = 0; k < protocol_1.OBJECTS_TYPE.length; k++) {
|
|
76
|
+
if (response?.data?.type.includes(protocol_1.OBJECTS_TYPE[k])) { // type: pack::m::Object<...>
|
|
77
|
+
param.data = { target: protocol_1.OBJECTS_TYPE_PREFIX[k] + 'guard_query',
|
|
78
|
+
object: transactions_1.Inputs.SharedObjectRef({
|
|
79
|
+
objectId: param.objectid,
|
|
80
|
+
mutable: false,
|
|
81
|
+
initialSharedVersion: response.data.version,
|
|
82
|
+
}),
|
|
83
|
+
types: (0, util_1.parse_object_type)(response?.data?.type),
|
|
84
|
+
id: param.objectid, };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.query_cmd_fn = query_cmd_fn;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.change_owner = exports.remove_admin = exports.add_admin = exports.set_description = exports.remove_entity = exports.remove_index = exports.add_or_modify = exports.set_guard = exports.add_entity = exports.launch = exports.permission = exports.PermissionIndex = exports.MAX_PERMISSION_INDEX_COUNT = exports.MAX_ENTITY_COUNT = exports.MAX_ADMIN_COUNT = void 0;
|
|
4
|
+
const bcs_1 = require("@mysten/bcs");
|
|
5
|
+
const protocol_1 = require("./protocol");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
exports.MAX_ADMIN_COUNT = 64;
|
|
8
|
+
exports.MAX_ENTITY_COUNT = 1024;
|
|
9
|
+
exports.MAX_PERMISSION_INDEX_COUNT = 512;
|
|
10
|
+
var PermissionIndex;
|
|
11
|
+
(function (PermissionIndex) {
|
|
12
|
+
PermissionIndex[PermissionIndex["repository"] = 100] = "repository";
|
|
13
|
+
PermissionIndex[PermissionIndex["repository_set_description_set"] = 101] = "repository_set_description_set";
|
|
14
|
+
PermissionIndex[PermissionIndex["repository_set_policy_mode"] = 102] = "repository_set_policy_mode";
|
|
15
|
+
PermissionIndex[PermissionIndex["repository_add_policies"] = 106] = "repository_add_policies";
|
|
16
|
+
PermissionIndex[PermissionIndex["repository_remove_policies"] = 107] = "repository_remove_policies";
|
|
17
|
+
PermissionIndex[PermissionIndex["repository_set_policy_description"] = 109] = "repository_set_policy_description";
|
|
18
|
+
PermissionIndex[PermissionIndex["repository_set_policy_permission"] = 110] = "repository_set_policy_permission";
|
|
19
|
+
PermissionIndex[PermissionIndex["vote"] = 150] = "vote";
|
|
20
|
+
PermissionIndex[PermissionIndex["vote_set_description"] = 151] = "vote_set_description";
|
|
21
|
+
PermissionIndex[PermissionIndex["vote_set_reference"] = 152] = "vote_set_reference";
|
|
22
|
+
PermissionIndex[PermissionIndex["vote_add_guard"] = 153] = "vote_add_guard";
|
|
23
|
+
PermissionIndex[PermissionIndex["vote_remove_guard"] = 154] = "vote_remove_guard";
|
|
24
|
+
PermissionIndex[PermissionIndex["vote_add_option"] = 155] = "vote_add_option";
|
|
25
|
+
PermissionIndex[PermissionIndex["vote_remove_option"] = 156] = "vote_remove_option";
|
|
26
|
+
PermissionIndex[PermissionIndex["vote_set_max_choice_count"] = 157] = "vote_set_max_choice_count";
|
|
27
|
+
PermissionIndex[PermissionIndex["vote_open_voting"] = 158] = "vote_open_voting";
|
|
28
|
+
PermissionIndex[PermissionIndex["vote_lock_deadline"] = 159] = "vote_lock_deadline";
|
|
29
|
+
PermissionIndex[PermissionIndex["vote_expand_deadline"] = 160] = "vote_expand_deadline";
|
|
30
|
+
PermissionIndex[PermissionIndex["vote_lock_guard"] = 161] = "vote_lock_guard";
|
|
31
|
+
PermissionIndex[PermissionIndex["service"] = 200] = "service";
|
|
32
|
+
PermissionIndex[PermissionIndex["service_set_description"] = 201] = "service_set_description";
|
|
33
|
+
PermissionIndex[PermissionIndex["service_set_price"] = 202] = "service_set_price";
|
|
34
|
+
PermissionIndex[PermissionIndex["service_set_stock"] = 203] = "service_set_stock";
|
|
35
|
+
PermissionIndex[PermissionIndex["service_add_stock"] = 203] = "service_add_stock";
|
|
36
|
+
PermissionIndex[PermissionIndex["service_reduce_stock"] = 203] = "service_reduce_stock";
|
|
37
|
+
PermissionIndex[PermissionIndex["service_set_payee"] = 205] = "service_set_payee";
|
|
38
|
+
PermissionIndex[PermissionIndex["service_repository_add"] = 206] = "service_repository_add";
|
|
39
|
+
PermissionIndex[PermissionIndex["service_repository_remove"] = 207] = "service_repository_remove";
|
|
40
|
+
PermissionIndex[PermissionIndex["service_add_withdraw_guards"] = 208] = "service_add_withdraw_guards";
|
|
41
|
+
PermissionIndex[PermissionIndex["service_remove_withdraw_guards"] = 209] = "service_remove_withdraw_guards";
|
|
42
|
+
PermissionIndex[PermissionIndex["service_add_refund_guards"] = 210] = "service_add_refund_guards";
|
|
43
|
+
PermissionIndex[PermissionIndex["service_remove_refund_guards"] = 211] = "service_remove_refund_guards";
|
|
44
|
+
PermissionIndex[PermissionIndex["service_add_sales"] = 212] = "service_add_sales";
|
|
45
|
+
PermissionIndex[PermissionIndex["service_remove_sales"] = 213] = "service_remove_sales";
|
|
46
|
+
PermissionIndex[PermissionIndex["service_discount_transfer"] = 214] = "service_discount_transfer";
|
|
47
|
+
PermissionIndex[PermissionIndex["service_withdraw"] = 216] = "service_withdraw";
|
|
48
|
+
PermissionIndex[PermissionIndex["service_set_buy_guard"] = 217] = "service_set_buy_guard";
|
|
49
|
+
PermissionIndex[PermissionIndex["service_set_machine"] = 218] = "service_set_machine";
|
|
50
|
+
PermissionIndex[PermissionIndex["service_set_endpoint"] = 219] = "service_set_endpoint";
|
|
51
|
+
PermissionIndex[PermissionIndex["service_publish"] = 220] = "service_publish";
|
|
52
|
+
PermissionIndex[PermissionIndex["service_clone"] = 221] = "service_clone";
|
|
53
|
+
PermissionIndex[PermissionIndex["service_set_customer_required"] = 222] = "service_set_customer_required";
|
|
54
|
+
PermissionIndex[PermissionIndex["service_remove_customer_required"] = 222] = "service_remove_customer_required";
|
|
55
|
+
PermissionIndex[PermissionIndex["service_change_required_pubkey"] = 222] = "service_change_required_pubkey";
|
|
56
|
+
PermissionIndex[PermissionIndex["service_change_order_required_pubkey"] = 224] = "service_change_order_required_pubkey";
|
|
57
|
+
PermissionIndex[PermissionIndex["service_pause"] = 225] = "service_pause";
|
|
58
|
+
PermissionIndex[PermissionIndex["reward"] = 240] = "reward";
|
|
59
|
+
PermissionIndex[PermissionIndex["reward_refund"] = 241] = "reward_refund";
|
|
60
|
+
PermissionIndex[PermissionIndex["reward_expand_time"] = 242] = "reward_expand_time";
|
|
61
|
+
PermissionIndex[PermissionIndex["reward_add_guard"] = 243] = "reward_add_guard";
|
|
62
|
+
PermissionIndex[PermissionIndex["reward_remove_guard"] = 244] = "reward_remove_guard";
|
|
63
|
+
PermissionIndex[PermissionIndex["reward_set_description"] = 245] = "reward_set_description";
|
|
64
|
+
PermissionIndex[PermissionIndex["reward_lock_guards"] = 246] = "reward_lock_guards";
|
|
65
|
+
PermissionIndex[PermissionIndex["demand"] = 260] = "demand";
|
|
66
|
+
PermissionIndex[PermissionIndex["demand_refund"] = 261] = "demand_refund";
|
|
67
|
+
PermissionIndex[PermissionIndex["demand_expand_time"] = 262] = "demand_expand_time";
|
|
68
|
+
PermissionIndex[PermissionIndex["demand_set_guard"] = 263] = "demand_set_guard";
|
|
69
|
+
PermissionIndex[PermissionIndex["demand_set_description"] = 264] = "demand_set_description";
|
|
70
|
+
PermissionIndex[PermissionIndex["demand_yes"] = 265] = "demand_yes";
|
|
71
|
+
PermissionIndex[PermissionIndex["machine"] = 600] = "machine";
|
|
72
|
+
PermissionIndex[PermissionIndex["machine_set_description"] = 601] = "machine_set_description";
|
|
73
|
+
PermissionIndex[PermissionIndex["machine_add_repository"] = 602] = "machine_add_repository";
|
|
74
|
+
PermissionIndex[PermissionIndex["machine_remove_repository"] = 603] = "machine_remove_repository";
|
|
75
|
+
PermissionIndex[PermissionIndex["machine_clone"] = 604] = "machine_clone";
|
|
76
|
+
PermissionIndex[PermissionIndex["machine_add_node"] = 606] = "machine_add_node";
|
|
77
|
+
PermissionIndex[PermissionIndex["machine_add_node2"] = 606] = "machine_add_node2";
|
|
78
|
+
PermissionIndex[PermissionIndex["machine_remove_node"] = 607] = "machine_remove_node";
|
|
79
|
+
PermissionIndex[PermissionIndex["machine_set_endpoint"] = 608] = "machine_set_endpoint";
|
|
80
|
+
PermissionIndex[PermissionIndex["machine_pause"] = 609] = "machine_pause";
|
|
81
|
+
PermissionIndex[PermissionIndex["machine_publish"] = 610] = "machine_publish";
|
|
82
|
+
PermissionIndex[PermissionIndex["progress"] = 650] = "progress";
|
|
83
|
+
PermissionIndex[PermissionIndex["progress_set_namedOperator"] = 651] = "progress_set_namedOperator";
|
|
84
|
+
PermissionIndex[PermissionIndex["progress_bind_task"] = 652] = "progress_bind_task";
|
|
85
|
+
PermissionIndex[PermissionIndex["progress_set_context_repository"] = 653] = "progress_set_context_repository";
|
|
86
|
+
PermissionIndex[PermissionIndex["progress_unhold"] = 654] = "progress_unhold";
|
|
87
|
+
})(PermissionIndex || (exports.PermissionIndex = PermissionIndex = {}));
|
|
88
|
+
function permission(txb, description) {
|
|
89
|
+
return txb.moveCall({
|
|
90
|
+
target: protocol_1.PROTOCOL.PermissionFn('new'),
|
|
91
|
+
arguments: [txb.pure((0, protocol_1.description_data)(description))]
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.permission = permission;
|
|
95
|
+
function launch(txb, permission) {
|
|
96
|
+
return txb.moveCall({
|
|
97
|
+
target: protocol_1.PROTOCOL.PermissionFn('create'),
|
|
98
|
+
arguments: [permission]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
exports.launch = launch;
|
|
102
|
+
function add_entity(txb, permission, entities) {
|
|
103
|
+
let guards = [];
|
|
104
|
+
for (let i = 0; i < entities.length; i++) {
|
|
105
|
+
let entity = entities[i];
|
|
106
|
+
let indexes = [];
|
|
107
|
+
for (let j = 0; j < entity.permissions.length; j++) {
|
|
108
|
+
let index = entity.permissions[j];
|
|
109
|
+
if (index?.guard) {
|
|
110
|
+
guards.push({ who: entity.who, index: index.index, guard: index.guard });
|
|
111
|
+
}
|
|
112
|
+
if (!indexes.includes(index.index)) {
|
|
113
|
+
indexes.push(index.index);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (indexes.length > 0) {
|
|
117
|
+
txb.moveCall({
|
|
118
|
+
target: protocol_1.PROTOCOL.PermissionFn('add_batch'),
|
|
119
|
+
arguments: [permission, txb.pure(entity.who, bcs_1.BCS.ADDRESS), txb.pure(indexes, 'vector<u64>')]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// set guards
|
|
124
|
+
guards.forEach(({ who, index, guard }) => {
|
|
125
|
+
txb.moveCall({
|
|
126
|
+
target: protocol_1.PROTOCOL.PermissionFn('guard_set'),
|
|
127
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, guard)]
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.add_entity = add_entity;
|
|
132
|
+
// guard: undefine to set none
|
|
133
|
+
function set_guard(txb, permission, who, index, guard) {
|
|
134
|
+
if (guard) {
|
|
135
|
+
txb.moveCall({
|
|
136
|
+
target: protocol_1.PROTOCOL.PermissionFn('guard_set'),
|
|
137
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, guard)]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
txb.moveCall({
|
|
142
|
+
target: protocol_1.PROTOCOL.PermissionFn('guard_none'),
|
|
143
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, bcs_1.BCS.U64)]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.set_guard = set_guard;
|
|
148
|
+
function add_or_modify(txb, permission, who, index, modifyIfOldExist, guard) {
|
|
149
|
+
if (guard) {
|
|
150
|
+
txb.moveCall({
|
|
151
|
+
target: protocol_1.PROTOCOL.PermissionFn('add_or_modify'),
|
|
152
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, guard), txb.pure(modifyIfOldExist, bcs_1.BCS.BOOL)]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
txb.moveCall({
|
|
157
|
+
target: protocol_1.PROTOCOL.PermissionFn('add_or_modify'),
|
|
158
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, bcs_1.BCS.U64), txb.pure([], bcs_1.BCS.U8), txb.pure(modifyIfOldExist, bcs_1.BCS.BOOL)]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.add_or_modify = add_or_modify;
|
|
163
|
+
function remove_index(txb, permission, who, index) {
|
|
164
|
+
if (index) {
|
|
165
|
+
txb.moveCall({
|
|
166
|
+
target: protocol_1.PROTOCOL.PermissionFn('remove_index'),
|
|
167
|
+
arguments: [permission, txb.pure(who, bcs_1.BCS.ADDRESS), txb.pure(index, 'vector<u64>')]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.remove_index = remove_index;
|
|
172
|
+
function remove_entity(txb, permission, who) {
|
|
173
|
+
if (who) {
|
|
174
|
+
txb.moveCall({
|
|
175
|
+
target: protocol_1.PROTOCOL.PermissionFn('remove'),
|
|
176
|
+
arguments: [permission, txb.pure(who, 'vector<address>')]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.remove_entity = remove_entity;
|
|
181
|
+
function set_description(txb, permission, description) {
|
|
182
|
+
txb.moveCall({
|
|
183
|
+
target: protocol_1.PROTOCOL.PermissionFn('description_set'),
|
|
184
|
+
arguments: [permission, txb.pure((0, protocol_1.description_data)(description))]
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
exports.set_description = set_description;
|
|
188
|
+
function add_admin(txb, permission, admin) {
|
|
189
|
+
let n = (0, util_1.array_unique)(admin);
|
|
190
|
+
txb.moveCall({
|
|
191
|
+
target: protocol_1.PROTOCOL.PermissionFn('admin_add_batch'),
|
|
192
|
+
arguments: [permission, txb.pure(n, 'vector<address>')]
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
exports.add_admin = add_admin;
|
|
196
|
+
function remove_admin(txb, permission, admin, removeall) {
|
|
197
|
+
if (removeall) {
|
|
198
|
+
txb.moveCall({
|
|
199
|
+
target: protocol_1.PROTOCOL.PermissionFn('admins_clear'),
|
|
200
|
+
arguments: [permission]
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
txb.moveCall({
|
|
205
|
+
target: protocol_1.PROTOCOL.PermissionFn('admin_remove_batch'),
|
|
206
|
+
arguments: [permission, txb.pure(admin, 'vector<address>')]
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.remove_admin = remove_admin;
|
|
211
|
+
function change_owner(txb, permission, new_owner) {
|
|
212
|
+
txb.moveCall({
|
|
213
|
+
target: protocol_1.PROTOCOL.PermissionFn('builder_set'),
|
|
214
|
+
arguments: [permission, txb.pure(new_owner, bcs_1.BCS.ADDRESS)]
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
exports.change_owner = change_owner;
|