wowok 1.3.6 → 1.3.10
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/entity.ts +42 -6
- package/src/guard.ts +6 -9
- package/src/machine.ts +25 -2
- package/src/permission.ts +2 -2
- package/src/protocol.ts +12 -6
- package/src/service.ts +29 -16
- package/src/utils.ts +5 -17
- package/src/wowok.ts +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wowok",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.10",
|
|
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/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/machine.ts
CHANGED
|
@@ -424,9 +424,32 @@ export class Machine {
|
|
|
424
424
|
this.add_node2([n], passport);
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
remove_pair(node_prior:string, node_name:string, passport?:PassportObject) {
|
|
428
|
+
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'remove_pair');
|
|
429
|
+
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'remove_pair');
|
|
430
|
+
let n : any;
|
|
431
|
+
if (passport) {
|
|
432
|
+
n = this.txb.moveCall({
|
|
433
|
+
target:Protocol.Instance().MachineFn('node_fetch_with_passport') as FnCallType,
|
|
434
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
} else {
|
|
438
|
+
n = this.txb.moveCall({
|
|
439
|
+
target:Protocol.Instance().MachineFn('node_fetch') as FnCallType,
|
|
440
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
441
|
+
})
|
|
442
|
+
}
|
|
443
|
+
this.txb.moveCall({
|
|
444
|
+
target:Protocol.Instance().MachineFn('pair_remove') as FnCallType,
|
|
445
|
+
arguments:[n, this.txb.pure.string(node_prior)],
|
|
446
|
+
})
|
|
447
|
+
this.add_node2([n], passport);
|
|
448
|
+
}
|
|
449
|
+
|
|
427
450
|
remove_forward(node_prior:string, node_name:string, foward_name: string, passport?:PassportObject) {
|
|
428
|
-
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, '
|
|
429
|
-
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, '
|
|
451
|
+
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'remove_forward');
|
|
452
|
+
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'remove_forward');
|
|
430
453
|
|
|
431
454
|
let n : any;
|
|
432
455
|
if (passport) {
|
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'},
|
package/src/protocol.ts
CHANGED
|
@@ -156,8 +156,8 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
156
156
|
{type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false', validator:(value:any) => { return (value === true || value === false)}},
|
|
157
157
|
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af', validator:IsValidAddress},
|
|
158
158
|
{type: ContextType.TYPE_WITNESS_ID, name: 'future address', description:"eg: machine's future progress, service's future order", validator:IsValidAddress},
|
|
159
|
-
{type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction, "
|
|
160
|
-
{type: ContextType.TYPE_CLOCK, name: 'txn time', description:"unsigned-64 number for the transaction time"
|
|
159
|
+
{type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction, "},
|
|
160
|
+
{type: ContextType.TYPE_CLOCK, name: 'txn time', description:"unsigned-64 number for the transaction time"},
|
|
161
161
|
{type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233', validator:IsValidU64},
|
|
162
162
|
{type: ValueType.TYPE_U8, name: 'number', description:'unsigned-8 number. eg:255', validator:IsValidU8},
|
|
163
163
|
{type: ValueType.TYPE_VEC_U8, name: 'string', description:'string or unsigned-8 number array. eg:"[1,2,3]"'},
|
|
@@ -191,15 +191,17 @@ export enum ENTRYPOINT {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
const TESTNET = {
|
|
194
|
-
package: "
|
|
195
|
-
wowok_object: '
|
|
196
|
-
entity_object: '
|
|
194
|
+
package: "0x98e5209cf5cf31a38ebde562681441d7544f38ee6a879266dc7273160635f6ba",
|
|
195
|
+
wowok_object: '0x676243951ed0d32341680b10d888887dfb39603b1af747036164e90fdfed1274',
|
|
196
|
+
entity_object: '0xe32334d663d0e7d058682b5170632672a11df1cdaa3f522859e75b451bdc67d5',
|
|
197
|
+
treasury_cap:'0x10bec6d987cf7fc16fc62246f3c382d84ee285d9ec9f038bc03845fe620bf2d3',
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
const MAINNET = {
|
|
200
201
|
package: "",
|
|
201
202
|
wowok_object: '',
|
|
202
203
|
entity_object: '',
|
|
204
|
+
treasury_cap:'',
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
export interface CoinTypeInfo {
|
|
@@ -214,6 +216,7 @@ export class Protocol {
|
|
|
214
216
|
protected signer = '';
|
|
215
217
|
protected wowok_object = '';
|
|
216
218
|
protected entity_object = '';
|
|
219
|
+
protected treasury_cap = '';
|
|
217
220
|
protected graphql = '';
|
|
218
221
|
protected txb: TransactionBlock | undefined;
|
|
219
222
|
static _instance: any;
|
|
@@ -243,19 +246,22 @@ export class Protocol {
|
|
|
243
246
|
this.package = TESTNET.package;
|
|
244
247
|
this.wowok_object = TESTNET.wowok_object;
|
|
245
248
|
this.entity_object= TESTNET.entity_object;
|
|
249
|
+
this.treasury_cap = TESTNET.treasury_cap;
|
|
246
250
|
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
247
251
|
break;
|
|
248
252
|
case ENTRYPOINT.mainnet:
|
|
249
253
|
this.package = MAINNET.package;
|
|
250
254
|
this.wowok_object = MAINNET.wowok_object;
|
|
251
255
|
this.entity_object= MAINNET.entity_object;
|
|
256
|
+
this.treasury_cap = MAINNET.treasury_cap;
|
|
252
257
|
this.graphql = 'https://sui-mainnet.mystenlabs.com/graphql';
|
|
253
258
|
break;
|
|
254
259
|
};
|
|
255
260
|
}
|
|
256
|
-
|
|
261
|
+
Package(): string { return this.package }
|
|
257
262
|
WowokObject(): string { return this.wowok_object }
|
|
258
263
|
EntityObject(): string { return this.entity_object }
|
|
264
|
+
TreasuryCap() : string { return this.treasury_cap }
|
|
259
265
|
GraphqlUrl() : string { return this.graphql }
|
|
260
266
|
|
|
261
267
|
NetworkUrl() : string {
|
package/src/service.ts
CHANGED
|
@@ -35,7 +35,6 @@ export type Service_Buy_RequiredInfo = {
|
|
|
35
35
|
customer_info: string[];
|
|
36
36
|
}
|
|
37
37
|
export type Customer_RequiredInfo = {
|
|
38
|
-
pubkey: string;
|
|
39
38
|
customer_pubkey: string;
|
|
40
39
|
customer_info_crypt: string[];
|
|
41
40
|
}
|
|
@@ -625,7 +624,7 @@ export class Service {
|
|
|
625
624
|
});
|
|
626
625
|
}
|
|
627
626
|
|
|
628
|
-
//
|
|
627
|
+
// support both withdraw guard and permission guard
|
|
629
628
|
withdraw(order:OrderObject, passport?:PassportObject) {
|
|
630
629
|
if (!Protocol.IsValidObjects([order])) {
|
|
631
630
|
ERROR(Errors.IsValidObjects, 'order')
|
|
@@ -644,8 +643,8 @@ export class Service {
|
|
|
644
643
|
typeArguments:[this.pay_token_type]
|
|
645
644
|
})
|
|
646
645
|
}
|
|
647
|
-
|
|
648
646
|
}
|
|
647
|
+
|
|
649
648
|
set_buy_guard(guard?:GuardObject, passport?:PassportObject) {
|
|
650
649
|
if (passport) {
|
|
651
650
|
if (guard) {
|
|
@@ -729,6 +728,7 @@ export class Service {
|
|
|
729
728
|
})
|
|
730
729
|
}
|
|
731
730
|
}
|
|
731
|
+
|
|
732
732
|
publish(passport?:PassportObject) {
|
|
733
733
|
if (passport) {
|
|
734
734
|
this.txb.moveCall({
|
|
@@ -745,6 +745,7 @@ export class Service {
|
|
|
745
745
|
}
|
|
746
746
|
|
|
747
747
|
}
|
|
748
|
+
|
|
748
749
|
clone(new_token_type?:string, passport?:PassportObject) : ServiceObject {
|
|
749
750
|
if (passport) {
|
|
750
751
|
return this.txb.moveCall({
|
|
@@ -786,6 +787,7 @@ export class Service {
|
|
|
786
787
|
})
|
|
787
788
|
}
|
|
788
789
|
}
|
|
790
|
+
|
|
789
791
|
remove_customer_required(passport?:PassportObject) {
|
|
790
792
|
if (passport) {
|
|
791
793
|
this.txb.moveCall({
|
|
@@ -801,6 +803,7 @@ export class Service {
|
|
|
801
803
|
})
|
|
802
804
|
}
|
|
803
805
|
}
|
|
806
|
+
|
|
804
807
|
change_required_pubkey(pubkey:string, passport?:PassportObject) {
|
|
805
808
|
if (!pubkey) {
|
|
806
809
|
ERROR(Errors.InvalidParam, 'pubkey')
|
|
@@ -822,6 +825,7 @@ export class Service {
|
|
|
822
825
|
})
|
|
823
826
|
}
|
|
824
827
|
}
|
|
828
|
+
/*
|
|
825
829
|
change_order_required_pubkey(order:OrderObject, pubkey:string, passport?:PassportObject) {
|
|
826
830
|
if (!Protocol.IsValidObjects([order])) {
|
|
827
831
|
ERROR(Errors.IsValidObjects, 'order')
|
|
@@ -845,7 +849,8 @@ export class Service {
|
|
|
845
849
|
typeArguments:[this.pay_token_type]
|
|
846
850
|
})
|
|
847
851
|
}
|
|
848
|
-
}
|
|
852
|
+
} */
|
|
853
|
+
|
|
849
854
|
pause(pause:boolean, passport?:PassportObject) {
|
|
850
855
|
if (passport) {
|
|
851
856
|
this.txb.moveCall({
|
|
@@ -860,9 +865,9 @@ export class Service {
|
|
|
860
865
|
typeArguments:[this.pay_token_type]
|
|
861
866
|
})
|
|
862
867
|
}
|
|
863
|
-
|
|
864
868
|
}
|
|
865
|
-
|
|
869
|
+
|
|
870
|
+
refund(order:OrderObject, passport?:PassportObject) {
|
|
866
871
|
if (!Protocol.IsValidObjects([order])) {
|
|
867
872
|
ERROR(Errors.IsValidObjects, 'order')
|
|
868
873
|
}
|
|
@@ -883,22 +888,21 @@ export class Service {
|
|
|
883
888
|
}
|
|
884
889
|
|
|
885
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
|
+
|
|
886
895
|
if (!Protocol.IsValidObjects([order])) {
|
|
887
896
|
ERROR(Errors.IsValidObjects, 'order')
|
|
888
897
|
}
|
|
889
|
-
if (!customer_info_crypto.pubkey || !customer_info_crypto.customer_info_crypt) {
|
|
890
|
-
ERROR(Errors.InvalidParam, 'customer_info_crypto')
|
|
891
|
-
}
|
|
892
898
|
|
|
893
899
|
this.txb.moveCall({
|
|
894
900
|
target:Protocol.Instance().ServiceFn('order_required_info_update') as FnCallType,
|
|
895
901
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, order),
|
|
896
|
-
this.txb.pure.string(customer_info_crypto.pubkey),
|
|
897
902
|
this.txb.pure.string(customer_info_crypto.customer_pubkey),
|
|
898
|
-
this.txb.pure.vector('
|
|
903
|
+
this.txb.pure.vector('string', customer_info_crypto.customer_info_crypt)],
|
|
899
904
|
typeArguments:[this.pay_token_type]
|
|
900
905
|
})
|
|
901
|
-
|
|
902
906
|
}
|
|
903
907
|
|
|
904
908
|
buy(buy_items:Service_Buy[], coin:CoinObject, discount?:DiscountObject, machine?:MachineObject,
|
|
@@ -924,7 +928,6 @@ export class Service {
|
|
|
924
928
|
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
925
929
|
if (passport) {
|
|
926
930
|
if (discount) {
|
|
927
|
-
console.log(1)
|
|
928
931
|
order = this.txb.moveCall({
|
|
929
932
|
target:Protocol.Instance().ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
930
933
|
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
@@ -932,7 +935,6 @@ export class Service {
|
|
|
932
935
|
Protocol.TXB_OBJECT(this.txb, coin), Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
|
|
933
936
|
typeArguments:[this.pay_token_type]
|
|
934
937
|
})} else {
|
|
935
|
-
console.log(2)
|
|
936
938
|
order = this.txb.moveCall({
|
|
937
939
|
target:Protocol.Instance().ServiceFn('buy_with_passport') as FnCallType,
|
|
938
940
|
arguments: [passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
@@ -941,7 +943,6 @@ export class Service {
|
|
|
941
943
|
typeArguments:[this.pay_token_type]
|
|
942
944
|
})}
|
|
943
945
|
} else {
|
|
944
|
-
console.log(3)
|
|
945
946
|
if (discount) {
|
|
946
947
|
order = this.txb.moveCall({
|
|
947
948
|
target:Protocol.Instance().ServiceFn('disoucnt_buy') as FnCallType,
|
|
@@ -952,7 +953,6 @@ export class Service {
|
|
|
952
953
|
Protocol.TXB_OBJECT(this.txb, discount), this.txb.object(clock)],
|
|
953
954
|
typeArguments:[this.pay_token_type]
|
|
954
955
|
})} else {
|
|
955
|
-
console.log(4)
|
|
956
956
|
order = this.txb.moveCall({
|
|
957
957
|
target:Protocol.Instance().ServiceFn('buy') as FnCallType,
|
|
958
958
|
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
@@ -1022,6 +1022,18 @@ export class Service {
|
|
|
1022
1022
|
}
|
|
1023
1023
|
return '';
|
|
1024
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
|
+
|
|
1025
1037
|
static endpoint = (service_endpoint:string, item_endpoint:string, item_name:string) => {
|
|
1026
1038
|
if (item_endpoint) {
|
|
1027
1039
|
return item_endpoint
|
|
@@ -1029,6 +1041,7 @@ export class Service {
|
|
|
1029
1041
|
return service_endpoint + '/sales/' + encodeURI(item_name);
|
|
1030
1042
|
}
|
|
1031
1043
|
}
|
|
1044
|
+
|
|
1032
1045
|
static DiscountObjects = (owner:string, handleDiscountObject:handleDiscountObject) => {
|
|
1033
1046
|
Protocol.Client().getOwnedObjects({owner:owner,
|
|
1034
1047
|
filter:{MoveModule:{module:'order', package:Protocol.Instance().Package()}},
|
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 ''
|
|
@@ -558,7 +546,7 @@ export interface query_object_param {
|
|
|
558
546
|
export const query_object = (param:query_object_param) => {
|
|
559
547
|
if (param.id) {
|
|
560
548
|
if(param?.onBegin) param.onBegin(param.id);
|
|
561
|
-
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) => {
|
|
562
550
|
if (res.error) {
|
|
563
551
|
if(param?.onObjectErr) param.onObjectErr(param.id, res.error);
|
|
564
552
|
} else {
|
package/src/wowok.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject} from './protocol';
|
|
2
|
-
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
|
|
2
|
+
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, IsValidU64, } from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
5
5
|
|
|
@@ -47,5 +47,15 @@ export class Wowok {
|
|
|
47
47
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(new_name)]
|
|
48
48
|
})
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
mint(amount: string, recipient: string) {
|
|
52
|
+
if (!IsValidAddress(recipient)) ERROR(Errors.IsValidAddress, 'mint');
|
|
53
|
+
if (!IsValidU64(amount)) ERROR(Errors.IsValidU64, 'mint');
|
|
54
|
+
this.txb.moveCall({
|
|
55
|
+
target:Protocol.Instance().WowokFn('mint') as FnCallType,
|
|
56
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, Protocol.Instance().TreasuryCap()), this.txb.pure.u64(amount),
|
|
57
|
+
this.txb.pure.address(recipient)]
|
|
58
|
+
})
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
|