wowok 1.2.5 → 1.2.7
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.d.ts +3 -2
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +21 -7
- package/dist/entity.d.ts +2 -1
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +23 -7
- package/dist/exception.d.ts +3 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +3 -1
- package/dist/guard.js +1 -1
- package/dist/machine.js +2 -2
- package/dist/permission.d.ts +20 -4
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +146 -13
- package/dist/protocol.d.ts +30 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +124 -17
- package/dist/repository.d.ts +6 -3
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +59 -40
- package/dist/resource.d.ts +20 -6
- package/dist/resource.d.ts.map +1 -1
- package/dist/resource.js +58 -21
- package/dist/reward.d.ts +6 -3
- package/dist/reward.d.ts.map +1 -1
- package/dist/reward.js +43 -19
- package/dist/service.d.ts +6 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +76 -44
- package/dist/utils.d.ts +15 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +150 -13
- package/dist/vote.d.ts +2 -2
- package/dist/vote.d.ts.map +1 -1
- package/dist/vote.js +14 -14
- package/package.json +1 -1
- package/src/demand.ts +22 -8
- package/src/entity.ts +25 -6
- package/src/exception.ts +3 -1
- package/src/guard.ts +1 -1
- package/src/machine.ts +2 -2
- package/src/permission.ts +165 -10
- package/src/protocol.ts +127 -17
- package/src/repository.ts +64 -44
- package/src/resource.ts +61 -20
- package/src/reward.ts +46 -23
- package/src/service.ts +79 -46
- package/src/utils.ts +141 -15
- package/src/vote.ts +14 -14
package/dist/utils.js
CHANGED
|
@@ -1,8 +1,70 @@
|
|
|
1
1
|
import { BCS, getSuiMoveConfig } from '@mysten/bcs';
|
|
2
2
|
import { ERROR, Errors } from './exception';
|
|
3
3
|
import { isValidSuiAddress } from '@mysten/sui.js/utils';
|
|
4
|
-
import { ValueType } from './protocol';
|
|
4
|
+
import { RepositoryValueType, ValueType } from './protocol';
|
|
5
|
+
export const MAX_U8 = BigInt('256');
|
|
6
|
+
export const MAX_U64 = BigInt('18446744073709551615');
|
|
7
|
+
export const MAX_U128 = BigInt('340282366920938463463374607431768211455');
|
|
8
|
+
export const MAX_U256 = BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639935');
|
|
5
9
|
export const OPTION_NONE = 0;
|
|
10
|
+
export const ValueTypeConvert = (type) => {
|
|
11
|
+
if (type === ValueType.TYPE_U8 || type === ValueType.TYPE_U64 || type === ValueType.TYPE_U128 ||
|
|
12
|
+
type === ValueType.TYPE_U256 || type === ValueType.TYPE_BOOL) {
|
|
13
|
+
return RepositoryValueType.PositiveNumber;
|
|
14
|
+
}
|
|
15
|
+
else if (type === ValueType.TYPE_VEC_U8 || type === ValueType.TYPE_VEC_U64 || type === ValueType.TYPE_VEC_U128 ||
|
|
16
|
+
type === ValueType.TYPE_VEC_U256 || type === ValueType.TYPE_VEC_BOOL) {
|
|
17
|
+
return RepositoryValueType.PositiveNumber_Vec;
|
|
18
|
+
}
|
|
19
|
+
else if (type === ValueType.TYPE_ADDRESS) {
|
|
20
|
+
return RepositoryValueType.Address;
|
|
21
|
+
}
|
|
22
|
+
else if (type === ValueType.TYPE_VEC_ADDRESS) {
|
|
23
|
+
return RepositoryValueType.Address_Vec;
|
|
24
|
+
}
|
|
25
|
+
else if (type === ValueType.TYPE_STRING) {
|
|
26
|
+
return RepositoryValueType.String;
|
|
27
|
+
}
|
|
28
|
+
else if (type === ValueType.TYPE_VEC_STRING) {
|
|
29
|
+
return RepositoryValueType.String_Vec;
|
|
30
|
+
}
|
|
31
|
+
return -1;
|
|
32
|
+
};
|
|
33
|
+
export const ResolveRepositoryData = (dataType, data) => {
|
|
34
|
+
if (dataType === RepositoryValueType.String) {
|
|
35
|
+
return { type: ValueType.TYPE_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_VEC_U8, new TextEncoder().encode(data.toString())) };
|
|
36
|
+
}
|
|
37
|
+
else if (dataType === RepositoryValueType.PositiveNumber) {
|
|
38
|
+
try {
|
|
39
|
+
const value = BigInt(data.toString());
|
|
40
|
+
var t = ValueType.TYPE_U8;
|
|
41
|
+
if (value <= MAX_U8) {
|
|
42
|
+
}
|
|
43
|
+
else if (value <= MAX_U64) {
|
|
44
|
+
t = ValueType.TYPE_U64;
|
|
45
|
+
}
|
|
46
|
+
else if (value <= MAX_U128) {
|
|
47
|
+
t = ValueType.TYPE_U128;
|
|
48
|
+
}
|
|
49
|
+
else if (value <= MAX_U256) {
|
|
50
|
+
t = ValueType.TYPE_U256;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.log(e);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return { type: t, data: Bcs.getInstance().ser(t, data) };
|
|
61
|
+
}
|
|
62
|
+
else if (dataType === RepositoryValueType.Address) {
|
|
63
|
+
return { type: ValueType.TYPE_ADDRESS, data: Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, data) };
|
|
64
|
+
}
|
|
65
|
+
//@ todo vector....
|
|
66
|
+
return undefined;
|
|
67
|
+
};
|
|
6
68
|
export const readOption = (arr, de) => {
|
|
7
69
|
let o = arr.splice(0, 1);
|
|
8
70
|
if (o[0] == 1) { // true
|
|
@@ -122,6 +184,20 @@ export class Bcs {
|
|
|
122
184
|
'none': null,
|
|
123
185
|
'some': 'T',
|
|
124
186
|
});
|
|
187
|
+
this.bcs.registerStructType('EntStruct', {
|
|
188
|
+
'avatar': 'vector<u8>',
|
|
189
|
+
'resource': "Option<address>",
|
|
190
|
+
'like': BCS.U32,
|
|
191
|
+
'dislike': BCS.U32,
|
|
192
|
+
});
|
|
193
|
+
this.bcs.registerStructType('PersonalInfo', {
|
|
194
|
+
'name': 'vector<u8>',
|
|
195
|
+
'description': 'vector<u8>',
|
|
196
|
+
'avatar': BCS.STRING,
|
|
197
|
+
'twitter': BCS.STRING,
|
|
198
|
+
'discord': BCS.STRING,
|
|
199
|
+
'homepage': BCS.STRING,
|
|
200
|
+
});
|
|
125
201
|
}
|
|
126
202
|
static getInstance() {
|
|
127
203
|
if (!Bcs._instance) {
|
|
@@ -190,6 +266,7 @@ export class Bcs {
|
|
|
190
266
|
case ValueType.TYPE_U64:
|
|
191
267
|
return this.bcs.de(BCS.U64, data);
|
|
192
268
|
case ValueType.TYPE_U8:
|
|
269
|
+
console.log(data);
|
|
193
270
|
return this.bcs.de(BCS.U8, data);
|
|
194
271
|
case ValueType.TYPE_VEC_U8:
|
|
195
272
|
return this.bcs.de('vector<u8>', data);
|
|
@@ -231,6 +308,29 @@ export class Bcs {
|
|
|
231
308
|
ERROR(Errors.bcsTypeInvalid, 'de');
|
|
232
309
|
}
|
|
233
310
|
}
|
|
311
|
+
de_ent(data) {
|
|
312
|
+
const struct_vec = this.bcs.de('vector<u8>', data);
|
|
313
|
+
return this.bcs.de('EntStruct', Uint8Array.from(struct_vec));
|
|
314
|
+
/* const reader = new BcsReader(data);
|
|
315
|
+
const total_len = reader.readULEB();
|
|
316
|
+
console.log(avatar_len)
|
|
317
|
+
const avatar = reader.readBytes(avatar_len);
|
|
318
|
+
console.log(avatar)
|
|
319
|
+
const option_resource = reader.read8();
|
|
320
|
+
var resource = '';
|
|
321
|
+
if (option_resource != 0) {
|
|
322
|
+
resource = reader.read256();
|
|
323
|
+
}
|
|
324
|
+
const like = reader.read32();
|
|
325
|
+
const dislike = reader.read32();
|
|
326
|
+
return {avatar:avatar, resource:resource, like:like, dislike:dislike}*/
|
|
327
|
+
}
|
|
328
|
+
de_entInfo(data) {
|
|
329
|
+
let r = this.bcs.de('PersonalInfo', data);
|
|
330
|
+
r.name = new TextDecoder().decode(Uint8Array.from(r.name));
|
|
331
|
+
r.description = new TextDecoder().decode(Uint8Array.from(r.description));
|
|
332
|
+
return r;
|
|
333
|
+
}
|
|
234
334
|
}
|
|
235
335
|
export function stringToUint8Array(str) {
|
|
236
336
|
var arr = [];
|
|
@@ -251,7 +351,6 @@ export function numToUint8Array(num) {
|
|
|
251
351
|
}
|
|
252
352
|
return new Uint8Array(a);
|
|
253
353
|
}
|
|
254
|
-
// 判断是否为数组
|
|
255
354
|
export const isArr = (origin) => {
|
|
256
355
|
let str = '[object Array]';
|
|
257
356
|
return Object.prototype.toString.call(origin) == str ? true : false;
|
|
@@ -287,7 +386,7 @@ export const IsValidAddress = (addr) => {
|
|
|
287
386
|
}
|
|
288
387
|
return true;
|
|
289
388
|
};
|
|
290
|
-
export const
|
|
389
|
+
export const IsValidTokenType = (argType) => {
|
|
291
390
|
if (!argType || argType.length === 0) {
|
|
292
391
|
return false;
|
|
293
392
|
}
|
|
@@ -295,7 +394,17 @@ export const IsValidArgType = (argType) => {
|
|
|
295
394
|
if (arr.length !== 3) {
|
|
296
395
|
return false;
|
|
297
396
|
}
|
|
298
|
-
if (!IsValidAddress(arr[0]) || arr[1].length === 0 || arr[2].length === 0) {
|
|
397
|
+
if ((!IsValidAddress(arr[0]) && arr[0] != '0x2') || arr[1].length === 0 || arr[2].length === 0) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
};
|
|
402
|
+
export const IsValidArgType = (argType) => {
|
|
403
|
+
if (!argType || argType.length === 0) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
let arr = argType.split('::');
|
|
407
|
+
if (arr.length < 3) {
|
|
299
408
|
return false;
|
|
300
409
|
}
|
|
301
410
|
return true;
|
|
@@ -319,20 +428,48 @@ export const IsValidPercent = (value) => {
|
|
|
319
428
|
return Number.isSafeInteger(value) && value > 0 && value <= 100;
|
|
320
429
|
};
|
|
321
430
|
export const IsValidArray = (arr, validFunc) => {
|
|
322
|
-
let
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
bValid = false;
|
|
431
|
+
for (let i = 0; i < arr.length; ++i) {
|
|
432
|
+
if (!validFunc(arr[i])) {
|
|
433
|
+
return false;
|
|
326
434
|
}
|
|
327
|
-
}
|
|
328
|
-
return
|
|
435
|
+
}
|
|
436
|
+
return true;
|
|
437
|
+
};
|
|
438
|
+
export const ResolveU64 = (value) => {
|
|
439
|
+
const max = MAX_U64;
|
|
440
|
+
if (value > max) {
|
|
441
|
+
return max;
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
export const ResolveBalance = (balance, decimals) => {
|
|
448
|
+
if (!balance)
|
|
449
|
+
return '';
|
|
450
|
+
if (balance === '0')
|
|
451
|
+
return '0';
|
|
452
|
+
if (decimals <= 0)
|
|
453
|
+
return balance;
|
|
454
|
+
var pos = decimals - balance.length;
|
|
455
|
+
if (pos === 0) {
|
|
456
|
+
return '.' + balance;
|
|
457
|
+
}
|
|
458
|
+
else if (pos < 0) {
|
|
459
|
+
let start = balance.slice(0, Math.abs(pos));
|
|
460
|
+
let end = balance.slice(Math.abs(pos));
|
|
461
|
+
return start + '.' + end;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
return '.' + balance.padStart(pos, '0');
|
|
465
|
+
}
|
|
329
466
|
};
|
|
330
467
|
export const OptionNone = (txb) => { return txb.pure([], BCS.U8); };
|
|
331
468
|
export const ParseType = (type) => {
|
|
332
469
|
if (type) {
|
|
333
|
-
const COIN = '
|
|
470
|
+
const COIN = '0x2::coin::Coin<';
|
|
334
471
|
let i = type.indexOf(COIN);
|
|
335
|
-
if (i
|
|
472
|
+
if (i >= 0) {
|
|
336
473
|
let coin = type.slice(i + COIN.length, type.length - 1);
|
|
337
474
|
if (coin.indexOf('<') === -1) {
|
|
338
475
|
while (coin[coin.length - 1] == '>') {
|
|
@@ -373,5 +510,5 @@ export function isValidHttpUrl(url) {
|
|
|
373
510
|
catch (_) {
|
|
374
511
|
return false;
|
|
375
512
|
}
|
|
376
|
-
return r.protocol === "http:" || r.protocol === "https:";
|
|
513
|
+
return r.protocol === "http:" || r.protocol === "https:" || r.protocol === 'ipfs:';
|
|
377
514
|
}
|
package/dist/vote.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Vote {
|
|
|
12
12
|
get_object(): TxbObject;
|
|
13
13
|
private constructor();
|
|
14
14
|
static From(protocol: Protocol, permission: PermissionObject, object: TxbObject): Vote;
|
|
15
|
-
static New(protocol: Protocol, permission: PermissionObject, description: string, minutes_duration: number, max_choice_count?: number, reference_address?: string, passport?: PassportObject): Vote;
|
|
15
|
+
static New(protocol: Protocol, permission: PermissionObject, description: string, minutes_duration: boolean, time: number, max_choice_count?: number, reference_address?: string, passport?: PassportObject): Vote;
|
|
16
16
|
launch(): VoteAddress;
|
|
17
17
|
destroy(): void;
|
|
18
18
|
set_description(description: string, passport?: PassportObject): void;
|
|
@@ -24,7 +24,7 @@ export declare class Vote {
|
|
|
24
24
|
set_max_choice_count(max_choice_count: number, passport?: PassportObject): void;
|
|
25
25
|
open_voting(passport?: PassportObject): void;
|
|
26
26
|
lock_deadline(passport?: PassportObject): void;
|
|
27
|
-
expand_deadline(
|
|
27
|
+
expand_deadline(ms_expand: boolean, time: number, passport?: PassportObject): void;
|
|
28
28
|
lock_guard(passport?: PassportObject): void;
|
|
29
29
|
agree(options: string[], passport?: PassportObject): void;
|
|
30
30
|
change_permission(new_permission: PermissionObject): void;
|
package/dist/vote.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vote.d.ts","sourceRoot":"","sources":["../src/vote.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAKxH,eAAO,MAAM,gBAAgB,MAAM,CAAC;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15 +20,15 @@ export class Vote {
|
|
|
20
20
|
v.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
|
|
21
21
|
return v;
|
|
22
22
|
}
|
|
23
|
-
static New(protocol, permission, description, minutes_duration, max_choice_count, reference_address, passport) {
|
|
23
|
+
static New(protocol, permission, description, minutes_duration, time, max_choice_count, reference_address, passport) {
|
|
24
24
|
if (!Protocol.IsValidObjects([permission])) {
|
|
25
25
|
ERROR(Errors.IsValidObjects, 'permission');
|
|
26
26
|
}
|
|
27
27
|
if (!IsValidDesription(description)) {
|
|
28
28
|
ERROR(Errors.IsValidDesription);
|
|
29
29
|
}
|
|
30
|
-
if (!IsValidUint(
|
|
31
|
-
ERROR(Errors.IsValidUint, '
|
|
30
|
+
if (!IsValidUint(time)) {
|
|
31
|
+
ERROR(Errors.IsValidUint, 'time');
|
|
32
32
|
}
|
|
33
33
|
if (max_choice_count && !IsValidUint(max_choice_count)) {
|
|
34
34
|
ERROR(Errors.IsValidUint, 'max_choice_count');
|
|
@@ -46,15 +46,15 @@ export class Vote {
|
|
|
46
46
|
if (passport) {
|
|
47
47
|
v.object = txb.moveCall({
|
|
48
48
|
target: protocol.VoteFn('new_with_passport'),
|
|
49
|
-
arguments: [passport, txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT),
|
|
50
|
-
txb.pure(
|
|
49
|
+
arguments: [passport, txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
|
|
50
|
+
txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
v.object = txb.moveCall({
|
|
55
55
|
target: protocol.VoteFn('new'),
|
|
56
|
-
arguments: [txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT),
|
|
57
|
-
txb.pure(
|
|
56
|
+
arguments: [txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
|
|
57
|
+
txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
return v;
|
|
@@ -298,23 +298,23 @@ export class Vote {
|
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
-
expand_deadline(
|
|
302
|
-
if (!IsValidUint(
|
|
303
|
-
ERROR(Errors.IsValidUint, '
|
|
301
|
+
expand_deadline(ms_expand, time, passport) {
|
|
302
|
+
if (!IsValidUint(time)) {
|
|
303
|
+
ERROR(Errors.IsValidUint, 'time');
|
|
304
304
|
}
|
|
305
305
|
let txb = this.protocol.CurrentSession();
|
|
306
306
|
if (passport) {
|
|
307
307
|
txb.moveCall({
|
|
308
308
|
target: this.protocol.VoteFn('deadline_expand_with_passport'),
|
|
309
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
310
|
-
txb.pure(
|
|
309
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
|
|
310
|
+
txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
314
314
|
txb.moveCall({
|
|
315
315
|
target: this.protocol.VoteFn('deadline_expand'),
|
|
316
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object),
|
|
317
|
-
txb.pure(
|
|
316
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
|
|
317
|
+
txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
}
|
package/package.json
CHANGED
package/src/demand.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class Demand {
|
|
|
28
28
|
this.object = '';
|
|
29
29
|
}
|
|
30
30
|
static New(protocol:Protocol, bounty_type:string, permission:PermissionObject, description:string,
|
|
31
|
-
bounty:TransactionResult, passport?:PassportObject) : Demand {
|
|
31
|
+
bounty:TransactionResult | string, passport?:PassportObject) : Demand {
|
|
32
32
|
if (!Protocol.IsValidObjects([permission, bounty])) {
|
|
33
33
|
ERROR(Errors.IsValidObjects, 'permission, bounty');
|
|
34
34
|
}
|
|
@@ -44,13 +44,13 @@ export class Demand {
|
|
|
44
44
|
if (passport) {
|
|
45
45
|
d.object = txb.moveCall({
|
|
46
46
|
target:protocol.DemandFn('new_with_passport') as FnCallType,
|
|
47
|
-
arguments:[passport, txb.pure(description), bounty, Protocol.TXB_OBJECT(txb, permission)],
|
|
47
|
+
arguments:[passport, txb.pure(description), txb.object(bounty), Protocol.TXB_OBJECT(txb, permission)],
|
|
48
48
|
typeArguments:[bounty_type],
|
|
49
49
|
})
|
|
50
50
|
} else {
|
|
51
51
|
d.object = txb.moveCall({
|
|
52
52
|
target:protocol.DemandFn('new') as FnCallType,
|
|
53
|
-
arguments:[txb.pure(description), bounty, Protocol.TXB_OBJECT(txb, permission)],
|
|
53
|
+
arguments:[txb.pure(description), txb.object(bounty), Protocol.TXB_OBJECT(txb, permission)],
|
|
54
54
|
typeArguments:[bounty_type],
|
|
55
55
|
})
|
|
56
56
|
}
|
|
@@ -92,23 +92,26 @@ export class Demand {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
// minutes_duration TRUE , time is minutes count; otherwise, the deadline time
|
|
96
|
+
expand_time(minutes_duration:boolean, time: number, passport?:PassportObject) {
|
|
97
|
+
if (!IsValidUint(time)) {
|
|
98
|
+
ERROR(Errors.IsValidUint, 'time');
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
let txb = this.protocol.CurrentSession();
|
|
101
102
|
if (passport) {
|
|
102
103
|
txb.moveCall({
|
|
103
104
|
target:this.protocol.DemandFn('time_expand_with_passport') as FnCallType,
|
|
104
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.
|
|
105
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.BOOL),
|
|
106
|
+
txb.pure(time, BCS.U64),
|
|
105
107
|
txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
106
108
|
typeArguments:[this.bounty_type],
|
|
107
109
|
})
|
|
108
110
|
} else {
|
|
109
111
|
txb.moveCall({
|
|
110
112
|
target:this.protocol.DemandFn('time_expand') as FnCallType,
|
|
111
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
113
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(minutes_duration, BCS.BOOL),
|
|
114
|
+
txb.pure(time, BCS.U64),
|
|
112
115
|
txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
113
116
|
typeArguments:[this.bounty_type],
|
|
114
117
|
})
|
|
@@ -255,6 +258,17 @@ export class Demand {
|
|
|
255
258
|
})
|
|
256
259
|
this.permission = new_permission
|
|
257
260
|
}
|
|
261
|
+
static parseObjectType = (chain_type:string) : string => {
|
|
262
|
+
if (chain_type) {
|
|
263
|
+
const s = 'demand::Demand<'
|
|
264
|
+
const i = chain_type.indexOf(s);
|
|
265
|
+
if (i > 0) {
|
|
266
|
+
let r = chain_type.slice(i + s.length, chain_type.length-1);
|
|
267
|
+
return r
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return '';
|
|
271
|
+
}
|
|
258
272
|
|
|
259
273
|
static MAX_BOUNTY_COUNT = 200;
|
|
260
274
|
static MAX_PRESENTERS_COUNT = 200;
|
package/src/entity.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BCS } from '@mysten/bcs';
|
|
1
|
+
import { BCS, encodeStr, getSuiMoveConfig } from '@mysten/bcs';
|
|
2
2
|
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject, ResourceObject} from './protocol';
|
|
3
3
|
import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
@@ -48,19 +48,26 @@ export class Entity {
|
|
|
48
48
|
if (info?.homepage && !isValidHttpUrl(info.homepage)) ERROR(Errors.isValidHttpUrl, 'update:homepage');
|
|
49
49
|
if (info?.discord && !IsValidName(info.discord)) ERROR(Errors.IsValidName, 'update:discord');
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
const txb = this.protocol.CurrentSession();
|
|
52
|
+
const bytes = Bcs.getInstance().bcs.ser('PersonalInfo', {
|
|
53
|
+
name:info.name ? new TextEncoder().encode(info.name) :'',
|
|
54
|
+
description : info?.description ? new TextEncoder().encode(info.description) : '',
|
|
55
|
+
avatar : info?.avatar ?? '',
|
|
56
|
+
twitter : info?.twitter ?? '',
|
|
57
|
+
discord : info?.discord ?? '',
|
|
58
|
+
homepage : info?.homepage ?? '',
|
|
59
|
+
}).toBytes();
|
|
52
60
|
txb.moveCall({
|
|
53
61
|
target:this.protocol.EntityFn('avatar_update') as FnCallType,
|
|
54
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(
|
|
62
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure([].slice.call(bytes), 'vector<u8>')]
|
|
55
63
|
})
|
|
56
64
|
}
|
|
57
65
|
|
|
58
|
-
create_resource(
|
|
59
|
-
if (!IsValidDesription(description)) ERROR(Errors.IsValidDesription, 'create_resource');
|
|
66
|
+
create_resource() : ResourceAddress {
|
|
60
67
|
let txb = this.protocol.CurrentSession();
|
|
61
68
|
return txb.moveCall({
|
|
62
69
|
target:this.protocol.EntityFn('resource_create') as FnCallType,
|
|
63
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object)
|
|
70
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
64
71
|
})
|
|
65
72
|
}
|
|
66
73
|
|
|
@@ -80,4 +87,16 @@ export class Entity {
|
|
|
80
87
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, resource.get_object()), txb.pure(new_address, BCS.ADDRESS)]
|
|
81
88
|
})
|
|
82
89
|
}
|
|
90
|
+
|
|
91
|
+
query_ent(address_queried:string) {
|
|
92
|
+
if (!address_queried) {
|
|
93
|
+
ERROR(Errors.InvalidParam, 'query_ent');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const txb = this.protocol.CurrentSession();
|
|
97
|
+
txb.moveCall({
|
|
98
|
+
target:this.protocol.EntityFn('QueryEnt') as FnCallType,
|
|
99
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(address_queried, BCS.ADDRESS)]
|
|
100
|
+
})
|
|
101
|
+
}
|
|
83
102
|
}
|
package/src/exception.ts
CHANGED
|
@@ -5,7 +5,8 @@ export enum Errors {
|
|
|
5
5
|
IsValidName_AllowEmpty = 'invalid name',
|
|
6
6
|
IsValidEndpoint = 'invalid endpoint',
|
|
7
7
|
IsValidAddress = 'invalid address',
|
|
8
|
-
IsValidArgType = 'invalid
|
|
8
|
+
IsValidArgType = 'invalid argument type',
|
|
9
|
+
IsValidTokenType = 'invalid token type',
|
|
9
10
|
IsValidUint = 'invalid uint',
|
|
10
11
|
IsValidInt = 'invalid int',
|
|
11
12
|
IsValidPercent = 'invalid percent',
|
|
@@ -18,6 +19,7 @@ export enum Errors {
|
|
|
18
19
|
Fail = 'fail',
|
|
19
20
|
IsValidIndentifier = 'indentifier invalid',
|
|
20
21
|
isValidHttpUrl = 'invalid url',
|
|
22
|
+
IsValidUserDefinedIndex = 'invalid user defined permission index',
|
|
21
23
|
bcsTypeInvalid = 'invalid bcs type',
|
|
22
24
|
}
|
|
23
25
|
|
package/src/guard.ts
CHANGED
|
@@ -194,7 +194,7 @@ export class Guard {
|
|
|
194
194
|
[MODULES.reward, 'sponsor', 162, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
195
195
|
[MODULES.reward, 'sponsor_count', 163, [], ValueType.TYPE_U64],
|
|
196
196
|
[MODULES.reward, 'bAllowRepeatClaim', 164, [], ValueType.TYPE_BOOL],
|
|
197
|
-
[MODULES.reward, '
|
|
197
|
+
[MODULES.reward, 'claimed_portions_count', 165, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64],
|
|
198
198
|
|
|
199
199
|
[MODULES.vote, 'permission', 171, [], ValueType.TYPE_ADDRESS],
|
|
200
200
|
[MODULES.vote, 'bOptions_locked_for_voting', 172, [], ValueType.TYPE_BOOL],
|
package/src/machine.ts
CHANGED
|
@@ -247,7 +247,7 @@ export class Machine {
|
|
|
247
247
|
} else {
|
|
248
248
|
txb.moveCall({
|
|
249
249
|
target:this.protocol.MachineFn('repository_remove_with_passport') as FnCallType,
|
|
250
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(repositories, 'vector<address>'),
|
|
250
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
|
|
251
251
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
252
252
|
})
|
|
253
253
|
}
|
|
@@ -260,7 +260,7 @@ export class Machine {
|
|
|
260
260
|
} else {
|
|
261
261
|
txb.moveCall({
|
|
262
262
|
target:this.protocol.MachineFn('repository_remove') as FnCallType,
|
|
263
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(repositories, 'vector<address>'),
|
|
263
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(repositories), 'vector<address>'),
|
|
264
264
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
265
265
|
})
|
|
266
266
|
}
|