wowok 1.2.3 → 1.2.5

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/utils.js CHANGED
@@ -1,6 +1,7 @@
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
5
  export const OPTION_NONE = 0;
5
6
  export const readOption = (arr, de) => {
6
7
  let o = arr.splice(0, 1);
@@ -15,6 +16,22 @@ export const readOption = (arr, de) => {
15
16
  return { bNone: true, value: OPTION_NONE };
16
17
  }
17
18
  };
19
+ export const readOptionString = (arr) => {
20
+ let o = arr.splice(0, 1);
21
+ if (o[0] == 1) { // true
22
+ let r = ulebDecode(Uint8Array.from(arr));
23
+ let value = Bcs.getInstance().de(ValueType.TYPE_STRING, Uint8Array.from(arr));
24
+ arr.splice(0, r.value + r.length);
25
+ return { bNone: false, value: value };
26
+ }
27
+ else if (o[0] == 0) {
28
+ return { bNone: true, value: OPTION_NONE };
29
+ }
30
+ else {
31
+ ERROR(Errors.Fail, 'readOption: option invalid');
32
+ return { bNone: true, value: OPTION_NONE };
33
+ }
34
+ };
18
35
  export const ulebDecode = (arr) => {
19
36
  let total = 0;
20
37
  let shift = 0;
@@ -113,62 +130,106 @@ export class Bcs {
113
130
  ;
114
131
  return Bcs._instance;
115
132
  }
116
- ser_option_string(data) {
117
- return this.bcs.ser('Option<string>', { 'some': data }).toBytes();
118
- }
119
- ser_option_u64(data) {
120
- return this.bcs.ser('Option<u64>', { 'some': data }).toBytes();
121
- }
122
- ser_option_address(data) {
123
- return this.bcs.ser('Option<address>', { 'some': data }).toBytes();
124
- }
125
- ser_vector_string(data) {
126
- return this.bcs.ser('vector<string>', data).toBytes();
127
- }
128
- ser_vector_vector_u8(data) {
129
- return this.bcs.ser('vector<vector<u8>>', data).toBytes();
130
- }
131
- ser_vector_u64(data) {
132
- return this.bcs.ser('vector<u64>', data).toBytes();
133
- }
134
- ser_vector_u8(data) {
135
- return this.bcs.ser('vector<u8>', data).toBytes();
136
- }
137
- ser_vector_address(data) {
138
- return this.bcs.ser('vector<address>', data).toBytes();
139
- }
140
- ser_vector_bool(data) {
141
- return this.bcs.ser('vector<bool>', data).toBytes();
142
- }
143
- ser_vector_u128(data) {
144
- return this.bcs.ser('vector<u128>', data).toBytes();
145
- }
146
- ser_address(data) {
147
- return this.bcs.ser(BCS.ADDRESS, data).toBytes();
148
- }
149
- ser_bool(data) {
150
- return this.bcs.ser(BCS.BOOL, data).toBytes();
151
- }
152
- ser_u8(data) {
153
- return this.bcs.ser(BCS.U8, data).toBytes();
154
- }
155
- ser_u64(data) {
156
- return this.bcs.ser(BCS.U64, data).toBytes();
157
- }
158
- ser_u128(data) {
159
- return this.bcs.ser(BCS.U128, data).toBytes();
160
- }
161
- ser_u256(data) {
162
- return this.bcs.ser(BCS.U256, data).toBytes();
163
- }
164
- ser_string(data) {
165
- return this.bcs.ser(BCS.STRING, data).toBytes();
166
- }
167
133
  ser(type, data) {
168
- return this.bcs.ser(type, data).toBytes();
134
+ switch (type) {
135
+ case ValueType.TYPE_BOOL:
136
+ return this.bcs.ser(BCS.BOOL, data).toBytes();
137
+ case ValueType.TYPE_ADDRESS:
138
+ return this.bcs.ser(BCS.ADDRESS, data).toBytes();
139
+ case ValueType.TYPE_U64:
140
+ return this.bcs.ser(BCS.U64, data).toBytes();
141
+ case ValueType.TYPE_U8:
142
+ return this.bcs.ser(BCS.U8, data).toBytes();
143
+ case ValueType.TYPE_VEC_U8:
144
+ return this.bcs.ser('vector<u8>', data).toBytes();
145
+ case ValueType.TYPE_U128:
146
+ return this.bcs.ser(BCS.U128, data).toBytes();
147
+ case ValueType.TYPE_VEC_ADDRESS:
148
+ return this.bcs.ser('vector<address>', data).toBytes();
149
+ case ValueType.TYPE_VEC_BOOL:
150
+ return this.bcs.ser('vector<bool>', data).toBytes();
151
+ case ValueType.TYPE_VEC_VEC_U8:
152
+ return this.bcs.ser('vector<vector<u8>>', data).toBytes();
153
+ case ValueType.TYPE_VEC_U64:
154
+ return this.bcs.ser('vector<u64>', data).toBytes();
155
+ case ValueType.TYPE_VEC_U128:
156
+ return this.bcs.ser('vector<u128>', data).toBytes();
157
+ case ValueType.TYPE_OPTION_ADDRESS:
158
+ return this.bcs.ser('Option<address>', { 'some': data }).toBytes();
159
+ case ValueType.TYPE_OPTION_BOOL:
160
+ return this.bcs.ser('Option<bool>', { 'some': data }).toBytes();
161
+ case ValueType.TYPE_OPTION_U8:
162
+ return this.bcs.ser('Option<u8>', { 'some': data }).toBytes();
163
+ case ValueType.TYPE_OPTION_U64:
164
+ return this.bcs.ser('Option<u64>', { 'some': data }).toBytes();
165
+ case ValueType.TYPE_OPTION_U128:
166
+ return this.bcs.ser('Option<u128>', { 'some': data }).toBytes();
167
+ case ValueType.TYPE_OPTION_U256:
168
+ return this.bcs.ser('Option<u256>', { 'some': data }).toBytes();
169
+ case ValueType.TYPE_OPTION_STRING:
170
+ return this.bcs.ser('Option<string>', { 'some': data }).toBytes();
171
+ case ValueType.TYPE_VEC_U256:
172
+ return this.bcs.ser('vector<u256>', data).toBytes();
173
+ case ValueType.TYPE_U256:
174
+ return this.bcs.ser(BCS.U256, data).toBytes();
175
+ case ValueType.TYPE_STRING:
176
+ return this.bcs.ser(BCS.STRING, data).toBytes();
177
+ case ValueType.TYPE_VEC_STRING:
178
+ return this.bcs.ser('vector<string>', data).toBytes();
179
+ default:
180
+ ERROR(Errors.bcsTypeInvalid, 'ser');
181
+ }
182
+ return new Uint8Array();
169
183
  }
170
184
  de(type, data) {
171
- return this.bcs.de(type, data);
185
+ switch (type) {
186
+ case ValueType.TYPE_BOOL:
187
+ return this.bcs.de(BCS.BOOL, data);
188
+ case ValueType.TYPE_ADDRESS:
189
+ return this.bcs.de(BCS.ADDRESS, data);
190
+ case ValueType.TYPE_U64:
191
+ return this.bcs.de(BCS.U64, data);
192
+ case ValueType.TYPE_U8:
193
+ return this.bcs.de(BCS.U8, data);
194
+ case ValueType.TYPE_VEC_U8:
195
+ return this.bcs.de('vector<u8>', data);
196
+ case ValueType.TYPE_U128:
197
+ return this.bcs.de(BCS.U128, data);
198
+ case ValueType.TYPE_VEC_ADDRESS:
199
+ return this.bcs.de('vector<address>', data);
200
+ case ValueType.TYPE_VEC_BOOL:
201
+ return this.bcs.de('vector<bool>', data);
202
+ case ValueType.TYPE_VEC_VEC_U8:
203
+ return this.bcs.de('vector<vector<u8>>', data);
204
+ case ValueType.TYPE_VEC_U64:
205
+ return this.bcs.de('vector<u64>', data);
206
+ case ValueType.TYPE_VEC_U128:
207
+ return this.bcs.de('vector<u128>', data);
208
+ case ValueType.TYPE_OPTION_ADDRESS:
209
+ return this.bcs.de('Option<address>', data);
210
+ case ValueType.TYPE_OPTION_BOOL:
211
+ return this.bcs.de('Option<bool>', data);
212
+ case ValueType.TYPE_OPTION_U8:
213
+ return this.bcs.de('Option<u8>', data);
214
+ case ValueType.TYPE_OPTION_U64:
215
+ return this.bcs.de('Option<u64>', data);
216
+ case ValueType.TYPE_OPTION_U128:
217
+ return this.bcs.de('Option<u128>', data);
218
+ case ValueType.TYPE_OPTION_U256:
219
+ return this.bcs.de('Option<u256>', data);
220
+ case ValueType.TYPE_OPTION_STRING:
221
+ return this.bcs.de('Option<string>', data);
222
+ case ValueType.TYPE_VEC_U256:
223
+ return this.bcs.de('vector<u256>', data);
224
+ case ValueType.TYPE_STRING:
225
+ return this.bcs.de(BCS.STRING, data);
226
+ case ValueType.TYPE_VEC_STRING:
227
+ return this.bcs.de('vector<string>', data);
228
+ case ValueType.TYPE_U256:
229
+ return this.bcs.de(BCS.U256, data);
230
+ default:
231
+ ERROR(Errors.bcsTypeInvalid, 'de');
232
+ }
172
233
  }
173
234
  }
174
235
  export function stringToUint8Array(str) {
@@ -220,13 +281,43 @@ export const IsValidName = (name) => { if (!name)
220
281
  export const IsValidName_AllowEmpty = (name) => { return name.length <= MAX_NAME_LENGTH; };
221
282
  export const IsValidEndpoint = (endpoint) => { if (!endpoint)
222
283
  return false; return endpoint.length <= MAX_ENDPOINT_LENGTH; };
223
- export const IsValidAddress = (addr) => { if (!addr || !isValidSuiAddress(addr))
224
- return false; return true; };
225
- export const IsValidArgType = (argType) => { if (!argType)
226
- return false; return argType.length != 0; };
227
- export const IsValidUint = (value) => { return Number.isSafeInteger(value) && value != 0; };
228
- export const IsValidInt = (value) => { return Number.isSafeInteger(value); };
229
- export const IsValidPercent = (value) => { return Number.isSafeInteger(value) && value > 0 && value <= 100; };
284
+ export const IsValidAddress = (addr) => {
285
+ if (!addr || !isValidSuiAddress(addr)) {
286
+ return false;
287
+ }
288
+ return true;
289
+ };
290
+ export const IsValidArgType = (argType) => {
291
+ if (!argType || argType.length === 0) {
292
+ return false;
293
+ }
294
+ let arr = argType.split('::');
295
+ if (arr.length !== 3) {
296
+ return false;
297
+ }
298
+ if (!IsValidAddress(arr[0]) || arr[1].length === 0 || arr[2].length === 0) {
299
+ return false;
300
+ }
301
+ return true;
302
+ };
303
+ export const IsValidUint = (value) => {
304
+ if (typeof (value) === 'string') {
305
+ value = parseInt(value);
306
+ }
307
+ return Number.isSafeInteger(value) && value > 0;
308
+ };
309
+ export const IsValidInt = (value) => {
310
+ if (typeof (value) === 'string') {
311
+ value = parseInt(value);
312
+ }
313
+ return Number.isSafeInteger(value);
314
+ };
315
+ export const IsValidPercent = (value) => {
316
+ if (typeof (value) === 'string') {
317
+ value = parseInt(value);
318
+ }
319
+ return Number.isSafeInteger(value) && value > 0 && value <= 100;
320
+ };
230
321
  export const IsValidArray = (arr, validFunc) => {
231
322
  let bValid = true;
232
323
  arr.forEach((v) => {
@@ -238,13 +329,19 @@ export const IsValidArray = (arr, validFunc) => {
238
329
  };
239
330
  export const OptionNone = (txb) => { return txb.pure([], BCS.U8); };
240
331
  export const ParseType = (type) => {
241
- let i = type.indexOf('<');
242
- if (i > 0 && type.length > 12) {
243
- let c = type.slice(0, i);
244
- if (c === '0x2::coin::Coin' || c === '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin') {
245
- let coin = type.slice(i + 1, type.length - 1); // < >>
246
- let t = coin.lastIndexOf('::');
247
- return { isCoin: true, coin: coin, token: coin.slice(t + 2) };
332
+ if (type) {
333
+ const COIN = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<';
334
+ let i = type.indexOf(COIN);
335
+ if (i > 0) {
336
+ let coin = type.slice(i + COIN.length, type.length - 1);
337
+ if (coin.indexOf('<') === -1) {
338
+ while (coin[coin.length - 1] == '>') {
339
+ coin = coin.slice(0, -1);
340
+ }
341
+ ;
342
+ let t = coin.lastIndexOf('::');
343
+ return { isCoin: true, coin: coin, token: coin.slice(t + 2) };
344
+ }
248
345
  }
249
346
  }
250
347
  return { isCoin: false, coin: '', token: '' };
package/dist/vote.js CHANGED
@@ -2,6 +2,7 @@ import { BCS } from '@mysten/bcs';
2
2
  import { Protocol } from './protocol';
3
3
  import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
4
4
  import { ERROR, Errors } from './exception';
5
+ import { ValueType } from './protocol';
5
6
  export const MAX_AGREES_COUNT = 200;
6
7
  export const MAX_CHOICE_COUNT = 200;
7
8
  export class Vote {
@@ -40,7 +41,7 @@ export class Vote {
40
41
  }
41
42
  let v = new Vote(protocol, permission);
42
43
  let txb = protocol.CurrentSession();
43
- let reference = reference_address ? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
44
+ let reference = reference_address ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
44
45
  let choice_count = max_choice_count ? max_choice_count : 1;
45
46
  if (passport) {
46
47
  v.object = txb.moveCall({
@@ -95,7 +96,7 @@ export class Vote {
95
96
  ERROR(Errors.IsValidAddress);
96
97
  }
97
98
  let txb = this.protocol.CurrentSession();
98
- let reference = reference_address ? txb.pure(Bcs.getInstance().ser_option_address(reference_address)) : OptionNone(txb);
99
+ let reference = reference_address ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
99
100
  if (passport) {
100
101
  txb.moveCall({
101
102
  target: this.protocol.VoteFn('reference_set_with_passport'),
@@ -189,7 +190,7 @@ export class Vote {
189
190
  let txb = this.protocol.CurrentSession();
190
191
  options.forEach((option) => {
191
192
  let reference = option?.reference_address ?
192
- txb.pure(Bcs.getInstance().ser_option_address(option.reference_address)) :
193
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, option.reference_address)) :
193
194
  OptionNone(txb);
194
195
  if (passport) {
195
196
  txb.moveCall({
@@ -226,7 +227,7 @@ export class Vote {
226
227
  txb.moveCall({
227
228
  target: this.protocol.VoteFn('agrees_remove_with_passport'),
228
229
  arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
229
- txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
230
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
230
231
  Protocol.TXB_OBJECT(txb, this.permission)]
231
232
  });
232
233
  }
@@ -242,7 +243,7 @@ export class Vote {
242
243
  txb.moveCall({
243
244
  target: this.protocol.VoteFn('agrees_remove'),
244
245
  arguments: [Protocol.TXB_OBJECT(txb, this.object),
245
- txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options))),
246
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
246
247
  Protocol.TXB_OBJECT(txb, this.permission)]
247
248
  });
248
249
  }
@@ -341,14 +342,14 @@ export class Vote {
341
342
  txb.moveCall({
342
343
  target: this.protocol.VoteFn('with_passport'),
343
344
  arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
344
- txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
345
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
345
346
  });
346
347
  }
347
348
  else {
348
349
  txb.moveCall({
349
350
  target: this.protocol.VoteFn('this.object'),
350
351
  arguments: [Protocol.TXB_OBJECT(txb, this.object),
351
- txb.pure(Bcs.getInstance().ser_vector_string(array_unique(options)))]
352
+ txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
352
353
  });
353
354
  }
354
355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/exception.ts CHANGED
@@ -18,6 +18,7 @@ export enum Errors {
18
18
  Fail = 'fail',
19
19
  IsValidIndentifier = 'indentifier invalid',
20
20
  isValidHttpUrl = 'invalid url',
21
+ bcsTypeInvalid = 'invalid bcs type',
21
22
  }
22
23
 
23
24
  export const ERROR = (error:Errors, info?:any) => {
package/src/guard.ts CHANGED
@@ -269,7 +269,8 @@ export class GuardConstantHelper {
269
269
  let v = constants.get(identifier);
270
270
  if (!v || v.type == ContextType.TYPE_WITNESS_ID) {
271
271
  if (bNeedSerialize) {
272
- constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().ser_address(value) : undefined, witness:witness ? Bcs.getInstance().ser_address(witness) : undefined})
272
+ constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, value) : undefined,
273
+ witness:witness ? Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, witness) : undefined})
273
274
  } else {
274
275
  constants.set(identifier, {type:ContextType.TYPE_WITNESS_ID, value:value?value:undefined, witness:witness?witness:undefined});
275
276
  }
@@ -301,12 +302,12 @@ export class GuardConstantHelper {
301
302
  case ValueType.TYPE_VEC_U256:
302
303
  let ser = SER_VALUE.find(s=>s.type==type);
303
304
  if (!ser) ERROR(Errors.Fail, 'add_constant: invalid type');
304
- bNeedSerialize ? constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.name, value)}) :
305
+ bNeedSerialize ? constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ser!.type, value)}) :
305
306
  constants.set(identifier, {type:type, value:value})
306
307
  return
307
308
  case ValueType.TYPE_VEC_U8:
308
309
  if (typeof(value) === 'string') {
309
- constants.set(identifier, {type:type, value:Bcs.getInstance().ser_string(value)})
310
+ constants.set(identifier, {type:type, value:Bcs.getInstance().ser(ValueType.TYPE_STRING, value)})
310
311
  } else {
311
312
  constants.set(identifier, {type:type, value:value})
312
313
  }
@@ -344,10 +345,10 @@ export class GuardMaker {
344
345
 
345
346
  private serValueParam(type:ValueType, param?:any) {
346
347
  if (!param) ERROR(Errors.InvalidParam, 'param');
347
- this.data.push(Bcs.getInstance().ser_u8(type));
348
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
348
349
  let ser = SER_VALUE.find(s=>s.type==type);
349
350
  if (!ser) ERROR(Errors.Fail, 'serValueParam: invalid type');
350
- this.data.push(Bcs.getInstance().ser(ser!.name, param));
351
+ this.data.push(Bcs.getInstance().ser(ser!.type, param));
351
352
  this.type_validator.push(type);
352
353
  }
353
354
 
@@ -376,26 +377,26 @@ export class GuardMaker {
376
377
  break;
377
378
  case ValueType.TYPE_VEC_U8:
378
379
  if (!param) ERROR(Errors.InvalidParam, 'param');
379
- this.data.push(Bcs.getInstance().ser_u8(type));
380
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
380
381
  if (typeof(param) == 'string') {
381
- this.data.push(Bcs.getInstance().ser_string(param));
382
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_STRING, param));
382
383
  } else {
383
- this.data.push(Bcs.getInstance().ser_vector_u8(param));
384
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_VEC_U8, param));
384
385
  }
385
386
  this.type_validator.push(type);
386
387
  break;
387
388
  case ContextType.TYPE_SIGNER:
388
- this.data.push(Bcs.getInstance().ser_u8(type));
389
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
389
390
  this.type_validator.push(ValueType.TYPE_ADDRESS);
390
391
  break;
391
392
  case ContextType.TYPE_CLOCK:
392
- this.data.push(Bcs.getInstance().ser_u8(type));
393
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
393
394
  this.type_validator.push(ValueType.TYPE_U64);
394
395
  break;
395
396
  case ContextType.TYPE_WITNESS_ID:
396
397
  if (!param) ERROR(Errors.InvalidParam, 'param');
397
- this.data.push(Bcs.getInstance().ser_u8(type));
398
- this.data.push(Bcs.getInstance().ser_address(param));
398
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
399
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, param));
399
400
  this.type_validator.push(ValueType.TYPE_ADDRESS);
400
401
  break;
401
402
  case ContextType.TYPE_CONSTANT:
@@ -409,8 +410,8 @@ export class GuardMaker {
409
410
  var v = this.constant.get(param);
410
411
  if (!v) ERROR(Errors.Fail, 'identifier not in constant');
411
412
  this.type_validator.push(v!.type);
412
- this.data.push(Bcs.getInstance().ser_u8(type));
413
- this.data.push(Bcs.getInstance().ser_u8(param));
413
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type));
414
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, param));
414
415
  break;
415
416
  default:
416
417
  ERROR(Errors.InvalidParam, 'add_param type');
@@ -445,23 +446,23 @@ export class GuardMaker {
445
446
  ERROR(Errors.Fail, 'array_equal');
446
447
  }
447
448
 
448
- this.data.push(Bcs.getInstance().ser_u8(OperatorType.TYPE_QUERY)); // QUERY TYPE
449
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE
449
450
  if (typeof(object_address_from) == 'string') {
450
- bWitness ? this.data.push(Bcs.getInstance().ser_u8(ContextType.TYPE_WITNESS_ID)) :
451
- this.data.push(Bcs.getInstance().ser_u8(ValueType.TYPE_ADDRESS));
452
- this.data.push(Bcs.getInstance().ser_address(object_address_from)); // object address
451
+ bWitness ? this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_WITNESS_ID)) :
452
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
453
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, object_address_from)); // object address
453
454
  } else {
454
455
  let v = this.constant.get(object_address_from);
455
456
  if (!v) ERROR(Errors.Fail, 'object_address_from not in constant');
456
457
  if ((bWitness && v?.type == ContextType.TYPE_WITNESS_ID) || (!bWitness && v?.type == ValueType.TYPE_ADDRESS)) {
457
- this.data.push(Bcs.getInstance().ser_u8(ContextType.TYPE_CONSTANT));
458
- this.data.push(Bcs.getInstance().ser_u8(object_address_from)); // object identifer in constants
458
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
459
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, object_address_from)); // object identifer in constants
459
460
  } else {
460
461
  ERROR(Errors.Fail, 'type bWitness not match')
461
462
  }
462
463
  }
463
464
 
464
- this.data.push(Bcs.getInstance().ser_u8(Guard.QUERIES[query_index][2])); // cmd
465
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, Guard.QUERIES[query_index][2])); // cmd
465
466
  this.type_validator.splice(offset, Guard.QUERIES[query_index][3].length); // delete type stack
466
467
  this.type_validator.push(Guard.QUERIES[query_index][4]); // add the return value type to type stack
467
468
  return this;
@@ -499,7 +500,7 @@ export class GuardMaker {
499
500
  default:
500
501
  ERROR(Errors.InvalidParam, 'type')
501
502
  }
502
- this.data.push(Bcs.getInstance().ser_u8(type)); // TYPE
503
+ this.data.push(Bcs.getInstance().ser(ValueType.TYPE_U8, type)); // TYPE
503
504
  this.type_validator.splice(this.type_validator.length - splice_len); // delete type stack
504
505
  this.type_validator.push(ValueType.TYPE_BOOL); // add bool to type stack
505
506
  return this;
@@ -536,7 +537,7 @@ export class GuardMaker {
536
537
  maker.constant.set(k, {type:v.type, value:v.value, witness:v.witness});
537
538
  })
538
539
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
539
- maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser_u8(op)));
540
+ maker.data.push(concatenate(Uint8Array, ...this.data, ...otherBuilt.data, Bcs.getInstance().ser(ValueType.TYPE_U8, op)));
540
541
  this.data.splice(0, this.data.length-1);
541
542
  maker.type_validator = this.type_validator;
542
543
  return maker
@@ -547,10 +548,10 @@ export class GuardMaker {
547
548
 
548
549
  static input_combine(input1:Uint8Array, input2:Uint8Array, bAnd:boolean = true) : Uint8Array {
549
550
  let op = bAnd ? OperatorType.TYPE_LOGIC_AND : OperatorType.TYPE_LOGIC_OR;
550
- return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser_u8(op)) as Uint8Array;
551
+ return concatenate(Uint8Array, input1, input2, Bcs.getInstance().ser(ValueType.TYPE_U8, op)) as Uint8Array;
551
552
  }
552
553
  static input_not(input:Uint8Array) : Uint8Array {
553
- return concatenate(Uint8Array, input, Bcs.getInstance().ser_u8(OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
554
+ return concatenate(Uint8Array, input, Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_LOGIC_NOT)) as Uint8Array;
554
555
  }
555
556
 
556
557
  static match_u256(type:number) : boolean {
package/src/machine.ts CHANGED
@@ -5,7 +5,7 @@ import { IsValidInt, IsValidUint, Bcs, array_unique, IsValidArray, IsValidAddres
5
5
  IsValidEndpoint, OptionNone, IsValidDesription} from './utils'
6
6
  import { Permission, PermissionIndexType } from './permission';
7
7
  import { Errors, ERROR} from './exception'
8
- import { Resource } from './resource';
8
+ import { ValueType } from './protocol';
9
9
 
10
10
 
11
11
  export type MachineNodeObject = TransactionResult | String;
@@ -59,7 +59,7 @@ export class Machine {
59
59
 
60
60
  let m = new Machine(protocol, permission);
61
61
  let txb = protocol.CurrentSession();
62
- let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
62
+ let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
63
63
 
64
64
  if (passport) {
65
65
  m.object = txb.moveCall({
@@ -104,11 +104,11 @@ export class Machine {
104
104
  arguments:[txb.pure(node.name), txb.pure(node.description)]
105
105
  });
106
106
  node.pairs.forEach((pair) => {
107
- let threshold = pair?.threshold ? txb.pure(Bcs.getInstance().ser_option_u64(pair.threshold)) : OptionNone(txb);
107
+ let threshold = pair?.threshold ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, pair.threshold)) : OptionNone(txb);
108
108
 
109
109
  pair.forwards.forEach((forward) => {
110
110
  let weight = forward?.weight ? forward.weight : 1;
111
- let perm = forward?.permission ? txb.pure(Bcs.getInstance().ser_option_u64(forward.permission)) : OptionNone(txb);
111
+ let perm = forward?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, forward.permission)) : OptionNone(txb);
112
112
  let namedOperator = forward?.namedOperator ? txb.pure(forward.namedOperator) : txb.pure('');
113
113
  let f;
114
114
 
@@ -169,13 +169,13 @@ export class Machine {
169
169
  if (passport) {
170
170
  txb.moveCall({
171
171
  target:this.protocol.MachineFn('node_remove_with_passport') as FnCallType,
172
- arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(nodes_name)),
172
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)),
173
173
  txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
174
174
  });
175
175
  } else {
176
176
  txb.moveCall({
177
177
  target:this.protocol.MachineFn('node_remove') as FnCallType,
178
- arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser_vector_string(nodes_name)), txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
178
+ arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, nodes_name)), txb.pure(bTransferMyself, BCS.BOOL), Protocol.TXB_OBJECT(txb, this.permission)],
179
179
  });
180
180
  }
181
181
  }
@@ -288,7 +288,7 @@ export class Machine {
288
288
  }
289
289
 
290
290
  let txb = this.protocol.CurrentSession();
291
- let ep = endpoint? txb.pure(Bcs.getInstance().ser_option_string(endpoint)) : OptionNone(txb);
291
+ let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
292
292
 
293
293
  if (passport) {
294
294
  txb.moveCall({