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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/demand.d.ts +2 -3
  3. package/dist/demand.d.ts.map +1 -1
  4. package/dist/demand.js +19 -11
  5. package/dist/exception.d.ts +2 -1
  6. package/dist/exception.d.ts.map +1 -1
  7. package/dist/exception.js +1 -0
  8. package/dist/graphql.d.ts +2 -0
  9. package/dist/graphql.d.ts.map +1 -1
  10. package/dist/graphql.js +19 -0
  11. package/dist/guard.d.ts +18 -23
  12. package/dist/guard.d.ts.map +1 -1
  13. package/dist/guard.js +220 -199
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/machine.d.ts +6 -6
  18. package/dist/machine.d.ts.map +1 -1
  19. package/dist/machine.js +7 -7
  20. package/dist/passport.d.ts +34 -22
  21. package/dist/passport.d.ts.map +1 -1
  22. package/dist/passport.js +124 -214
  23. package/dist/permission.d.ts +3 -0
  24. package/dist/permission.d.ts.map +1 -1
  25. package/dist/permission.js +5 -2
  26. package/dist/progress.js +3 -3
  27. package/dist/protocol.d.ts +11 -5
  28. package/dist/protocol.d.ts.map +1 -1
  29. package/dist/protocol.js +30 -6
  30. package/dist/repository.d.ts +2 -0
  31. package/dist/repository.d.ts.map +1 -1
  32. package/dist/repository.js +73 -5
  33. package/dist/service.d.ts +3 -3
  34. package/dist/service.d.ts.map +1 -1
  35. package/dist/service.js +115 -116
  36. package/dist/utils.d.ts +10 -2
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js +39 -1
  39. package/dist/vote.js +8 -8
  40. package/package.json +1 -1
  41. package/src/exception.ts +1 -0
  42. package/src/graphql.ts +20 -0
  43. package/src/guard.ts +208 -192
  44. package/src/index.ts +1 -0
  45. package/src/machine.ts +10 -10
  46. package/src/passport.ts +139 -251
  47. package/src/permission.ts +5 -2
  48. package/src/progress.ts +3 -3
  49. package/src/protocol.ts +26 -5
  50. package/src/repository.ts +73 -5
  51. package/src/service.ts +25 -25
  52. package/src/utils.ts +44 -4
  53. package/src/vote.ts +8 -8
  54. 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
- constructor();
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
@@ -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,CAAC;AACzG,OAAO,EAAE,gBAAgB,EAA6B,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE/G,eAAO,MAAM,UA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ED,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, BCS_CONVERT, array_unique, IsValidArray, IsValidName } from './utils';
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(BCS_CONVERT.ser_option_address(reference_address)) : OptionNone(txb);
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(BCS_CONVERT.ser_option_address(reference_address)) : OptionNone(txb);
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(BCS_CONVERT.ser_option_address(option.reference_address)) :
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(BCS_CONVERT.ser_vector_string(array_unique(options))),
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(BCS_CONVERT.ser_vector_string(array_unique(options))),
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(BCS_CONVERT.ser_vector_string(array_unique(options)))]
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(BCS_CONVERT.ser_vector_string(array_unique(options)))]
351
+ txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
352
352
  });
353
353
  }
354
354
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "AI-oriented web3 collaboration protocol, driving innovaion and making it more likely to happen.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/exception.ts CHANGED
@@ -15,6 +15,7 @@ export enum Errors {
15
15
  InvalidParam = 'invalid parameter',
16
16
  IsValidPermissionIndex = 'invalid permission index',
17
17
  IsValidKey = 'invalid key',
18
+ Fail = 'fail',
18
19
  }
19
20
 
20
21
  export const ERROR = (error:Errors, info?:any) => {
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
+ `);