wowok 1.0.6 → 1.0.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/reward.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.change_permission = exports.deposit = exports.claim = exports.reward_lock_guards = exports.reward_set_description = exports.allow_repeat_claim = exports.reward_remove_guard = exports.reward_add_guard = exports.MAX_PORTIONS_COUNT = exports.reward_expand_time = exports.reward_refund = exports.destroy = exports.launch = exports.reward = void 0;
3
+ exports.change_permission = exports.deposit = exports.claim = exports.reward_lock_guards = exports.reward_set_description = exports.allow_repeat_claim = exports.reward_remove_guard = exports.reward_add_guard = exports.reward_expand_time = exports.reward_refund = exports.destroy = exports.launch = exports.reward = exports.MAX_PORTIONS_COUNT = void 0;
4
4
  const bcs_1 = require("@mysten/bcs");
5
5
  const protocol_1 = require("./protocol");
6
- const util_1 = require("./util");
6
+ const utils_1 = require("./utils");
7
+ exports.MAX_PORTIONS_COUNT = 255;
7
8
  function reward(reward_type, txb, permission, description, minutes_duration, passport) {
8
9
  if (!(0, protocol_1.IsValidObjects)([permission]))
9
10
  return false;
@@ -101,7 +102,6 @@ function reward_expand_time(reward_type, txb, reward, permission, minutes_expand
101
102
  return true;
102
103
  }
103
104
  exports.reward_expand_time = reward_expand_time;
104
- exports.MAX_PORTIONS_COUNT = 255;
105
105
  function reward_add_guard(reward_type, txb, reward, permission, gurads, passport) {
106
106
  if (!(0, protocol_1.IsValidObjects)([reward, permission]))
107
107
  return false;
@@ -155,7 +155,7 @@ function reward_remove_guard(reward_type, txb, reward, permission, guards, remov
155
155
  else {
156
156
  txb.moveCall({
157
157
  target: protocol_1.PROTOCOL.RewardFn('guard_remove_with_passport'),
158
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, reward), txb.pure((0, util_1.array_unique)(guards), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
158
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, reward), txb.pure((0, utils_1.array_unique)(guards), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
159
159
  typeArguments: [reward_type]
160
160
  });
161
161
  }
@@ -278,7 +278,7 @@ function deposit(reward_type, txb, reward, rewards) {
278
278
  return false;
279
279
  txb.moveCall({
280
280
  target: protocol_1.PROTOCOL.RewardFn('deposit'),
281
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, reward), txb.makeMoveVec({ objects: (0, util_1.array_unique)(rewards) })],
281
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, reward), txb.makeMoveVec({ objects: (0, utils_1.array_unique)(rewards) })],
282
282
  typeArguments: [reward_type]
283
283
  });
284
284
  return true;
package/dist/service.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.change_permission = exports.order_bind_service_machine = exports.buy = exports.update_order_required_info = exports.customer_refund = exports.service_pause = exports.service_change_order_required_pubkey = exports.service_change_required_pubkey = exports.service_remove_customer_required = exports.service_set_customer_required = exports.BuyRequiredEnum = exports.service_clone = exports.service_publish = exports.service_set_endpoint = exports.service_set_machine = exports.service_set_buy_guard = exports.service_withdraw = exports.service_discount_transfer = exports.Service_Discount_Type = exports.service_remove_sales = exports.service_add_sale = exports.service_remove_refund_guards = exports.service_add_refund_guards = exports.service_remove_withdraw_guards = exports.service_add_withdraw_guards = exports.service_repository_remove = exports.service_repository_add = exports.service_set_payee = exports.service_reduce_stock = exports.service_add_stock = exports.service_set_stock = exports.service_set_price = exports.service_set_description = exports.destroy = exports.launch = exports.service = void 0;
3
+ exports.change_permission = exports.order_bind_service_machine = exports.buy = exports.update_order_required_info = exports.customer_refund = exports.service_pause = exports.service_change_order_required_pubkey = exports.service_change_required_pubkey = exports.service_remove_customer_required = exports.service_set_customer_required = exports.BuyRequiredEnum = exports.service_clone = exports.service_publish = exports.service_set_endpoint = exports.service_set_machine = exports.service_set_buy_guard = exports.service_withdraw = exports.service_discount_transfer = exports.MAX_DISCOUNT_RECEIVER_COUNT = exports.MAX_DISCOUNT_COUNT_ONCE = exports.Service_Discount_Type = exports.service_remove_sales = exports.service_add_sale = exports.is_valid_sale = exports.service_remove_refund_guards = exports.service_add_refund_guards = exports.service_remove_withdraw_guards = exports.service_add_withdraw_guards = exports.service_repository_remove = exports.service_repository_add = exports.service_set_payee = exports.service_reduce_stock = exports.service_add_stock = exports.service_set_stock = exports.service_set_price = exports.service_set_description = exports.destroy = exports.launch = exports.service = void 0;
4
4
  const bcs_1 = require("@mysten/bcs");
5
- const util_1 = require("./util");
5
+ const utils_1 = require("./utils");
6
6
  const protocol_1 = require("./protocol");
7
7
  function service(pay_type, txb, permission, description, payee_address, endpoint, passport) {
8
8
  if (!(0, protocol_1.IsValidObjects)([permission]))
@@ -15,7 +15,7 @@ function service(pay_type, txb, permission, description, payee_address, endpoint
15
15
  return false;
16
16
  if (endpoint && !(0, protocol_1.IsValidEndpoint)(endpoint))
17
17
  return false;
18
- let ep = endpoint ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
18
+ let ep = endpoint ? txb.pure(utils_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
19
19
  if (passport) {
20
20
  return txb.moveCall({
21
21
  target: protocol_1.PROTOCOL.ServiceFn('new_with_passport'),
@@ -81,7 +81,7 @@ function service_set_description(pay_type, txb, service, permission, description
81
81
  return true;
82
82
  }
83
83
  exports.service_set_description = service_set_description;
84
- function service_set_price(pay_type, txb, service, permission, item, price, passport) {
84
+ function service_set_price(pay_type, txb, service, permission, item, price, bNotFoundAssert = true, passport) {
85
85
  if (!(0, protocol_1.IsValidObjects)([service, permission]))
86
86
  return false;
87
87
  if (!(0, protocol_1.IsValidArgType)(pay_type))
@@ -91,21 +91,23 @@ function service_set_price(pay_type, txb, service, permission, item, price, pass
91
91
  if (passport) {
92
92
  txb.moveCall({
93
93
  target: protocol_1.PROTOCOL.ServiceFn('price_set_with_passport'),
94
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(price, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
94
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(price, bcs_1.BCS.U64),
95
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
95
96
  typeArguments: [pay_type]
96
97
  });
97
98
  }
98
99
  else {
99
100
  txb.moveCall({
100
101
  target: protocol_1.PROTOCOL.ServiceFn('price_set'),
101
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(price, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
102
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(price, bcs_1.BCS.U64),
103
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
102
104
  typeArguments: [pay_type]
103
105
  });
104
106
  }
105
107
  return true;
106
108
  }
107
109
  exports.service_set_price = service_set_price;
108
- function service_set_stock(pay_type, txb, service, permission, item, stock, passport) {
110
+ function service_set_stock(pay_type, txb, service, permission, item, stock, bNotFoundAssert = true, passport) {
109
111
  if (!(0, protocol_1.IsValidObjects)([service, permission]))
110
112
  return false;
111
113
  if (!(0, protocol_1.IsValidArgType)(pay_type))
@@ -115,21 +117,23 @@ function service_set_stock(pay_type, txb, service, permission, item, stock, pass
115
117
  if (passport) {
116
118
  txb.moveCall({
117
119
  target: protocol_1.PROTOCOL.ServiceFn('stock_set_with_passport'),
118
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
120
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock, bcs_1.BCS.U64),
121
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
119
122
  typeArguments: [pay_type]
120
123
  });
121
124
  }
122
125
  else {
123
126
  txb.moveCall({
124
127
  target: protocol_1.PROTOCOL.ServiceFn('stock_set'),
125
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
128
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock, bcs_1.BCS.U64),
129
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
126
130
  typeArguments: [pay_type]
127
131
  });
128
132
  }
129
133
  return true;
130
134
  }
131
135
  exports.service_set_stock = service_set_stock;
132
- function service_add_stock(pay_type, txb, service, permission, item, stock_add, passport) {
136
+ function service_add_stock(pay_type, txb, service, permission, item, stock_add, bNotFoundAssert = true, passport) {
133
137
  if (!(0, protocol_1.IsValidObjects)([service, permission]))
134
138
  return false;
135
139
  if (!(0, protocol_1.IsValidArgType)(pay_type))
@@ -139,21 +143,23 @@ function service_add_stock(pay_type, txb, service, permission, item, stock_add,
139
143
  if (passport) {
140
144
  txb.moveCall({
141
145
  target: protocol_1.PROTOCOL.ServiceFn('stock_add_with_passport'),
142
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_add, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
146
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_add, bcs_1.BCS.U64),
147
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
143
148
  typeArguments: [pay_type]
144
149
  });
145
150
  }
146
151
  else {
147
152
  txb.moveCall({
148
153
  target: protocol_1.PROTOCOL.ServiceFn('stock_add'),
149
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_add, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
154
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_add, bcs_1.BCS.U64),
155
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
150
156
  typeArguments: [pay_type]
151
157
  });
152
158
  }
153
159
  return true;
154
160
  }
155
161
  exports.service_add_stock = service_add_stock;
156
- function service_reduce_stock(pay_type, txb, service, permission, item, stock_reduce, passport) {
162
+ function service_reduce_stock(pay_type, txb, service, permission, item, stock_reduce, bNotFoundAssert = true, passport) {
157
163
  if (!(0, protocol_1.IsValidObjects)([service, permission]))
158
164
  return false;
159
165
  if (!(0, protocol_1.IsValidArgType)(pay_type))
@@ -163,14 +169,16 @@ function service_reduce_stock(pay_type, txb, service, permission, item, stock_re
163
169
  if (passport) {
164
170
  txb.moveCall({
165
171
  target: protocol_1.PROTOCOL.ServiceFn('stock_reduce_with_passport'),
166
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_reduce, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
172
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_reduce, bcs_1.BCS.U64),
173
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
167
174
  typeArguments: [pay_type]
168
175
  });
169
176
  }
170
177
  else {
171
178
  txb.moveCall({
172
179
  target: protocol_1.PROTOCOL.ServiceFn('stock_reduce'),
173
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_reduce, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
180
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(item), txb.pure(stock_reduce, bcs_1.BCS.U64),
181
+ txb.pure(bNotFoundAssert, bcs_1.BCS.BOOL), (0, protocol_1.TXB_OBJECT)(txb, permission)],
174
182
  typeArguments: [pay_type]
175
183
  });
176
184
  }
@@ -243,7 +251,7 @@ function service_repository_remove(pay_type, txb, service, permission, repositor
243
251
  else {
244
252
  txb.moveCall({
245
253
  target: protocol_1.PROTOCOL.ServiceFn('repository_remove_with_passport'),
246
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(repository_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
254
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(repository_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
247
255
  typeArguments: [pay_type]
248
256
  });
249
257
  }
@@ -259,7 +267,7 @@ function service_repository_remove(pay_type, txb, service, permission, repositor
259
267
  else {
260
268
  txb.moveCall({
261
269
  target: protocol_1.PROTOCOL.ServiceFn('repository_remove'),
262
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(repository_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
270
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(repository_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
263
271
  typeArguments: [pay_type]
264
272
  });
265
273
  }
@@ -320,7 +328,7 @@ function service_remove_withdraw_guards(pay_type, txb, service, permission, guar
320
328
  else {
321
329
  txb.moveCall({
322
330
  target: protocol_1.PROTOCOL.ServiceFn('withdraw_guard_remove_with_passport'),
323
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
331
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
324
332
  typeArguments: [pay_type]
325
333
  });
326
334
  }
@@ -336,7 +344,7 @@ function service_remove_withdraw_guards(pay_type, txb, service, permission, guar
336
344
  else {
337
345
  txb.moveCall({
338
346
  target: protocol_1.PROTOCOL.ServiceFn('withdraw_guard_remove'),
339
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
347
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
340
348
  typeArguments: [pay_type]
341
349
  });
342
350
  }
@@ -397,7 +405,7 @@ function service_remove_refund_guards(pay_type, txb, service, permission, guard_
397
405
  else {
398
406
  txb.moveCall({
399
407
  target: protocol_1.PROTOCOL.ServiceFn('refund_guard_remove_with_passport'),
400
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
408
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
401
409
  typeArguments: [pay_type]
402
410
  });
403
411
  }
@@ -413,7 +421,7 @@ function service_remove_refund_guards(pay_type, txb, service, permission, guard_
413
421
  else {
414
422
  txb.moveCall({
415
423
  target: protocol_1.PROTOCOL.ServiceFn('refund_guard_remove'),
416
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, util_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
424
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure((0, utils_1.array_unique)(guard_address), 'vector<address>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
417
425
  typeArguments: [pay_type]
418
426
  });
419
427
  }
@@ -421,33 +429,54 @@ function service_remove_refund_guards(pay_type, txb, service, permission, guard_
421
429
  return true;
422
430
  }
423
431
  exports.service_remove_refund_guards = service_remove_refund_guards;
424
- function service_add_sale(pay_type, txb, service, permission, sales, passport) {
425
- if (!(0, protocol_1.IsValidObjects)([service, permission]))
426
- return false;
427
- if (!(0, protocol_1.IsValidArgType)(pay_type))
428
- return false;
432
+ function is_valid_sale(sales) {
429
433
  let bValid = true;
434
+ let names = [];
430
435
  sales.forEach((v) => {
431
436
  if (!(0, protocol_1.IsValidName)(v.item))
432
437
  bValid = false;
433
438
  if (!(0, protocol_1.IsValidInt)(v.price))
434
439
  bValid = false;
435
- if (!(0, protocol_1.IsValidInt)(v.stock))
440
+ if (!(0, protocol_1.IsValidUint)(v.stock))
441
+ bValid = false;
442
+ if (names.includes(v.item))
436
443
  bValid = false;
444
+ names.push(v.item);
437
445
  });
446
+ return bValid;
447
+ }
448
+ exports.is_valid_sale = is_valid_sale;
449
+ function service_add_sale(pay_type, txb, service, permission, sales, passport) {
450
+ if (!(0, protocol_1.IsValidObjects)([service, permission]))
451
+ return false;
452
+ if (!(0, protocol_1.IsValidArgType)(pay_type))
453
+ return false;
454
+ if (!sales)
455
+ return false;
456
+ let bValid = is_valid_sale(sales);
438
457
  if (!bValid)
439
458
  return false;
459
+ let names = [];
460
+ let price = [];
461
+ let stock = [];
462
+ sales.forEach((s) => {
463
+ names.push(s.item);
464
+ price.push(s.price);
465
+ stock.push(s.stock);
466
+ });
440
467
  if (passport) {
441
468
  sales.forEach((sale) => txb.moveCall({
442
469
  target: protocol_1.PROTOCOL.ServiceFn('sales_add_with_passport'),
443
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(sale.item), txb.pure(sale.price, bcs_1.BCS.U64), txb.pure(sale.stock, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
470
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(names)),
471
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, permission)],
444
472
  typeArguments: [pay_type]
445
473
  }));
446
474
  }
447
475
  else {
448
476
  sales.forEach((sale) => txb.moveCall({
449
477
  target: protocol_1.PROTOCOL.ServiceFn('sales_add'),
450
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(sale.item), txb.pure(sale.price, bcs_1.BCS.U64), txb.pure(sale.stock, bcs_1.BCS.U64), (0, protocol_1.TXB_OBJECT)(txb, permission)],
478
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(names)),
479
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, permission)],
451
480
  typeArguments: [pay_type]
452
481
  }));
453
482
  }
@@ -474,7 +503,7 @@ function service_remove_sales(pay_type, txb, service, permission, sales, removea
474
503
  else {
475
504
  txb.moveCall({
476
505
  target: protocol_1.PROTOCOL.ServiceFn('sales_remove_with_passport'),
477
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string((0, util_1.array_unique)(sales))), (0, protocol_1.TXB_OBJECT)(txb, permission)],
506
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(sales))), (0, protocol_1.TXB_OBJECT)(txb, permission)],
478
507
  typeArguments: [pay_type]
479
508
  });
480
509
  }
@@ -490,7 +519,7 @@ function service_remove_sales(pay_type, txb, service, permission, sales, removea
490
519
  else {
491
520
  txb.moveCall({
492
521
  target: protocol_1.PROTOCOL.ServiceFn('sales_remove'),
493
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string((0, util_1.array_unique)(sales))), (0, protocol_1.TXB_OBJECT)(txb, permission)],
522
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string((0, utils_1.array_unique)(sales))), (0, protocol_1.TXB_OBJECT)(txb, permission)],
494
523
  typeArguments: [pay_type]
495
524
  });
496
525
  }
@@ -503,20 +532,20 @@ var Service_Discount_Type;
503
532
  Service_Discount_Type[Service_Discount_Type["ratio"] = 0] = "ratio";
504
533
  Service_Discount_Type[Service_Discount_Type["minus"] = 1] = "minus";
505
534
  })(Service_Discount_Type || (exports.Service_Discount_Type = Service_Discount_Type = {}));
506
- const MAX_DISCOUNT_COUNT_ONCE = 200;
507
- const MAX_DISCOUNT_RECEIVER_COUNT = 200;
535
+ exports.MAX_DISCOUNT_COUNT_ONCE = 200;
536
+ exports.MAX_DISCOUNT_RECEIVER_COUNT = 200;
508
537
  function service_discount_transfer(pay_type, txb, service, permission, discount_dispatch, passport) {
509
538
  if (!(0, protocol_1.IsValidObjects)([service, permission]))
510
539
  return false;
511
540
  if (!(0, protocol_1.IsValidArgType)(pay_type))
512
541
  return false;
513
- if (!discount_dispatch || discount_dispatch.length > MAX_DISCOUNT_RECEIVER_COUNT)
542
+ if (!discount_dispatch || discount_dispatch.length > exports.MAX_DISCOUNT_RECEIVER_COUNT)
514
543
  return false;
515
544
  let bValid = true;
516
545
  discount_dispatch.forEach((v) => {
517
546
  if (!(0, protocol_1.IsValidAddress)(v.receiver))
518
547
  bValid = false;
519
- if (!(0, protocol_1.IsValidUint)(v.count) || v.count > MAX_DISCOUNT_COUNT_ONCE)
548
+ if (!(0, protocol_1.IsValidUint)(v.count) || v.count > exports.MAX_DISCOUNT_COUNT_ONCE)
520
549
  return false;
521
550
  if (!(0, protocol_1.IsValidName_AllowEmpty)(v.discount.name))
522
551
  return false;
@@ -533,9 +562,9 @@ function service_discount_transfer(pay_type, txb, service, permission, discount_
533
562
  return false;
534
563
  discount_dispatch.forEach((discount) => {
535
564
  let price_greater = discount.discount?.price_greater ?
536
- txb.pure(util_1.BCS_CONVERT.ser_option_u64(discount.discount.price_greater)) : (0, protocol_1.OptionNone)(txb);
565
+ txb.pure(utils_1.BCS_CONVERT.ser_option_u64(discount.discount.price_greater)) : (0, protocol_1.OptionNone)(txb);
537
566
  let time_start = discount.discount?.time_start ?
538
- txb.pure(util_1.BCS_CONVERT.ser_option_u64(discount.discount.time_start)) : (0, protocol_1.OptionNone)(txb);
567
+ txb.pure(utils_1.BCS_CONVERT.ser_option_u64(discount.discount.time_start)) : (0, protocol_1.OptionNone)(txb);
539
568
  if (passport) {
540
569
  txb.moveCall({
541
570
  target: protocol_1.PROTOCOL.ServiceFn('dicscount_create_with_passport'),
@@ -670,7 +699,7 @@ function service_set_endpoint(pay_type, txb, service, permission, endpoint, pass
670
699
  return false;
671
700
  if (endpoint && !(0, protocol_1.IsValidEndpoint)(endpoint))
672
701
  return false;
673
- let ep = endpoint ? txb.pure(util_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
702
+ let ep = endpoint ? txb.pure(utils_1.BCS_CONVERT.ser_option_string(endpoint)) : (0, protocol_1.OptionNone)(txb);
674
703
  if (passport) {
675
704
  txb.moveCall({
676
705
  target: protocol_1.PROTOCOL.ServiceFn('endpoint_set_with_passport'),
@@ -749,14 +778,14 @@ function service_set_customer_required(pay_type, txb, service, permission, servi
749
778
  if (passport) {
750
779
  txb.moveCall({
751
780
  target: protocol_1.PROTOCOL.ServiceFn('required_set_with_passport'),
752
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_vector_u8((0, util_1.array_unique)(customer_required))), txb.pure(service_pubkey, 'vector<u8>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
781
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_vector_u8((0, utils_1.array_unique)(customer_required))), txb.pure(service_pubkey, 'vector<u8>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
753
782
  typeArguments: [pay_type]
754
783
  });
755
784
  }
756
785
  else {
757
786
  txb.moveCall({
758
787
  target: protocol_1.PROTOCOL.ServiceFn('required_set'),
759
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_vector_u8((0, util_1.array_unique)(customer_required))), txb.pure(service_pubkey, 'vector<u8>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
788
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_vector_u8((0, utils_1.array_unique)(customer_required))), txb.pure(service_pubkey, 'vector<u8>'), (0, protocol_1.TXB_OBJECT)(txb, permission)],
760
789
  typeArguments: [pay_type]
761
790
  });
762
791
  }
@@ -889,7 +918,7 @@ function update_order_required_info(pay_type, txb, service, order, customer_info
889
918
  arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), (0, protocol_1.TXB_OBJECT)(txb, order),
890
919
  txb.pure(customer_info_crypto.service_pubkey, 'vector<u8>'),
891
920
  txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
892
- txb.pure(util_1.BCS_CONVERT.ser_vector_vector_u8((0, util_1.array_unique)(customer_info_crypto.customer_info_crypt)))],
921
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_vector_u8((0, utils_1.array_unique)(customer_info_crypto.customer_info_crypt)))],
893
922
  typeArguments: [pay_type]
894
923
  });
895
924
  return true;
@@ -903,32 +932,39 @@ function buy(pay_type, txb, service, buy_items, coin, discount, service_machine,
903
932
  if (!buy_items)
904
933
  return false;
905
934
  let bValid = true;
935
+ let names = [];
906
936
  buy_items.forEach((v) => {
907
937
  if (!(0, protocol_1.IsValidName)(v.item))
908
938
  bValid = false;
939
+ if (!(0, protocol_1.IsValidInt)(v.max_price))
940
+ bValid = false;
909
941
  if (!(0, protocol_1.IsValidUint)(v.count))
910
942
  bValid = false;
943
+ if (names.includes(v.item))
944
+ bValid = false;
945
+ names.push(v.item);
911
946
  });
912
947
  if (!bValid)
913
948
  return false;
914
- let i = [];
915
- let c = [];
949
+ let name = [];
950
+ let price = [];
951
+ let stock = [];
916
952
  let order;
917
- buy_items.forEach((item) => { i.push(item.item); c.push(item.count); });
953
+ buy_items.forEach((b) => { name.push(b.item); price.push(b.max_price); stock.push(b.count); });
918
954
  if (passport) {
919
955
  if (discount) {
920
956
  order = txb.moveCall({
921
957
  target: protocol_1.PROTOCOL.ServiceFn('dicount_buy_with_passport'),
922
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string(i)),
923
- txb.pure(util_1.BCS_CONVERT.ser_vector_u64(c)), (0, protocol_1.TXB_OBJECT)(txb, coin), (0, protocol_1.TXB_OBJECT)(txb, discount), txb.object(protocol_1.CLOCK_OBJECT)],
958
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(name)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)),
959
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, coin), (0, protocol_1.TXB_OBJECT)(txb, discount), txb.object(protocol_1.CLOCK_OBJECT)],
924
960
  typeArguments: [pay_type]
925
961
  });
926
962
  }
927
963
  else {
928
964
  order = txb.moveCall({
929
965
  target: protocol_1.PROTOCOL.ServiceFn('buy_with_passport'),
930
- arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string(i)),
931
- txb.pure(util_1.BCS_CONVERT.ser_vector_u64(c)), (0, protocol_1.TXB_OBJECT)(txb, coin)],
966
+ arguments: [passport, (0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(name)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)),
967
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, coin)],
932
968
  typeArguments: [pay_type]
933
969
  });
934
970
  }
@@ -937,16 +973,16 @@ function buy(pay_type, txb, service, buy_items, coin, discount, service_machine,
937
973
  if (discount) {
938
974
  order = txb.moveCall({
939
975
  target: protocol_1.PROTOCOL.ServiceFn('disoucnt_buy'),
940
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string(i)),
941
- txb.pure(util_1.BCS_CONVERT.ser_vector_u64(c)), (0, protocol_1.TXB_OBJECT)(txb, coin), (0, protocol_1.TXB_OBJECT)(txb, discount), txb.object(protocol_1.CLOCK_OBJECT)],
976
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(name)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)),
977
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, coin), (0, protocol_1.TXB_OBJECT)(txb, discount), txb.object(protocol_1.CLOCK_OBJECT)],
942
978
  typeArguments: [pay_type]
943
979
  });
944
980
  }
945
981
  else {
946
982
  order = txb.moveCall({
947
983
  target: protocol_1.PROTOCOL.ServiceFn('buy'),
948
- arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(util_1.BCS_CONVERT.ser_vector_string(i)),
949
- txb.pure(util_1.BCS_CONVERT.ser_vector_u64(c)), (0, protocol_1.TXB_OBJECT)(txb, coin)],
984
+ arguments: [(0, protocol_1.TXB_OBJECT)(txb, service), txb.pure(utils_1.BCS_CONVERT.ser_vector_string(name)), txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(price)),
985
+ txb.pure(utils_1.BCS_CONVERT.ser_vector_u64(stock)), (0, protocol_1.TXB_OBJECT)(txb, coin)],
950
986
  typeArguments: [pay_type]
951
987
  });
952
988
  }
package/dist/utils.js ADDED
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numToUint8Array = exports.stringToUint8Array = 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
+ const 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
+ const 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
+ const 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
+ const 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_option_address(data) {
88
+ return this.bcs.ser('Option<address>', { 'some': data }).toBytes();
89
+ }
90
+ ser_vector_string(data) {
91
+ return this.bcs.ser('vector<string>', data).toBytes();
92
+ }
93
+ ser_vector_vector_u8(data) {
94
+ return this.bcs.ser('vector<vector<u8>>', data).toBytes();
95
+ }
96
+ ser_vector_u64(data) {
97
+ return this.bcs.ser('vector<u64>', data).toBytes();
98
+ }
99
+ }
100
+ exports.Bcs = Bcs;
101
+ exports.BCS_CONVERT = new Bcs();
102
+ const Object_Type_Extra = () => {
103
+ let names = Object.keys(protocol_1.MODULES).map((key) => { return key + '::' + capitalize(key); });
104
+ names.push('order::Discount');
105
+ return names;
106
+ };
107
+ exports.Object_Type_Extra = Object_Type_Extra;
108
+ const objectids_from_response = (response, concat_result) => {
109
+ let ret = new Map();
110
+ if (response?.objectChanges) {
111
+ response.objectChanges.forEach((change) => {
112
+ (0, exports.Object_Type_Extra)().forEach((name) => {
113
+ let type = protocol_1.PROTOCOL.Package() + '::' + name;
114
+ if (change.type == 'created' && change.objectType.includes(type)) {
115
+ if (ret.has(name)) {
116
+ ret.get(name)?.push(change.objectId);
117
+ }
118
+ else {
119
+ ret.set(name, [change.objectId]);
120
+ }
121
+ }
122
+ });
123
+ });
124
+ }
125
+ if (concat_result) {
126
+ ret.forEach((value, key) => {
127
+ if (concat_result.has(key)) {
128
+ concat_result.set(key, concat_result.get(key).concat(value));
129
+ }
130
+ else {
131
+ concat_result.set(key, value);
132
+ }
133
+ });
134
+ }
135
+ return ret;
136
+ };
137
+ exports.objectids_from_response = objectids_from_response;
138
+ function stringToUint8Array(str) {
139
+ var arr = [];
140
+ for (var i = 0, j = str.length; i < j; ++i) {
141
+ arr.push(str.charCodeAt(i));
142
+ }
143
+ var tmpUint8Array = new Uint8Array(arr);
144
+ return tmpUint8Array;
145
+ }
146
+ exports.stringToUint8Array = stringToUint8Array;
147
+ function numToUint8Array(num) {
148
+ if (!num)
149
+ return new Uint8Array(0);
150
+ const a = [];
151
+ a.unshift(num & 255);
152
+ while (num >= 256) {
153
+ num = num >>> 8;
154
+ a.unshift(num & 255);
155
+ }
156
+ return new Uint8Array(a);
157
+ }
158
+ exports.numToUint8Array = numToUint8Array;