wowok 1.6.67 → 1.6.70

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.6.67",
3
+ "version": "1.6.70",
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",
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 { GroupName, Resource } from './resource';
4
+ import { TagName, Resource } from './resource';
5
5
  import { Transaction as TransactionBlock, TransactionResult } from '@mysten/sui/transactions';
6
6
 
7
- export interface Safer {
8
- name: string;
9
- value: string;
10
- }
7
+
11
8
  export interface Entity_Info {
12
9
  name: string;
13
10
  description?: string;
@@ -33,7 +30,7 @@ export class Entity {
33
30
  return r
34
31
  }
35
32
 
36
- mark(resource:Resource, address:string | TransactionResult, like:GroupName.LikeName | GroupName.DislikeName) {
33
+ mark(resource:Resource, address:string | TransactionResult, like:TagName.Like | TagName.Dislike) {
37
34
  if (typeof(address) === 'string' && !IsValidAddress(address)) {
38
35
  ERROR(Errors.IsValidAddress, like);
39
36
  }
@@ -44,41 +41,6 @@ export class Entity {
44
41
  typeof(address) === 'string' ? this.txb.pure.address(address) : address]
45
42
  })
46
43
  }
47
- /*
48
- add_safer(safer: Safer[], bExistModify:boolean=true) {
49
- if (safer.length === 0) return ;
50
- if (!IsValidArray(safer, (v:Safer) => {
51
- if (!IsValidName(v.name) || !IsValidDesription(v.value)) {
52
- return false
53
- }
54
- })) {
55
- ERROR(Errors.InvalidParam, 'add_safer');
56
- }
57
-
58
- const name = safer.map((v)=>v.name);
59
- const value = safer.map((v)=>v.value);
60
- this.txb.moveCall({
61
- target:Protocol.Instance().entityFn('safer_add') as FnCallType,
62
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name),
63
- this.txb.pure.vector('string', value), this.txb.pure.bool(bExistModify)]
64
- })
65
- }
66
-
67
- remove_safer(name:string[], removeall?:boolean) {
68
- if (name.length === 0 && !removeall) return;
69
-
70
- if (removeall) {
71
- this.txb.moveCall({
72
- target:Protocol.Instance().entityFn('safer_remove_all') as FnCallType,
73
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
74
- })
75
- } else {
76
- this.txb.moveCall({
77
- target:Protocol.Instance().entityFn('safer_remove') as FnCallType,
78
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', name)]
79
- })
80
- }
81
- }*/
82
44
 
83
45
  update(info: Entity_Info) {
84
46
  if (info?.name && !IsValidName(info.name)) ERROR(Errors.IsValidName, 'update');
@@ -116,14 +78,21 @@ export class Entity {
116
78
  })
117
79
  }
118
80
 
119
- destroy_resource(resource:Resource) {
81
+ destroy_resource(resource:Resource) { // Resource must self-owned.
120
82
  return this.txb.moveCall({
121
83
  target:Protocol.Instance().entityFn('resource_destroy') as FnCallType,
122
84
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
123
85
  })
124
86
  }
125
87
 
126
- transfer_resource(resource:Resource, new_address:string) {
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.
127
96
  if (!IsValidAddress(new_address)) ERROR(Errors.IsValidAddress, 'transfer_resource');
128
97
 
129
98
  return this.txb.moveCall({
package/src/exception.ts CHANGED
@@ -21,10 +21,11 @@ export enum Errors {
21
21
  Fail = 'fail',
22
22
  IsValidIndentifier = 'indentifier invalid',
23
23
  isValidHttpUrl = 'invalid url',
24
- IsValidUserDefinedIndex = 'invalid user defined permission index',
24
+ IsValidBizPermissionIndex = 'invalid biz-permission index',
25
25
  bcsTypeInvalid = 'invalid bcs type',
26
26
  IsValidServiceItemName = 'invalid service item name',
27
27
  IsValidCoinType = 'not the coin type',
28
+ IsValidGuardIdentifier = 'guard identifier invalid',
28
29
  noPermission = 'no permission',
29
30
  }
30
31
 
package/src/guard.ts CHANGED
@@ -466,6 +466,10 @@ export class Guard {
466
466
  return Guard.CommonOptions(ret_type);
467
467
  }
468
468
  }
469
+
470
+ export const IsValidGuardIdentifier = (identifier:number | undefined) : boolean => {
471
+ return IsValidU8(identifier) && identifier !== 0;
472
+ }
469
473
  export class GuardMaker {
470
474
  protected data : Uint8Array[] = [];
471
475
  protected type_validator : Data_Type[] = [];
@@ -556,8 +560,8 @@ export class GuardMaker {
556
560
  this.type_validator.push(ValueType.TYPE_U64);
557
561
  break;
558
562
  case ContextType.TYPE_CONSTANT:
559
- if (typeof(param) !== 'number' || !IsValidInt(param) || param > 255) {
560
- ERROR(Errors.InvalidParam, 'add_param param:'+type);
563
+ if (!IsValidGuardIdentifier(param)) {
564
+ ERROR(Errors.IsValidGuardIdentifier, 'add_param param:'+type);
561
565
  }
562
566
 
563
567
  var v = this.constant.get(param);
package/src/permission.ts CHANGED
@@ -233,7 +233,7 @@ export interface Permission_Index {
233
233
  entities: Permission_Index_Entity[];
234
234
  }
235
235
 
236
- export interface UserDefinedIndex {
236
+ export interface BizPermission {
237
237
  index: PermissionIndexType;
238
238
  name: string;
239
239
  }
@@ -271,13 +271,13 @@ export class Permission {
271
271
  })
272
272
  }
273
273
 
274
- add_userdefine(index: number, name:string) {
275
- if (!Permission.IsValidUserDefinedIndex(index)) {
276
- ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
274
+ add_bizPermission(index: number, name:string) {
275
+ if (!Permission.IsValidBizPermissionIndex(index)) {
276
+ ERROR(Errors.IsValidBizPermissionIndex, 'add_bizPermission');
277
277
  }
278
278
 
279
279
  if (!IsValidName(name)) {
280
- ERROR(Errors.IsValidName, 'add_userdefine');
280
+ ERROR(Errors.IsValidName, 'add_bizPermission');
281
281
  }
282
282
  this.txb.moveCall({
283
283
  target:Protocol.Instance().permissionFn('user_define_add') as FnCallType,
@@ -285,9 +285,9 @@ export class Permission {
285
285
  })
286
286
  }
287
287
 
288
- remove_userdefine(index: number) {
289
- if (!Permission.IsValidUserDefinedIndex(index)) {
290
- ERROR(Errors.IsValidUserDefinedIndex, 'add_userdefine');
288
+ remove_bizPermission(index: number) {
289
+ if (!Permission.IsValidBizPermissionIndex(index)) {
290
+ ERROR(Errors.IsValidBizPermissionIndex, 'remove_bizPermission');
291
291
  }
292
292
 
293
293
  this.txb.moveCall({
@@ -407,7 +407,7 @@ export class Permission {
407
407
  if (!IsValidAddress(address)) {
408
408
  ERROR(Errors.IsValidAddress, 'address')
409
409
  }
410
- if(!Permission.IsValidPermissionIndex(index) && !Permission.IsValidUserDefinedIndex(index)) {
410
+ if(!Permission.IsValidPermissionIndex(index) && !Permission.IsValidBizPermissionIndex(index)) {
411
411
  ERROR(Errors.IsValidPermissionIndex, 'index')
412
412
  }
413
413
 
@@ -572,7 +572,7 @@ export class Permission {
572
572
  static PERMISSION_OWNER_AND_ADMIN = 3;
573
573
  static BUSINESS_PERMISSIONS_START = PermissionIndex.user_defined_start;
574
574
 
575
- static IsValidUserDefinedIndex = (index:number) => {
575
+ static IsValidBizPermissionIndex = (index:number) => {
576
576
  return index >= Permission.BUSINESS_PERMISSIONS_START && IsValidU64(index)
577
577
  }
578
578
 
@@ -582,6 +582,6 @@ export class Permission {
582
582
  return true
583
583
  }
584
584
  //console.log(Object.keys(PermissionIndex))
585
- return Permission.IsValidUserDefinedIndex(index);
585
+ return Permission.IsValidBizPermissionIndex(index);
586
586
  }
587
587
  }
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: "0x30ed8dfa0b8597b1c753b8345e3c7b8792041feeaa7dc765bacd10f63c4402b7",
223
- wowok_origin:'0x30ed8dfa0b8597b1c753b8345e3c7b8792041feeaa7dc765bacd10f63c4402b7' ,
224
- base: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
225
- base_origin: '0x75eae2a5c8e9bcee76ff8f684bcc38e49a26530526ef8c32703dc0b4a4281f93',
226
-
227
- wowok_object: '0xc26fcc691dbd4c05d753e170a11c151dbdec130b77691b391d1012dfb8c445bf',
228
- entity_object: '0x1de2c69c9a795f56a8c409b54bbf50e544d4178d7c64b5520d929f5eea65b5ff',
229
- treasury_cap:'0x9f415c863f0c26103e70fc4a739fea479ff20544057a3c5665db16c0b8650f7c',
230
- oracle_object:'0x6c7d9b8ab0e9d21291e0128ca3e0d550b30f375f1e008381f2fbeef6753e6dcf',
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, ResourceAddress} from './protocol';
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
- nick: string; // named address
9
+ name?: string; // named address
9
10
  tags: string[]; // tags for address
10
11
  }
11
12
 
12
- export interface ResourceData { // personal folder
13
- name: string; // folder name
13
+ export interface TagData {
14
+ tag: string; // tag name
14
15
  address: string[]; // objects in folder
15
- }
16
- export enum GroupName {
17
- LikeName = "like",
18
- DislikeName = "dislike",
19
- FavorName = "favor",
20
- LaunchName = 'launch',
21
- OrderName = 'order',
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 MAX_ADDRESS_COUNT = 600;
26
- static MAX_TAGS = 8;
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,146 +43,111 @@ 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
- if (object.length === 0) return;
52
-
53
- var bString = true;
54
- if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add.name');
55
- if (!IsValidArray(object, (item:any) => {
56
- if (typeof(item) === 'string') {
57
- return IsValidAddress(item)
58
- } else {
59
- bString = false;
60
- }
61
- return true;
62
- })) {
63
- ERROR(Errors.IsValidArray, 'add.object');
64
- }
65
53
 
66
- if (bString) {
67
- this.txb.moveCall({
68
- target:Protocol.Instance().resourceFn('add') as FnCallType,
69
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
70
- this.txb.pure.vector('address', object as string[])]
71
- });
72
- } else {
73
- this.txb.moveCall({
74
- target:Protocol.Instance().resourceFn('add') as FnCallType,
75
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
76
- this.txb.makeMoveVec({elements:object as TransactionResult[], type:'address'})]
77
- });
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);
78
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)));
79
62
  }
80
63
 
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');
86
-
87
- this.txb.moveCall({
88
- target:Protocol.Instance().resourceFn('add2') as FnCallType,
89
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), typeof(object) === 'string' ? this.txb.pure.address(object) : object,
90
- this.txb.pure.vector('string', name)]
91
- });
92
- }
64
+ add(address:TransactionResult | string, tags:string[], name?:string) {
65
+ if (typeof(address) === 'string' && !IsValidAddress(address)) {
66
+ ERROR(Errors.IsValidAddress, 'Resource: add.address');
67
+ }
93
68
 
94
- remove(name:string, object:string[] | TransactionResult[], removeall?:boolean) {
95
- if (object.length===0 && !removeall) return;
96
- if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
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
- }
69
+ var realtags = this.resolve_add(address, tags);
70
+ if (!name && realtags.length === 0) return;
109
71
 
110
- if (removeall) {
111
- this.txb.moveCall({
112
- target:Protocol.Instance().resourceFn('remove_all') as FnCallType,
113
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name)]
114
- });
115
- } else if(object) {
116
- this.txb.moveCall({
117
- target:Protocol.Instance().resourceFn('remove') as FnCallType,
118
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name),
119
- bString ? this.txb.pure.vector('address', object as string[]) : this.txb.makeMoveVec({elements:object as TransactionResult[], type:'address'})]
120
- });
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)
121
75
  }
122
- }
123
76
 
124
- remove2(object:TransactionResult | string, name:string[]) {
125
- if (typeof(object) === 'string' && !IsValidAddress(object)) {
126
- ERROR(Errors.IsValidAddress, 'Resource: remove2');
127
- }
128
- if (!IsValidArray(name, IsValidName)) ERROR(Errors.InvalidParam, 'Resource: remove2');
129
- if (!name) return
130
-
131
77
  this.txb.moveCall({
132
- target:Protocol.Instance().resourceFn('remove2') as FnCallType,
78
+ target:Protocol.Instance().resourceFn('add') as FnCallType,
133
79
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
134
- typeof(object) === 'string' ? this.txb.pure.address(object) : object,
135
- this.txb.pure.vector('string', name)]
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
+ ]
136
84
  });
137
85
  }
138
86
 
139
- rename(old_name:string, new_name:string) {
140
- if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'Resource: rename');
141
-
142
- this.txb.moveCall({
143
- target:Protocol.Instance().resourceFn('rename') as FnCallType,
144
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(old_name),
145
- this.txb.pure.string(new_name)]
146
- });
147
- }
148
-
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)
87
+ remove(address:TransactionResult | string, tags:string[]) {
88
+ if (typeof(address) === 'string' && !IsValidAddress(address)) {
89
+ ERROR(Errors.IsValidAddress, 'Resource: remove.address');
160
90
  }
161
-
91
+
162
92
  this.txb.moveCall({
163
- target:Protocol.Instance().resourceFn('tags_add') as FnCallType,
93
+ target:Protocol.Instance().resourceFn('remove') as FnCallType,
164
94
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
165
- typeof(object) === 'string' ? this.txb.pure.address(object) : object,
166
- this.txb.pure.string(nick),
95
+ typeof(address) === 'string' ? this.txb.pure.address(address) : address,
167
96
  this.txb.pure.vector('string', tags)
168
97
  ]
169
98
  });
170
99
  }
171
100
 
172
- remove_tags(object:TransactionResult | string) {
173
- if (typeof(object) === 'string' && !IsValidAddress(object)) {
174
- ERROR(Errors.IsValidAddress, 'Resource: remove_tags');
101
+ removeall(address: TxbAddress) {
102
+ if (typeof(address) === 'string' && !IsValidAddress(address)) {
103
+ ERROR(Errors.IsValidAddress, 'Resource: removeall.address');
175
104
  }
176
105
 
177
106
  this.txb.moveCall({
178
- target:Protocol.Instance().resourceFn('tags_remove') as FnCallType,
107
+ target:Protocol.Instance().resourceFn('removeall') as FnCallType,
179
108
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
180
- typeof(object) === 'string' ? this.txb.pure.address(object) : object,
109
+ typeof(address) === 'string' ? this.txb.pure.address(address) : address,
181
110
  ]
182
111
  });
183
112
  }
113
+
114
+ static TagData(tags: Tags[], innerTag:boolean=true) : TagData[] {
115
+ const data : TagData[] = [];
116
+ tags.forEach(v => {
117
+ v.tags.forEach(i => {
118
+ const f = data.find(k => k.tag === i);
119
+ if (f) {
120
+ if (!f.address.find(k => k === v.address)) { // add address
121
+ f.address.push(v.address)
122
+ }
123
+ } else {
124
+ data.push({tag:i, address:[v.address]}); // add tag
125
+ }
126
+ })
127
+ })
128
+ if (innerTag) {
129
+ (Object.keys(TagName) as Array<keyof typeof TagName>).forEach(i => {
130
+ if (!data.find(v => v.tag === TagName[i])) {
131
+ data.push({tag:TagName[i], address:[]})
132
+ }
133
+ })
134
+ }
135
+ return data;
136
+ }
137
+
138
+ static Tags(data: TagData) : Tags[] {
139
+ const tags : Tags[] = [];
140
+ data.address.forEach(v => {
141
+ const f = tags.find(i => i.address === v);
142
+ if (f) {
143
+ if (!f.tags.find(k => k === data.tag)) {
144
+ f.tags.push(data.tag)
145
+ }
146
+ } else {
147
+ tags.push({address:v, tags:[data.tag]})
148
+ }
149
+ })
150
+ return tags;
151
+ }
184
152
  }
185
153
 
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:string) : string => {
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?.length <= MAX_DESCRIPTION_LENGTH }
394
- export const IsValidName = (name:string) : boolean => { if(!name) return false; return name.length <= MAX_NAME_LENGTH && name.length != 0 }
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)) ;