wowok 1.0.6 → 1.0.8
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/README.md +1 -1
- package/dist/demand.js +4 -4
- package/dist/guard.js +377 -51
- package/dist/index.js +122 -2
- package/dist/machine.js +10 -10
- package/dist/passport.js +53 -27
- package/dist/permission.js +5 -5
- package/dist/progress.js +5 -5
- package/dist/protocol.js +53 -30
- package/dist/repository.js +5 -5
- package/dist/reward.js +5 -5
- package/dist/service.js +92 -56
- package/dist/utils.js +201 -0
- package/dist/vote.js +10 -10
- package/package.json +20 -4
- package/src/demand.ts +4 -4
- package/src/guard.ts +366 -50
- package/src/index.ts +2 -1
- package/src/machine.ts +1 -2
- package/src/passport.ts +64 -31
- package/src/progress.ts +2 -2
- package/src/protocol.ts +52 -28
- package/src/service.ts +62 -36
- package/src/utils.ts +48 -2
package/dist/utils.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepClone = exports.isArr = 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
|
+
const bcs_1 = require("@mysten/bcs");
|
|
5
|
+
const protocol_1 = require("./protocol");
|
|
6
|
+
const ulebDecode = (arr) => {
|
|
7
|
+
let total = 0;
|
|
8
|
+
let shift = 0;
|
|
9
|
+
let len = 0;
|
|
10
|
+
// eslint-disable-next-line no-constant-condition
|
|
11
|
+
while (true) {
|
|
12
|
+
let byte = arr[len];
|
|
13
|
+
len += 1;
|
|
14
|
+
total |= (byte & 0x7f) << shift;
|
|
15
|
+
if ((byte & 0x80) === 0) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
shift += 7;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
value: total,
|
|
22
|
+
length: len,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.ulebDecode = ulebDecode;
|
|
26
|
+
const concatenate = (resultConstructor, ...arrays) => {
|
|
27
|
+
let totalLength = 0;
|
|
28
|
+
for (const arr of arrays) {
|
|
29
|
+
totalLength += arr.length;
|
|
30
|
+
}
|
|
31
|
+
const result = new resultConstructor(totalLength);
|
|
32
|
+
let offset = 0;
|
|
33
|
+
for (const arr of arrays) {
|
|
34
|
+
result.set(arr, offset);
|
|
35
|
+
offset += arr.length;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
exports.concatenate = concatenate;
|
|
40
|
+
const array_equal = (arr1, arr2) => {
|
|
41
|
+
// Array.some(): 有一项不满足,返回false
|
|
42
|
+
if (arr1.length !== arr2.length) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return !arr1.some((item) => !arr2.includes(item));
|
|
46
|
+
};
|
|
47
|
+
exports.array_equal = array_equal;
|
|
48
|
+
const array_unique = (arr) => {
|
|
49
|
+
var newArr = [];
|
|
50
|
+
for (var i = 0; i < arr.length; i++) {
|
|
51
|
+
if (newArr.indexOf(arr[i]) == -1) {
|
|
52
|
+
newArr.push(arr[i]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return newArr;
|
|
56
|
+
};
|
|
57
|
+
exports.array_unique = array_unique;
|
|
58
|
+
function capitalize(s) {
|
|
59
|
+
return s && s[0].toUpperCase() + s.slice(1);
|
|
60
|
+
}
|
|
61
|
+
exports.capitalize = capitalize;
|
|
62
|
+
// for: "0xsdjfkskf<0x2::sui::coin<xxx>, 0xfdfff<>>"
|
|
63
|
+
function parse_object_type(object_data) {
|
|
64
|
+
var object_type = [];
|
|
65
|
+
let type_pos = object_data.indexOf('<');
|
|
66
|
+
if (type_pos >= 0) {
|
|
67
|
+
let t = object_data.slice((type_pos + 1), object_data.length - 1);
|
|
68
|
+
object_type = t.split(',');
|
|
69
|
+
}
|
|
70
|
+
return object_type;
|
|
71
|
+
}
|
|
72
|
+
exports.parse_object_type = parse_object_type;
|
|
73
|
+
class Bcs {
|
|
74
|
+
bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
|
|
75
|
+
constructor() {
|
|
76
|
+
this.bcs.registerEnumType('Option<T>', {
|
|
77
|
+
'none': null,
|
|
78
|
+
'some': 'T',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
ser_option_string(data) {
|
|
82
|
+
return this.bcs.ser('Option<string>', { 'some': data }).toBytes();
|
|
83
|
+
}
|
|
84
|
+
ser_option_u64(data) {
|
|
85
|
+
return this.bcs.ser('Option<u64>', { 'some': data }).toBytes();
|
|
86
|
+
}
|
|
87
|
+
ser_option_address(data) {
|
|
88
|
+
return this.bcs.ser('Option<address>', { 'some': data }).toBytes();
|
|
89
|
+
}
|
|
90
|
+
ser_vector_string(data) {
|
|
91
|
+
return this.bcs.ser('vector<string>', data).toBytes();
|
|
92
|
+
}
|
|
93
|
+
ser_vector_vector_u8(data) {
|
|
94
|
+
return this.bcs.ser('vector<vector<u8>>', data).toBytes();
|
|
95
|
+
}
|
|
96
|
+
ser_vector_u64(data) {
|
|
97
|
+
return this.bcs.ser('vector<u64>', data).toBytes();
|
|
98
|
+
}
|
|
99
|
+
ser_vector_u8(data) {
|
|
100
|
+
return this.bcs.ser('vector<u8>', data).toBytes();
|
|
101
|
+
}
|
|
102
|
+
ser_address(data) {
|
|
103
|
+
return this.bcs.ser(bcs_1.BCS.ADDRESS, data).toBytes();
|
|
104
|
+
}
|
|
105
|
+
ser_bool(data) {
|
|
106
|
+
return this.bcs.ser(bcs_1.BCS.BOOL, data).toBytes();
|
|
107
|
+
}
|
|
108
|
+
ser_u8(data) {
|
|
109
|
+
return this.bcs.ser(bcs_1.BCS.U8, data).toBytes();
|
|
110
|
+
}
|
|
111
|
+
ser_u64(data) {
|
|
112
|
+
return this.bcs.ser(bcs_1.BCS.U64, data).toBytes();
|
|
113
|
+
}
|
|
114
|
+
ser_string(data) {
|
|
115
|
+
return this.bcs.ser(bcs_1.BCS.STRING, data).toBytes();
|
|
116
|
+
}
|
|
117
|
+
de(type, data) {
|
|
118
|
+
return this.bcs.de(type, data);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.Bcs = Bcs;
|
|
122
|
+
exports.BCS_CONVERT = new Bcs();
|
|
123
|
+
const Object_Type_Extra = () => {
|
|
124
|
+
let names = Object.keys(protocol_1.MODULES).map((key) => { return key + '::' + capitalize(key); });
|
|
125
|
+
names.push('order::Discount');
|
|
126
|
+
return names;
|
|
127
|
+
};
|
|
128
|
+
exports.Object_Type_Extra = Object_Type_Extra;
|
|
129
|
+
const objectids_from_response = (response, concat_result) => {
|
|
130
|
+
let ret = new Map();
|
|
131
|
+
if (response?.objectChanges) {
|
|
132
|
+
response.objectChanges.forEach((change) => {
|
|
133
|
+
(0, exports.Object_Type_Extra)().forEach((name) => {
|
|
134
|
+
let type = protocol_1.PROTOCOL.Package() + '::' + name;
|
|
135
|
+
if (change.type == 'created' && change.objectType.includes(type)) {
|
|
136
|
+
if (ret.has(name)) {
|
|
137
|
+
ret.get(name)?.push(change.objectId);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
ret.set(name, [change.objectId]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (concat_result) {
|
|
147
|
+
ret.forEach((value, key) => {
|
|
148
|
+
if (concat_result.has(key)) {
|
|
149
|
+
concat_result.set(key, concat_result.get(key).concat(value));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
concat_result.set(key, value);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return ret;
|
|
157
|
+
};
|
|
158
|
+
exports.objectids_from_response = objectids_from_response;
|
|
159
|
+
function stringToUint8Array(str) {
|
|
160
|
+
var arr = [];
|
|
161
|
+
for (var i = 0, j = str.length; i < j; ++i) {
|
|
162
|
+
arr.push(str.charCodeAt(i));
|
|
163
|
+
}
|
|
164
|
+
var tmpUint8Array = new Uint8Array(arr);
|
|
165
|
+
return tmpUint8Array;
|
|
166
|
+
}
|
|
167
|
+
exports.stringToUint8Array = stringToUint8Array;
|
|
168
|
+
function numToUint8Array(num) {
|
|
169
|
+
if (!num)
|
|
170
|
+
return new Uint8Array(0);
|
|
171
|
+
const a = [];
|
|
172
|
+
a.unshift(num & 255);
|
|
173
|
+
while (num >= 256) {
|
|
174
|
+
num = num >>> 8;
|
|
175
|
+
a.unshift(num & 255);
|
|
176
|
+
}
|
|
177
|
+
return new Uint8Array(a);
|
|
178
|
+
}
|
|
179
|
+
exports.numToUint8Array = numToUint8Array;
|
|
180
|
+
// 判断是否为数组
|
|
181
|
+
const isArr = (origin) => {
|
|
182
|
+
let str = '[object Array]';
|
|
183
|
+
return Object.prototype.toString.call(origin) == str ? true : false;
|
|
184
|
+
};
|
|
185
|
+
exports.isArr = isArr;
|
|
186
|
+
const deepClone = (origin, target) => {
|
|
187
|
+
let tar = target || {};
|
|
188
|
+
for (const key in origin) {
|
|
189
|
+
if (Object.prototype.hasOwnProperty.call(origin, key)) {
|
|
190
|
+
if (typeof origin[key] === 'object' && origin[key] !== null) {
|
|
191
|
+
tar[key] = (0, exports.isArr)(origin[key]) ? [] : {};
|
|
192
|
+
(0, exports.deepClone)(origin[key], tar[key]);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
tar[key] = origin[key];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return tar;
|
|
200
|
+
};
|
|
201
|
+
exports.deepClone = deepClone;
|
package/dist/vote.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.change_permission = exports.agree = exports.vote_lock_guard = exports.vote_expand_deadline = exports.vote_lock_deadline = exports.vote_open_voting = exports.vote_set_max_choice_count = exports.vote_remove_option = exports.vote_add_option = exports.vote_remove_guard = exports.vote_add_guard = exports.vote_set_reference = exports.vote_set_description = exports.destroy = exports.launch = exports.vote = exports.MAX_CHOICE_COUNT = exports.MAX_AGREES_COUNT = void 0;
|
|
4
4
|
const bcs_1 = require("@mysten/bcs");
|
|
5
5
|
const protocol_1 = require("./protocol");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
7
|
exports.MAX_AGREES_COUNT = 200;
|
|
8
8
|
exports.MAX_CHOICE_COUNT = 200;
|
|
9
9
|
function vote(txb, permission, description, minutes_duration, max_choice_count, reference_address, passport) {
|
|
@@ -19,7 +19,7 @@ function vote(txb, permission, description, minutes_duration, max_choice_count,
|
|
|
19
19
|
return false;
|
|
20
20
|
if (reference_address && !(0, protocol_1.IsValidAddress)(reference_address))
|
|
21
21
|
return false;
|
|
22
|
-
let reference = reference_address ? txb.pure(
|
|
22
|
+
let reference = reference_address ? txb.pure(utils_1.BCS_CONVERT.ser_option_address(reference_address)) : (0, protocol_1.OptionNone)(txb);
|
|
23
23
|
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
24
24
|
if (passport) {
|
|
25
25
|
return txb.moveCall({
|
|
@@ -81,7 +81,7 @@ function vote_set_reference(txb, vote, permission, reference_address, passport)
|
|
|
81
81
|
return false;
|
|
82
82
|
if (reference_address && !(0, protocol_1.IsValidAddress)(reference_address))
|
|
83
83
|
return false;
|
|
84
|
-
let reference = reference_address ? txb.pure(
|
|
84
|
+
let reference = reference_address ? txb.pure(utils_1.BCS_CONVERT.ser_option_address(reference_address)) : (0, protocol_1.OptionNone)(txb);
|
|
85
85
|
if (passport) {
|
|
86
86
|
txb.moveCall({
|
|
87
87
|
target: protocol_1.PROTOCOL.VoteFn('reference_set_with_passport'),
|
|
@@ -134,7 +134,7 @@ function vote_remove_guard(txb, vote, permission, guard_address, removeall, pass
|
|
|
134
134
|
else {
|
|
135
135
|
txb.moveCall({
|
|
136
136
|
target: protocol_1.PROTOCOL.VoteFn('guard_remove_with_passport'),
|
|
137
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure((0,
|
|
137
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -148,7 +148,7 @@ function vote_remove_guard(txb, vote, permission, guard_address, removeall, pass
|
|
|
148
148
|
else {
|
|
149
149
|
txb.moveCall({
|
|
150
150
|
target: protocol_1.PROTOCOL.VoteFn('guard_remove'),
|
|
151
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure((0,
|
|
151
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -170,7 +170,7 @@ function vote_add_option(txb, vote, permission, options, passport) {
|
|
|
170
170
|
if (!bValid)
|
|
171
171
|
return false;
|
|
172
172
|
options.forEach((option) => {
|
|
173
|
-
let reference = option?.reference_address ? txb.pure(
|
|
173
|
+
let reference = option?.reference_address ? txb.pure(utils_1.BCS_CONVERT.ser_option_address(option.reference_address)) : (0, protocol_1.OptionNone)(txb);
|
|
174
174
|
if (passport) {
|
|
175
175
|
txb.moveCall({
|
|
176
176
|
target: protocol_1.PROTOCOL.VoteFn('agrees_add_with_passport'),
|
|
@@ -204,7 +204,7 @@ function vote_remove_option(txb, vote, permission, options, removeall, passport)
|
|
|
204
204
|
else {
|
|
205
205
|
txb.moveCall({
|
|
206
206
|
target: protocol_1.PROTOCOL.VoteFn('agrees_remove_with_passport'),
|
|
207
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(
|
|
207
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(options))), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
}
|
|
@@ -218,7 +218,7 @@ function vote_remove_option(txb, vote, permission, options, removeall, passport)
|
|
|
218
218
|
else {
|
|
219
219
|
txb.moveCall({
|
|
220
220
|
target: protocol_1.PROTOCOL.VoteFn('agrees_remove'),
|
|
221
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(
|
|
221
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(options))), (0, protocol_1.TXB_OBJECT)(txb, permission)]
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -327,13 +327,13 @@ function agree(txb, vote, options, passport) {
|
|
|
327
327
|
if (passport) {
|
|
328
328
|
txb.moveCall({
|
|
329
329
|
target: protocol_1.PROTOCOL.VoteFn('vote_with_passport'),
|
|
330
|
-
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(
|
|
330
|
+
arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(options)))]
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
333
|
else {
|
|
334
334
|
txb.moveCall({
|
|
335
335
|
target: protocol_1.PROTOCOL.VoteFn('vote'),
|
|
336
|
-
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(
|
|
336
|
+
arguments: [(0, protocol_1.TXB_OBJECT)(txb, vote), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(options)))]
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wowok",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|
|
@@ -13,13 +13,29 @@
|
|
|
13
13
|
"web3",
|
|
14
14
|
"AI",
|
|
15
15
|
"wowok",
|
|
16
|
-
"sui"
|
|
16
|
+
"sui",
|
|
17
|
+
"collaboration",
|
|
18
|
+
"protocol",
|
|
19
|
+
"WOW",
|
|
20
|
+
"permission",
|
|
21
|
+
"guard",
|
|
22
|
+
"service",
|
|
23
|
+
"order",
|
|
24
|
+
"machine",
|
|
25
|
+
"progress",
|
|
26
|
+
"passport",
|
|
27
|
+
"demand",
|
|
28
|
+
"reward",
|
|
29
|
+
"discount",
|
|
30
|
+
"mark",
|
|
31
|
+
"message",
|
|
32
|
+
"vote"
|
|
17
33
|
],
|
|
18
|
-
"author": "
|
|
34
|
+
"author": "wowok",
|
|
19
35
|
"license": "Apache License",
|
|
20
36
|
"dependencies": {
|
|
21
37
|
"@mysten/bcs": "^0.11.1",
|
|
22
|
-
"@mysten/sui.js": "^0.
|
|
38
|
+
"@mysten/sui.js": "^0.51.2",
|
|
23
39
|
"graphql-tag": "^2.12.6"
|
|
24
40
|
},
|
|
25
41
|
"devDependencies": {
|
package/src/demand.ts
CHANGED
|
@@ -150,21 +150,21 @@ export function demand_set_description(earnest_type:string, txb:TransactionBlock
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export function demand_yes(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:PermissionObject,
|
|
153
|
-
|
|
153
|
+
service_id:string, passport?:PassportObject) : boolean {
|
|
154
154
|
if (!IsValidObjects([demand, permission])) return false;
|
|
155
155
|
if (!IsValidArgType(earnest_type)) return false;
|
|
156
|
-
if (!IsValidAddress(
|
|
156
|
+
if (!IsValidAddress(service_id)) return false;
|
|
157
157
|
|
|
158
158
|
if (passport) {
|
|
159
159
|
txb.moveCall({
|
|
160
160
|
target:PROTOCOL.DemandFn('yes_with_passport') as FnCallType,
|
|
161
|
-
arguments:[passport, TXB_OBJECT(txb, demand), txb.pure(
|
|
161
|
+
arguments:[passport, TXB_OBJECT(txb, demand), txb.pure(service_id, BCS.ADDRESS), TXB_OBJECT(txb, permission)],
|
|
162
162
|
typeArguments:[earnest_type],
|
|
163
163
|
})
|
|
164
164
|
} else {
|
|
165
165
|
txb.moveCall({
|
|
166
166
|
target:PROTOCOL.DemandFn('yes') as FnCallType,
|
|
167
|
-
arguments:[TXB_OBJECT(txb, demand), txb.pure(
|
|
167
|
+
arguments:[TXB_OBJECT(txb, demand), txb.pure(service_id, BCS.ADDRESS), TXB_OBJECT(txb, permission)],
|
|
168
168
|
typeArguments:[earnest_type],
|
|
169
169
|
})
|
|
170
170
|
}
|