wowok 1.3.4 → 1.3.9
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 +2 -3
- package/src/demand.ts +10 -4
- package/src/entity.ts +42 -6
- package/src/guard.ts +6 -9
- package/src/permission.ts +3 -2
- package/src/protocol.ts +5 -4
- package/src/service.ts +41 -17
- package/src/utils.ts +8 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wowok",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
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",
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@mysten/bcs": "^0.11.1",
|
|
45
|
-
"@mysten/sui": "^1.7.0"
|
|
46
|
-
"graphql-tag": "^2.12.6"
|
|
45
|
+
"@mysten/sui": "^1.7.0"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@types/node": "^20.12.12",
|
package/src/demand.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class Demand {
|
|
|
24
24
|
this.txb = txb;
|
|
25
25
|
this.object = '';
|
|
26
26
|
}
|
|
27
|
-
static New(txb:TransactionBlock, bounty_type:string, permission:PermissionObject, description:string,
|
|
27
|
+
static New(txb:TransactionBlock, bounty_type:string, ms_expand:boolean, time:number, permission:PermissionObject, description:string,
|
|
28
28
|
bounty:TransactionResult | string, passport?:PassportObject) : Demand {
|
|
29
29
|
if (!Protocol.IsValidObjects([permission, bounty])) {
|
|
30
30
|
ERROR(Errors.IsValidObjects, 'permission, bounty');
|
|
@@ -35,18 +35,24 @@ export class Demand {
|
|
|
35
35
|
if (!IsValidArgType(bounty_type)) {
|
|
36
36
|
ERROR(Errors.IsValidArgType, bounty_type);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
if (!IsValidUintLarge(time)) {
|
|
39
|
+
ERROR(Errors.IsValidUint, 'time')
|
|
40
|
+
}
|
|
41
|
+
|
|
39
42
|
let d = new Demand(txb, bounty_type, permission);
|
|
43
|
+
const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
40
44
|
if (passport) {
|
|
41
45
|
d.object = txb.moveCall({
|
|
42
46
|
target:Protocol.Instance().DemandFn('new_with_passport') as FnCallType,
|
|
43
|
-
arguments:[passport, txb.pure.string(description), txb.object(bounty),
|
|
47
|
+
arguments:[passport, txb.pure.string(description), txb.object(bounty), txb.pure.bool(ms_expand), txb.pure.u64(time),
|
|
48
|
+
txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
|
|
44
49
|
typeArguments:[bounty_type],
|
|
45
50
|
})
|
|
46
51
|
} else {
|
|
47
52
|
d.object = txb.moveCall({
|
|
48
53
|
target:Protocol.Instance().DemandFn('new') as FnCallType,
|
|
49
|
-
arguments:[txb.pure.string(description), txb.object(bounty),
|
|
54
|
+
arguments:[txb.pure.string(description), txb.object(bounty), txb.pure.bool(ms_expand), txb.pure.u64(time),
|
|
55
|
+
txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
|
|
50
56
|
typeArguments:[bounty_type],
|
|
51
57
|
})
|
|
52
58
|
}
|
package/src/entity.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject, ResourceObject} from './protocol';
|
|
2
|
-
import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, } from './utils';
|
|
2
|
+
import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, IsValidArray, } from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { Resource } from './resource';
|
|
5
5
|
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
|
+
export interface Safer {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}
|
|
7
11
|
export interface Entity_Info {
|
|
8
12
|
name: string;
|
|
9
13
|
description?: string;
|
|
@@ -39,7 +43,42 @@ export class Entity {
|
|
|
39
43
|
this.txb.pure.address(address)]
|
|
40
44
|
})
|
|
41
45
|
}
|
|
42
|
-
|
|
46
|
+
|
|
47
|
+
add_safer(safer: Safer[], bExistModify:boolean=true) {
|
|
48
|
+
if (safer.length === 0) return ;
|
|
49
|
+
if (!IsValidArray(safer, (v:Safer) => {
|
|
50
|
+
if (!IsValidName(v.name) || !IsValidDesription(v.value)) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
})) {
|
|
54
|
+
ERROR(Errors.InvalidParam, 'add_safer');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const name = safer.map((v)=>v.name);
|
|
58
|
+
const value = safer.map((v)=>v.value);
|
|
59
|
+
this.txb.moveCall({
|
|
60
|
+
target:Protocol.Instance().EntityFn('safer_add') as FnCallType,
|
|
61
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
62
|
+
this.txb.pure.vector('string', value), this.txb.pure.bool(bExistModify)]
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
remove_safer(name:string[], removeall?:boolean) {
|
|
67
|
+
if (name.length === 0 && !removeall) return;
|
|
68
|
+
|
|
69
|
+
if (removeall) {
|
|
70
|
+
this.txb.moveCall({
|
|
71
|
+
target:Protocol.Instance().EntityFn('safer_remove_all') as FnCallType,
|
|
72
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
73
|
+
})
|
|
74
|
+
} else {
|
|
75
|
+
this.txb.moveCall({
|
|
76
|
+
target:Protocol.Instance().EntityFn('safer_remove') as FnCallType,
|
|
77
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name)]
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
43
82
|
update(info: Entity_Info) {
|
|
44
83
|
if (!IsValidName(info.name)) ERROR(Errors.IsValidName, 'update');
|
|
45
84
|
if (info?.description && !IsValidDesription(info.description)) ERROR(Errors.IsValidDesription, 'update');
|
|
@@ -63,7 +102,6 @@ export class Entity {
|
|
|
63
102
|
}
|
|
64
103
|
|
|
65
104
|
create_resource() : ResourceAddress {
|
|
66
|
-
|
|
67
105
|
return this.txb.moveCall({
|
|
68
106
|
target:Protocol.Instance().EntityFn('resource_create') as FnCallType,
|
|
69
107
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
@@ -71,7 +109,6 @@ export class Entity {
|
|
|
71
109
|
}
|
|
72
110
|
|
|
73
111
|
create_resource2(): ResourceObject {
|
|
74
|
-
|
|
75
112
|
return this.txb.moveCall({
|
|
76
113
|
target:Protocol.Instance().EntityFn('resource_create2') as FnCallType,
|
|
77
114
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
@@ -79,7 +116,6 @@ export class Entity {
|
|
|
79
116
|
}
|
|
80
117
|
|
|
81
118
|
destroy_resource(resource:Resource) {
|
|
82
|
-
|
|
83
119
|
return this.txb.moveCall({
|
|
84
120
|
target:Protocol.Instance().EntityFn('resource_destroy') as FnCallType,
|
|
85
121
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
|
|
@@ -98,7 +134,7 @@ export class Entity {
|
|
|
98
134
|
|
|
99
135
|
query_ent(address_queried:string) {
|
|
100
136
|
if (!IsValidAddress(address_queried)) {
|
|
101
|
-
ERROR(Errors.InvalidParam, 'query_ent');
|
|
137
|
+
ERROR(Errors.InvalidParam, 'query_ent');
|
|
102
138
|
}
|
|
103
139
|
|
|
104
140
|
this.txb.moveCall({
|
package/src/guard.ts
CHANGED
|
@@ -157,15 +157,12 @@ export class Guard {
|
|
|
157
157
|
[MODULES.order, 'Service', 93, [], ValueType.TYPE_ADDRESS],
|
|
158
158
|
[MODULES.order, 'Has Progress', 94, [], ValueType.TYPE_BOOL],
|
|
159
159
|
[MODULES.order, 'Progress', 95, [], ValueType.TYPE_ADDRESS],
|
|
160
|
-
[MODULES.order, '
|
|
161
|
-
[MODULES.order, '
|
|
162
|
-
[MODULES.order, '
|
|
163
|
-
[MODULES.order, '
|
|
164
|
-
[MODULES.order, '
|
|
165
|
-
[MODULES.order, '
|
|
166
|
-
[MODULES.order, 'Balance', 102, [], ValueType.TYPE_U64],
|
|
167
|
-
[MODULES.order, 'Be Refunded', 103, [], ValueType.TYPE_BOOL],
|
|
168
|
-
[MODULES.order, 'Be Withdrawed', 104, [], ValueType.TYPE_BOOL],
|
|
160
|
+
[MODULES.order, 'Required Info Counts', 96, [], ValueType.TYPE_U64],
|
|
161
|
+
[MODULES.order, 'Discount Used', 97, [], ValueType.TYPE_BOOL],
|
|
162
|
+
[MODULES.order, 'Discount', 98, [], ValueType.TYPE_ADDRESS],
|
|
163
|
+
[MODULES.order, 'Balance', 99, [], ValueType.TYPE_U64],
|
|
164
|
+
[MODULES.order, 'Be Refunded', 100, [], ValueType.TYPE_BOOL],
|
|
165
|
+
[MODULES.order, 'Be Withdrawed', 101, [], ValueType.TYPE_BOOL],
|
|
169
166
|
|
|
170
167
|
[MODULES.service, 'Permission', 111, [], ValueType.TYPE_ADDRESS],
|
|
171
168
|
[MODULES.service, 'Payee', 112, [], ValueType.TYPE_ADDRESS],
|
package/src/permission.ts
CHANGED
|
@@ -44,7 +44,7 @@ export enum PermissionIndex {
|
|
|
44
44
|
service_publish = 220,
|
|
45
45
|
service_clone = 221,
|
|
46
46
|
service_customer_required = 222,
|
|
47
|
-
service_change_order_required_pubkey = 224,
|
|
47
|
+
//service_change_order_required_pubkey = 224,
|
|
48
48
|
service_pause = 225,
|
|
49
49
|
|
|
50
50
|
reward = 240,
|
|
@@ -141,7 +141,7 @@ export const PermissionInfo : PermissionInfoType[] = [
|
|
|
141
141
|
{index:PermissionIndex.service_publish, name:'Publish', description:'Publish Service', module: 'service'},
|
|
142
142
|
{index:PermissionIndex.service_clone, name:'Clone', description:'Clone Service', module: 'service'},
|
|
143
143
|
{index:PermissionIndex.service_customer_required, name:'Buyer info', description:'Set Service buyer info required', module: 'service'},
|
|
144
|
-
{index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'Update Serivce order pubkey', module: 'service'},
|
|
144
|
+
//{index:PermissionIndex.service_change_order_required_pubkey, name:'Order pubkey', description:'Update Serivce order pubkey', module: 'service'},
|
|
145
145
|
{index:PermissionIndex.service_pause, name:'Pause', description:'Pause/Unpause Service', module: 'service'},
|
|
146
146
|
|
|
147
147
|
{index:PermissionIndex.reward, name:'Reward', description:'Launch new Reward', module: 'reward'},
|
|
@@ -523,6 +523,7 @@ export class Permission {
|
|
|
523
523
|
onPermissionAnswer({who:address_queried, object:permission});
|
|
524
524
|
})
|
|
525
525
|
}
|
|
526
|
+
|
|
526
527
|
static HasPermission(answer:PermissionAnswer|undefined, index:PermissionIndexType, bStrict:boolean=false) : {has:boolean, guard?:string, owner?:boolean} | undefined {
|
|
527
528
|
if (answer) {
|
|
528
529
|
if (answer.admin) return {has:true, owner:answer.owner}; // admin
|
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: "0x366cbf58452fca91d1028af0bc9709c1826c2d89dce258ddf1d4fe9a95ffa6d7",
|
|
195
|
+
wowok_object: '0xadd1755c84aa7e99ecd84a71eed6b7150f097a88f3a60f4770be72a93f03fca4',
|
|
196
|
+
entity_object: '0x41b5e7defd512bb098c367c04f2731c81e468365f824b2ab354fb9dbf5a42549',
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
const MAINNET = {
|
|
@@ -253,7 +253,7 @@ export class Protocol {
|
|
|
253
253
|
break;
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
Package(): string { return this.package }
|
|
257
257
|
WowokObject(): string { return this.wowok_object }
|
|
258
258
|
EntityObject(): string { return this.entity_object }
|
|
259
259
|
GraphqlUrl() : string { return this.graphql }
|
|
@@ -380,6 +380,7 @@ export class Protocol {
|
|
|
380
380
|
];
|
|
381
381
|
|
|
382
382
|
GetCoinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
|
|
383
|
+
if (!token_type) return 'loading';
|
|
383
384
|
let r = this.COINS_TYPE().find((v) => v?.type === token_type);
|
|
384
385
|
if (!r) {
|
|
385
386
|
Protocol.Client().getCoinMetadata({coinType:token_type}).then((res) => {
|
package/src/service.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryOb
|
|
|
4
4
|
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
5
5
|
TxbObject} from './protocol';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
|
-
import {
|
|
7
|
+
import { Transaction as TransactionBlock, } from '@mysten/sui/transactions';
|
|
8
|
+
import { SuiObjectData } from '@mysten/sui/client';
|
|
8
9
|
|
|
9
10
|
export type Service_Guard_Percent = {
|
|
10
11
|
guard:GuardObject;
|
|
@@ -34,7 +35,6 @@ export type Service_Buy_RequiredInfo = {
|
|
|
34
35
|
customer_info: string[];
|
|
35
36
|
}
|
|
36
37
|
export type Customer_RequiredInfo = {
|
|
37
|
-
pubkey: string;
|
|
38
38
|
customer_pubkey: string;
|
|
39
39
|
customer_info_crypt: string[];
|
|
40
40
|
}
|
|
@@ -57,6 +57,7 @@ export type DicountDispatch = {
|
|
|
57
57
|
discount: Service_Discount;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export type handleDiscountObject = (owner:string, objects:(SuiObjectData|null|undefined)[]) => void;
|
|
60
61
|
export class Service {
|
|
61
62
|
protected pay_token_type;
|
|
62
63
|
protected permission;
|
|
@@ -623,7 +624,7 @@ export class Service {
|
|
|
623
624
|
});
|
|
624
625
|
}
|
|
625
626
|
|
|
626
|
-
//
|
|
627
|
+
// support both withdraw guard and permission guard
|
|
627
628
|
withdraw(order:OrderObject, passport?:PassportObject) {
|
|
628
629
|
if (!Protocol.IsValidObjects([order])) {
|
|
629
630
|
ERROR(Errors.IsValidObjects, 'order')
|
|
@@ -642,8 +643,8 @@ export class Service {
|
|
|
642
643
|
typeArguments:[this.pay_token_type]
|
|
643
644
|
})
|
|
644
645
|
}
|
|
645
|
-
|
|
646
646
|
}
|
|
647
|
+
|
|
647
648
|
set_buy_guard(guard?:GuardObject, passport?:PassportObject) {
|
|
648
649
|
if (passport) {
|
|
649
650
|
if (guard) {
|
|
@@ -727,6 +728,7 @@ export class Service {
|
|
|
727
728
|
})
|
|
728
729
|
}
|
|
729
730
|
}
|
|
731
|
+
|
|
730
732
|
publish(passport?:PassportObject) {
|
|
731
733
|
if (passport) {
|
|
732
734
|
this.txb.moveCall({
|
|
@@ -743,6 +745,7 @@ export class Service {
|
|
|
743
745
|
}
|
|
744
746
|
|
|
745
747
|
}
|
|
748
|
+
|
|
746
749
|
clone(new_token_type?:string, passport?:PassportObject) : ServiceObject {
|
|
747
750
|
if (passport) {
|
|
748
751
|
return this.txb.moveCall({
|
|
@@ -760,11 +763,8 @@ export class Service {
|
|
|
760
763
|
}
|
|
761
764
|
|
|
762
765
|
set_customer_required(pubkey:string, customer_required: BuyRequiredEnum[], passport?:PassportObject) {
|
|
763
|
-
if
|
|
766
|
+
if(customer_required.length > 0 && !pubkey) {
|
|
764
767
|
ERROR(Errors.InvalidParam, 'pubkey')
|
|
765
|
-
}
|
|
766
|
-
if(!customer_required) {
|
|
767
|
-
ERROR(Errors.InvalidParam, 'customer_required')
|
|
768
768
|
}
|
|
769
769
|
|
|
770
770
|
let req = array_unique(customer_required) as string[];
|
|
@@ -787,6 +787,7 @@ export class Service {
|
|
|
787
787
|
})
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
|
+
|
|
790
791
|
remove_customer_required(passport?:PassportObject) {
|
|
791
792
|
if (passport) {
|
|
792
793
|
this.txb.moveCall({
|
|
@@ -802,6 +803,7 @@ export class Service {
|
|
|
802
803
|
})
|
|
803
804
|
}
|
|
804
805
|
}
|
|
806
|
+
|
|
805
807
|
change_required_pubkey(pubkey:string, passport?:PassportObject) {
|
|
806
808
|
if (!pubkey) {
|
|
807
809
|
ERROR(Errors.InvalidParam, 'pubkey')
|
|
@@ -823,6 +825,7 @@ export class Service {
|
|
|
823
825
|
})
|
|
824
826
|
}
|
|
825
827
|
}
|
|
828
|
+
/*
|
|
826
829
|
change_order_required_pubkey(order:OrderObject, pubkey:string, passport?:PassportObject) {
|
|
827
830
|
if (!Protocol.IsValidObjects([order])) {
|
|
828
831
|
ERROR(Errors.IsValidObjects, 'order')
|
|
@@ -846,7 +849,8 @@ export class Service {
|
|
|
846
849
|
typeArguments:[this.pay_token_type]
|
|
847
850
|
})
|
|
848
851
|
}
|
|
849
|
-
}
|
|
852
|
+
} */
|
|
853
|
+
|
|
850
854
|
pause(pause:boolean, passport?:PassportObject) {
|
|
851
855
|
if (passport) {
|
|
852
856
|
this.txb.moveCall({
|
|
@@ -861,9 +865,9 @@ export class Service {
|
|
|
861
865
|
typeArguments:[this.pay_token_type]
|
|
862
866
|
})
|
|
863
867
|
}
|
|
864
|
-
|
|
865
868
|
}
|
|
866
|
-
|
|
869
|
+
|
|
870
|
+
refund(order:OrderObject, passport?:PassportObject) {
|
|
867
871
|
if (!Protocol.IsValidObjects([order])) {
|
|
868
872
|
ERROR(Errors.IsValidObjects, 'order')
|
|
869
873
|
}
|
|
@@ -884,22 +888,21 @@ export class Service {
|
|
|
884
888
|
}
|
|
885
889
|
|
|
886
890
|
update_order_required_info(order:OrderObject, customer_info_crypto: Customer_RequiredInfo) {
|
|
891
|
+
if (!customer_info_crypto.customer_pubkey || customer_info_crypto.customer_info_crypt.length === 0) {
|
|
892
|
+
return
|
|
893
|
+
}
|
|
894
|
+
|
|
887
895
|
if (!Protocol.IsValidObjects([order])) {
|
|
888
896
|
ERROR(Errors.IsValidObjects, 'order')
|
|
889
897
|
}
|
|
890
|
-
if (!customer_info_crypto.pubkey || !customer_info_crypto.customer_info_crypt) {
|
|
891
|
-
ERROR(Errors.InvalidParam, 'customer_info_crypto')
|
|
892
|
-
}
|
|
893
898
|
|
|
894
899
|
this.txb.moveCall({
|
|
895
900
|
target:Protocol.Instance().ServiceFn('order_required_info_update') as FnCallType,
|
|
896
901
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
|
|
897
|
-
this.txb.pure.string(customer_info_crypto.pubkey),
|
|
898
902
|
this.txb.pure.string(customer_info_crypto.customer_pubkey),
|
|
899
|
-
this.txb.pure.vector('
|
|
903
|
+
this.txb.pure.vector('string', customer_info_crypto.customer_info_crypt)],
|
|
900
904
|
typeArguments:[this.pay_token_type]
|
|
901
905
|
})
|
|
902
|
-
|
|
903
906
|
}
|
|
904
907
|
|
|
905
908
|
buy(buy_items:Service_Buy[], coin:CoinObject, discount?:DiscountObject, machine?:MachineObject,
|
|
@@ -1019,6 +1022,18 @@ export class Service {
|
|
|
1019
1022
|
}
|
|
1020
1023
|
return '';
|
|
1021
1024
|
}
|
|
1025
|
+
|
|
1026
|
+
static parseOrderObjectType = (chain_type:string | undefined | null) : string => {
|
|
1027
|
+
if (chain_type) {
|
|
1028
|
+
const s = 'order::Order<'
|
|
1029
|
+
const i = chain_type.indexOf(s);
|
|
1030
|
+
if (i > 0) {
|
|
1031
|
+
return chain_type.slice(i + s.length, chain_type.length-1);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
return '';
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1022
1037
|
static endpoint = (service_endpoint:string, item_endpoint:string, item_name:string) => {
|
|
1023
1038
|
if (item_endpoint) {
|
|
1024
1039
|
return item_endpoint
|
|
@@ -1027,4 +1042,13 @@ export class Service {
|
|
|
1027
1042
|
}
|
|
1028
1043
|
}
|
|
1029
1044
|
|
|
1045
|
+
static DiscountObjects = (owner:string, handleDiscountObject:handleDiscountObject) => {
|
|
1046
|
+
Protocol.Client().getOwnedObjects({owner:owner,
|
|
1047
|
+
filter:{MoveModule:{module:'order', package:Protocol.Instance().Package()}},
|
|
1048
|
+
options:{showContent:true, showType:true}}).then((res) => {
|
|
1049
|
+
handleDiscountObject(owner, res.data.map((v)=>v.data));
|
|
1050
|
+
}).catch((e) => {
|
|
1051
|
+
console.log(e);
|
|
1052
|
+
})
|
|
1053
|
+
}
|
|
1030
1054
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Transaction as TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
|
|
1
|
+
import { BCS, getSuiMoveConfig, } from '@mysten/bcs';
|
|
3
2
|
import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui/client';
|
|
4
3
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import { isValidSuiAddress
|
|
4
|
+
import { isValidSuiAddress} from '@mysten/sui/utils'
|
|
6
5
|
import { RepositoryValueType, ValueType, Protocol } from './protocol'
|
|
7
6
|
|
|
8
7
|
export const MAX_U8 = BigInt('255');
|
|
@@ -162,6 +161,8 @@ export class Bcs {
|
|
|
162
161
|
this.bcs.registerStructType('EntStruct', {
|
|
163
162
|
'avatar': 'vector<u8>',
|
|
164
163
|
'resource': "Option<address>",
|
|
164
|
+
"safer_name": "vector<string>",
|
|
165
|
+
"safer_value": "vector<string>",
|
|
165
166
|
'like': BCS.U32,
|
|
166
167
|
'dislike': BCS.U32,
|
|
167
168
|
})
|
|
@@ -306,19 +307,6 @@ export class Bcs {
|
|
|
306
307
|
if (!data || data.length < 2) return ''
|
|
307
308
|
const struct_vec = this.bcs.de('vector<u8>', data);
|
|
308
309
|
return this.bcs.de('EntStruct', Uint8Array.from(struct_vec));
|
|
309
|
-
/* const reader = new BcsReader(data);
|
|
310
|
-
const total_len = reader.readULEB();
|
|
311
|
-
console.log(avatar_len)
|
|
312
|
-
const avatar = reader.readBytes(avatar_len);
|
|
313
|
-
console.log(avatar)
|
|
314
|
-
const option_resource = reader.read8();
|
|
315
|
-
var resource = '';
|
|
316
|
-
if (option_resource != 0) {
|
|
317
|
-
resource = reader.read256();
|
|
318
|
-
}
|
|
319
|
-
const like = reader.read32();
|
|
320
|
-
const dislike = reader.read32();
|
|
321
|
-
return {avatar:avatar, resource:resource, like:like, dislike:dislike}*/
|
|
322
310
|
}
|
|
323
311
|
de_entInfo(data:Uint8Array | undefined) : any {
|
|
324
312
|
if (!data || data.length === 0) return ''
|
|
@@ -388,7 +376,9 @@ export const MAX_ENDPOINT_LENGTH = 1024;
|
|
|
388
376
|
export const IsValidDesription = (description:string) : boolean => { return description?.length <= MAX_DESCRIPTION_LENGTH }
|
|
389
377
|
export const IsValidName = (name:string) : boolean => { if(!name) return false; return name.length <= MAX_NAME_LENGTH && name.length != 0 }
|
|
390
378
|
export const IsValidName_AllowEmpty = (name:string) : boolean => { return name.length <= MAX_NAME_LENGTH }
|
|
391
|
-
export const IsValidEndpoint = (endpoint:string) : boolean => {
|
|
379
|
+
export const IsValidEndpoint = (endpoint:string) : boolean => {
|
|
380
|
+
return (endpoint.length > 0 && endpoint.length <= MAX_ENDPOINT_LENGTH && isValidHttpUrl(endpoint)) ;
|
|
381
|
+
}
|
|
392
382
|
export const IsValidAddress = (addr:string | undefined) : boolean => {
|
|
393
383
|
if (!addr || !isValidSuiAddress(addr)) {
|
|
394
384
|
return false;
|
|
@@ -556,7 +546,7 @@ export interface query_object_param {
|
|
|
556
546
|
export const query_object = (param:query_object_param) => {
|
|
557
547
|
if (param.id) {
|
|
558
548
|
if(param?.onBegin) param.onBegin(param.id);
|
|
559
|
-
Protocol.Client().getObject({id:param.id, options:{showContent:true, showType:true}}).then((res) => {
|
|
549
|
+
Protocol.Client().getObject({id:param.id, options:{showContent:true, showType:true, showOwner:true}}).then((res) => {
|
|
560
550
|
if (res.error) {
|
|
561
551
|
if(param?.onObjectErr) param.onObjectErr(param.id, res.error);
|
|
562
552
|
} else {
|