wowok 1.6.66 → 1.6.69
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 +17 -46
- package/src/exception.ts +1 -0
- package/src/index.ts +1 -1
- package/src/protocol.ts +10 -9
- package/src/repository.ts +0 -3
- package/src/resource.ts +105 -98
- package/src/treasury.ts +1 -1
- package/src/utils.ts +19 -3
package/package.json
CHANGED
package/src/entity.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
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 { TagName, Resource } from './resource';
|
|
5
|
+
import { Transaction as TransactionBlock, TransactionResult } from '@mysten/sui/transactions';
|
|
6
|
+
|
|
6
7
|
|
|
7
|
-
export interface Safer {
|
|
8
|
-
name: string;
|
|
9
|
-
value: string;
|
|
10
|
-
}
|
|
11
8
|
export interface Entity_Info {
|
|
12
9
|
name: string;
|
|
13
10
|
description?: string;
|
|
@@ -33,51 +30,18 @@ export class Entity {
|
|
|
33
30
|
return r
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
mark(resource:Resource, address:string, like:
|
|
37
|
-
if (!IsValidAddress(address))
|
|
33
|
+
mark(resource:Resource, address:string | TransactionResult, like:TagName.Like | TagName.Dislike) {
|
|
34
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
35
|
+
ERROR(Errors.IsValidAddress, like);
|
|
36
|
+
}
|
|
38
37
|
|
|
39
38
|
this.txb.moveCall({
|
|
40
39
|
target:Protocol.Instance().entityFn(like) as FnCallType,
|
|
41
40
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object()),
|
|
42
|
-
this.txb.pure.address(address)]
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
/*
|
|
46
|
-
add_safer(safer: Safer[], bExistModify:boolean=true) {
|
|
47
|
-
if (safer.length === 0) return ;
|
|
48
|
-
if (!IsValidArray(safer, (v:Safer) => {
|
|
49
|
-
if (!IsValidName(v.name) || !IsValidDesription(v.value)) {
|
|
50
|
-
return false
|
|
51
|
-
}
|
|
52
|
-
})) {
|
|
53
|
-
ERROR(Errors.InvalidParam, 'add_safer');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const name = safer.map((v)=>v.name);
|
|
57
|
-
const value = safer.map((v)=>v.value);
|
|
58
|
-
this.txb.moveCall({
|
|
59
|
-
target:Protocol.Instance().entityFn('safer_add') as FnCallType,
|
|
60
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
|
|
61
|
-
this.txb.pure.vector('string', value), this.txb.pure.bool(bExistModify)]
|
|
41
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address]
|
|
62
42
|
})
|
|
63
43
|
}
|
|
64
44
|
|
|
65
|
-
remove_safer(name:string[], removeall?:boolean) {
|
|
66
|
-
if (name.length === 0 && !removeall) return;
|
|
67
|
-
|
|
68
|
-
if (removeall) {
|
|
69
|
-
this.txb.moveCall({
|
|
70
|
-
target:Protocol.Instance().entityFn('safer_remove_all') as FnCallType,
|
|
71
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
72
|
-
})
|
|
73
|
-
} else {
|
|
74
|
-
this.txb.moveCall({
|
|
75
|
-
target:Protocol.Instance().entityFn('safer_remove') as FnCallType,
|
|
76
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name)]
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
}*/
|
|
80
|
-
|
|
81
45
|
update(info: Entity_Info) {
|
|
82
46
|
if (info?.name && !IsValidName(info.name)) ERROR(Errors.IsValidName, 'update');
|
|
83
47
|
if (info?.description && !IsValidDesription(info.description)) ERROR(Errors.IsValidDesription, 'update');
|
|
@@ -114,14 +78,21 @@ export class Entity {
|
|
|
114
78
|
})
|
|
115
79
|
}
|
|
116
80
|
|
|
117
|
-
destroy_resource(resource:Resource) {
|
|
81
|
+
destroy_resource(resource:Resource) { // Resource must self-owned.
|
|
118
82
|
return this.txb.moveCall({
|
|
119
83
|
target:Protocol.Instance().entityFn('resource_destroy') as FnCallType,
|
|
120
84
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
|
|
121
85
|
})
|
|
122
86
|
}
|
|
123
87
|
|
|
124
|
-
|
|
88
|
+
use_resource(resource:Resource) { // Resource must self-owned.
|
|
89
|
+
return this.txb.moveCall({
|
|
90
|
+
target:Protocol.Instance().entityFn('resource_use') as FnCallType,
|
|
91
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
transfer_resource(resource:Resource, new_address:string) { // Resource must self-owned.
|
|
125
96
|
if (!IsValidAddress(new_address)) ERROR(Errors.IsValidAddress, 'transfer_resource');
|
|
126
97
|
|
|
127
98
|
return this.txb.moveCall({
|
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/protocol.ts
CHANGED
|
@@ -64,6 +64,7 @@ export type PaymentAddress = TransactionResult;
|
|
|
64
64
|
export type ReceivedObject = TransactionResult | string | TransactionArgument;
|
|
65
65
|
export type CoinWrapperObject = TransactionResult;
|
|
66
66
|
|
|
67
|
+
export type TxbAddress = string | TransactionResult;
|
|
67
68
|
export type TxbObject = string | TransactionResult | TransactionArgument | GuardObject | RepositoryObject | PermissionObject | MachineObject | PassportObject |
|
|
68
69
|
DemandObject | ServiceObject | OrderObject | DiscountObject | DemandObject | ResourceObject | EntityObject | ArbitrationObject | ArbObject | TreasuryObject;
|
|
69
70
|
|
|
@@ -219,15 +220,15 @@ const TESTNET = {
|
|
|
219
220
|
}
|
|
220
221
|
*/
|
|
221
222
|
const TESTNET = {
|
|
222
|
-
wowok: "
|
|
223
|
-
wowok_origin:'
|
|
224
|
-
base: '
|
|
225
|
-
base_origin: '
|
|
226
|
-
|
|
227
|
-
wowok_object: '
|
|
228
|
-
entity_object: '
|
|
229
|
-
treasury_cap:'
|
|
230
|
-
oracle_object:'
|
|
223
|
+
wowok: "0xe98ef6b139de57b59d71496dc2b48d4e36e195013194748bdfe90688a9821132",
|
|
224
|
+
wowok_origin:'0xe98ef6b139de57b59d71496dc2b48d4e36e195013194748bdfe90688a9821132' ,
|
|
225
|
+
base: '0xa475682a229bcf913b2d561370ed44a055d0091a4a02b25d780d48aed03df267',
|
|
226
|
+
base_origin: '0xa475682a229bcf913b2d561370ed44a055d0091a4a02b25d780d48aed03df267',
|
|
227
|
+
|
|
228
|
+
wowok_object: '0xf2d3dc8667e21ca03fd808e51f7f9f291bad861bab1f62b4f07f39834830a5d9',
|
|
229
|
+
entity_object: '0x40eb7a354875548a55a196c0f1cbbf217026fee9d86f94615b992878a6629e03',
|
|
230
|
+
treasury_cap:'0x405105d71add6c57c1de0dbceb2676320ddb5bbe4c3cfdf79c7b23783e9e3761',
|
|
231
|
+
oracle_object:'0x4592d870a3c79c37d49fe55d1eba3ed2e82bcf707822d698beeceacce0dabdc6',
|
|
231
232
|
}
|
|
232
233
|
const MAINNET = {
|
|
233
234
|
wowok: "",
|
package/src/repository.ts
CHANGED
|
@@ -460,9 +460,6 @@ export class Repository {
|
|
|
460
460
|
static IsValidValue = (value:Uint8Array) => {
|
|
461
461
|
return value.length < Repository.MAX_VALUE_LENGTH;
|
|
462
462
|
}
|
|
463
|
-
static parseObjectType = (chain_type?:string | null) : string => {
|
|
464
|
-
return parseObjectType(chain_type, 'repository::Repository<');
|
|
465
|
-
}
|
|
466
463
|
|
|
467
464
|
static rpc_de_data(fields:any) : RepData [] {
|
|
468
465
|
const rep: RepData[] = fields?.map((v:any) => {
|
package/src/resource.ts
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import { Protocol, FnCallType, TxbObject,
|
|
1
|
+
import { Protocol, FnCallType, TxbObject, TxbAddress} from './protocol';
|
|
2
2
|
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
5
|
+
import { Entity } from './entity';
|
|
5
6
|
|
|
6
7
|
export interface Tags { // tag am address
|
|
7
8
|
address: string; // address to tag
|
|
8
|
-
|
|
9
|
+
name?: string; // named address
|
|
9
10
|
tags: string[]; // tags for address
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export interface
|
|
13
|
-
|
|
13
|
+
export interface TagData {
|
|
14
|
+
tag: string; // tag name
|
|
14
15
|
address: string[]; // objects in folder
|
|
15
|
-
}
|
|
16
|
-
export enum
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
}
|
|
17
|
+
export enum TagName {
|
|
18
|
+
Like = "like",
|
|
19
|
+
Dislike = "dislike",
|
|
20
|
+
Launch = 'launch',
|
|
21
|
+
Order = 'order',
|
|
22
|
+
Payment = 'payment'
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export class Resource {
|
|
25
|
-
static
|
|
26
|
-
static
|
|
26
|
+
static MAX_ADDRESS_COUNT_FOR_TAG = 1000; // max address count
|
|
27
|
+
static MAX_TAG_COUNT_FOR_ADDRESS = 64; // max tag count for an address
|
|
28
|
+
//static MAX_ADDRESS_COUNT_FOR_MARK = 200; // max address count for a mark
|
|
29
|
+
//static MAX_MARK_COUNT = 600; // max mark count
|
|
27
30
|
|
|
28
31
|
protected object:TxbObject;
|
|
29
32
|
protected txb;
|
|
@@ -40,120 +43,124 @@ export class Resource {
|
|
|
40
43
|
return r
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
launch() {
|
|
46
|
+
launch() : TxbAddress{
|
|
44
47
|
if (!this.object) ERROR(Errors.Fail, 'launch object Invalid');
|
|
45
|
-
this.txb.moveCall({
|
|
48
|
+
return this.txb.moveCall({
|
|
46
49
|
target:Protocol.Instance().resourceFn('create') as FnCallType,
|
|
47
50
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
|
-
add(name:string, object:string[] | TransactionResult[]) {
|
|
51
|
-
var bString = true;
|
|
52
|
-
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add.name');
|
|
53
|
-
if (!IsValidArray(object, (item:any) => {
|
|
54
|
-
if (typeof(item) === 'string') {
|
|
55
|
-
return IsValidAddress(item)
|
|
56
|
-
} else {
|
|
57
|
-
bString = false;
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
})) {
|
|
61
|
-
ERROR(Errors.IsValidArray, 'add.object');
|
|
62
|
-
}
|
|
63
53
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
68
|
-
this.txb.pure.vector('address', object as string[])]
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
this.txb.moveCall({
|
|
72
|
-
target:Protocol.Instance().resourceFn('add') as FnCallType,
|
|
73
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
74
|
-
this.txb.makeMoveVec({elements:object as TransactionResult[], type:'address'})]
|
|
75
|
-
});
|
|
54
|
+
private resolve_add(address:TransactionResult | string, tags:string[]) {
|
|
55
|
+
if (tags.find(v => v===TagName.Like)) {
|
|
56
|
+
Entity.From(this.txb).mark(this, address, TagName.Like);
|
|
76
57
|
}
|
|
58
|
+
if (tags.find(v => v===TagName.Dislike)) {
|
|
59
|
+
Entity.From(this.txb).mark(this, address, TagName.Dislike);
|
|
60
|
+
}
|
|
61
|
+
return (tags.filter(v => v !== TagName.Like && v !== TagName.Dislike && IsValidName(v)));
|
|
77
62
|
}
|
|
78
63
|
|
|
79
|
-
|
|
80
|
-
if (typeof(
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
add(address:TransactionResult | string, tags:string[], name?:string) {
|
|
65
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
66
|
+
ERROR(Errors.IsValidAddress, 'Resource: add.address');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var realtags = this.resolve_add(address, tags);
|
|
70
|
+
if (!name && realtags.length === 0) return;
|
|
71
|
+
|
|
72
|
+
if (name && !IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: add.name');
|
|
73
|
+
if (realtags.length > Resource.MAX_TAG_COUNT_FOR_ADDRESS) {
|
|
74
|
+
realtags = realtags.slice(0, Resource.MAX_TAG_COUNT_FOR_ADDRESS)
|
|
75
|
+
}
|
|
83
76
|
|
|
84
77
|
this.txb.moveCall({
|
|
85
|
-
target:Protocol.Instance().resourceFn('
|
|
86
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
87
|
-
this.txb.pure.
|
|
78
|
+
target:Protocol.Instance().resourceFn('add') as FnCallType,
|
|
79
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
80
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address,
|
|
81
|
+
this.txb.pure.option('string', name),
|
|
82
|
+
this.txb.pure.vector('string', realtags)
|
|
83
|
+
]
|
|
88
84
|
});
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
remove(
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (removeall) {
|
|
96
|
-
this.txb.moveCall({
|
|
97
|
-
target:Protocol.Instance().resourceFn('remove_all') as FnCallType,
|
|
98
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name)]
|
|
99
|
-
});
|
|
100
|
-
} else if(object) {
|
|
101
|
-
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
102
|
-
|
|
103
|
-
this.txb.moveCall({
|
|
104
|
-
target:Protocol.Instance().resourceFn('remove') as FnCallType,
|
|
105
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
|
|
106
|
-
this.txb.pure.vector('address', object)]
|
|
107
|
-
});
|
|
87
|
+
remove(address:TransactionResult | string, tags:string[]) {
|
|
88
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
89
|
+
ERROR(Errors.IsValidAddress, 'Resource: remove.address');
|
|
108
90
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
remove2(object:string, name:string[]) {
|
|
112
|
-
if (!IsValidAddress(object)) ERROR(Errors.IsValidAddress, 'Resource: remove2');
|
|
113
|
-
if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
|
|
114
|
-
if (!name) return
|
|
115
91
|
|
|
116
92
|
this.txb.moveCall({
|
|
117
|
-
target:Protocol.Instance().resourceFn('
|
|
118
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
119
|
-
this.txb.pure.
|
|
93
|
+
target:Protocol.Instance().resourceFn('remove') as FnCallType,
|
|
94
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
95
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address,
|
|
96
|
+
this.txb.pure.vector('string', tags)
|
|
97
|
+
]
|
|
120
98
|
});
|
|
121
99
|
}
|
|
122
100
|
|
|
123
|
-
|
|
124
|
-
if (
|
|
101
|
+
removeall(address: TxbAddress) {
|
|
102
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
103
|
+
ERROR(Errors.IsValidAddress, 'Resource: removeall.address');
|
|
104
|
+
}
|
|
125
105
|
|
|
126
106
|
this.txb.moveCall({
|
|
127
|
-
target:Protocol.Instance().resourceFn('
|
|
128
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
129
|
-
this.txb.pure.
|
|
130
|
-
|
|
107
|
+
target:Protocol.Instance().resourceFn('removeall') as FnCallType,
|
|
108
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
109
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address,
|
|
110
|
+
]
|
|
111
|
+
});
|
|
131
112
|
}
|
|
132
113
|
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
|
|
138
|
-
if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
|
|
114
|
+
query(address: TxbAddress) {
|
|
115
|
+
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
116
|
+
ERROR(Errors.IsValidAddress, 'Resource: query.address');
|
|
117
|
+
}
|
|
139
118
|
|
|
140
|
-
const encode = new TextEncoder();
|
|
141
119
|
this.txb.moveCall({
|
|
142
|
-
target:Protocol.Instance().resourceFn('
|
|
143
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
144
|
-
this.txb.pure.
|
|
145
|
-
this.txb.pure.vector('string', tags)
|
|
120
|
+
target:Protocol.Instance().resourceFn('query') as FnCallType,
|
|
121
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
122
|
+
typeof(address) === 'string' ? this.txb.pure.address(address) : address,
|
|
146
123
|
]
|
|
147
|
-
})
|
|
124
|
+
})
|
|
148
125
|
}
|
|
149
126
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
127
|
+
static TagData(tags: Tags[], innerTag:boolean=true) : TagData[] {
|
|
128
|
+
const data : TagData[] = [];
|
|
129
|
+
tags.forEach(v => {
|
|
130
|
+
v.tags.forEach(i => {
|
|
131
|
+
const f = data.find(k => k.tag === i);
|
|
132
|
+
if (f) {
|
|
133
|
+
if (!f.address.find(k => k === v.address)) { // add address
|
|
134
|
+
f.address.push(v.address)
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
data.push({tag:i, address:[v.address]}); // add tag
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
if (innerTag) {
|
|
142
|
+
(Object.keys(TagName) as Array<keyof typeof TagName>).forEach(i => {
|
|
143
|
+
if (!data.find(v => v.tag === TagName[i])) {
|
|
144
|
+
data.push({tag:TagName[i], address:[]})
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
return data;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static Tags(data: TagData) : Tags[] {
|
|
152
|
+
const tags : Tags[] = [];
|
|
153
|
+
data.address.forEach(v => {
|
|
154
|
+
const f = tags.find(i => i.address === v);
|
|
155
|
+
if (f) {
|
|
156
|
+
if (!f.tags.find(k => k === data.tag)) {
|
|
157
|
+
f.tags.push(data.tag)
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
tags.push({address:v, tags:[data.tag]})
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
return tags;
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
|
package/src/treasury.ts
CHANGED
|
@@ -415,7 +415,7 @@ export class Treasury {
|
|
|
415
415
|
})
|
|
416
416
|
this.permission = new_permission
|
|
417
417
|
}
|
|
418
|
-
static parseObjectType = (chain_type
|
|
418
|
+
static parseObjectType = (chain_type?:string) : string => {
|
|
419
419
|
return parseObjectType(chain_type, 'treasury::Treasury<')
|
|
420
420
|
}
|
|
421
421
|
|
package/src/utils.ts
CHANGED
|
@@ -177,6 +177,10 @@ export class Bcs {
|
|
|
177
177
|
"safer_value": "vector<string>",
|
|
178
178
|
'like': BCS.U32,
|
|
179
179
|
'dislike': BCS.U32,
|
|
180
|
+
});
|
|
181
|
+
this.bcs.registerStructType('TagStruct', {
|
|
182
|
+
'nick': 'string',
|
|
183
|
+
'tags': "vector<string>",
|
|
180
184
|
})
|
|
181
185
|
this.bcs.registerStructType('PersonalInfo', {
|
|
182
186
|
'name': 'vector<u8>',
|
|
@@ -335,7 +339,12 @@ export class Bcs {
|
|
|
335
339
|
r.name = new TextDecoder().decode(Uint8Array.from(r.name));
|
|
336
340
|
r.description = new TextDecoder().decode(Uint8Array.from(r.description));
|
|
337
341
|
return r
|
|
338
|
-
}
|
|
342
|
+
}
|
|
343
|
+
de_tags(data:Uint8Array | undefined) : any {
|
|
344
|
+
if (!data || data.length === 0) return ''
|
|
345
|
+
const struct_vec = this.bcs.de('vector<u8>', data);
|
|
346
|
+
return this.bcs.de('TagStruct', Uint8Array.from(struct_vec));
|
|
347
|
+
}
|
|
339
348
|
de_perms(data:Uint8Array | undefined) : any {
|
|
340
349
|
if (!data || data.length < 1) return ''
|
|
341
350
|
let r = this.bcs.de('Perms', data);
|
|
@@ -390,8 +399,8 @@ export const MAX_NAME_LENGTH = 64;
|
|
|
390
399
|
export const MAX_ENDPOINT_LENGTH = 1024;
|
|
391
400
|
// export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure([], BCS.U8) };
|
|
392
401
|
|
|
393
|
-
export const IsValidDesription = (description:string) : boolean => { return description
|
|
394
|
-
export const IsValidName = (name
|
|
402
|
+
export const IsValidDesription = (description:string) : boolean => { return description.length <= MAX_DESCRIPTION_LENGTH }
|
|
403
|
+
export const IsValidName = (name?:string) : boolean => { if(!name) return false; return name.length <= MAX_NAME_LENGTH && name.length != 0 }
|
|
395
404
|
export const IsValidName_AllowEmpty = (name:string) : boolean => { return name.length <= MAX_NAME_LENGTH }
|
|
396
405
|
export const IsValidEndpoint = (endpoint:string) : boolean => {
|
|
397
406
|
return (endpoint.length > 0 && endpoint.length <= MAX_ENDPOINT_LENGTH && isValidHttpUrl(endpoint)) ;
|
|
@@ -402,6 +411,13 @@ export const IsValidAddress = (addr:string | undefined) : boolean => {
|
|
|
402
411
|
}
|
|
403
412
|
return true
|
|
404
413
|
}
|
|
414
|
+
export const IsValidCoinType = (coin_type:string | undefined) : boolean => {
|
|
415
|
+
if (!coin_type) {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
return coin_type.startsWith('0x2::coin::Coin') || coin_type.startsWith('0x0000000000000000000000000000000000000000000000000000000000000002')
|
|
419
|
+
}
|
|
420
|
+
|
|
405
421
|
export const IsValidBigint = (value:string | number | undefined | bigint, max:bigint=MAX_U256, min?:bigint) : boolean => {
|
|
406
422
|
if (value === '' || value === undefined) return false;
|
|
407
423
|
try {
|