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/util.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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
|
+
function 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
|
+
function 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
|
+
function 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
|
+
function 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_vector_string(data) {
|
|
88
|
+
return this.bcs.ser('vector<string>', data).toBytes();
|
|
89
|
+
}
|
|
90
|
+
ser_vector_u64(data) {
|
|
91
|
+
return this.bcs.ser('vector<u64>', data).toBytes();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.Bcs = Bcs;
|
|
95
|
+
exports.BCS_CONVERT = new Bcs();
|
|
96
|
+
const Object_Type_Extra = () => {
|
|
97
|
+
let names = Object.keys(protocol_1.MODULES).map((key) => { return key + '::' + capitalize(key); });
|
|
98
|
+
names.push('order::Discount');
|
|
99
|
+
return names;
|
|
100
|
+
};
|
|
101
|
+
exports.Object_Type_Extra = Object_Type_Extra;
|
|
102
|
+
const objectids_from_response = (response, concat_result) => {
|
|
103
|
+
let ret = new Map();
|
|
104
|
+
if (response?.objectChanges) {
|
|
105
|
+
response.objectChanges.forEach((change) => {
|
|
106
|
+
(0, exports.Object_Type_Extra)().forEach((name) => {
|
|
107
|
+
let type = protocol_1.PROTOCOL.Package() + '::' + name;
|
|
108
|
+
if (change.type == 'created' && change.objectType.includes(type)) {
|
|
109
|
+
if (ret.has(name)) {
|
|
110
|
+
ret.get(name)?.push(change.objectId);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
ret.set(name, [change.objectId]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (concat_result) {
|
|
120
|
+
ret.forEach((value, key) => {
|
|
121
|
+
if (concat_result.has(key)) {
|
|
122
|
+
concat_result.set(key, concat_result.get(key).concat(value));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
concat_result.set(key, value);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return ret;
|
|
130
|
+
};
|
|
131
|
+
exports.objectids_from_response = objectids_from_response;
|
package/dist/vote.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 = void 0;
|
|
4
|
+
const bcs_1 = require("@mysten/bcs");
|
|
5
|
+
const protocol_1 = require("./protocol");
|
|
6
|
+
function vote(txb, permission, description, minutes_duration, max_choice_count, reference_address, passport) {
|
|
7
|
+
let reference = txb.pure([], bcs_1.BCS.U8);
|
|
8
|
+
if (reference_address) {
|
|
9
|
+
reference = txb.pure(reference_address, bcs_1.BCS.ADDRESS);
|
|
10
|
+
}
|
|
11
|
+
if (passport) {
|
|
12
|
+
return txb.moveCall({
|
|
13
|
+
target: protocol_1.PROTOCOL.VoteFn('new_with_passport'),
|
|
14
|
+
arguments: [passport, txb.pure((0, protocol_1.description_data)(description)), reference, txb.pure(protocol_1.CLOCK_OBJECT),
|
|
15
|
+
txb.pure(minutes_duration, bcs_1.BCS.U64), txb.pure(max_choice_count, bcs_1.BCS.U8), permission]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return txb.moveCall({
|
|
20
|
+
target: protocol_1.PROTOCOL.VoteFn('new'),
|
|
21
|
+
arguments: [txb.pure((0, protocol_1.description_data)(description)), reference, txb.pure(protocol_1.CLOCK_OBJECT),
|
|
22
|
+
txb.pure(minutes_duration, bcs_1.BCS.U64), txb.pure(max_choice_count, bcs_1.BCS.U8), permission]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.vote = vote;
|
|
27
|
+
function launch(txb, vote) {
|
|
28
|
+
return txb.moveCall({
|
|
29
|
+
target: protocol_1.PROTOCOL.VoteFn('create'),
|
|
30
|
+
arguments: [vote]
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.launch = launch;
|
|
34
|
+
function destroy(txb, vote) {
|
|
35
|
+
txb.moveCall({
|
|
36
|
+
target: protocol_1.PROTOCOL.VoteFn('destroy'),
|
|
37
|
+
arguments: [vote]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.destroy = destroy;
|
|
41
|
+
function vote_set_description(txb, vote, permission, description, passport) {
|
|
42
|
+
if (passport) {
|
|
43
|
+
txb.moveCall({
|
|
44
|
+
target: protocol_1.PROTOCOL.VoteFn('description_set_with_passport'),
|
|
45
|
+
arguments: [passport, vote, txb.pure((0, protocol_1.description_data)(description)), permission]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
txb.moveCall({
|
|
50
|
+
target: protocol_1.PROTOCOL.VoteFn('description_set'),
|
|
51
|
+
arguments: [vote, txb.pure((0, protocol_1.description_data)(description)), permission]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.vote_set_description = vote_set_description;
|
|
56
|
+
function vote_set_reference(txb, vote, permission, reference_address, passport) {
|
|
57
|
+
let reference = txb.pure([], bcs_1.BCS.U8);
|
|
58
|
+
if (reference_address) {
|
|
59
|
+
reference = txb.pure(reference_address, bcs_1.BCS.ADDRESS);
|
|
60
|
+
}
|
|
61
|
+
if (passport) {
|
|
62
|
+
txb.moveCall({
|
|
63
|
+
target: protocol_1.PROTOCOL.VoteFn('reference_set_with_passport'),
|
|
64
|
+
arguments: [passport, vote, reference, permission]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
txb.moveCall({
|
|
69
|
+
target: protocol_1.PROTOCOL.VoteFn('reference_set'),
|
|
70
|
+
arguments: [vote, reference, permission]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.vote_set_reference = vote_set_reference;
|
|
75
|
+
function vote_add_guard(txb, vote, permission, guard, vote_weight, passport) {
|
|
76
|
+
if (passport) {
|
|
77
|
+
txb.moveCall({
|
|
78
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_add_with_passport'),
|
|
79
|
+
arguments: [passport, vote, guard, txb.pure(vote_weight, bcs_1.BCS.U64), permission]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
txb.moveCall({
|
|
84
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_add'),
|
|
85
|
+
arguments: [vote, guard, txb.pure(vote_weight, bcs_1.BCS.U64), permission]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.vote_add_guard = vote_add_guard;
|
|
90
|
+
function vote_remove_guard(txb, vote, permission, guard_address, removeall, passport) {
|
|
91
|
+
if (passport) {
|
|
92
|
+
if (removeall) {
|
|
93
|
+
txb.moveCall({
|
|
94
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_remove_all_with_passport'),
|
|
95
|
+
arguments: [passport, vote, permission]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
txb.moveCall({
|
|
100
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_remove_with_passport'),
|
|
101
|
+
arguments: [passport, vote, txb.pure(guard_address, 'vector<address>'), permission]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
if (removeall) {
|
|
107
|
+
txb.moveCall({
|
|
108
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_remove_all'),
|
|
109
|
+
arguments: [vote, permission]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
txb.moveCall({
|
|
114
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_remove'),
|
|
115
|
+
arguments: [vote, txb.pure(guard_address, 'vector<address>'), permission]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.vote_remove_guard = vote_remove_guard;
|
|
121
|
+
function vote_add_option(txb, vote, permission, options, passport) {
|
|
122
|
+
options.forEach((option) => {
|
|
123
|
+
let reference = txb.pure([], bcs_1.BCS.U8);
|
|
124
|
+
if (option.reference_address) {
|
|
125
|
+
reference = txb.pure(option.reference_address, bcs_1.BCS.ADDRESS);
|
|
126
|
+
}
|
|
127
|
+
if (passport) {
|
|
128
|
+
txb.moveCall({
|
|
129
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_add_with_passport'),
|
|
130
|
+
arguments: [passport, vote, txb.pure((0, protocol_1.name_data)(option.name)), reference, permission]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
txb.moveCall({
|
|
135
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_add'),
|
|
136
|
+
arguments: [vote, txb.pure((0, protocol_1.name_data)(option.name)), reference, permission]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
exports.vote_add_option = vote_add_option;
|
|
142
|
+
function vote_remove_option(txb, vote, permission, options, removeall, passport) {
|
|
143
|
+
if (passport) {
|
|
144
|
+
if (removeall) {
|
|
145
|
+
txb.moveCall({
|
|
146
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_remove_all_with_passport'),
|
|
147
|
+
arguments: [passport, vote, permission]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
options.forEach((option) => {
|
|
152
|
+
txb.moveCall({
|
|
153
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_remove_with_passport'),
|
|
154
|
+
arguments: [passport, vote, txb.pure((0, protocol_1.name_data)(option)), permission]
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (removeall) {
|
|
161
|
+
txb.moveCall({
|
|
162
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_remove_all'),
|
|
163
|
+
arguments: [vote, permission]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
options.forEach((option) => {
|
|
168
|
+
txb.moveCall({
|
|
169
|
+
target: protocol_1.PROTOCOL.VoteFn('agrees_remove'),
|
|
170
|
+
arguments: [vote, txb.pure((0, protocol_1.name_data)(option)), permission]
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.vote_remove_option = vote_remove_option;
|
|
177
|
+
function vote_set_max_choice_count(txb, vote, permission, max_choice_count, passport) {
|
|
178
|
+
if (passport) {
|
|
179
|
+
txb.moveCall({
|
|
180
|
+
target: protocol_1.PROTOCOL.VoteFn('max_choice_count_set_with_passport'),
|
|
181
|
+
arguments: [passport, vote, txb.pure(max_choice_count, bcs_1.BCS.U8), permission]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
txb.moveCall({
|
|
186
|
+
target: protocol_1.PROTOCOL.VoteFn('max_choice_count_set'),
|
|
187
|
+
arguments: [vote, txb.pure(max_choice_count, bcs_1.BCS.U8), permission]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.vote_set_max_choice_count = vote_set_max_choice_count;
|
|
192
|
+
function vote_open_voting(txb, vote, permission, passport) {
|
|
193
|
+
if (passport) {
|
|
194
|
+
txb.moveCall({
|
|
195
|
+
target: protocol_1.PROTOCOL.VoteFn('options_locked_for_voting_with_passport'),
|
|
196
|
+
arguments: [passport, vote, permission]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
txb.moveCall({
|
|
201
|
+
target: protocol_1.PROTOCOL.VoteFn('options_locked_for_voting'),
|
|
202
|
+
arguments: [vote, permission]
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.vote_open_voting = vote_open_voting;
|
|
207
|
+
function vote_lock_deadline(txb, vote, permission, passport) {
|
|
208
|
+
if (passport) {
|
|
209
|
+
txb.moveCall({
|
|
210
|
+
target: protocol_1.PROTOCOL.VoteFn('deadline_locked_with_passport'),
|
|
211
|
+
arguments: [passport, vote, txb.object(protocol_1.CLOCK_OBJECT), permission]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
txb.moveCall({
|
|
216
|
+
target: protocol_1.PROTOCOL.VoteFn('deadline_locked'),
|
|
217
|
+
arguments: [vote, txb.object(protocol_1.CLOCK_OBJECT), permission]
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.vote_lock_deadline = vote_lock_deadline;
|
|
222
|
+
function vote_expand_deadline(txb, vote, permission, minutes_expand, passport) {
|
|
223
|
+
if (passport) {
|
|
224
|
+
txb.moveCall({
|
|
225
|
+
target: protocol_1.PROTOCOL.VoteFn('deadline_expand_with_passport'),
|
|
226
|
+
arguments: [passport, vote, txb.pure(minutes_expand, bcs_1.BCS.U64), permission]
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
txb.moveCall({
|
|
231
|
+
target: protocol_1.PROTOCOL.VoteFn('deadline_expand'),
|
|
232
|
+
arguments: [vote, txb.pure(minutes_expand, bcs_1.BCS.U64), permission]
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.vote_expand_deadline = vote_expand_deadline;
|
|
237
|
+
function vote_lock_guard(txb, vote, permission, passport) {
|
|
238
|
+
if (passport) {
|
|
239
|
+
txb.moveCall({
|
|
240
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_lock_with_passport'),
|
|
241
|
+
arguments: [passport, vote, permission]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
txb.moveCall({
|
|
246
|
+
target: protocol_1.PROTOCOL.VoteFn('guard_lock'),
|
|
247
|
+
arguments: [vote, permission]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.vote_lock_guard = vote_lock_guard;
|
|
252
|
+
function agree(txb, vote, options, passport) {
|
|
253
|
+
if (passport) {
|
|
254
|
+
txb.moveCall({
|
|
255
|
+
target: protocol_1.PROTOCOL.VoteFn('vote_with_passport'),
|
|
256
|
+
arguments: [passport, vote, txb.pure(options, 'vector<string>')]
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
txb.moveCall({
|
|
261
|
+
target: protocol_1.PROTOCOL.VoteFn('vote'),
|
|
262
|
+
arguments: [vote, txb.pure(options, 'vector<string>')]
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.agree = agree;
|
|
267
|
+
function change_permission(txb, vote, old_permission, new_permission) {
|
|
268
|
+
txb.moveCall({
|
|
269
|
+
target: protocol_1.PROTOCOL.VoteFn('permission_set'),
|
|
270
|
+
arguments: [vote, old_permission, new_permission],
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
exports.change_permission = change_permission;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wowok",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "node",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@digitak/esrun": "^3.2.26",
|
|
17
|
+
"@mysten/bcs": "^0.11.1",
|
|
18
|
+
"@mysten/sui.js": "^0.50.1",
|
|
19
|
+
"esrun": "^3.2.26"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsx": "^4.7.1"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/demand.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { SuiClient, getFullnodeUrl, SuiObjectResponse } from '@mysten/sui.js/client';
|
|
2
|
+
import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
3
|
+
import { BCS } from '@mysten/bcs';
|
|
4
|
+
import { CLOCK_OBJECT, FnCallType, PROTOCOL, description_data} from './protocol';
|
|
5
|
+
import { GuardObject } from './protocol';
|
|
6
|
+
import { verify, PassportObject} from './passport'
|
|
7
|
+
import { PermissionIndex, PermissionObject } from './permission'
|
|
8
|
+
import { ServiceObject } from './service'
|
|
9
|
+
|
|
10
|
+
export type DemandAddress = TransactionResult;
|
|
11
|
+
export type DemandObject = TransactionResult;
|
|
12
|
+
|
|
13
|
+
export const MAX_EARNEST_COUNT = 200;
|
|
14
|
+
export const MAX_PRESENTERS_COUNT = 200;
|
|
15
|
+
|
|
16
|
+
export function demand(earnest_type:string, txb:TransactionBlock, permission:TransactionResult, description:string, earnest:TransactionResult, passport?:PassportObject) : DemandObject {
|
|
17
|
+
if (passport) {
|
|
18
|
+
return txb.moveCall({
|
|
19
|
+
target:PROTOCOL.DemandFn('new_with_passport') as FnCallType,
|
|
20
|
+
arguments:[passport, txb.pure(description_data(description)), earnest, permission],
|
|
21
|
+
typeArguments:[earnest_type],
|
|
22
|
+
})
|
|
23
|
+
} else {
|
|
24
|
+
return txb.moveCall({
|
|
25
|
+
target:PROTOCOL.DemandFn('new') as FnCallType,
|
|
26
|
+
arguments:[txb.pure(description_data(description)), earnest, permission],
|
|
27
|
+
typeArguments:[earnest_type],
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function launch(earnest_type:string, txb:TransactionBlock, demand:DemandObject) : DemandAddress {
|
|
33
|
+
return txb.moveCall({
|
|
34
|
+
target:PROTOCOL.DemandFn('create') as FnCallType,
|
|
35
|
+
arguments:[demand],
|
|
36
|
+
typeArguments:[earnest_type],
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function destroy(earnest_type:string, txb:TransactionBlock, demand:DemandObject) {
|
|
41
|
+
return txb.moveCall({
|
|
42
|
+
target:PROTOCOL.DemandFn('destroy') as FnCallType,
|
|
43
|
+
arguments: [demand],
|
|
44
|
+
typeArguments:[earnest_type]
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
export function demand_refund(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:TransactionResult, passport?:PassportObject) {
|
|
48
|
+
if (passport) {
|
|
49
|
+
txb.moveCall({
|
|
50
|
+
target:PROTOCOL.DemandFn('refund_with_passport') as FnCallType,
|
|
51
|
+
arguments:[passport, demand, txb.object(CLOCK_OBJECT), permission],
|
|
52
|
+
typeArguments:[earnest_type],
|
|
53
|
+
})
|
|
54
|
+
} else {
|
|
55
|
+
txb.moveCall({
|
|
56
|
+
target:PROTOCOL.DemandFn('refund') as FnCallType,
|
|
57
|
+
arguments:[demand, txb.object(CLOCK_OBJECT), permission],
|
|
58
|
+
typeArguments:[earnest_type],
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function demand_expand_time(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:TransactionResult,
|
|
64
|
+
minutes_duration:number, passport?:PassportObject) {
|
|
65
|
+
if (passport) {
|
|
66
|
+
return txb.moveCall({
|
|
67
|
+
target:PROTOCOL.DemandFn('time_expand_with_passport') as FnCallType,
|
|
68
|
+
arguments:[passport, demand, txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), permission],
|
|
69
|
+
typeArguments:[earnest_type],
|
|
70
|
+
})
|
|
71
|
+
} else {
|
|
72
|
+
return txb.moveCall({
|
|
73
|
+
target:PROTOCOL.DemandFn('time_expand') as FnCallType,
|
|
74
|
+
arguments:[demand, txb.pure(minutes_duration, BCS.U64), txb.object(CLOCK_OBJECT), permission],
|
|
75
|
+
typeArguments:[earnest_type],
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function demand_set_guard(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:TransactionResult, guard?:GuardObject, passport?:PassportObject) {
|
|
81
|
+
if (passport) {
|
|
82
|
+
if (guard) {
|
|
83
|
+
return txb.moveCall({
|
|
84
|
+
target:PROTOCOL.DemandFn('guard_set_with_passport') as FnCallType,
|
|
85
|
+
arguments:[passport, demand, guard, permission],
|
|
86
|
+
typeArguments:[earnest_type],
|
|
87
|
+
})
|
|
88
|
+
} else {
|
|
89
|
+
return txb.moveCall({
|
|
90
|
+
target:PROTOCOL.DemandFn('guard_none_with_passport') as FnCallType,
|
|
91
|
+
arguments:[passport, demand, permission],
|
|
92
|
+
typeArguments:[earnest_type],
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
if (guard) {
|
|
97
|
+
return txb.moveCall({
|
|
98
|
+
target:PROTOCOL.DemandFn('guard_set') as FnCallType,
|
|
99
|
+
arguments:[demand, guard, permission],
|
|
100
|
+
typeArguments:[earnest_type],
|
|
101
|
+
})
|
|
102
|
+
} else {
|
|
103
|
+
return txb.moveCall({
|
|
104
|
+
target:PROTOCOL.DemandFn('guard_none') as FnCallType,
|
|
105
|
+
arguments:[demand, permission],
|
|
106
|
+
typeArguments:[earnest_type],
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function demand_set_description(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:TransactionResult, description:string, passport?:PassportObject) {
|
|
113
|
+
if (passport) {
|
|
114
|
+
txb.moveCall({
|
|
115
|
+
target:PROTOCOL.DemandFn('description_set_with_passport') as FnCallType,
|
|
116
|
+
arguments:[passport, demand, txb.pure(description_data(description)), permission],
|
|
117
|
+
typeArguments:[earnest_type],
|
|
118
|
+
})
|
|
119
|
+
} else {
|
|
120
|
+
txb.moveCall({
|
|
121
|
+
target:PROTOCOL.DemandFn('description_set') as FnCallType,
|
|
122
|
+
arguments:[demand, txb.pure(description_data(description)), permission],
|
|
123
|
+
typeArguments:[earnest_type],
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function demand_yes(earnest_type:string, txb:TransactionBlock, demand:DemandObject, permission:TransactionResult, service:string, passport?:PassportObject) {
|
|
129
|
+
if (passport) {
|
|
130
|
+
txb.moveCall({
|
|
131
|
+
target:PROTOCOL.DemandFn('yes_with_passport') as FnCallType,
|
|
132
|
+
arguments:[passport, demand, txb.pure(service, BCS.ADDRESS), permission],
|
|
133
|
+
typeArguments:[earnest_type],
|
|
134
|
+
})
|
|
135
|
+
} else {
|
|
136
|
+
txb.moveCall({
|
|
137
|
+
target:PROTOCOL.DemandFn('yes') as FnCallType,
|
|
138
|
+
arguments:[demand, txb.pure(service, BCS.ADDRESS), permission],
|
|
139
|
+
typeArguments:[earnest_type],
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function deposit(earnest_type:string, txb:TransactionBlock, demand:DemandObject, earnest:TransactionResult) {
|
|
145
|
+
return txb.moveCall({
|
|
146
|
+
target:PROTOCOL.DemandFn('deposit') as FnCallType,
|
|
147
|
+
arguments:[demand, earnest],
|
|
148
|
+
typeArguments:[earnest_type],
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function present(earnest_type:string, service_type:string, txb:TransactionBlock, demand:DemandObject, service:ServiceObject, tips:string, passport?:PassportObject) {
|
|
153
|
+
if (passport) {
|
|
154
|
+
return txb.moveCall({
|
|
155
|
+
target:PROTOCOL.DemandFn('present_with_passport') as FnCallType,
|
|
156
|
+
arguments:[passport, demand, service, txb.pure(description_data(tips)), ],
|
|
157
|
+
typeArguments:[earnest_type, service_type],
|
|
158
|
+
})
|
|
159
|
+
} else {
|
|
160
|
+
return txb.moveCall({
|
|
161
|
+
target:PROTOCOL.DemandFn('present') as FnCallType,
|
|
162
|
+
arguments:[demand, service, txb.pure(description_data(tips)), ],
|
|
163
|
+
typeArguments:[earnest_type, service_type],
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export function change_permission(earnest_type:string, txb:TransactionBlock, demand:DemandObject, old_permission:PermissionObject, new_permission:PermissionObject) {
|
|
168
|
+
txb.moveCall({
|
|
169
|
+
target:PROTOCOL.DemandFn('permission_set') as FnCallType,
|
|
170
|
+
arguments: [demand, old_permission, new_permission],
|
|
171
|
+
typeArguments:[earnest_type]
|
|
172
|
+
})
|
|
173
|
+
}
|