wowok 1.6.66 → 1.6.67
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/entity.ts +7 -5
- package/src/exception.ts +1 -0
- package/src/index.ts +1 -1
- package/src/resource.ts +50 -24
- package/src/utils.ts +7 -0
package/package.json
CHANGED
package/src/entity.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject, ResourceObject} from './protocol';
|
|
2
2
|
import { IsValidDesription, IsValidAddress, IsValidName, isValidHttpUrl, Bcs, IsValidArray, } from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
|
-
import {
|
|
5
|
-
import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
4
|
+
import { GroupName, Resource } from './resource';
|
|
5
|
+
import { Transaction as TransactionBlock, TransactionResult } from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
7
|
export interface Safer {
|
|
8
8
|
name: string;
|
|
@@ -33,13 +33,15 @@ export class Entity {
|
|
|
33
33
|
return r
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
mark(resource:Resource, address:string, like:
|
|
37
|
-
if (!IsValidAddress(address))
|
|
36
|
+
mark(resource:Resource, address:string | TransactionResult, like:GroupName.LikeName | GroupName.DislikeName) {
|
|
37
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
38
|
+
ERROR(Errors.IsValidAddress, like);
|
|
39
|
+
}
|
|
38
40
|
|
|
39
41
|
this.txb.moveCall({
|
|
40
42
|
target:Protocol.Instance().entityFn(like) as FnCallType,
|
|
41
43
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object()),
|
|
42
|
-
this.txb.pure.address(address)]
|
|
44
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address]
|
|
43
45
|
})
|
|
44
46
|
}
|
|
45
47
|
/*
|
package/src/exception.ts
CHANGED
|
@@ -24,6 +24,7 @@ export enum Errors {
|
|
|
24
24
|
IsValidUserDefinedIndex = 'invalid user defined permission index',
|
|
25
25
|
bcsTypeInvalid = 'invalid bcs type',
|
|
26
26
|
IsValidServiceItemName = 'invalid service item name',
|
|
27
|
+
IsValidCoinType = 'not the coin type',
|
|
27
28
|
noPermission = 'no permission',
|
|
28
29
|
}
|
|
29
30
|
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export * from './arbitration'
|
|
|
17
17
|
export * from './exception'
|
|
18
18
|
export { BCS, getSuiMoveConfig, } from '@mysten/bcs';
|
|
19
19
|
export { Transaction as TransactionBlock, type TransactionArgument, type TransactionResult} from '@mysten/sui/transactions';
|
|
20
|
-
export { SuiClient, type SuiObjectResponse, type SuiTransactionBlockResponseOptions, type DynamicFieldPage,
|
|
20
|
+
export { SuiClient, type SuiObjectResponse, type SuiTransactionBlockResponseOptions, type DynamicFieldPage, type CoinBalance, type CoinStruct,
|
|
21
21
|
type SuiTransactionBlockResponse as CallResponse} from '@mysten/sui/client';
|
|
22
22
|
export { Ed25519Keypair, } from '@mysten/sui/keypairs/ed25519';
|
|
23
23
|
export { fromHEX, toHEX } from '@mysten/bcs';
|
package/src/resource.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface ResourceData { // personal folder
|
|
|
13
13
|
name: string; // folder name
|
|
14
14
|
address: string[]; // objects in folder
|
|
15
15
|
}
|
|
16
|
-
export enum
|
|
16
|
+
export enum GroupName {
|
|
17
17
|
LikeName = "like",
|
|
18
18
|
DislikeName = "dislike",
|
|
19
19
|
FavorName = "favor",
|
|
@@ -48,6 +48,8 @@ export class Resource {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
add(name:string, object:string[] | TransactionResult[]) {
|
|
51
|
+
if (object.length === 0) return;
|
|
52
|
+
|
|
51
53
|
var bString = true;
|
|
52
54
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add.name');
|
|
53
55
|
if (!IsValidArray(object, (item:any) => {
|
|
@@ -76,10 +78,11 @@ export class Resource {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
add2(object:
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
if (!
|
|
81
|
+
add2(object:TransactionResult | string, name:string[]) {
|
|
82
|
+
if (name.length === 0) return;
|
|
83
|
+
|
|
84
|
+
if (typeof(object) === 'string' && !IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'add2.object');
|
|
85
|
+
if (!IsValidArray(name, IsValidName)) ERROR(Errors.IsValidArray, 'add2.name');
|
|
83
86
|
|
|
84
87
|
this.txb.moveCall({
|
|
85
88
|
target:Protocol.Instance().resourceFn('add2') as FnCallType,
|
|
@@ -88,34 +91,47 @@ export class Resource {
|
|
|
88
91
|
});
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
remove(name:string, object:string[], removeall?:boolean) {
|
|
92
|
-
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
94
|
+
remove(name:string, object:string[] | TransactionResult[], removeall?:boolean) {
|
|
93
95
|
if (object.length===0 && !removeall) return;
|
|
96
|
+
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
94
97
|
|
|
98
|
+
var bString = true;
|
|
99
|
+
if (!IsValidArray(object, (item:any) => {
|
|
100
|
+
if (typeof(item) === 'string') {
|
|
101
|
+
return IsValidAddress(item)
|
|
102
|
+
} else {
|
|
103
|
+
bString = false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
})) {
|
|
107
|
+
ERROR(Errors.IsValidArray, 'remove.object');
|
|
108
|
+
}
|
|
109
|
+
|
|
95
110
|
if (removeall) {
|
|
96
111
|
this.txb.moveCall({
|
|
97
112
|
target:Protocol.Instance().resourceFn('remove_all') as FnCallType,
|
|
98
113
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name)]
|
|
99
114
|
});
|
|
100
115
|
} else if(object) {
|
|
101
|
-
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
102
|
-
|
|
103
116
|
this.txb.moveCall({
|
|
104
117
|
target:Protocol.Instance().resourceFn('remove') as FnCallType,
|
|
105
118
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
106
|
-
this.txb.pure.vector('address', object)]
|
|
119
|
+
bString ? this.txb.pure.vector('address', object as string[]) : this.txb.makeMoveVec({elements:object as TransactionResult[], type:'address'})]
|
|
107
120
|
});
|
|
108
121
|
}
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
remove2(object:string, name:string[]) {
|
|
112
|
-
if (
|
|
124
|
+
remove2(object:TransactionResult | string, name:string[]) {
|
|
125
|
+
if (typeof(object) === 'string' && !IsValidAddress(object)) {
|
|
126
|
+
ERROR(Errors.IsValidAddress, 'Resource: remove2');
|
|
127
|
+
}
|
|
113
128
|
if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
|
|
114
129
|
if (!name) return
|
|
115
130
|
|
|
116
131
|
this.txb.moveCall({
|
|
117
132
|
target:Protocol.Instance().resourceFn('remove2') as FnCallType,
|
|
118
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
133
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
134
|
+
typeof(object) === 'string' ? this.txb.pure.address(object) : object,
|
|
119
135
|
this.txb.pure.vector('string', name)]
|
|
120
136
|
});
|
|
121
137
|
}
|
|
@@ -130,29 +146,39 @@ export class Resource {
|
|
|
130
146
|
});
|
|
131
147
|
}
|
|
132
148
|
|
|
133
|
-
add_tags(object:string, nick:string, tags:string[]) {
|
|
134
|
-
if (!
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
149
|
+
add_tags(object:TransactionResult | string, nick:string, tags:string[]) {
|
|
150
|
+
if (!nick && tags.length === 0) return;
|
|
151
|
+
|
|
152
|
+
if (typeof(object) === 'string' && !IsValidAddress(object)) {
|
|
153
|
+
ERROR(Errors.IsValidAddress, 'Resource: add_tags.object');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (nick && !IsValidName(nick)) ERROR(Errors.IsValidName, 'Resource: add_tags.nick');
|
|
157
|
+
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'Resource: add_tags.tags');
|
|
158
|
+
if (tags.length > Resource.MAX_TAGS) {
|
|
159
|
+
tags = tags.slice(0, Resource.MAX_TAGS)
|
|
160
|
+
}
|
|
139
161
|
|
|
140
|
-
const encode = new TextEncoder();
|
|
141
162
|
this.txb.moveCall({
|
|
142
163
|
target:Protocol.Instance().resourceFn('tags_add') as FnCallType,
|
|
143
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
164
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
165
|
+
typeof(object) === 'string' ? this.txb.pure.address(object) : object,
|
|
144
166
|
this.txb.pure.string(nick),
|
|
145
167
|
this.txb.pure.vector('string', tags)
|
|
146
168
|
]
|
|
147
169
|
});
|
|
148
170
|
}
|
|
149
171
|
|
|
150
|
-
remove_tags(object:string) {
|
|
151
|
-
if (
|
|
172
|
+
remove_tags(object:TransactionResult | string) {
|
|
173
|
+
if (typeof(object) === 'string' && !IsValidAddress(object)) {
|
|
174
|
+
ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
|
|
175
|
+
}
|
|
152
176
|
|
|
153
177
|
this.txb.moveCall({
|
|
154
178
|
target:Protocol.Instance().resourceFn('tags_remove') as FnCallType,
|
|
155
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
179
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
180
|
+
typeof(object) === 'string' ? this.txb.pure.address(object) : object,
|
|
181
|
+
]
|
|
156
182
|
});
|
|
157
183
|
}
|
|
158
184
|
}
|
package/src/utils.ts
CHANGED
|
@@ -402,6 +402,13 @@ export const IsValidAddress = (addr:string | undefined) : boolean => {
|
|
|
402
402
|
}
|
|
403
403
|
return true
|
|
404
404
|
}
|
|
405
|
+
export const IsValidCoinType = (coin_type:string | undefined) : boolean => {
|
|
406
|
+
if (!coin_type) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return coin_type.startsWith('0x2::coin::Coin') || coin_type.startsWith('0x0000000000000000000000000000000000000000000000000000000000000002')
|
|
410
|
+
}
|
|
411
|
+
|
|
405
412
|
export const IsValidBigint = (value:string | number | undefined | bigint, max:bigint=MAX_U256, min?:bigint) : boolean => {
|
|
406
413
|
if (value === '' || value === undefined) return false;
|
|
407
414
|
try {
|