wowok 1.3.3 → 1.3.4
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/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/machine.ts +2 -2
- package/src/passport.ts +7 -4
- package/src/permission.ts +50 -23
- package/src/progress.ts +0 -1
- package/src/protocol.ts +14 -10
- package/src/repository.ts +2 -2
- package/src/resource.ts +7 -7
- package/src/service.ts +52 -51
- package/src/utils.ts +33 -18
- package/src/vote.ts +4 -4
package/package.json
CHANGED
package/src/exception.ts
CHANGED
|
@@ -9,6 +9,7 @@ export enum Errors {
|
|
|
9
9
|
IsValidTokenType = 'invalid token type',
|
|
10
10
|
IsValidUint = 'invalid uint',
|
|
11
11
|
IsValidInt = 'invalid int',
|
|
12
|
+
IsValidU64 = 'invalid u64',
|
|
12
13
|
IsValidPercent = 'invalid percent',
|
|
13
14
|
IsValidArray = 'invalid array',
|
|
14
15
|
IsValidObjects = 'invalid objects',
|
package/src/machine.ts
CHANGED
|
@@ -223,13 +223,13 @@ export class Machine {
|
|
|
223
223
|
if (passport) {
|
|
224
224
|
this.txb.moveCall({
|
|
225
225
|
target:Protocol.Instance().MachineFn('node_remove_with_passport') as FnCallType,
|
|
226
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
226
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
|
|
227
227
|
this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
228
228
|
});
|
|
229
229
|
} else {
|
|
230
230
|
this.txb.moveCall({
|
|
231
231
|
target:Protocol.Instance().MachineFn('node_remove') as FnCallType,
|
|
232
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
232
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
|
|
233
233
|
this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
234
234
|
});
|
|
235
235
|
}
|
package/src/passport.ts
CHANGED
|
@@ -478,11 +478,15 @@ export class GuardParser {
|
|
|
478
478
|
|
|
479
479
|
let guard_list = array_unique(guards);
|
|
480
480
|
const protocol = Protocol.Instance();
|
|
481
|
-
|
|
481
|
+
|
|
482
482
|
if (onGuardInfo) {
|
|
483
483
|
protocol.Query_Raw(guard_list)
|
|
484
|
-
.then((res) => {
|
|
485
|
-
|
|
484
|
+
.then((res) => {
|
|
485
|
+
onGuardInfo(GuardParser.Parse_Guard_Helper(guards, res));
|
|
486
|
+
}).catch((e) => {
|
|
487
|
+
console.log(e);
|
|
488
|
+
onGuardInfo(undefined);
|
|
489
|
+
})
|
|
486
490
|
} else {
|
|
487
491
|
const res = await protocol.Query_Raw(guard_list);
|
|
488
492
|
return GuardParser.Parse_Guard_Helper(guards, res);
|
|
@@ -638,7 +642,6 @@ export class GuardParser {
|
|
|
638
642
|
objects.push(this.get_object(g.id, q, fill));
|
|
639
643
|
})
|
|
640
644
|
})
|
|
641
|
-
|
|
642
645
|
if (onPassportQueryReady) {
|
|
643
646
|
Protocol.Instance().Query_Raw(array_unique(objects), {showType:true}).then((res) => {
|
|
644
647
|
onPassportQueryReady(this.done_helper(res));
|
package/src/permission.ts
CHANGED
|
@@ -38,7 +38,7 @@ export enum PermissionIndex {
|
|
|
38
38
|
service_remove_sales = 213,
|
|
39
39
|
service_discount_transfer = 214,
|
|
40
40
|
service_withdraw = 216,
|
|
41
|
-
|
|
41
|
+
service_buyer_guard = 217,
|
|
42
42
|
service_machine = 218,
|
|
43
43
|
service_endpoint = 219,
|
|
44
44
|
service_publish = 220,
|
|
@@ -135,7 +135,7 @@ export const PermissionInfo : PermissionInfoType[] = [
|
|
|
135
135
|
{index:PermissionIndex.service_remove_sales, name:'Remove sales', description:'Remove sale items for Service', module: 'service'},
|
|
136
136
|
{index:PermissionIndex.service_discount_transfer, name:'Discount', description:'Launch discounts for Service', module: 'service'},
|
|
137
137
|
{index:PermissionIndex.service_withdraw, name:'Withdraw', description:'Widthraw from Service orders', module: 'service'},
|
|
138
|
-
{index:PermissionIndex.
|
|
138
|
+
{index:PermissionIndex.service_buyer_guard, name:'Buyer Guard', description:'Set Guard of buying for Service', module: 'service'},
|
|
139
139
|
{index:PermissionIndex.service_machine, name:'Machine', description:'Set Machine for Service', module: 'service'},
|
|
140
140
|
{index:PermissionIndex.service_endpoint, name:'Endpoint', description:'Set Service endpoint', module: 'service'},
|
|
141
141
|
{index:PermissionIndex.service_publish, name:'Publish', description:'Publish Service', module: 'service'},
|
|
@@ -375,7 +375,7 @@ export class Permission {
|
|
|
375
375
|
this.txb.moveCall({
|
|
376
376
|
target:Protocol.Instance().PermissionFn('remove_index') as FnCallType,
|
|
377
377
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(entity_address),
|
|
378
|
-
this.txb.pure
|
|
378
|
+
this.txb.pure.vector('u64', array_unique(index))]
|
|
379
379
|
})
|
|
380
380
|
}
|
|
381
381
|
remove_entity(entity_address:string[]) {
|
|
@@ -444,6 +444,8 @@ export class Permission {
|
|
|
444
444
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(new_owner)]
|
|
445
445
|
});
|
|
446
446
|
}
|
|
447
|
+
|
|
448
|
+
// query some permissions for address
|
|
447
449
|
query_permissions(address_queried:string, permissions:PermissionIndexType[]) {
|
|
448
450
|
if (!IsValidAddress(address_queried)) {
|
|
449
451
|
ERROR(Errors.InvalidParam, 'query_permissions');
|
|
@@ -460,36 +462,61 @@ export class Permission {
|
|
|
460
462
|
})
|
|
461
463
|
}
|
|
462
464
|
|
|
463
|
-
|
|
465
|
+
// query all permissions for address
|
|
466
|
+
query_permissions_all(address_queried:string) {
|
|
467
|
+
if (!IsValidAddress(address_queried)) {
|
|
468
|
+
ERROR(Errors.InvalidParam, 'query_permissions');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
this.txb.moveCall({
|
|
472
|
+
target:Protocol.Instance().PermissionFn('query_permissions_all') as FnCallType,
|
|
473
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(address_queried)]
|
|
474
|
+
})
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
QueryPermissions(permission:string, address_queried:string, permissions:PermissionIndexType[]|'all', onPermissionAnswer:OnPermissionAnswer, sender?:string) {
|
|
464
478
|
//@ be the same txb
|
|
465
|
-
|
|
479
|
+
if (permissions === 'all') {
|
|
480
|
+
this.query_permissions_all(address_queried);
|
|
481
|
+
} else {
|
|
482
|
+
this.query_permissions(address_queried, permissions);
|
|
483
|
+
}
|
|
484
|
+
|
|
466
485
|
Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:this.txb}).then((res) => {
|
|
467
486
|
if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
|
|
468
487
|
onPermissionAnswer({who:address_queried, object:permission});
|
|
469
488
|
return
|
|
470
489
|
}
|
|
471
|
-
|
|
472
490
|
const perm = Bcs.getInstance().de(BCS.U8, Uint8Array.from((res.results as any)[0].returnValues[0][0]));
|
|
473
|
-
|
|
474
491
|
if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
|
|
475
492
|
onPermissionAnswer({who:address_queried, admin:true, owner:perm%2===1, items:[], object:permission})
|
|
476
493
|
} else {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
494
|
+
if (permissions === 'all') {
|
|
495
|
+
const perms = Bcs.getInstance().de('vector<u64>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
|
|
496
|
+
const guards = Bcs.getInstance().de_guards(Uint8Array.from((res.results as any)[0].returnValues[2][0]));
|
|
497
|
+
const items: PermissionAnswerItem[] = [];
|
|
498
|
+
for(let i = 0; i < perms.length; ++i) {
|
|
499
|
+
items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
|
|
500
|
+
}
|
|
501
|
+
onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
|
|
502
|
+
} else {
|
|
503
|
+
const perms = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[1][0]));
|
|
504
|
+
const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from((res.results as any)[0].returnValues[2][0]));
|
|
505
|
+
if (perms.length !== permissions.length) {
|
|
506
|
+
onPermissionAnswer({who:address_queried, object:permission});
|
|
507
|
+
return
|
|
489
508
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
509
|
+
|
|
510
|
+
const items: PermissionAnswerItem[] = (permissions as PermissionIndexType[]).map((v, index) => {
|
|
511
|
+
const p = perms[index] === Permission.PERMISSION_QUERY_NONE ? false : true;
|
|
512
|
+
let g : any = undefined;
|
|
513
|
+
if (p && perms[index] < guards.length) {
|
|
514
|
+
g = '0x' + guards[perms[index] as number];
|
|
515
|
+
}
|
|
516
|
+
return {query:v, permission:p, guard:g}
|
|
517
|
+
})
|
|
518
|
+
onPermissionAnswer({who:address_queried, admin:false, owner:perm%2===1, items:items, object:permission});
|
|
519
|
+
}
|
|
493
520
|
}
|
|
494
521
|
}).catch((e) => {
|
|
495
522
|
console.log(e);
|
|
@@ -499,7 +526,7 @@ export class Permission {
|
|
|
499
526
|
static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType, bStrict:boolean=false) : {has:boolean, guard?:string, owner?:boolean} | undefined {
|
|
500
527
|
if (answer) {
|
|
501
528
|
if (answer.admin) return {has:true, owner:answer.owner}; // admin
|
|
502
|
-
let i = answer.items?.find((v)=>v.query
|
|
529
|
+
let i = answer.items?.find((v)=>v.query == index); // index maybe string, so ==
|
|
503
530
|
if (i) {
|
|
504
531
|
return {has:i.permission, guard:i.guard, owner:answer.owner};
|
|
505
532
|
}
|
package/src/progress.ts
CHANGED
|
@@ -272,7 +272,6 @@ export class Progress {
|
|
|
272
272
|
let sub = this.txb.pure.option('address', sub_id ? sub_id : undefined);
|
|
273
273
|
|
|
274
274
|
if (passport) {
|
|
275
|
-
console.log(11111)
|
|
276
275
|
this.txb.moveCall({
|
|
277
276
|
target:Protocol.Instance().ProgressFn('next_with_passport') as FnCallType,
|
|
278
277
|
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.machine),
|
package/src/protocol.ts
CHANGED
|
@@ -191,9 +191,9 @@ export enum ENTRYPOINT {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
const TESTNET = {
|
|
194
|
-
package: "
|
|
195
|
-
wowok_object: '
|
|
196
|
-
entity_object: '
|
|
194
|
+
package: "0xdfead784f096e93d025e3e29c4fa48cf5585867e7bcc304c83d3f410f210e4c9",
|
|
195
|
+
wowok_object: '0xe386bb9e01b3528b75f3751ad8a1e418b207ad979fea364087deef5250a73d3f',
|
|
196
|
+
entity_object: '0xbc8be56e8924f7ddcce0ebbc8bd9a2bf1f00d1db9a12e36b9290f009ba305dd9',
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
const MAINNET = {
|
|
@@ -206,6 +206,7 @@ export interface CoinTypeInfo {
|
|
|
206
206
|
symbol: string;
|
|
207
207
|
type: string;
|
|
208
208
|
decimals: number;
|
|
209
|
+
alias ?: boolean;
|
|
209
210
|
}
|
|
210
211
|
export class Protocol {
|
|
211
212
|
protected network = '';
|
|
@@ -334,9 +335,9 @@ export class Protocol {
|
|
|
334
335
|
COINS_TYPE = () => {
|
|
335
336
|
switch(this.network) {
|
|
336
337
|
case ENTRYPOINT.testnet:
|
|
337
|
-
return this.CoinTypes_Testnet;
|
|
338
|
+
return this.CoinTypes_Testnet.filter((v)=>v.alias !== true);
|
|
338
339
|
case ENTRYPOINT.mainnet:
|
|
339
|
-
return this.CoinTypes_Mainnet;
|
|
340
|
+
return this.CoinTypes_Mainnet.filter((v)=>v.alias !== true);
|
|
340
341
|
}; return [];
|
|
341
342
|
}
|
|
342
343
|
Update_CoinType = (token_type: string, decimals:number, symbol: string) => {
|
|
@@ -363,8 +364,14 @@ export class Protocol {
|
|
|
363
364
|
}
|
|
364
365
|
|
|
365
366
|
CoinTypes_Testnet:CoinTypeInfo[] = [
|
|
366
|
-
{symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9},
|
|
367
|
-
{symbol:'SUI', type:'0x2::sui::SUI', decimals:9},
|
|
367
|
+
{symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
|
|
368
|
+
{symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
|
|
369
|
+
{symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
|
|
370
|
+
];
|
|
371
|
+
|
|
372
|
+
CoinTypes_Mainnet:CoinTypeInfo[] = [
|
|
373
|
+
{symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
|
|
374
|
+
{symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
|
|
368
375
|
{symbol:'WOW', type:TESTNET.package + '::wowok::WOWOK', decimals:9},
|
|
369
376
|
{symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
|
|
370
377
|
{symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
|
|
@@ -372,9 +379,6 @@ export class Protocol {
|
|
|
372
379
|
{symbol:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
|
|
373
380
|
];
|
|
374
381
|
|
|
375
|
-
CoinTypes_Mainnet:CoinTypeInfo[] = [
|
|
376
|
-
];
|
|
377
|
-
|
|
378
382
|
GetCoinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
|
|
379
383
|
let r = this.COINS_TYPE().find((v) => v?.type === token_type);
|
|
380
384
|
if (!r) {
|
package/src/repository.ts
CHANGED
|
@@ -254,14 +254,14 @@ export class Repository {
|
|
|
254
254
|
this.txb.moveCall({
|
|
255
255
|
target:Protocol.Instance().RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
256
256
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
257
|
-
this.txb.pure
|
|
257
|
+
this.txb.pure.vector('string', array_unique(policy_keys)),
|
|
258
258
|
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
259
259
|
})
|
|
260
260
|
} else {
|
|
261
261
|
this.txb.moveCall({
|
|
262
262
|
target:Protocol.Instance().RepositoryFn('policy_remove') as FnCallType,
|
|
263
263
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
264
|
-
this.txb.pure
|
|
264
|
+
this.txb.pure.vector('string', array_unique(policy_keys)),
|
|
265
265
|
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
266
266
|
})
|
|
267
267
|
}
|
package/src/resource.ts
CHANGED
|
@@ -3,15 +3,15 @@ import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from '
|
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
5
5
|
|
|
6
|
-
export interface Tags {
|
|
7
|
-
address: string;
|
|
8
|
-
nick: string;
|
|
9
|
-
tags: string[];
|
|
6
|
+
export interface Tags { // tag am address
|
|
7
|
+
address: string; // address to tag
|
|
8
|
+
nick: string; // named address
|
|
9
|
+
tags: string[]; // tags for address
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface ResourceData {
|
|
13
|
-
name: string;
|
|
14
|
-
address: string[];
|
|
12
|
+
export interface ResourceData { // personal folder
|
|
13
|
+
name: string; // folder name
|
|
14
|
+
address: string[]; // objects in folder
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export class Resource {
|
package/src/service.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidTokenType, IsValidDesription,
|
|
2
|
-
IsValidAddress, IsValidEndpoint,
|
|
2
|
+
IsValidAddress, IsValidEndpoint, IsValidU64, IsValidName,} from './utils'
|
|
3
3
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
|
|
4
4
|
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
5
5
|
TxbObject} from './protocol';
|
|
@@ -12,8 +12,8 @@ export type Service_Guard_Percent = {
|
|
|
12
12
|
}
|
|
13
13
|
export type Service_Sale = {
|
|
14
14
|
item:string;
|
|
15
|
-
price:
|
|
16
|
-
stock:
|
|
15
|
+
price:bigint;
|
|
16
|
+
stock:bigint;
|
|
17
17
|
endpoint?:string;
|
|
18
18
|
}
|
|
19
19
|
export enum Service_Discount_Type {
|
|
@@ -26,7 +26,7 @@ export type Service_Discount = {
|
|
|
26
26
|
off: number;
|
|
27
27
|
duration_minutes: number;
|
|
28
28
|
time_start?: number; // current time if undefined
|
|
29
|
-
price_greater?:
|
|
29
|
+
price_greater?: bigint;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export type Service_Buy_RequiredInfo = {
|
|
@@ -47,13 +47,13 @@ export enum BuyRequiredEnum {
|
|
|
47
47
|
|
|
48
48
|
export type Service_Buy = {
|
|
49
49
|
item: string;
|
|
50
|
-
max_price:
|
|
51
|
-
count:
|
|
50
|
+
max_price: bigint;
|
|
51
|
+
count: bigint;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
export type DicountDispatch = {
|
|
55
55
|
receiver: string;
|
|
56
|
-
count:
|
|
56
|
+
count: bigint;
|
|
57
57
|
discount: Service_Discount;
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -152,9 +152,9 @@ export class Service {
|
|
|
152
152
|
})
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
set_price(item:string, price:
|
|
156
|
-
if (!
|
|
157
|
-
ERROR(Errors.
|
|
155
|
+
set_price(item:string, price:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
|
|
156
|
+
if (!IsValidU64(price)) {
|
|
157
|
+
ERROR(Errors.IsValidU64, 'price')
|
|
158
158
|
}
|
|
159
159
|
if (!IsValidName(item)) {
|
|
160
160
|
ERROR(Errors.IsValidName, 'item')
|
|
@@ -178,12 +178,12 @@ export class Service {
|
|
|
178
178
|
})
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
set_stock(item:string, stock:
|
|
181
|
+
set_stock(item:string, stock:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
|
|
182
182
|
if (!IsValidName(item)) {
|
|
183
183
|
ERROR(Errors.IsValidName, 'item')
|
|
184
184
|
}
|
|
185
|
-
if (!
|
|
186
|
-
ERROR(Errors.
|
|
185
|
+
if (!IsValidU64(stock)) {
|
|
186
|
+
ERROR(Errors.IsValidU64, 'stock')
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
if (passport) {
|
|
@@ -204,11 +204,11 @@ export class Service {
|
|
|
204
204
|
})
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
add_stock(item:string, stock_add:
|
|
207
|
+
add_stock(item:string, stock_add:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
|
|
208
208
|
if (!IsValidName(item)) {
|
|
209
209
|
ERROR(Errors.IsValidName, 'item')
|
|
210
210
|
}
|
|
211
|
-
if (!
|
|
211
|
+
if (!IsValidU64(stock_add)) {
|
|
212
212
|
ERROR(Errors.IsValidUint, 'stock_add')
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -230,11 +230,11 @@ export class Service {
|
|
|
230
230
|
})
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
reduce_stock(item:string, stock_reduce:
|
|
233
|
+
reduce_stock(item:string, stock_reduce:bigint, bNotFoundAssert:boolean=true, passport?:PassportObject) {
|
|
234
234
|
if (!IsValidName(item)) {
|
|
235
235
|
ERROR(Errors.IsValidName, 'item')
|
|
236
236
|
}
|
|
237
|
-
if (!
|
|
237
|
+
if (!IsValidU64(stock_reduce)) {
|
|
238
238
|
ERROR(Errors.IsValidUint, 'stock_reduce')
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -505,8 +505,8 @@ export class Service {
|
|
|
505
505
|
let bValid = true; let names:string[] = [];
|
|
506
506
|
sales.forEach((v) => {
|
|
507
507
|
if (!IsValidName(v.item)) bValid = false;
|
|
508
|
-
if (!
|
|
509
|
-
if (!
|
|
508
|
+
if (!IsValidU64(v.price)) bValid = false;
|
|
509
|
+
if (!IsValidU64(v.stock)) bValid = false;
|
|
510
510
|
if (names.includes(v.item)) bValid = false;
|
|
511
511
|
names.push(v.item)
|
|
512
512
|
})
|
|
@@ -520,7 +520,7 @@ export class Service {
|
|
|
520
520
|
ERROR(Errors.InvalidParam, 'add_sales')
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
let names: string[] = []; let price:
|
|
523
|
+
let names: string[] = []; let price: bigint[] = []; let stock: bigint[] = []; let endpoint: string[] = [];
|
|
524
524
|
sales.forEach((s) => {
|
|
525
525
|
if (s.endpoint && !IsValidEndpoint(s.endpoint)) {
|
|
526
526
|
ERROR(Errors.IsValidEndpoint, 'add_sales')
|
|
@@ -531,24 +531,26 @@ export class Service {
|
|
|
531
531
|
if (passport) {
|
|
532
532
|
this.txb.moveCall({
|
|
533
533
|
target:Protocol.Instance().ServiceFn('sales_add_with_passport') as FnCallType,
|
|
534
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
535
|
-
this.txb.pure
|
|
536
|
-
this.txb.pure
|
|
534
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', names),
|
|
535
|
+
this.txb.pure.vector('string', endpoint),
|
|
536
|
+
this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
|
|
537
|
+
this.txb.pure.bool(bExistAssert),
|
|
537
538
|
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
538
539
|
typeArguments:[this.pay_token_type]
|
|
539
540
|
})
|
|
540
541
|
} else {
|
|
541
542
|
this.txb.moveCall({
|
|
542
543
|
target:Protocol.Instance().ServiceFn('sales_add') as FnCallType,
|
|
543
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
544
|
-
this.txb.pure
|
|
545
|
-
this.txb.pure
|
|
546
|
-
this.txb.pure
|
|
544
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', names),
|
|
545
|
+
this.txb.pure.vector('string', endpoint),
|
|
546
|
+
this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
|
|
547
|
+
this.txb.pure.bool(bExistAssert),
|
|
547
548
|
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
548
549
|
typeArguments:[this.pay_token_type]
|
|
549
550
|
})
|
|
550
551
|
}
|
|
551
552
|
}
|
|
553
|
+
|
|
552
554
|
remove_sales(sales:string[], passport?:PassportObject) {
|
|
553
555
|
if (sales.length === 0) return;
|
|
554
556
|
|
|
@@ -559,14 +561,14 @@ export class Service {
|
|
|
559
561
|
if (passport) {
|
|
560
562
|
this.txb.moveCall({
|
|
561
563
|
target:Protocol.Instance().ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
562
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
564
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', array_unique(sales!)),
|
|
563
565
|
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
564
566
|
typeArguments:[this.pay_token_type]
|
|
565
567
|
})
|
|
566
568
|
} else {
|
|
567
569
|
this.txb.moveCall({
|
|
568
570
|
target:Protocol.Instance().ServiceFn('sales_remove') as FnCallType,
|
|
569
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
571
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', array_unique(sales!)),
|
|
570
572
|
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
571
573
|
typeArguments:[this.pay_token_type]
|
|
572
574
|
})
|
|
@@ -581,12 +583,12 @@ export class Service {
|
|
|
581
583
|
let bValid = true;
|
|
582
584
|
discount_dispatch.forEach((v) => {
|
|
583
585
|
if (!IsValidAddress(v.receiver)) bValid = false;
|
|
584
|
-
if (!
|
|
586
|
+
if (!IsValidU64(v.count) || v.count > Service.MAX_DISCOUNT_COUNT_ONCE) bValid = false;
|
|
585
587
|
if (!IsValidName_AllowEmpty(v.discount.name)) bValid = false;
|
|
586
588
|
if (v.discount.type == Service_Discount_Type.ratio && !IsValidPercent(v.discount.off)) bValid = false;
|
|
587
|
-
if (!
|
|
588
|
-
if (v.discount?.time_start && !
|
|
589
|
-
if (v.discount?.price_greater && !
|
|
589
|
+
if (!IsValidU64(v.discount.duration_minutes)) bValid = false;
|
|
590
|
+
if (v.discount?.time_start && !IsValidU64(v.discount.time_start)) bValid = false;
|
|
591
|
+
if (v.discount?.price_greater && !IsValidU64(v.discount.price_greater)) bValid = false;
|
|
590
592
|
})
|
|
591
593
|
if (!bValid) {
|
|
592
594
|
ERROR(Errors.InvalidParam, 'discount_dispatch')
|
|
@@ -741,18 +743,18 @@ export class Service {
|
|
|
741
743
|
}
|
|
742
744
|
|
|
743
745
|
}
|
|
744
|
-
clone(passport?:PassportObject) : ServiceObject {
|
|
746
|
+
clone(new_token_type?:string, passport?:PassportObject) : ServiceObject {
|
|
745
747
|
if (passport) {
|
|
746
748
|
return this.txb.moveCall({
|
|
747
749
|
target:Protocol.Instance().ServiceFn('clone_withpassport') as FnCallType,
|
|
748
750
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
749
|
-
typeArguments:[this.pay_token_type]
|
|
751
|
+
typeArguments:[this.pay_token_type, new_token_type ? new_token_type : this.pay_token_type]
|
|
750
752
|
})
|
|
751
753
|
} else {
|
|
752
754
|
return this.txb.moveCall({
|
|
753
755
|
target:Protocol.Instance().ServiceFn('clone') as FnCallType,
|
|
754
756
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
755
|
-
typeArguments:[this.pay_token_type]
|
|
757
|
+
typeArguments:[this.pay_token_type, new_token_type ? new_token_type : this.pay_token_type]
|
|
756
758
|
})
|
|
757
759
|
}
|
|
758
760
|
}
|
|
@@ -771,7 +773,7 @@ export class Service {
|
|
|
771
773
|
this.txb.moveCall({
|
|
772
774
|
target:Protocol.Instance().ServiceFn('required_set_with_passport') as FnCallType,
|
|
773
775
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
774
|
-
this.txb.pure
|
|
776
|
+
this.txb.pure.vector('string', req),
|
|
775
777
|
this.txb.pure.string(pubkey), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
776
778
|
typeArguments:[this.pay_token_type]
|
|
777
779
|
})
|
|
@@ -779,7 +781,7 @@ export class Service {
|
|
|
779
781
|
this.txb.moveCall({
|
|
780
782
|
target:Protocol.Instance().ServiceFn('required_set') as FnCallType,
|
|
781
783
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
782
|
-
this.txb.pure
|
|
784
|
+
this.txb.pure.vector('string', req),
|
|
783
785
|
this.txb.pure.string(pubkey), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
784
786
|
typeArguments:[this.pay_token_type]
|
|
785
787
|
})
|
|
@@ -894,7 +896,7 @@ export class Service {
|
|
|
894
896
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
|
|
895
897
|
this.txb.pure.string(customer_info_crypto.pubkey),
|
|
896
898
|
this.txb.pure.string(customer_info_crypto.customer_pubkey),
|
|
897
|
-
this.txb.pure
|
|
899
|
+
this.txb.pure.vector('vector<u8>', array_unique(customer_info_crypto.customer_info_crypt))],
|
|
898
900
|
typeArguments:[this.pay_token_type]
|
|
899
901
|
})
|
|
900
902
|
|
|
@@ -909,8 +911,8 @@ export class Service {
|
|
|
909
911
|
let bValid = true; let names:string[] = [];
|
|
910
912
|
buy_items.forEach((v) => {
|
|
911
913
|
if (!IsValidName(v.item)) bValid = false;
|
|
912
|
-
if (!
|
|
913
|
-
if (!
|
|
914
|
+
if (!IsValidU64(v.max_price)) bValid = false;
|
|
915
|
+
if (!IsValidU64(v.count)) bValid = false;
|
|
914
916
|
if (names.includes(v.item)) bValid = false;
|
|
915
917
|
names.push(v.item)
|
|
916
918
|
})
|
|
@@ -918,23 +920,22 @@ export class Service {
|
|
|
918
920
|
ERROR(Errors.InvalidParam, 'buy_items 2')
|
|
919
921
|
}
|
|
920
922
|
|
|
921
|
-
let name:string[] = []; let price:
|
|
923
|
+
let name:string[] = []; let price:bigint[] = []; let stock:bigint[] = []; let order;
|
|
922
924
|
buy_items.forEach((b) => { name.push(b.item); price.push(b.max_price); stock.push(b.count)})
|
|
923
925
|
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
924
926
|
if (passport) {
|
|
925
927
|
if (discount) {
|
|
926
928
|
order = this.txb.moveCall({
|
|
927
929
|
target:Protocol.Instance().ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
928
|
-
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
929
|
-
this.txb.pure
|
|
930
|
+
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
931
|
+
this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
|
|
930
932
|
Protocol.TXB_OBJECT(this.txb, coin), Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
|
|
931
933
|
typeArguments:[this.pay_token_type]
|
|
932
934
|
})} else {
|
|
933
935
|
order = this.txb.moveCall({
|
|
934
936
|
target:Protocol.Instance().ServiceFn('buy_with_passport') as FnCallType,
|
|
935
|
-
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure
|
|
936
|
-
this.txb.pure
|
|
937
|
-
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
937
|
+
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
938
|
+
this.txb.pure.vector('u64', price), this.txb.pure.vector('u64', stock),
|
|
938
939
|
Protocol.TXB_OBJECT(this.txb, coin)],
|
|
939
940
|
typeArguments:[this.pay_token_type]
|
|
940
941
|
})}
|
|
@@ -943,8 +944,8 @@ export class Service {
|
|
|
943
944
|
order = this.txb.moveCall({
|
|
944
945
|
target:Protocol.Instance().ServiceFn('disoucnt_buy') as FnCallType,
|
|
945
946
|
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
946
|
-
this.txb.pure
|
|
947
|
-
this.txb.pure
|
|
947
|
+
this.txb.pure.vector('u64', price),
|
|
948
|
+
this.txb.pure.vector('u64', stock),
|
|
948
949
|
Protocol.TXB_OBJECT(this.txb, coin),
|
|
949
950
|
Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
|
|
950
951
|
typeArguments:[this.pay_token_type]
|
|
@@ -952,8 +953,8 @@ export class Service {
|
|
|
952
953
|
order = this.txb.moveCall({
|
|
953
954
|
target:Protocol.Instance().ServiceFn('buy') as FnCallType,
|
|
954
955
|
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
955
|
-
this.txb.pure
|
|
956
|
-
this.txb.pure
|
|
956
|
+
this.txb.pure.vector('u64', price),
|
|
957
|
+
this.txb.pure.vector('u64', stock),
|
|
957
958
|
Protocol.TXB_OBJECT(this.txb, coin)],
|
|
958
959
|
typeArguments:[this.pay_token_type]
|
|
959
960
|
})}
|
package/src/utils.ts
CHANGED
|
@@ -173,6 +173,12 @@ export class Bcs {
|
|
|
173
173
|
'discord': BCS.STRING,
|
|
174
174
|
'homepage': BCS.STRING,
|
|
175
175
|
})
|
|
176
|
+
this.bcs.registerStructType('OptionAddress', {
|
|
177
|
+
'address': 'Option<address>',
|
|
178
|
+
})
|
|
179
|
+
this.bcs.registerStructType('Guards', {
|
|
180
|
+
'guards':'vector<OptionAddress>',
|
|
181
|
+
})
|
|
176
182
|
}
|
|
177
183
|
static getInstance() : Bcs {
|
|
178
184
|
if (!Bcs._instance) {
|
|
@@ -254,7 +260,6 @@ export class Bcs {
|
|
|
254
260
|
case ValueType.TYPE_U64:
|
|
255
261
|
return this.bcs.de(BCS.U64, data);
|
|
256
262
|
case ValueType.TYPE_U8:
|
|
257
|
-
console.log(data)
|
|
258
263
|
return this.bcs.de(BCS.U8, data);
|
|
259
264
|
case ValueType.TYPE_VEC_U8:
|
|
260
265
|
return this.bcs.de('vector<u8>', data);
|
|
@@ -297,7 +302,8 @@ export class Bcs {
|
|
|
297
302
|
}
|
|
298
303
|
}
|
|
299
304
|
|
|
300
|
-
de_ent(data:Uint8Array) : any {
|
|
305
|
+
de_ent(data:Uint8Array | undefined) : any {
|
|
306
|
+
if (!data || data.length < 2) return ''
|
|
301
307
|
const struct_vec = this.bcs.de('vector<u8>', data);
|
|
302
308
|
return this.bcs.de('EntStruct', Uint8Array.from(struct_vec));
|
|
303
309
|
/* const reader = new BcsReader(data);
|
|
@@ -321,6 +327,14 @@ export class Bcs {
|
|
|
321
327
|
r.description = new TextDecoder().decode(Uint8Array.from(r.description));
|
|
322
328
|
return r
|
|
323
329
|
}
|
|
330
|
+
de_guards(data:Uint8Array | undefined) : any {
|
|
331
|
+
if (!data || data.length < 1) return ''
|
|
332
|
+
let r = this.bcs.de('Guards', data);
|
|
333
|
+
return r?.guards?.map((v:any) => {
|
|
334
|
+
if (v?.address?.none) return undefined;
|
|
335
|
+
return v?.address?.some;
|
|
336
|
+
})
|
|
337
|
+
}
|
|
324
338
|
}
|
|
325
339
|
|
|
326
340
|
export function stringToUint8Array(str:string) : Uint8Array {
|
|
@@ -381,28 +395,31 @@ export const IsValidAddress = (addr:string | undefined) : boolean => {
|
|
|
381
395
|
}
|
|
382
396
|
return true
|
|
383
397
|
}
|
|
384
|
-
export const IsValidBigint = (value:string | number | undefined, max:bigint=MAX_U256) : boolean => {
|
|
398
|
+
export const IsValidBigint = (value:string | number | undefined | bigint, max:bigint=MAX_U256, min?:bigint) : boolean => {
|
|
385
399
|
if (value === '' || value === undefined) return false;
|
|
386
400
|
try {
|
|
387
401
|
const v = BigInt(value);
|
|
388
402
|
if (v <= max) {
|
|
403
|
+
if (min !== undefined) {
|
|
404
|
+
return v >= min;
|
|
405
|
+
}
|
|
389
406
|
return true
|
|
390
407
|
}
|
|
391
408
|
} catch (e) {
|
|
392
409
|
}; return false
|
|
393
410
|
}
|
|
394
411
|
|
|
395
|
-
export const IsValidUintLarge = (value:string | number | undefined) : boolean => {
|
|
396
|
-
return IsValidBigint(value)
|
|
412
|
+
export const IsValidUintLarge = (value:string | number | undefined | bigint) : boolean => {
|
|
413
|
+
return IsValidBigint(value, MAX_U64, BigInt(0))
|
|
397
414
|
}
|
|
398
|
-
export const IsValidU8 = (value:string | number | undefined) : boolean => {
|
|
399
|
-
return IsValidBigint(value, MAX_U8)
|
|
415
|
+
export const IsValidU8 = (value:string | number | undefined | bigint) : boolean => {
|
|
416
|
+
return IsValidBigint(value, MAX_U8, BigInt(0))
|
|
400
417
|
}
|
|
401
|
-
export const IsValidU64 = (value:string | number | undefined) : boolean => {
|
|
402
|
-
return IsValidBigint(value, MAX_U64)
|
|
418
|
+
export const IsValidU64 = (value:string | number | undefined | bigint) : boolean => {
|
|
419
|
+
return IsValidBigint(value, MAX_U64, BigInt(0))
|
|
403
420
|
}
|
|
404
|
-
export const IsValidU128 = (value:string | number | undefined) : boolean => {
|
|
405
|
-
return IsValidBigint(value, MAX_U128)
|
|
421
|
+
export const IsValidU128 = (value:string | number | undefined | bigint) : boolean => {
|
|
422
|
+
return IsValidBigint(value, MAX_U128, BigInt(0))
|
|
406
423
|
}
|
|
407
424
|
|
|
408
425
|
export const IsValidTokenType = (argType: string) : boolean => {
|
|
@@ -434,14 +451,12 @@ export const IsValidInt = (value: number | string) : boolean => {
|
|
|
434
451
|
}
|
|
435
452
|
return Number.isSafeInteger(value)
|
|
436
453
|
}
|
|
437
|
-
export const IsValidPercent = (value: number | string) : boolean => {
|
|
438
|
-
|
|
439
|
-
value = parseInt(value as string);
|
|
440
|
-
}
|
|
441
|
-
return Number.isSafeInteger(value) && value > 0 && value <= 100
|
|
454
|
+
export const IsValidPercent = (value: number | string | bigint) : boolean => {
|
|
455
|
+
return IsValidBigint(value, BigInt(100), BigInt(0))
|
|
442
456
|
}
|
|
443
|
-
|
|
444
|
-
|
|
457
|
+
|
|
458
|
+
export const IsValidArray = (arr: any, validFunc:any) : boolean => {
|
|
459
|
+
for (let i = 0; i < arr.length; i++) {
|
|
445
460
|
if (!validFunc(arr[i])) {
|
|
446
461
|
return false
|
|
447
462
|
}
|
package/src/vote.ts
CHANGED
|
@@ -229,7 +229,7 @@ export class Vote {
|
|
|
229
229
|
this.txb.moveCall({
|
|
230
230
|
target:Protocol.Instance().VoteFn('agrees_remove_with_passport') as FnCallType,
|
|
231
231
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
232
|
-
this.txb.pure
|
|
232
|
+
this.txb.pure.vector('string', array_unique(options)),
|
|
233
233
|
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
234
234
|
})
|
|
235
235
|
}
|
|
@@ -243,7 +243,7 @@ export class Vote {
|
|
|
243
243
|
this.txb.moveCall({
|
|
244
244
|
target:Protocol.Instance().VoteFn('agrees_remove') as FnCallType,
|
|
245
245
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
246
|
-
this.txb.pure
|
|
246
|
+
this.txb.pure.vector('string', array_unique(options)),
|
|
247
247
|
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
248
248
|
})
|
|
249
249
|
}
|
|
@@ -341,13 +341,13 @@ export class Vote {
|
|
|
341
341
|
this.txb.moveCall({
|
|
342
342
|
target:Protocol.Instance().VoteFn('with_passport') as FnCallType,
|
|
343
343
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
344
|
-
this.txb.pure
|
|
344
|
+
this.txb.pure.vector('string', array_unique(options))]
|
|
345
345
|
})
|
|
346
346
|
} else {
|
|
347
347
|
this.txb.moveCall({
|
|
348
348
|
target:Protocol.Instance().VoteFn('this.object') as FnCallType,
|
|
349
349
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
350
|
-
this.txb.pure
|
|
350
|
+
this.txb.pure.vector('string', array_unique(options))]
|
|
351
351
|
})
|
|
352
352
|
}
|
|
353
353
|
}
|