wowok 1.1.0 → 1.1.2
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.d.ts +2 -3
- package/dist/demand.d.ts.map +1 -1
- package/dist/demand.js +19 -11
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/graphql.d.ts +2 -0
- package/dist/graphql.d.ts.map +1 -1
- package/dist/graphql.js +19 -0
- package/dist/guard.d.ts +18 -23
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +220 -199
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/machine.d.ts +6 -6
- package/dist/machine.d.ts.map +1 -1
- package/dist/machine.js +7 -7
- package/dist/passport.d.ts +34 -22
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +124 -214
- package/dist/permission.d.ts +3 -0
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +5 -2
- package/dist/progress.js +3 -3
- package/dist/protocol.d.ts +11 -5
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +30 -6
- package/dist/repository.d.ts +2 -0
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +73 -5
- package/dist/service.d.ts +3 -3
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +115 -116
- package/dist/utils.d.ts +10 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +39 -1
- package/dist/vote.js +8 -8
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/graphql.ts +20 -0
- package/src/guard.ts +208 -192
- package/src/index.ts +1 -0
- package/src/machine.ts +10 -10
- package/src/passport.ts +139 -251
- package/src/permission.ts +5 -2
- package/src/progress.ts +3 -3
- package/src/protocol.ts +26 -5
- package/src/repository.ts +73 -5
- package/src/service.ts +25 -25
- package/src/utils.ts +44 -4
- package/src/vote.ts +8 -8
- package/tsconfig.json +3 -2
package/dist/utils.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export declare function capitalize(s: string): string;
|
|
|
11
11
|
export declare function parse_object_type(object_data: string): string[];
|
|
12
12
|
export declare class Bcs {
|
|
13
13
|
bcs: BCS;
|
|
14
|
-
|
|
14
|
+
private static _instance;
|
|
15
|
+
private constructor();
|
|
16
|
+
static getInstance(): Bcs;
|
|
15
17
|
ser_option_string(data: string): Uint8Array;
|
|
16
18
|
ser_option_u64(data: number): Uint8Array;
|
|
17
19
|
ser_option_address(data: string): Uint8Array;
|
|
@@ -26,7 +28,6 @@ export declare class Bcs {
|
|
|
26
28
|
ser_string(data: string): Uint8Array;
|
|
27
29
|
de(type: TypeName | StructTypeDefinition, data: Uint8Array): any;
|
|
28
30
|
}
|
|
29
|
-
export declare const BCS_CONVERT: Bcs;
|
|
30
31
|
export declare function stringToUint8Array(str: string): Uint8Array;
|
|
31
32
|
export declare function numToUint8Array(num: number): Uint8Array;
|
|
32
33
|
export declare const isArr: (origin: any) => boolean;
|
|
@@ -45,4 +46,11 @@ export declare const IsValidInt: (value: number) => boolean;
|
|
|
45
46
|
export declare const IsValidPercent: (value: number) => boolean;
|
|
46
47
|
export declare const IsValidArray: (arr: any[], validFunc: any) => boolean;
|
|
47
48
|
export declare const OptionNone: (txb: TransactionBlock) => TransactionArgument;
|
|
49
|
+
export type ArgType = {
|
|
50
|
+
isCoin: boolean;
|
|
51
|
+
coin: string;
|
|
52
|
+
token: string;
|
|
53
|
+
};
|
|
54
|
+
export declare const ParseType: (type: string) => ArgType;
|
|
55
|
+
export declare function toFixed(x: number): string;
|
|
48
56
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,GAAG,EAAoC,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa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AGxC,eAAO,MAAM,iBAAiB,gBAAgB,MAAM,KAAI,OAAmE,CAAA;AAC3H,eAAO,MAAM,WAAW,SAAS,MAAM,KAAI,OAAgG,CAAA;AAC3I,eAAO,MAAM,sBAAsB,SAAS,MAAM,KAAI,OAAoD,CAAA;AAC1G,eAAO,MAAM,eAAe,aAAa,MAAM,KAAI,OAAyF,CAAA;AAC5I,eAAO,MAAM,cAAc,SAAS,MAAM,KAAI,OAAkD,CAAA;AAChG,eAAO,MAAM,cAAc,YAAa,MAAM,KAAI,OAAqE,CAAA;AACvH,eAAO,MAAM,WAAW,UAAW,MAAM,KAAI,OAA+D,CAAA;AAC5G,eAAO,MAAM,UAAU,UAAW,MAAM,KAAI,OAAiD,CAAA;AAC7F,eAAO,MAAM,cAAc,UAAW,MAAM,KAAI,OAA8E,CAAA;AAC9H,eAAO,MAAM,YAAY,QAAS,GAAG,EAAE,aAAY,GAAG,KAAI,OAQzD,CAAA;AAED,eAAO,MAAM,UAAU,QAAQ,gBAAgB,KAAI,mBAAsD,CAAC;AAE1G,MAAM,MAAM,OAAO,GAAG;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACjB,CAAA;AACD,eAAO,MAAM,SAAS,SAAS,MAAM,KAAI,OAWxC,CAAA;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAC,MAAM,UAiB7B"}
|
package/dist/utils.js
CHANGED
|
@@ -62,12 +62,20 @@ export function parse_object_type(object_data) {
|
|
|
62
62
|
}
|
|
63
63
|
export class Bcs {
|
|
64
64
|
bcs = new BCS(getSuiMoveConfig());
|
|
65
|
+
static _instance;
|
|
65
66
|
constructor() {
|
|
66
67
|
this.bcs.registerEnumType('Option<T>', {
|
|
67
68
|
'none': null,
|
|
68
69
|
'some': 'T',
|
|
69
70
|
});
|
|
70
71
|
}
|
|
72
|
+
static getInstance() {
|
|
73
|
+
if (!Bcs._instance) {
|
|
74
|
+
Bcs._instance = new Bcs();
|
|
75
|
+
}
|
|
76
|
+
;
|
|
77
|
+
return Bcs._instance;
|
|
78
|
+
}
|
|
71
79
|
ser_option_string(data) {
|
|
72
80
|
return this.bcs.ser('Option<string>', { 'some': data }).toBytes();
|
|
73
81
|
}
|
|
@@ -108,7 +116,6 @@ export class Bcs {
|
|
|
108
116
|
return this.bcs.de(type, data);
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
|
-
export const BCS_CONVERT = new Bcs();
|
|
112
119
|
export function stringToUint8Array(str) {
|
|
113
120
|
var arr = [];
|
|
114
121
|
for (var i = 0, j = str.length; i < j; ++i) {
|
|
@@ -175,3 +182,34 @@ export const IsValidArray = (arr, validFunc) => {
|
|
|
175
182
|
return bValid;
|
|
176
183
|
};
|
|
177
184
|
export const OptionNone = (txb) => { return txb.pure([], BCS.U8); };
|
|
185
|
+
export const ParseType = (type) => {
|
|
186
|
+
let i = type.indexOf('<');
|
|
187
|
+
if (i > 0 && type.length > 12) {
|
|
188
|
+
let c = type.slice(0, i);
|
|
189
|
+
if (c === '0x2::coin::Coin' || c === '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin') {
|
|
190
|
+
let coin = type.slice(i + 1, type.length - 1); // < >>
|
|
191
|
+
let t = coin.lastIndexOf('::');
|
|
192
|
+
return { isCoin: true, coin: coin, token: coin.slice(t + 2) };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { isCoin: false, coin: '', token: '' };
|
|
196
|
+
};
|
|
197
|
+
export function toFixed(x) {
|
|
198
|
+
let res = '';
|
|
199
|
+
if (Math.abs(x) < 1.0) {
|
|
200
|
+
var e = parseInt(x.toString().split('e-')[1]);
|
|
201
|
+
if (e) {
|
|
202
|
+
x *= Math.pow(10, e - 1);
|
|
203
|
+
res = '0.' + (new Array(e)).join('0') + x.toString().substring(2);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
var e = parseInt(x.toString().split('+')[1]);
|
|
208
|
+
if (e > 20) {
|
|
209
|
+
e -= 20;
|
|
210
|
+
x /= Math.pow(10, e);
|
|
211
|
+
res = x + (new Array(e + 1)).join('0');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return res;
|
|
215
|
+
}
|
package/dist/vote.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { Protocol } from './protocol';
|
|
3
|
-
import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone,
|
|
3
|
+
import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
5
|
export const MAX_AGREES_COUNT = 200;
|
|
6
6
|
export const MAX_CHOICE_COUNT = 200;
|
|
@@ -40,7 +40,7 @@ export class Vote {
|
|
|
40
40
|
ERROR(Errors.IsValidAddress, 'reference_address');
|
|
41
41
|
}
|
|
42
42
|
let txb = protocol.CurrentSession();
|
|
43
|
-
let reference = reference_address ? txb.pure(
|
|
43
|
+
let reference = reference_address ? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
|
|
44
44
|
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
45
45
|
if (passport) {
|
|
46
46
|
v.object = txb.moveCall({
|
|
@@ -95,7 +95,7 @@ export class Vote {
|
|
|
95
95
|
ERROR(Errors.IsValidAddress);
|
|
96
96
|
}
|
|
97
97
|
let txb = this.protocol.CurrentSession();
|
|
98
|
-
let reference = reference_address ? txb.pure(
|
|
98
|
+
let reference = reference_address ? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
|
|
99
99
|
if (passport) {
|
|
100
100
|
txb.moveCall({
|
|
101
101
|
target: this.protocol.VoteFn('reference_set_with_passport'),
|
|
@@ -189,7 +189,7 @@ export class Vote {
|
|
|
189
189
|
let txb = this.protocol.CurrentSession();
|
|
190
190
|
options.forEach((option) => {
|
|
191
191
|
let reference = option?.reference_address ?
|
|
192
|
-
txb.pure(
|
|
192
|
+
txb.pure(Bcs.getInstance().ser_option_address(option.reference_address)) :
|
|
193
193
|
OptionNone(txb);
|
|
194
194
|
if (passport) {
|
|
195
195
|
txb.moveCall({
|
|
@@ -226,7 +226,7 @@ export class Vote {
|
|
|
226
226
|
txb.moveCall({
|
|
227
227
|
target: this.protocol.VoteFn('agrees_remove_with_passport'),
|
|
228
228
|
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
229
|
-
txb.pure(
|
|
229
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
|
|
230
230
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
231
231
|
});
|
|
232
232
|
}
|
|
@@ -242,7 +242,7 @@ export class Vote {
|
|
|
242
242
|
txb.moveCall({
|
|
243
243
|
target: this.protocol.VoteFn('agrees_remove'),
|
|
244
244
|
arguments: [Protocol.TXB_OBJECT(txb, this.object),
|
|
245
|
-
txb.pure(
|
|
245
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
|
|
246
246
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
247
247
|
});
|
|
248
248
|
}
|
|
@@ -341,14 +341,14 @@ export class Vote {
|
|
|
341
341
|
txb.moveCall({
|
|
342
342
|
target: this.protocol.VoteFn('with_passport'),
|
|
343
343
|
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
344
|
-
txb.pure(
|
|
344
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
else {
|
|
348
348
|
txb.moveCall({
|
|
349
349
|
target: this.protocol.VoteFn('this.object'),
|
|
350
350
|
arguments: [Protocol.TXB_OBJECT(txb, this.object),
|
|
351
|
-
txb.pure(
|
|
351
|
+
txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
}
|
package/package.json
CHANGED
package/src/exception.ts
CHANGED
package/src/graphql.ts
CHANGED
|
@@ -17,6 +17,18 @@ export const GRAPHQL_OBJECTS_TYPE = gql(`
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
`);
|
|
20
|
+
export const GRAPHQL_CHILD_OBJECT = gql(`
|
|
21
|
+
query object($ObjectID:SuiAddress!) {
|
|
22
|
+
object(address:$ObjectID) {
|
|
23
|
+
address
|
|
24
|
+
asMoveObject {
|
|
25
|
+
contents {
|
|
26
|
+
json
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`);
|
|
20
32
|
|
|
21
33
|
export const GRAPHQL_OBJECT = gql(`
|
|
22
34
|
query object($ObjectID:SuiAddress!) {
|
|
@@ -101,3 +113,11 @@ export const GRAPHQL_OBJECTS = gql(`
|
|
|
101
113
|
}
|
|
102
114
|
}
|
|
103
115
|
`);
|
|
116
|
+
|
|
117
|
+
export const GRAPHQL_DECIMALS = gql(`
|
|
118
|
+
query getTotalSupply($coinType: String!) {
|
|
119
|
+
coinMetadata(coinType: $coinType) {
|
|
120
|
+
decimals
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`);
|