wowok 1.0.4 → 1.0.6
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/demand.js +2 -2
- package/dist/graphql.js +102 -0
- package/dist/guard.js +175 -41
- package/dist/index.js +46 -0
- package/dist/machine.js +17 -10
- package/dist/passport.js +54 -20
- package/dist/permission.js +8 -2
- package/dist/progress.js +62 -13
- package/dist/protocol.js +15 -7
- package/dist/repository.js +11 -14
- package/dist/reward.js +6 -5
- package/dist/service.js +9 -5
- package/dist/util.js +13 -1
- package/package.json +9 -4
- package/src/demand.ts +2 -2
- package/src/graphql.ts +103 -0
- package/src/guard.ts +191 -43
- package/src/index.ts +32 -0
- package/src/machine.ts +18 -12
- package/src/passport.ts +60 -26
- package/src/permission.ts +7 -2
- package/src/progress.ts +70 -15
- package/src/protocol.ts +16 -9
- package/src/repository.ts +17 -20
- package/src/reward.ts +12 -9
- package/src/service.ts +12 -8
- package/src/{util.ts → utils.ts} +18 -9
- package/src/vote.ts +1 -1
- package/src/address.graphql +0 -0
- package/src/object.graphql +0 -30
package/dist/passport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.graphql_query_objects = exports.rpc_query_cmd_fn = exports.destroy = exports.verify = exports.passport_queries = exports.MAX_GUARD_COUNT = void 0;
|
|
4
4
|
const transactions_1 = require("@mysten/sui.js/transactions");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
6
|
const util_1 = require("./util");
|
|
@@ -16,39 +16,54 @@ exports.MAX_GUARD_COUNT = 8;
|
|
|
16
16
|
// 6. destroy passport
|
|
17
17
|
const passport_queries = async (guards) => {
|
|
18
18
|
let sense_objects = guards.map((value) => {
|
|
19
|
-
return { objectid: value, callback: guard_1.
|
|
19
|
+
return { objectid: value, callback: guard_1.rpc_sense_objects_fn, data: [] };
|
|
20
20
|
});
|
|
21
21
|
await protocol_1.PROTOCOL.Query(sense_objects); // objects need quering in guards
|
|
22
22
|
let sense_objects_result = [];
|
|
23
23
|
sense_objects.forEach((value) => {
|
|
24
24
|
sense_objects_result = sense_objects_result.concat(value.data);
|
|
25
25
|
});
|
|
26
|
-
sense_objects_result = (0, util_1.array_unique)(sense_objects_result);
|
|
27
|
-
console.log(sense_objects_result);
|
|
26
|
+
sense_objects_result = (0, util_1.array_unique)(sense_objects_result); // objects in guards
|
|
27
|
+
// console.log(sense_objects_result);
|
|
28
28
|
let queries = sense_objects_result.map((value) => {
|
|
29
|
-
return { objectid: value, callback: exports.
|
|
29
|
+
return { objectid: value, callback: exports.rpc_query_cmd_fn, data: [] };
|
|
30
30
|
});
|
|
31
31
|
await protocol_1.PROTOCOL.Query(queries, { 'showType': true }); // queries for passport verifing
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
let res = [];
|
|
33
|
+
sense_objects.forEach((guard) => {
|
|
34
|
+
res = res.concat(guard.data.map((object) => {
|
|
35
|
+
let data = queries.filter((v) => {
|
|
36
|
+
return v.objectid == object;
|
|
37
|
+
});
|
|
38
|
+
if (!data) {
|
|
39
|
+
console.error('error find data');
|
|
40
|
+
console.log(queries);
|
|
41
|
+
console.log(object);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return data[0].data;
|
|
45
|
+
}));
|
|
34
46
|
});
|
|
47
|
+
return res;
|
|
35
48
|
};
|
|
36
49
|
exports.passport_queries = passport_queries;
|
|
37
|
-
// return passport object
|
|
38
|
-
function verify(txb, passport_queries) {
|
|
39
|
-
if (passport_queries.length == 0 || passport_queries.length > exports.MAX_GUARD_COUNT) {
|
|
50
|
+
// return passport object used
|
|
51
|
+
function verify(txb, guards, passport_queries) {
|
|
52
|
+
if (!guards || passport_queries.length == 0 || passport_queries.length > exports.MAX_GUARD_COUNT) {
|
|
40
53
|
return false;
|
|
41
54
|
}
|
|
42
|
-
|
|
55
|
+
console.log(guards);
|
|
56
|
+
console.log(passport_queries);
|
|
43
57
|
var passport = txb.moveCall({
|
|
44
58
|
target: protocol_1.PROTOCOL.PassportFn('new'),
|
|
45
|
-
arguments: [
|
|
59
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, guards[0]), txb.object(protocol_1.CLOCK_OBJECT)]
|
|
46
60
|
});
|
|
47
61
|
// add others guards, if any
|
|
48
|
-
for (let i = 1; i <
|
|
62
|
+
for (let i = 1; i < guards.length; i++) {
|
|
63
|
+
console.log('dfdfdf');
|
|
49
64
|
txb.moveCall({
|
|
50
65
|
target: protocol_1.PROTOCOL.PassportFn('guard_add'),
|
|
51
|
-
arguments: [passport,
|
|
66
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, guards[i])]
|
|
52
67
|
});
|
|
53
68
|
}
|
|
54
69
|
// rules: 'verify' & 'query' in turns;'verify' at final end.
|
|
@@ -79,13 +94,13 @@ function destroy(txb, passport) {
|
|
|
79
94
|
}
|
|
80
95
|
exports.destroy = destroy;
|
|
81
96
|
// construct Guard_Query_Object of wowok objects for passport verify
|
|
82
|
-
const
|
|
97
|
+
const rpc_query_cmd_fn = (response, param, option) => {
|
|
83
98
|
if (!response.error && response.data?.objectId == param.objectid && response.data?.type) {
|
|
84
|
-
for (let k = 0; k < protocol_1.OBJECTS_TYPE.length; k++) {
|
|
85
|
-
if (response?.data?.type.includes(protocol_1.OBJECTS_TYPE[k])) { // type: pack::m::Object<...>
|
|
86
|
-
param.data = { target: protocol_1.OBJECTS_TYPE_PREFIX[k] + 'guard_query',
|
|
99
|
+
for (let k = 0; k < (0, protocol_1.OBJECTS_TYPE)().length; k++) {
|
|
100
|
+
if (response?.data?.type.includes((0, protocol_1.OBJECTS_TYPE)()[k])) { // type: pack::m::Object<...>
|
|
101
|
+
param.data = { target: (0, protocol_1.OBJECTS_TYPE_PREFIX)()[k] + 'guard_query',
|
|
87
102
|
object: transactions_1.Inputs.SharedObjectRef({
|
|
88
|
-
objectId:
|
|
103
|
+
objectId: response.data.objectId,
|
|
89
104
|
mutable: false,
|
|
90
105
|
initialSharedVersion: response.data.version,
|
|
91
106
|
}),
|
|
@@ -95,4 +110,23 @@ const query_cmd_fn = (response, param, option) => {
|
|
|
95
110
|
}
|
|
96
111
|
}
|
|
97
112
|
};
|
|
98
|
-
exports.
|
|
113
|
+
exports.rpc_query_cmd_fn = rpc_query_cmd_fn;
|
|
114
|
+
const graphql_query_objects = (nodes) => {
|
|
115
|
+
let ret = [];
|
|
116
|
+
nodes.forEach((node) => {
|
|
117
|
+
for (let k = 0; k < (0, protocol_1.OBJECTS_TYPE)().length; k++) {
|
|
118
|
+
if (node?.asMoveObject?.contents?.type?.repr?.includes((0, protocol_1.OBJECTS_TYPE)()[k])) { // type: pack::m::Object<...>
|
|
119
|
+
ret.push({ target: (0, protocol_1.OBJECTS_TYPE_PREFIX)()[k] + 'guard_query',
|
|
120
|
+
object: transactions_1.Inputs.SharedObjectRef({
|
|
121
|
+
objectId: node.address,
|
|
122
|
+
mutable: false,
|
|
123
|
+
initialSharedVersion: node.version,
|
|
124
|
+
}),
|
|
125
|
+
types: (0, util_1.parse_object_type)(node.asMoveObject.contents.type.repr),
|
|
126
|
+
id: node.address, });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return ret;
|
|
131
|
+
};
|
|
132
|
+
exports.graphql_query_objects = graphql_query_objects;
|
package/dist/permission.js
CHANGED
|
@@ -91,9 +91,11 @@ const IsValidUserDefinedIndex = (index) => {
|
|
|
91
91
|
};
|
|
92
92
|
exports.IsValidUserDefinedIndex = IsValidUserDefinedIndex;
|
|
93
93
|
const IsValidPermissionIndex = (index) => {
|
|
94
|
+
//console.log(index)
|
|
94
95
|
if (Object.values(PermissionIndex).includes(index)) {
|
|
95
96
|
return true;
|
|
96
97
|
}
|
|
98
|
+
//console.log(Object.keys(PermissionIndex))
|
|
97
99
|
return (0, exports.IsValidUserDefinedIndex)(index);
|
|
98
100
|
};
|
|
99
101
|
exports.IsValidPermissionIndex = IsValidPermissionIndex;
|
|
@@ -132,10 +134,14 @@ function add_entity(txb, permission, entities) {
|
|
|
132
134
|
return false;
|
|
133
135
|
let bValid = true;
|
|
134
136
|
let e = entities.forEach((v) => {
|
|
135
|
-
if (!(0, protocol_1.IsValidArray)(v.permissions, exports.IsValidPermissionIndex))
|
|
136
|
-
bValid = false;
|
|
137
137
|
if (!(0, protocol_1.IsValidAddress)(v.entity_address))
|
|
138
138
|
bValid = false;
|
|
139
|
+
v.permissions.forEach((p) => {
|
|
140
|
+
if (!(0, exports.IsValidPermissionIndex)(p.index))
|
|
141
|
+
bValid = false;
|
|
142
|
+
if (p?.guard && !(0, protocol_1.IsValidObjects)([p.guard]))
|
|
143
|
+
bValid = false;
|
|
144
|
+
});
|
|
139
145
|
});
|
|
140
146
|
if (!bValid)
|
|
141
147
|
return false;
|
package/dist/progress.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hold = exports.next = exports.progress_unhold = exports.progress_set_context_repository = exports.progress_bind_task = exports.progress_set_namedOperator = exports.destroy = exports.launch_as_child = exports.launch = exports.progress = exports.MAX_NAMED_OPERATOR_COUNT = void 0;
|
|
3
|
+
exports.hold = exports.next = exports.progress_parent = exports.progress_unhold = exports.progress_set_context_repository = exports.progress_bind_task = exports.progress_set_namedOperator = exports.destroy = exports.launch_as_child = exports.launch = exports.progress = exports.MAX_NAMED_OPERATOR_COUNT = void 0;
|
|
4
4
|
const bcs_1 = require("@mysten/bcs");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
6
|
const util_1 = require("./util");
|
|
@@ -132,41 +132,90 @@ function progress_set_context_repository(txb, machine, permission, progress, rep
|
|
|
132
132
|
return true;
|
|
133
133
|
}
|
|
134
134
|
exports.progress_set_context_repository = progress_set_context_repository;
|
|
135
|
-
function progress_unhold(txb, machine, permission, progress, next) {
|
|
135
|
+
function progress_unhold(txb, machine, permission, progress, next, passport) {
|
|
136
136
|
if (!(0, protocol_1.IsValidObjects)([machine, permission, progress]))
|
|
137
137
|
return false;
|
|
138
138
|
if (!IsValidProgressNext(next))
|
|
139
139
|
return false;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
if (passport) {
|
|
141
|
+
txb.moveCall({
|
|
142
|
+
target: protocol_1.PROTOCOL.ProgressFn('unhold_with_passport'),
|
|
143
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
txb.moveCall({
|
|
148
|
+
target: protocol_1.PROTOCOL.ProgressFn('unhold'),
|
|
149
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name), txb.pure(next.forward), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
144
152
|
return true;
|
|
145
153
|
}
|
|
146
154
|
exports.progress_unhold = progress_unhold;
|
|
155
|
+
function progress_parent(txb, machine, permission, progress, parent_progress, passport) {
|
|
156
|
+
if (!(0, protocol_1.IsValidObjects)([machine, permission, progress]))
|
|
157
|
+
return false;
|
|
158
|
+
if (parent_progress && (!(0, protocol_1.IsValidAddress)(parent_progress.parent_progress_id) || !(0, protocol_1.IsValidInt)(parent_progress.parent_session_id)))
|
|
159
|
+
return false;
|
|
160
|
+
if (passport) {
|
|
161
|
+
if (parent_progress) {
|
|
162
|
+
txb.moveCall({
|
|
163
|
+
target: protocol_1.PROTOCOL.ProgressFn('parent_set_with_passport'),
|
|
164
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(parent_progress.parent_progress_id, bcs_1.BCS.ADDRESS),
|
|
165
|
+
txb.pure(parent_progress.parent_session_id, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
txb.moveCall({
|
|
170
|
+
target: protocol_1.PROTOCOL.ProgressFn('parent_none_with_passport'),
|
|
171
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (parent_progress) {
|
|
177
|
+
txb.moveCall({
|
|
178
|
+
target: protocol_1.PROTOCOL.ProgressFn('parent_set'),
|
|
179
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(parent_progress.parent_progress_id, bcs_1.BCS.ADDRESS),
|
|
180
|
+
txb.pure(parent_progress.parent_session_id, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
txb.moveCall({
|
|
185
|
+
target: protocol_1.PROTOCOL.ProgressFn('parent_none'),
|
|
186
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
exports.progress_parent = progress_parent;
|
|
147
193
|
function IsValidProgressNext(next) {
|
|
148
194
|
return (0, protocol_1.IsValidName)(next.forward) && (0, protocol_1.IsValidName)(next.next_node_name);
|
|
149
195
|
}
|
|
150
|
-
function next(txb, machine, permission, progress, next, deliverables_address, passport) {
|
|
196
|
+
function next(txb, machine, permission, progress, next, deliverables_address, sub_progress_id, passport) {
|
|
151
197
|
if (!(0, protocol_1.IsValidObjects)([machine, permission, progress]))
|
|
152
198
|
return false;
|
|
153
199
|
if (!IsValidProgressNext(next))
|
|
154
200
|
return false;
|
|
155
201
|
if (deliverables_address && !(0, protocol_1.IsValidAddress)(deliverables_address))
|
|
156
202
|
return false;
|
|
203
|
+
if (sub_progress_id && !(0, protocol_1.IsValidAddress)(sub_progress_id))
|
|
204
|
+
return false;
|
|
157
205
|
let diliverable = deliverables_address ? txb.pure(util_1.BCS_CONVERT.ser_option_address(deliverables_address)) : (0, protocol_1.OptionNone)(txb);
|
|
206
|
+
let sub = sub_progress_id ? txb.pure(util_1.BCS_CONVERT.ser_option_address(sub_progress_id)) : (0, protocol_1.OptionNone)(txb);
|
|
158
207
|
if (passport) {
|
|
159
208
|
txb.moveCall({
|
|
160
|
-
target: protocol_1.PROTOCOL.ProgressFn('
|
|
161
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name),
|
|
162
|
-
txb.pure(next.forward), diliverable, (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
209
|
+
target: protocol_1.PROTOCOL.ProgressFn('next_with_passport'),
|
|
210
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name, bcs_1.BCS.STRING),
|
|
211
|
+
txb.pure(next.forward, bcs_1.BCS.STRING), diliverable, sub, (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
163
212
|
});
|
|
164
213
|
}
|
|
165
214
|
else {
|
|
166
215
|
txb.moveCall({
|
|
167
|
-
target: protocol_1.PROTOCOL.ProgressFn('
|
|
168
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name),
|
|
169
|
-
txb.pure(next.forward), diliverable, (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
216
|
+
target: protocol_1.PROTOCOL.ProgressFn('next'),
|
|
217
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, progress), (0, protocol_1.TXB_OBJECT)(txb, machine), txb.pure(next.next_node_name, bcs_1.BCS.STRING),
|
|
218
|
+
txb.pure(next.forward, bcs_1.BCS.STRING), diliverable, sub, (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
170
219
|
});
|
|
171
220
|
}
|
|
172
221
|
return true;
|
package/dist/protocol.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OBJECTS_TYPE = exports.OBJECTS_TYPE_PREFIX = exports.PROTOCOL = exports.Protocol = exports.ENTRYPOINT = exports.ContextType = exports.OperatorType = exports.ValueType = exports.CLOCK_OBJECT = exports.TXB_OBJECT = exports.MODULES = exports.IsValidObjects = exports.IsValidArray = exports.IsValidPercent = exports.IsValidInt = exports.IsValidUint = exports.IsValidArgType = exports.IsValidAddress = exports.IsValidEndpoint = exports.IsValidName_AllowEmpty = exports.IsValidName = exports.IsValidDesription = exports.OptionNone = exports.MAX_ENDPOINT_LENGTH = exports.MAX_NAME_LENGTH = exports.MAX_DESCRIPTION_LENGTH = void 0;
|
|
3
|
+
exports.OBJECTS_TYPE = exports.OBJECTS_TYPE_PREFIX = exports.WOWOK_TYPE = exports.SUI_TYPE = exports.PROTOCOL = exports.Protocol = exports.ENTRYPOINT = exports.ContextType = exports.OperatorType = exports.ValueType = exports.CLOCK_OBJECT = exports.TXB_OBJECT = exports.MODULES = exports.IsValidObjects = exports.IsValidArray = exports.IsValidPercent = exports.IsValidInt = exports.IsValidUint = exports.IsValidArgType = exports.IsValidAddress = exports.IsValidEndpoint = exports.IsValidName_AllowEmpty = exports.IsValidName = exports.IsValidDesription = exports.OptionNone = exports.MAX_ENDPOINT_LENGTH = exports.MAX_NAME_LENGTH = exports.MAX_DESCRIPTION_LENGTH = void 0;
|
|
4
4
|
const client_1 = require("@mysten/sui.js/client");
|
|
5
5
|
const ed25519_1 = require("@mysten/sui.js/keypairs/ed25519");
|
|
6
6
|
const bcs_1 = require("@mysten/bcs");
|
|
@@ -17,7 +17,7 @@ const IsValidName = (name) => { return name.length <= exports.MAX_NAME_LENGTH &&
|
|
|
17
17
|
exports.IsValidName = IsValidName;
|
|
18
18
|
const IsValidName_AllowEmpty = (name) => { return name.length <= exports.MAX_NAME_LENGTH; };
|
|
19
19
|
exports.IsValidName_AllowEmpty = IsValidName_AllowEmpty;
|
|
20
|
-
const IsValidEndpoint = (endpoint) => { return endpoint.length <= exports.
|
|
20
|
+
const IsValidEndpoint = (endpoint) => { return endpoint.length <= exports.MAX_ENDPOINT_LENGTH; };
|
|
21
21
|
exports.IsValidEndpoint = IsValidEndpoint;
|
|
22
22
|
const IsValidAddress = (address) => { return address.length != 0; };
|
|
23
23
|
exports.IsValidAddress = IsValidAddress;
|
|
@@ -124,6 +124,7 @@ class Protocol {
|
|
|
124
124
|
package = '';
|
|
125
125
|
signer = '';
|
|
126
126
|
everyone_guard = '';
|
|
127
|
+
graphql = '';
|
|
127
128
|
constructor(network = ENTRYPOINT.localnet, signer = "0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f") {
|
|
128
129
|
this.signer = signer;
|
|
129
130
|
this.UseNetwork(network);
|
|
@@ -138,8 +139,9 @@ class Protocol {
|
|
|
138
139
|
case ENTRYPOINT.devnet:
|
|
139
140
|
break;
|
|
140
141
|
case ENTRYPOINT.testnet:
|
|
141
|
-
this.package = "
|
|
142
|
-
this.everyone_guard = "
|
|
142
|
+
this.package = "0x877375bc3bde063e4b95f428df218af7faaeef431993f4a68f2dfa5ceb8acb2e";
|
|
143
|
+
this.everyone_guard = "0x78a41fcc4f566360839613f6b917fb101ae015e56b43143f496f265b6422fddc";
|
|
144
|
+
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
143
145
|
break;
|
|
144
146
|
case ENTRYPOINT.mainnet:
|
|
145
147
|
break;
|
|
@@ -148,6 +150,7 @@ class Protocol {
|
|
|
148
150
|
}
|
|
149
151
|
Package() { return this.package; }
|
|
150
152
|
EveryoneGuard() { return this.everyone_guard; }
|
|
153
|
+
GraphqlUrl() { return this.graphql; }
|
|
151
154
|
NetworkUrl() {
|
|
152
155
|
switch (this.network) {
|
|
153
156
|
case ENTRYPOINT.localnet:
|
|
@@ -192,7 +195,7 @@ class Protocol {
|
|
|
192
195
|
Sign_Excute = async (exes, priv_key, param, options = { showObjectChanges: true }) => {
|
|
193
196
|
const client = new client_1.SuiClient({ url: exports.PROTOCOL.NetworkUrl() });
|
|
194
197
|
const txb = new transactions_1.TransactionBlock();
|
|
195
|
-
exes(txb, param);
|
|
198
|
+
exes.forEach((e) => { e(txb, param); });
|
|
196
199
|
const privkey = (0, bcs_1.fromHEX)(priv_key);
|
|
197
200
|
const keypair = ed25519_1.Ed25519Keypair.fromSecretKey(privkey);
|
|
198
201
|
const response = await client.signAndExecuteTransactionBlock({
|
|
@@ -205,5 +208,10 @@ class Protocol {
|
|
|
205
208
|
}
|
|
206
209
|
exports.Protocol = Protocol;
|
|
207
210
|
exports.PROTOCOL = new Protocol();
|
|
208
|
-
exports.
|
|
209
|
-
|
|
211
|
+
exports.SUI_TYPE = '0x2::coin::Coin<0x2::sui::SUI>';
|
|
212
|
+
const WOWOK_TYPE = () => { '0x2::coin::Coin<' + exports.PROTOCOL.Package() + '::wowok::WOWOK'; };
|
|
213
|
+
exports.WOWOK_TYPE = WOWOK_TYPE;
|
|
214
|
+
const OBJECTS_TYPE_PREFIX = () => Object.keys(MODULES).map((key) => { return exports.PROTOCOL.Package() + '::' + key + '::'; });
|
|
215
|
+
exports.OBJECTS_TYPE_PREFIX = OBJECTS_TYPE_PREFIX;
|
|
216
|
+
const OBJECTS_TYPE = () => Object.keys(MODULES).map((key) => { let i = exports.PROTOCOL.Package() + '::' + key + '::'; return i + (0, util_1.capitalize)(key); });
|
|
217
|
+
exports.OBJECTS_TYPE = OBJECTS_TYPE;
|
package/dist/repository.js
CHANGED
|
@@ -67,9 +67,10 @@ function add_data(txb, repository, permission, data) {
|
|
|
67
67
|
return false;
|
|
68
68
|
let bValid = true;
|
|
69
69
|
data.data.forEach((value) => {
|
|
70
|
-
if (!(0,
|
|
70
|
+
if (!(0, protocol_1.IsValidAddress)(value.address))
|
|
71
|
+
bValid = false;
|
|
72
|
+
if (!(0, exports.IsValidValue)(value.bcsBytes))
|
|
71
73
|
bValid = false;
|
|
72
|
-
}
|
|
73
74
|
});
|
|
74
75
|
if (!bValid)
|
|
75
76
|
return false;
|
|
@@ -80,7 +81,7 @@ function add_data(txb, repository, permission, data) {
|
|
|
80
81
|
txb.pure(d.address, bcs_1.BCS.ADDRESS),
|
|
81
82
|
txb.pure(data.key),
|
|
82
83
|
txb.pure(data.value_type, bcs_1.BCS.U8),
|
|
83
|
-
txb.pure([...d.
|
|
84
|
+
txb.pure([...d.bcsBytes], 'vector<u8>'),
|
|
84
85
|
(0, protocol_1.TXB_OBJECT)(txb, permission),
|
|
85
86
|
],
|
|
86
87
|
}));
|
|
@@ -91,7 +92,7 @@ function add_data(txb, repository, permission, data) {
|
|
|
91
92
|
arguments: [(0, protocol_1.TXB_OBJECT)(txb, repository),
|
|
92
93
|
txb.pure(d.address, bcs_1.BCS.ADDRESS),
|
|
93
94
|
txb.pure(data.key),
|
|
94
|
-
txb.pure([...d.
|
|
95
|
+
txb.pure([...d.bcsBytes], 'vector<u8>'),
|
|
95
96
|
(0, protocol_1.TXB_OBJECT)(txb, permission),
|
|
96
97
|
],
|
|
97
98
|
}));
|
|
@@ -170,11 +171,9 @@ function repository_remove_policies(txb, repository, permission, policy_keys, re
|
|
|
170
171
|
});
|
|
171
172
|
}
|
|
172
173
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, repository), txb.pure((0, util_1.array_unique)(key)), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
177
|
-
});
|
|
174
|
+
txb.moveCall({
|
|
175
|
+
target: protocol_1.PROTOCOL.RepositoryFn('policy_remove_with_passport'),
|
|
176
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, repository), txb.pure(util_1.BCS_CONVERT.ser_vector_string((0, util_1.array_unique)(policy_keys))), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
178
177
|
});
|
|
179
178
|
}
|
|
180
179
|
}
|
|
@@ -186,11 +185,9 @@ function repository_remove_policies(txb, repository, permission, policy_keys, re
|
|
|
186
185
|
});
|
|
187
186
|
}
|
|
188
187
|
else {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, repository), txb.pure(key), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
193
|
-
});
|
|
188
|
+
txb.moveCall({
|
|
189
|
+
target: protocol_1.PROTOCOL.RepositoryFn('policy_remove'),
|
|
190
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, repository), txb.pure(util_1.BCS_CONVERT.ser_vector_string((0, util_1.array_unique)(policy_keys))), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
194
191
|
});
|
|
195
192
|
}
|
|
196
193
|
}
|
package/dist/reward.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.change_permission = exports.deposit = exports.claim = exports.reward_lock_guards = exports.reward_set_description = exports.allow_repeat_claim = exports.reward_remove_guard = exports.reward_add_guard = exports.reward_expand_time = exports.reward_refund = exports.destroy = exports.launch = exports.reward = void 0;
|
|
3
|
+
exports.change_permission = exports.deposit = exports.claim = exports.reward_lock_guards = exports.reward_set_description = exports.allow_repeat_claim = exports.reward_remove_guard = exports.reward_add_guard = exports.MAX_PORTIONS_COUNT = exports.reward_expand_time = exports.reward_refund = exports.destroy = exports.launch = exports.reward = void 0;
|
|
4
4
|
const bcs_1 = require("@mysten/bcs");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
6
|
const util_1 = require("./util");
|
|
@@ -101,6 +101,7 @@ function reward_expand_time(reward_type, txb, reward, permission, minutes_expand
|
|
|
101
101
|
return true;
|
|
102
102
|
}
|
|
103
103
|
exports.reward_expand_time = reward_expand_time;
|
|
104
|
+
exports.MAX_PORTIONS_COUNT = 255;
|
|
104
105
|
function reward_add_guard(reward_type, txb, reward, permission, gurads, passport) {
|
|
105
106
|
if (!(0, protocol_1.IsValidObjects)([reward, permission]))
|
|
106
107
|
return false;
|
|
@@ -110,7 +111,7 @@ function reward_add_guard(reward_type, txb, reward, permission, gurads, passport
|
|
|
110
111
|
return false;
|
|
111
112
|
let bValid = true;
|
|
112
113
|
gurads.forEach((v) => {
|
|
113
|
-
if (!(0, protocol_1.IsValidUint)(v.portions))
|
|
114
|
+
if (!(0, protocol_1.IsValidUint)(v.portions) || v.portions > exports.MAX_PORTIONS_COUNT)
|
|
114
115
|
bValid = false;
|
|
115
116
|
if (!(0, protocol_1.IsValidObjects)([v.guard]))
|
|
116
117
|
bValid = false;
|
|
@@ -120,14 +121,14 @@ function reward_add_guard(reward_type, txb, reward, permission, gurads, passport
|
|
|
120
121
|
if (passport) {
|
|
121
122
|
gurads.forEach((guard) => txb.moveCall({
|
|
122
123
|
target: protocol_1.PROTOCOL.RewardFn('guard_add_with_passport'),
|
|
123
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, reward), (0, protocol_1.TXB_OBJECT)(txb, guard.guard), txb.pure(guard.portions, bcs_1.BCS.
|
|
124
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, reward), (0, protocol_1.TXB_OBJECT)(txb, guard.guard), txb.pure(guard.portions, bcs_1.BCS.U8), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
124
125
|
typeArguments: [reward_type]
|
|
125
126
|
}));
|
|
126
127
|
}
|
|
127
128
|
else {
|
|
128
129
|
gurads.forEach((guard) => txb.moveCall({
|
|
129
130
|
target: protocol_1.PROTOCOL.RewardFn('guard_add'),
|
|
130
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, reward), (0, protocol_1.TXB_OBJECT)(txb, guard.guard), txb.pure(guard.portions, bcs_1.BCS.
|
|
131
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, reward), (0, protocol_1.TXB_OBJECT)(txb, guard.guard), txb.pure(guard.portions, bcs_1.BCS.U8), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
131
132
|
typeArguments: [reward_type]
|
|
132
133
|
}));
|
|
133
134
|
}
|
|
@@ -192,7 +193,7 @@ function allow_repeat_claim(reward_type, txb, reward, permission, allow_repeat_c
|
|
|
192
193
|
}
|
|
193
194
|
else {
|
|
194
195
|
txb.moveCall({
|
|
195
|
-
target: protocol_1.PROTOCOL.RewardFn('
|
|
196
|
+
target: protocol_1.PROTOCOL.RewardFn('allow_repeat_claim'),
|
|
196
197
|
arguments: [(0, protocol_1.TXB_OBJECT)(txb, reward), (0, protocol_1.TXB_OBJECT)(txb, permission), txb.pure(allow_repeat_claim, bcs_1.BCS.BOOL)],
|
|
197
198
|
typeArguments: [reward_type]
|
|
198
199
|
});
|
package/dist/service.js
CHANGED
|
@@ -539,16 +539,20 @@ function service_discount_transfer(pay_type, txb, service, permission, discount_
|
|
|
539
539
|
if (passport) {
|
|
540
540
|
txb.moveCall({
|
|
541
541
|
target: protocol_1.PROTOCOL.ServiceFn('dicscount_create_with_passport'),
|
|
542
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, bcs_1.BCS.U8),
|
|
543
|
-
|
|
542
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, bcs_1.BCS.U8),
|
|
543
|
+
txb.pure(discount.discount.off, bcs_1.BCS.U64), price_greater, time_start,
|
|
544
|
+
txb.pure(discount.discount.duration_minutes, bcs_1.BCS.U64), txb.pure(discount.count, bcs_1.BCS.U64),
|
|
545
|
+
(0, protocol_1.TXB_OBJECT)(txb, permission), txb.pure(discount.receiver, bcs_1.BCS.ADDRESS), txb.object(protocol_1.CLOCK_OBJECT)],
|
|
544
546
|
typeArguments: [pay_type]
|
|
545
547
|
});
|
|
546
548
|
}
|
|
547
549
|
else {
|
|
548
550
|
txb.moveCall({
|
|
549
551
|
target: protocol_1.PROTOCOL.ServiceFn('dicscount_create'),
|
|
550
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, bcs_1.BCS.U8),
|
|
551
|
-
|
|
552
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(discount.discount.name), txb.pure(discount.discount.type, bcs_1.BCS.U8),
|
|
553
|
+
txb.pure(discount.discount.off, bcs_1.BCS.U64), price_greater, time_start,
|
|
554
|
+
txb.pure(discount.discount.duration_minutes, bcs_1.BCS.U64), txb.pure(discount.count, bcs_1.BCS.U64),
|
|
555
|
+
(0, protocol_1.TXB_OBJECT)(txb, permission), txb.pure(discount.receiver, bcs_1.BCS.ADDRESS), txb.object(protocol_1.CLOCK_OBJECT)],
|
|
552
556
|
typeArguments: [pay_type]
|
|
553
557
|
});
|
|
554
558
|
}
|
|
@@ -565,7 +569,7 @@ function service_withdraw(pay_type, txb, service, permission, order, passport) {
|
|
|
565
569
|
if (passport) {
|
|
566
570
|
txb.moveCall({
|
|
567
571
|
target: protocol_1.PROTOCOL.ServiceFn('withdraw_with_passport'),
|
|
568
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), (0, protocol_1.TXB_OBJECT)(txb, order),
|
|
572
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), (0, protocol_1.TXB_OBJECT)(txb, order), (0, protocol_1.TXB_OBJECT)(txb, permission)],
|
|
569
573
|
typeArguments: [pay_type]
|
|
570
574
|
});
|
|
571
575
|
}
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringToUint8Array = exports.objectids_from_response = exports.Object_Type_Extra = exports.BCS_CONVERT = exports.Bcs = exports.parse_object_type = exports.capitalize = exports.array_unique = exports.array_equal = exports.concatenate = exports.ulebDecode = void 0;
|
|
3
|
+
exports.numToUint8Array = exports.stringToUint8Array = exports.objectids_from_response = exports.Object_Type_Extra = exports.BCS_CONVERT = exports.Bcs = exports.parse_object_type = exports.capitalize = exports.array_unique = exports.array_equal = exports.concatenate = exports.ulebDecode = void 0;
|
|
4
4
|
const bcs_1 = require("@mysten/bcs");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
6
|
function ulebDecode(arr) {
|
|
@@ -144,3 +144,15 @@ function stringToUint8Array(str) {
|
|
|
144
144
|
return tmpUint8Array;
|
|
145
145
|
}
|
|
146
146
|
exports.stringToUint8Array = stringToUint8Array;
|
|
147
|
+
function numToUint8Array(num) {
|
|
148
|
+
if (!num)
|
|
149
|
+
return new Uint8Array(0);
|
|
150
|
+
const a = [];
|
|
151
|
+
a.unshift(num & 255);
|
|
152
|
+
while (num >= 256) {
|
|
153
|
+
num = num >>> 8;
|
|
154
|
+
a.unshift(num & 255);
|
|
155
|
+
}
|
|
156
|
+
return new Uint8Array(a);
|
|
157
|
+
}
|
|
158
|
+
exports.numToUint8Array = numToUint8Array;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wowok",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "AI-oriented web3 collaboration protocol, driving innovaion and making it more likely to happen.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,13 +9,18 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
|
|
12
|
+
"keywords": [
|
|
13
|
+
"web3",
|
|
14
|
+
"AI",
|
|
15
|
+
"wowok",
|
|
16
|
+
"sui"
|
|
17
|
+
],
|
|
18
|
+
"author": "wowo",
|
|
14
19
|
"license": "Apache License",
|
|
15
20
|
"dependencies": {
|
|
16
21
|
"@mysten/bcs": "^0.11.1",
|
|
17
22
|
"@mysten/sui.js": "^0.50.1",
|
|
18
|
-
"graphql": "^
|
|
23
|
+
"graphql-tag": "^2.12.6"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
26
|
"tsx": "^4.7.1"
|
package/src/demand.ts
CHANGED
|
@@ -191,13 +191,13 @@ export function present(earnest_type:string, service_type:string, txb:Transactio
|
|
|
191
191
|
if (passport) {
|
|
192
192
|
txb.moveCall({
|
|
193
193
|
target:PROTOCOL.DemandFn('present_with_passport') as FnCallType,
|
|
194
|
-
arguments:[passport, TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips), ],
|
|
194
|
+
arguments:[passport, TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips, BCS.STRING), ],
|
|
195
195
|
typeArguments:[earnest_type, service_type],
|
|
196
196
|
})
|
|
197
197
|
} else {
|
|
198
198
|
txb.moveCall({
|
|
199
199
|
target:PROTOCOL.DemandFn('present') as FnCallType,
|
|
200
|
-
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips), ],
|
|
200
|
+
arguments:[TXB_OBJECT(txb, demand), TXB_OBJECT(txb, service), txb.pure(tips, BCS.STRING), ],
|
|
201
201
|
typeArguments:[earnest_type, service_type],
|
|
202
202
|
})
|
|
203
203
|
}
|
package/src/graphql.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { gql } from "graphql-tag";
|
|
2
|
+
|
|
3
|
+
export const GRAPHQL_OBJECTS_TYPE = gql(`
|
|
4
|
+
query objects_type_version($filter:ObjectFilter!) {
|
|
5
|
+
objects(filter:$filter) {
|
|
6
|
+
nodes {
|
|
7
|
+
address
|
|
8
|
+
version
|
|
9
|
+
asMoveObject {
|
|
10
|
+
contents {
|
|
11
|
+
type {
|
|
12
|
+
repr
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`);
|
|
20
|
+
|
|
21
|
+
export const GRAPHQL_OBJECT = gql(`
|
|
22
|
+
query object($ObjectID:SuiAddress!) {
|
|
23
|
+
object(address:$ObjectID) {
|
|
24
|
+
address
|
|
25
|
+
asMoveObject {
|
|
26
|
+
contents {
|
|
27
|
+
json
|
|
28
|
+
type {
|
|
29
|
+
repr
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
dynamicFields {
|
|
34
|
+
pageInfo {
|
|
35
|
+
hasNextPage
|
|
36
|
+
endCursor
|
|
37
|
+
}
|
|
38
|
+
nodes {
|
|
39
|
+
name {
|
|
40
|
+
json
|
|
41
|
+
}
|
|
42
|
+
value {
|
|
43
|
+
... on MoveValue {
|
|
44
|
+
json
|
|
45
|
+
}
|
|
46
|
+
... on MoveObject {
|
|
47
|
+
contents {
|
|
48
|
+
json
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
|
|
58
|
+
export const GRAPHQL_OWNER = gql(`
|
|
59
|
+
query owner($ObjectID:SuiAddress!) {
|
|
60
|
+
owner (address: $ObjectID) {
|
|
61
|
+
address
|
|
62
|
+
dynamicFields {
|
|
63
|
+
pageInfo {
|
|
64
|
+
hasNextPage
|
|
65
|
+
endCursor
|
|
66
|
+
}
|
|
67
|
+
nodes {
|
|
68
|
+
name {
|
|
69
|
+
json
|
|
70
|
+
}
|
|
71
|
+
value {
|
|
72
|
+
... on MoveValue {
|
|
73
|
+
json
|
|
74
|
+
}
|
|
75
|
+
... on MoveObject {
|
|
76
|
+
contents {
|
|
77
|
+
json
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`);
|
|
86
|
+
|
|
87
|
+
export const GRAPHQL_OBJECTS = gql(`
|
|
88
|
+
query objects($filter:ObjectFilter!){
|
|
89
|
+
objects(filter:$filter) {
|
|
90
|
+
nodes {
|
|
91
|
+
address
|
|
92
|
+
asMoveObject {
|
|
93
|
+
contents {
|
|
94
|
+
json
|
|
95
|
+
type {
|
|
96
|
+
repr
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`);
|