wowok_agent 0.1.4 → 0.1.6

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_agent",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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/account.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import * as os from 'os';
4
- import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey } from 'wowok';
4
+ import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey, Protocol, CoinBalance, CoinStruct, TransactionResult, TransactionBlock, TransactionArgument, ERROR, Errors } from 'wowok';
5
5
  import { getFaucetHost, requestSuiFromFaucetV0, requestSuiFromFaucetV1 } from 'wowok';
6
6
  export interface AccountData {
7
7
  name: string;
@@ -217,4 +217,67 @@ export class Account {
217
217
  })
218
218
  }
219
219
  }
220
- }
220
+
221
+ // token_type is 0x2::sui::SUI, if not specified.
222
+ balance = async (name?:string, token_type?:string) : Promise<CoinBalance | undefined> => {
223
+ const addr = this.get_address(name);
224
+ if (addr) {
225
+ return await Protocol.Client().getBalance({owner: addr, coinType:token_type});
226
+ }
227
+ }
228
+
229
+ // token_type is 0x2::sui::SUI, if not specified.
230
+ coin = async (name?:string, token_type?:string) : Promise<CoinStruct[] | undefined> => {
231
+ const addr = this.get_address(name);
232
+ if (addr) {
233
+ return (await Protocol.Client().getCoins({owner: addr, coinType:token_type})).data;
234
+ }
235
+ }
236
+
237
+ get_coin_object = async (txb: TransactionBlock, balance_required:string | bigint | number, name?:string, token_type?:string) : Promise<TransactionResult | undefined> => {
238
+ const addr = this.get_address(name);
239
+ const b = BigInt(balance_required);
240
+
241
+ if (addr && b > BigInt(0)) {
242
+ if (!token_type || token_type === '0x2::sui::SUI' || token_type === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
243
+ return txb.splitCoins(txb.gas, [balance_required]);
244
+ } else {
245
+ const r = await Protocol.Client().getCoins({owner: addr, coinType:token_type});
246
+ const objects : string[] = []; var current = BigInt(0);
247
+ for (let i = 0; i < r.data.length; ++ i) {
248
+ current += BigInt(r.data[i].balance);
249
+ objects.push(r.data[i].coinObjectId);
250
+ if (current >= b) {
251
+ break;
252
+ }
253
+ }
254
+
255
+ if (objects.length === 1) {
256
+ return txb.splitCoins(objects[0], [b]);
257
+ } else {
258
+ const ret = objects.pop()!;
259
+ txb.mergeCoins(ret, objects);
260
+ return txb.splitCoins(ret, [b])
261
+ }
262
+ }
263
+ }
264
+ }
265
+ coin_with_balance = async(balance_required:string | bigint | number, account?:string, token_type?:string) : Promise<string | undefined> => {
266
+ const pair = this.get_pair(account, true);
267
+ if (!pair) ERROR(Errors.Fail, 'account invalid')
268
+
269
+ const txb = new TransactionBlock();
270
+ const res = await Account.Instance().get_coin_object(txb, balance_required, account, token_type);
271
+ if (res) {
272
+ txb.transferObjects([(res as unknown) as TransactionArgument], pair?.toSuiAddress()!)
273
+ const r = await Protocol.Client().signAndExecuteTransaction({
274
+ transaction: txb,
275
+ signer: pair!,
276
+ options:{showObjectChanges:true},
277
+ });
278
+ const t = token_type ?? '0x2::sui::SUI';
279
+ return ((r as any)?.objectChanges.find((v:any) => v?.type === 'created' && (v?.objectType as string).includes(t)) as any)?.objectId;
280
+ }
281
+ }
282
+ }
283
+
package/src/cache.ts CHANGED
@@ -1,27 +1,52 @@
1
1
 
2
2
  import { Protocol } from "wowok";
3
3
 
4
+ export type CacheExpire = number | 'INFINITE';
5
+
6
+ export interface CachedData {
7
+ expire: number | 'INFINITE';
8
+ data: string | any;
9
+ }
10
+
4
11
  export abstract class CacheData {
5
12
  constructor(expire: number) { this.expire = expire; } // 10m default
6
13
  abstract load(key: string) : string | null | undefined;
7
14
  abstract save(key: string, data:string) : void;
15
+ abstract remove(key: string) : void;
8
16
  expire_time() {return this.expire};
9
17
  protected expire;
10
18
  }
11
19
 
12
- export const OBJECT_KEY = (object: string) : string => {
13
- return object + Protocol.Instance().package('wowok_origin') + 'V2';
20
+ export enum CacheName {
21
+ object = 'OBJECT',
22
+ resource = 'RESOURCE',
23
+ }
24
+
25
+ export const OBJECT_KEY = (object_address: string) : string => {
26
+ return object_address + Protocol.Instance().package('wowok_origin') + CacheName.object + '-V2';
27
+ }
28
+ export const PERSONAL_RESOURCE_KEY = (person_address: string) : string => {
29
+ return person_address + Protocol.Instance().package('wowok_origin') + CacheName.resource + '-V2';
30
+ }
31
+
32
+ export interface PersonalResouceCache {
33
+ address: string;
34
+ resource: string;
35
+ time_expire?: CacheExpire;
14
36
  }
15
37
 
16
38
  export class MemeryCache extends CacheData {
17
39
  constructor(expire: number = 10000) {super(expire)}
18
- protected data = new Map<string, string>;
40
+ protected data = new Map<string, string>();
19
41
  load(key: string) : string | null | undefined {
20
42
  return this.data.get(key)
21
43
  }
22
44
  save(key: string, data:string) : void {
23
45
  this.data.set(key, data);
24
46
  }
47
+ remove(key: string) : void {
48
+ this.data.delete(key)
49
+ }
25
50
  }
26
51
 
27
52
  export class LocalStorageCache extends CacheData {
@@ -32,11 +57,14 @@ export class LocalStorageCache extends CacheData {
32
57
  save(key: string, data:string) : void {
33
58
  return localStorage.setItem(key, data)
34
59
  }
60
+ remove(key: string) : void {
61
+ return localStorage.removeItem(key)
62
+ }
35
63
  }
36
64
 
37
65
  export class WowokCache {
38
66
  static _instance: any;
39
- private cache: any;
67
+ private cache: Map<string, CacheData | undefined> = new Map();
40
68
 
41
69
  constructor() {}
42
70
  static Instance() : WowokCache {
@@ -45,10 +73,11 @@ export class WowokCache {
45
73
  }; return WowokCache._instance
46
74
  }
47
75
 
48
- set(cache:CacheData) {
49
- this.cache = cache;
76
+ set(name:string | CacheName, cache:CacheData | undefined) {
77
+ this.cache.set(name, cache);
50
78
  }
51
- get() : CacheData {
52
- return this.cache;
79
+
80
+ get(name:string | CacheName) : CacheData | undefined {
81
+ return this.cache.get(name);
53
82
  }
54
83
  }
@@ -1,14 +1,14 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType} from 'wowok';
1
+ import { TransactionBlock, CallResponse, IsValidArgType, TransactionResult} from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, PermissionIndexType, Treasury,
3
3
  Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee, WitnessFill
4
4
  } from 'wowok';
5
5
  import { query_objects, ObjectArbitration, } from '../objects';
6
- import { CallBase, CallResult } from "./base";
6
+ import { CallBase, CallResult, AddressMark } from "./base";
7
7
 
8
8
  export interface CallArbitration_Data {
9
9
  object?: string; // undefined for creating a new object
10
10
  permission?: string;
11
-
11
+ mark?:AddressMark;
12
12
  type_parameter?: string;
13
13
  permission_new?: string;
14
14
  description?: string;
@@ -100,9 +100,9 @@ export class CallArbitration extends CallBase {
100
100
 
101
101
  return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
102
102
  }
103
- return this.exec(account);
103
+ return await this.exec(account);
104
104
  }
105
- protected async operate(txb:TransactionBlock, passport?:PassportObject) {
105
+ protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
106
106
  let obj : Arbitration | undefined ; let permission: any; let withdraw_treasury:any;
107
107
  if (!this.data.object) {
108
108
  if (!this.data?.permission || !IsValidAddress(this.data?.permission)) {
@@ -177,8 +177,15 @@ export class CallArbitration extends CallBase {
177
177
  if (permission) {
178
178
  permission.launch();
179
179
  }
180
+ var mark : TransactionResult | string | undefined ;
180
181
  if (!this.data.object) {
181
- obj?.launch();
182
+ mark = obj?.launch();
183
+ } else {
184
+ mark = this.data.object;
185
+ }
186
+
187
+ if (this.data?.mark !== undefined) {
188
+ this.mark(txb, mark, this.data?.mark, account)
182
189
  }
183
190
  }
184
191
  }
package/src/call/base.ts CHANGED
@@ -1,18 +1,22 @@
1
1
 
2
2
 
3
- import { Protocol, TransactionBlock, CallResponse, Guard} from 'wowok';
3
+ import { Protocol, TransactionBlock, CallResponse, Guard, TransactionArgument, Entity, IsValidAddress, Resource, TxbObject, TransactionResult} from 'wowok';
4
4
  import { PassportObject, Errors, ERROR, Permission,
5
5
  PermissionIndexType, GuardParser, Passport, WitnessFill
6
6
  } from 'wowok';
7
7
  import { query_permission } from '../permission';
8
8
  import { Account } from '../account';
9
- import { ObjectBase } from '../objects';
10
-
9
+ import { ObjectBase} from '../objects';
10
+ import { query_entity } from '../entity';
11
11
 
12
+ export interface AddressMark {
13
+ nick_name?:string;
14
+ tags:string[];
15
+ groups:string[];
16
+ }
12
17
  export interface ResponseData extends ObjectBase {
13
18
  change:'created' | 'mutated' | string;
14
19
  }
15
-
16
20
  export interface GuardInfo_forCall {
17
21
  guard: string[];
18
22
  witness: WitnessFill[];
@@ -39,7 +43,7 @@ export function ResponseData(response: CallResponse | undefined ) : ResponseData
39
43
  }
40
44
  export class CallBase {
41
45
  // operation implementation for a call
42
- protected async operate(txb:TransactionBlock, passport?:PassportObject) {};
46
+ protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
43
47
  constructor () {}
44
48
  // return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
45
49
  // return ResponseData when the call has completed;
@@ -56,7 +60,7 @@ export class CallBase {
56
60
  if (query) {
57
61
  const txb = new TransactionBlock();
58
62
  const passport = new Passport(txb, query!);
59
- this.operate(new TransactionBlock(), passport?.get_object())
63
+ this.operate(new TransactionBlock(), passport?.get_object(), param?.account)
60
64
  passport.destroy();
61
65
 
62
66
  return await Protocol.Client().signAndExecuteTransaction({
@@ -103,7 +107,7 @@ export class CallBase {
103
107
  if (query) {
104
108
  const txb = new TransactionBlock();
105
109
  const passport = new Passport(txb, query!);
106
- this.operate(new TransactionBlock(), passport?.get_object())
110
+ this.operate(new TransactionBlock(), passport?.get_object(), account)
107
111
  passport.destroy();
108
112
 
109
113
  return await Protocol.Client().signAndExecuteTransaction({
@@ -116,7 +120,7 @@ export class CallBase {
116
120
 
117
121
  return {guard:[...guards], witness:p!.future_fills()};
118
122
  } else { // no passport needed
119
- return this.exec()
123
+ return await this.exec()
120
124
  }
121
125
  }
122
126
  protected async exec (account?:string) : Promise<CallResponse> {
@@ -124,11 +128,27 @@ export class CallBase {
124
128
  if (!pair) ERROR(Errors.Fail, 'account invalid')
125
129
 
126
130
  const txb = new TransactionBlock();
127
- this.operate(txb);
131
+ this.operate(txb, undefined, account);
128
132
  return await Protocol.Client().signAndExecuteTransaction({
129
133
  transaction: txb,
130
134
  signer: pair!,
131
135
  options:{showObjectChanges:true},
132
136
  });
133
137
  }
138
+
139
+ protected mark = async (txb:TransactionBlock, object: string | TransactionResult, mark:AddressMark, account?:string) => {
140
+ const addr = Account.Instance().get_address(account);
141
+ if (addr) {
142
+ const r = await query_entity(addr);
143
+ if (r?.resource) {
144
+ const resource = Resource.From(txb, r.resource);
145
+ resource.add_tags(object, mark.nick_name??'', mark.tags);
146
+ if (mark.groups.length > 0) {
147
+ resource.add2(object, mark.groups);
148
+ }
149
+ }
150
+ } else {
151
+ ERROR(Errors.InvalidParam, 'account - ' + account)
152
+ }
153
+ }
134
154
  }
@@ -1,19 +1,18 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType} from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, PermissionIndex, UserDefinedIndex,
3
- PermissionIndexType, Demand, WitnessFill
4
- } from 'wowok';
1
+ import { TransactionBlock, IsValidArgType, IsValidCoinType } from 'wowok';
2
+ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
+ PermissionIndexType, Demand, } from 'wowok';
5
4
  import { query_objects, ObjectDemand } from '../objects';
6
5
  import { CallBase, CallResult } from "./base";
6
+ import { Account } from '../account';
7
7
 
8
8
  export interface CallDemand_Data {
9
9
  object?: string; // undefined for creating a new object
10
10
  permission?: string;
11
- permission_new?: string;
12
11
  type_parameter?: string;
13
12
  guard?: {address:string; service_id_in_guard?:number};
14
13
  description?: string;
15
14
  time_expire?: {op: 'duration'; minutes:number} | {op:'set'; time:number};
16
- bounty?: {op:'add'; object?:string; balance:string} | {op:'refund'} | {op:'reward'; service:string};
15
+ bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'refund'} | {op:'reward'; service:string};
17
16
  present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string | 'fetch'}; // guard is the present guard of Demand
18
17
  reward?: string; // rerward the service
19
18
  refund?: boolean;
@@ -36,9 +35,6 @@ export class CallDemand extends CallBase {
36
35
  if (!this.data?.object) {
37
36
  perms.push(PermissionIndex.demand)
38
37
  }
39
- if (this.data?.permission_new !== undefined) {
40
- checkOwner = true;
41
- }
42
38
  if (this.data?.description !== undefined && this.data.object) {
43
39
  perms.push(PermissionIndex.demand_description)
44
40
  }
@@ -75,9 +71,9 @@ export class CallDemand extends CallBase {
75
71
  }
76
72
  return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
77
73
  }
78
- return this.exec(account);
74
+ return await this.exec(account);
79
75
  }
80
- protected async operate(txb:TransactionBlock, passport?:PassportObject) {
76
+ protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
81
77
  let obj : Demand | undefined ; let permission: any;
82
78
 
83
79
  if (!this.data.object) {
@@ -109,16 +105,14 @@ export class CallDemand extends CallBase {
109
105
  }
110
106
  if (this.data?.bounty !== undefined) {
111
107
  if (this.data.bounty.op === 'add') {
112
- let deposit : any | undefined; let b = BigInt(this.data.bounty.balance);
113
- if (b > BigInt(0)) {
114
- if (this.data.type_parameter === '0x2::sui::SUI' || this.data.type_parameter === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
115
- deposit = txb.splitCoins(txb.gas, [b])[0];
116
- } else if (this.data?.bounty?.object) {
117
- deposit = txb.splitCoins(this.data.bounty.object, [b])[0];
118
- }
119
- if (deposit) {
120
- obj?.deposit(deposit);
108
+ if (IsValidAddress((this.data.bounty.object as any)?.address)) {
109
+ obj.deposit((this.data.bounty.object as any)?.address)
110
+ } else if ((this.data.bounty.object as any)?.balance !== undefined){
111
+ if (!IsValidCoinType(this.data.type_parameter)) {
112
+ ERROR(Errors.IsValidCoinType, 'demand bounty')
121
113
  }
114
+ const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.data.type_parameter);
115
+ if (r) obj.deposit(r)
122
116
  }
123
117
  } else if (this.data.bounty.op === 'refund') {
124
118
  obj?.refund(passport);
@@ -133,9 +127,6 @@ export class CallDemand extends CallBase {
133
127
  if (this.data?.guard !== undefined) {
134
128
  obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined, passport)
135
129
  }
136
- if (this.data?.permission_new !== undefined ) {
137
- obj?.change_permission(this.data.permission_new);
138
- }
139
130
  if (permission) {
140
131
  permission.launch();
141
132
  }
@@ -4,19 +4,19 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_E
4
4
  PermissionIndexType, WitnessFill
5
5
  } from 'wowok';
6
6
 
7
- export interface CallPermission_Data {
7
+ export interface CallEntityPermission_Data {
8
8
  object?: string; // undefined for creating a new object
9
9
  builder?: string;
10
10
  admin?: {op:'add' | 'remove' | 'set', admins:string[]};
11
11
  description?: string;
12
- entity?: {op:'add entity'; entities:Permission_Entity[]} | {op:'add permission'; permissions:Permission_Index[]}
12
+ permission?: {op:'add entity'; entities:Permission_Entity[]} | {op:'add permission'; permissions:Permission_Index[]}
13
13
  | {op:'remove entity'; addresses:string[]} | {op:'remove permission'; address:string; index:PermissionIndexType[]}
14
14
  | {op:'transfer permission', from_address: string; to_address: string};
15
15
  biz_permission?: {op:'add'; data: UserDefinedIndex[]} | {op:'remove'; permissions: PermissionIndexType[]};
16
16
  }
17
- export class CallPermission extends CallBase {
18
- data: CallPermission_Data;
19
- constructor(data:CallPermission_Data) {
17
+ export class CallEntityPermission extends CallBase {
18
+ data: CallEntityPermission_Data;
19
+ constructor(data:CallEntityPermission_Data) {
20
20
  super();
21
21
  this.data = data;
22
22
  }
@@ -27,7 +27,7 @@ export class CallPermission extends CallBase {
27
27
  if (this.data?.builder !== undefined || this.data?.admin !== undefined) {
28
28
  checkOwner = true;
29
29
  }
30
- if (this.data?.entity !== undefined || this.data?.biz_permission !== undefined) {
30
+ if (this.data?.permission !== undefined || this.data?.biz_permission !== undefined) {
31
31
  checkAdmin = true;
32
32
  }
33
33
  if (this.data?.description !== undefined) {
@@ -35,7 +35,7 @@ export class CallPermission extends CallBase {
35
35
  }
36
36
  return await this.check_permission_and_call(this.data.object, [], [], checkOwner, checkAdmin, account)
37
37
  }
38
- return this.exec(account)
38
+ return await this.exec(account)
39
39
  }
40
40
  protected async operate (txb:TransactionBlock, passport?:PassportObject) {
41
41
  let obj : Permission | undefined ;
@@ -62,42 +62,43 @@ export class CallPermission extends CallBase {
62
62
  break
63
63
  }
64
64
  }
65
+ if (this.data?.biz_permission !== undefined) { // High priority operate
66
+ switch(this.data.biz_permission.op) {
67
+ case 'add':
68
+ this.data.biz_permission.data.forEach(v => {
69
+ obj?.add_userdefine(v.index, v.name);
70
+ })
71
+ break;
72
+ case 'remove':
73
+ this.data.biz_permission.permissions.forEach(v => {
74
+ obj?.remove_userdefine(v);
75
+ })
76
+ break;
77
+ }
78
+ }
65
79
  if (this.data?.description !== undefined && this.data.object) {
66
80
  obj?.set_description(this.data.description)
67
81
  }
68
- if (this.data?.entity !== undefined) {
69
- switch (this.data.entity.op) {
82
+ if (this.data?.permission !== undefined) {
83
+ switch (this.data.permission.op) {
70
84
  case 'add entity':
71
- obj?.add_entity(this.data.entity.entities);
85
+ obj?.add_entity(this.data.permission.entities);
72
86
  break;
73
87
  case 'add permission':
74
- obj?.add_entity3(this.data.entity.permissions);
88
+ obj?.add_entity3(this.data.permission.permissions);
75
89
  break;
76
90
  case 'remove entity':
77
- obj?.remove_entity(this.data.entity.addresses);
91
+ obj?.remove_entity(this.data.permission.addresses);
78
92
  break;
79
93
  case 'remove permission':
80
- obj?.remove_index(this.data.entity.address, this.data.entity.index);
94
+ obj?.remove_index(this.data.permission.address, this.data.permission.index);
81
95
  break;
82
96
  case 'transfer permission':
83
- obj?.transfer_permission(this.data.entity.from_address, this.data.entity.to_address);
84
- break;
85
- }
86
- }
87
- if (this.data?.biz_permission !== undefined) {
88
- switch(this.data.biz_permission.op) {
89
- case 'add':
90
- this.data.biz_permission.data.forEach(v => {
91
- obj?.add_userdefine(v.index, v.name);
92
- })
93
- break;
94
- case 'remove':
95
- this.data.biz_permission.permissions.forEach(v => {
96
- obj?.remove_userdefine(v);
97
- })
97
+ obj?.transfer_permission(this.data.permission.from_address, this.data.permission.to_address);
98
98
  break;
99
99
  }
100
100
  }
101
+
101
102
  if (this.data?.builder !== undefined ) {
102
103
  obj?.change_owner(this.data.builder);
103
104
  }
@@ -1,5 +1,4 @@
1
- import { TransactionBlock, CallResponse} from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, WitnessFill,
1
+ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock,
3
2
  PermissionIndexType, Machine, Machine_Forward, Machine_Node, Deliverable, ParentProgress, Progress, ProgressNext,
4
3
  } from 'wowok';
5
4
  import { CallBase, CallResult } from "./base";
@@ -8,7 +7,6 @@ import { Account } from '../account';
8
7
  export interface CallMachine_Data {
9
8
  object?: string; // undefined for creating a new object
10
9
  permission?: string;
11
- permission_new?: string;
12
10
  bPaused?: boolean;
13
11
  bPublished?: boolean;
14
12
  consensus_repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
@@ -42,9 +40,6 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
42
40
  if (!this.data?.object) {
43
41
  perms.push(PermissionIndex.machine)
44
42
  }
45
- if (this.data?.permission_new !== undefined) {
46
- checkOwner = true;
47
- }
48
43
  if (this.data?.description !== undefined && this.data.object) {
49
44
  perms.push(PermissionIndex.machine_description)
50
45
  }
@@ -101,7 +96,7 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
101
96
 
102
97
  return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
103
98
  }
104
- return this.exec(account);
99
+ return await this.exec(account);
105
100
  }
106
101
 
107
102
  protected async operate(txb:TransactionBlock, passport?:PassportObject) {
@@ -203,9 +198,6 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
203
198
  if (this.data?.progress_next !== undefined) {
204
199
  Progress.From(txb, obj?.get_object(), permission??this.data?.permission, this.data?.progress_next.progress).next(this.data.progress_next.data, this.data.progress_next.deliverable, passport)
205
200
  }
206
- if (this.data?.permission_new !== undefined ) {
207
- obj?.change_permission(this.data.permission_new);
208
- }
209
201
  if (permission) {
210
202
  permission.launch();
211
203
  }
@@ -0,0 +1,60 @@
1
+ import { CallBase, CallResult } from "./base";
2
+ import { TransactionBlock, CallResponse, Protocol, Demand, DemandObject, Machine, Service, Treasury, Arbitration, Repository} from 'wowok';
3
+ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
4
+ PermissionIndexType, WitnessFill
5
+ } from 'wowok';
6
+ import { ObjectArbitration, ObjectDemand, ObjectMachine, ObjectRepository, ObjectService, ObjectTreasury, query_objects } from "../objects";
7
+
8
+ export interface CallObjectPermission_Data {
9
+ objects: string[];
10
+ new_permission: string;
11
+ }
12
+
13
+ export class CallObjectPermission extends CallBase {
14
+ data: CallObjectPermission_Data;
15
+ constructor(data:CallObjectPermission_Data) {
16
+ super();
17
+ this.data = data;
18
+ }
19
+
20
+ async call(account?:string) : Promise<CallResult> {
21
+ if (!IsValidAddress(this.data.new_permission)) {
22
+ ERROR(Errors.InvalidParam, 'CallObjectPermission_Data.new_permission' + this.data.new_permission)
23
+ }
24
+
25
+ if (this.data?.objects.length > 0) {
26
+ return await this.exec(account)
27
+ }
28
+ }
29
+ protected async operate (txb:TransactionBlock, passport?:PassportObject) {
30
+ const r = await query_objects({objects:this.data.objects, showContent:true});
31
+ r.objects?.forEach(v => {
32
+ switch(v.type) {
33
+ case 'Demand':
34
+ const demand = v as ObjectDemand;
35
+ Demand.From(txb, Demand.parseObjectType(demand.type_raw), demand.permission, demand.object).change_permission(this.data.new_permission);
36
+ break;
37
+ case 'Machine':
38
+ const machine = v as ObjectMachine;
39
+ Machine.From(txb, machine.permission, machine.object).change_permission(this.data.new_permission);
40
+ break;
41
+ case 'Service':
42
+ const service = v as ObjectService;
43
+ Service.From(txb, Service.parseObjectType(service.type_raw), service.permission, service.object).change_permission(this.data.new_permission);
44
+ break;
45
+ case 'Treasury':
46
+ const treasury = v as ObjectTreasury;
47
+ Treasury.From(txb, Treasury.parseObjectType(treasury.type_raw), treasury.permission, treasury.object).change_permission(this.data.new_permission);
48
+ break;
49
+ case 'Arbitration':
50
+ const arbitraion = v as ObjectArbitration;
51
+ Arbitration.From(txb, Arbitration.parseObjectType(arbitraion.type_raw), arbitraion.permission, arbitraion.object).change_permission(this.data.new_permission);
52
+ break;
53
+ case 'Repository':
54
+ const repository = v as ObjectRepository;
55
+ Repository.From(txb, repository.permission, repository.object).change_permission(this.data.new_permission);
56
+ break;
57
+ }
58
+ })
59
+ }
60
+ }
@@ -1,17 +1,17 @@
1
- import { TransactionBlock, CallResponse} from 'wowok';
2
- import { PassportObject, IsValidAddress, Errors, ERROR, Entity, Entity_Info, MarkName, Resource, WitnessFill} from 'wowok';
1
+ import { TransactionBlock } from 'wowok';
2
+ import { PassportObject, IsValidAddress, Errors, ERROR, Entity, Entity_Info, GroupName, Resource, WitnessFill} from 'wowok';
3
3
  import { CallBase, CallResult } from "./base";
4
4
 
5
5
  export interface CallPersonal_Data {
6
6
  object?: string; // undefined for creating a new object
7
7
  information?: Entity_Info;
8
8
  transfer_to?: string;
9
- marks?: {op:'add mark'; data:{mark_name:string; address:string[]}}
10
- | {op:'add address'; data:{address:string; mark_name:string[]}}
11
- | {op:'remove mark'; data:{mark_name:string; address:string[]}}
12
- | {op:'remove address'; data:{address:string; mark_name:string[]}}
13
- | {op:'clear mark'; mark_name:string};
14
- tags?: {op:'add'; data:{address:string; nick_name:string; tags:string[]}}
9
+ group?: {op:'add group'; data:{group_name:string | GroupName; address:string[]}}
10
+ | {op:'remove group'; data:{group_name:string | GroupName; address:string[]}}
11
+ | {op:'clear group'; group_name:string | GroupName}
12
+ | {op:'add address'; data:{address:string; group_name:(string | GroupName)[]}}
13
+ | {op:'remove address'; data:{address:string; group_name:(string | GroupName)[]}};
14
+ tag?: {op:'add'; data:{address:string; nick_name?:string; tags?:string[]}}
15
15
  | {op:'remove'; address:string};
16
16
  close?: boolean; // close a personal resource
17
17
  }
@@ -23,7 +23,7 @@ export class CallPersonal extends CallBase {
23
23
  this.data = data;
24
24
  }
25
25
  async call(account?:string) : Promise<CallResult> {
26
- return this.exec(account)
26
+ return await this.exec(account)
27
27
  }
28
28
  protected async operate (txb:TransactionBlock, passport?:PassportObject) {
29
29
  let obj : Resource | undefined ; let entity: Entity = Entity.From(txb);
@@ -44,42 +44,42 @@ export class CallPersonal extends CallBase {
44
44
  }
45
45
 
46
46
  if (obj && obj?.get_object()) {
47
- if (this.data?.marks !== undefined) {
48
- switch(this.data.marks.op) {
47
+ if (this.data?.group !== undefined) {
48
+ switch(this.data.group.op) {
49
49
  case 'add address':
50
- obj?.add2(this.data.marks.data.address, this.data.marks.data.mark_name)
50
+ obj?.add2(this.data.group.data.address, this.data.group.data.group_name)
51
51
  break;
52
- case 'add mark':
53
- if (this.data.marks.data.mark_name === MarkName.DislikeName || this.data.marks.data.mark_name === MarkName.LikeName) {
54
- const n = this.data.marks.data.mark_name;
55
- this.data.marks.data.address.forEach(v => {if (obj) entity.mark(obj, v, n)})
52
+ case 'add group':
53
+ if (this.data.group.data.group_name === GroupName.DislikeName || this.data.group.data.group_name === GroupName.LikeName) {
54
+ const n = this.data.group.data.group_name;
55
+ this.data.group.data.address.forEach(v => {if (obj) entity.mark(obj, v, n)})
56
56
  } else {
57
- obj?.add(this.data.marks.data.mark_name, this.data.marks.data.address)
57
+ obj?.add(this.data.group.data.group_name, this.data.group.data.address)
58
58
  }
59
59
  break;
60
- case 'clear mark':
61
- obj?.remove(this.data.marks.mark_name, [], true)
60
+ case 'clear group':
61
+ obj?.remove(this.data.group.group_name, [], true)
62
62
  break;
63
63
  case 'remove address':
64
- obj?.remove2(this.data.marks.data.address, this.data.marks.data.mark_name)
64
+ obj?.remove2(this.data.group.data.address, this.data.group.data.group_name)
65
65
  break;
66
- case 'remove mark':
67
- if (this.data.marks.data.mark_name === MarkName.DislikeName || this.data.marks.data.mark_name === MarkName.LikeName) {
68
- const n = this.data.marks.data.mark_name;
69
- this.data.marks.data.address.forEach(v => {if (obj) entity.mark(obj, v, n)})
66
+ case 'remove group':
67
+ if (this.data.group.data.group_name === GroupName.DislikeName || this.data.group.data.group_name === GroupName.LikeName) {
68
+ const n = this.data.group.data.group_name;
69
+ this.data.group.data.address.forEach(v => {if (obj) entity.mark(obj, v, n)})
70
70
  } else {
71
- obj?.remove(this.data.marks.data.mark_name, this.data.marks.data.address)
71
+ obj?.remove(this.data.group.data.group_name, this.data.group.data.address)
72
72
  }
73
73
  break;
74
74
  }
75
75
  }
76
- if (this.data?.tags !== undefined) {
77
- switch(this.data.tags.op) {
76
+ if (this.data?.tag !== undefined) {
77
+ switch(this.data.tag.op) {
78
78
  case 'add':
79
- obj?.add_tags(this.data.tags.data.address, this.data.tags.data.nick_name, this.data.tags.data.tags)
79
+ obj?.add_tags(this.data.tag.data.address, this.data.tag.data.nick_name, this.data.tag.data.tags)
80
80
  break;
81
81
  case 'remove':
82
- obj?.remove_tags(this.data.tags.address)
82
+ obj?.remove_tags(this.data.tag.address)
83
83
  break;
84
84
  }
85
85
  }
@@ -8,7 +8,6 @@ import { CallBase, CallResult} from "./base";
8
8
  export interface CallRepository_Data {
9
9
  object?: string; // undefined for creating a new object
10
10
  permission?: string;
11
- permission_new?: string; // change permission
12
11
  description?: string;
13
12
  mode?: Repository_Policy_Mode; // default: 'Relax' (POLICY_MODE_FREE)
14
13
  reference?: {op:'set' | 'add' | 'remove' ; addresses:string[]} | {op:'removeall'};
@@ -30,9 +29,6 @@ export class CallRepository extends CallBase {
30
29
  if (!this.data?.object) {
31
30
  perms.push(PermissionIndex.repository)
32
31
  }
33
- if (this.data?.permission_new !== undefined) {
34
- checkOwner = true;
35
- }
36
32
  if (this.data?.description !== undefined && this.data?.object) {
37
33
  perms.push(PermissionIndex.repository_description)
38
34
  }
@@ -47,7 +43,7 @@ export class CallRepository extends CallBase {
47
43
  }
48
44
  return await this.check_permission_and_call(this.data.permission, perms, [], checkOwner, undefined, account)
49
45
  }
50
- return this.exec(account);
46
+ return await this.exec(account);
51
47
  }
52
48
 
53
49
  protected async operate(txb:TransactionBlock, passport?:PassportObject) {
@@ -124,9 +120,6 @@ export class CallRepository extends CallBase {
124
120
  break;
125
121
  }
126
122
  }
127
- if (this.data?.permission_new !== undefined ) {
128
- obj?.change_permission(this.data.permission_new);
129
- }
130
123
  if (permission) {
131
124
  permission.launch();
132
125
  }
@@ -5,12 +5,12 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIn
5
5
  } from 'wowok';
6
6
  import { query_objects, ObjectService } from '../objects';
7
7
  import { CallBase, CallResult } from "./base";
8
+ import { Account } from '../account';
8
9
 
9
10
  export interface CallService_Data {
10
11
  object?: string; // undefined for creating a new object
11
12
  permission?: string;
12
13
  type_parameter?: string;
13
- permission_new?: string;
14
14
  bPaused?: boolean;
15
15
  bPublished?: boolean;
16
16
  description?: string;
@@ -31,7 +31,7 @@ export interface CallService_Data {
31
31
  | {op:'removeall'} | {op:'remove', addresses:string[]};
32
32
  customer_required_info?: {pubkey:string; required_info:(string | BuyRequiredEnum)[]};
33
33
  sales?: {op:'add', sales:Service_Sale[]} | {op:'remove'; sales_name:string[]}
34
- order_new?: {buy_items:Service_Buy[], coin_object?:string, discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string | 'fetch'}
34
+ order_new?: {buy_items:Service_Buy[], discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo, guard?:string | 'fetch'}
35
35
  order_required_info?: {order:string; info:Customer_RequiredInfo};
36
36
  order_refund?: {order:string; guard?:string;} | {order:string; arb:string; arb_token_type:string}; // guard address
37
37
  order_withdrawl?: {order:string; data:WithdrawPayee}; // guard address
@@ -56,9 +56,6 @@ export class CallService extends CallBase {
56
56
  if (!this.data?.object) {
57
57
  perms.push(PermissionIndex.service)
58
58
  }
59
- if (this.data?.permission_new !== undefined) {
60
- checkOwner = true;
61
- }
62
59
  if (this.data?.description !== undefined && this.data.object) {
63
60
  perms.push(PermissionIndex.service_description)
64
61
  }
@@ -144,9 +141,9 @@ export class CallService extends CallBase {
144
141
 
145
142
  return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
146
143
  }
147
- return this.exec(account);
144
+ return await this.exec(account);
148
145
  }
149
- protected async operate (txb:TransactionBlock, passport?:PassportObject) {
146
+ protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
150
147
  let obj : Service | undefined ; let permission: any; let payee: any;
151
148
 
152
149
  if (!this.data.object) {
@@ -300,16 +297,12 @@ export class CallService extends CallBase {
300
297
  b += BigInt(v.max_price) * BigInt(v.count)
301
298
  })
302
299
  if (b > BigInt(0)) {
303
- if (this.data?.type_parameter === '0x2::sui::SUI' || this.data?.type_parameter === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
304
- coin = txb.splitCoins(txb.gas, [b])[0];
305
- } else if (this.data?.order_new.coin_object) {
306
- coin = txb.splitCoins(this.data.order_new.coin_object, [b])[0];
307
- }
308
- }
309
-
310
- if (coin) {
311
- //@ crypto tools support
312
- obj?.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount, this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport)
300
+ const coin = await Account.Instance().get_coin_object(txb, b, account, this.data.type_parameter);
301
+ if (coin) {
302
+ //@ crypto tools support
303
+ obj?.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount,
304
+ this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport)
305
+ }
313
306
  }
314
307
  }
315
308
  if (this.data?.order_payer !== undefined && obj) {
@@ -331,9 +324,6 @@ export class CallService extends CallBase {
331
324
  if (this.data?.order_withdrawl !== undefined && passport) { //@ need withdrawal passport
332
325
  obj?.withdraw(this.data.order_withdrawl.order, this.data.order_withdrawl.data, passport)
333
326
  }
334
- if (this.data?.permission_new !== undefined) {
335
- obj?.change_permission(this.data.permission_new);
336
- }
337
327
  if (permission) {
338
328
  permission.launch();
339
329
  }
@@ -4,17 +4,17 @@ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIn
4
4
  } from 'wowok';
5
5
  import { query_objects, ObjectTreasury } from '../objects';
6
6
  import { CallBase, CallResult } from "./base";
7
+ import { Account } from '../account';
7
8
 
8
9
  export interface CallTreasury_Data {
9
10
  object?: string; // undefined for creating a new object
10
11
  permission?: string;
11
12
  type_parameter?: string;
12
- permission_new?: string;
13
13
  description?: string;
14
14
  withdraw_mode?: Treasury_WithdrawMode;
15
15
  withdraw_guard?: {op:'add' | 'set'; data:{guard:string, amount:string}[]} | {op:'remove', guards:string[]} | {op:'removeall'};
16
16
  deposit_guard?: string;
17
- deposit?: {data:DepositParam, guard?:string | 'fetch'};
17
+ deposit?: {data:{balance:string|number; index?:number; remark?:string; for_object?:string; for_guard?:string}; guard?:string | 'fetch'};
18
18
  receive?: {payment:string; received_object:string};
19
19
  withdraw?:WithdrawParam;
20
20
  }
@@ -37,9 +37,6 @@ export class CallTreasury extends CallBase {
37
37
  if (!this.data?.object) {
38
38
  perms.push(PermissionIndex.treasury)
39
39
  }
40
- if (this.data?.permission_new !== undefined) {
41
- checkOwner = true;
42
- }
43
40
  if (this.data?.description !== undefined && this.data.object) {
44
41
  perms.push(PermissionIndex.treasury_descritption)
45
42
  }
@@ -100,9 +97,9 @@ export class CallTreasury extends CallBase {
100
97
 
101
98
  return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
102
99
  }
103
- return this.exec(account);
100
+ return await this.exec(account);
104
101
  }
105
- protected async operate (txb:TransactionBlock, passport?:PassportObject) {
102
+ protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
106
103
  let obj : Treasury | undefined ; let permission: any;
107
104
  if (!this.data.object) {
108
105
  if (!this.data?.permission || !IsValidAddress(this.data?.permission)) {
@@ -149,10 +146,14 @@ export class CallTreasury extends CallBase {
149
146
  obj?.receive(this.data.receive.payment, this.data.receive.received_object, passport);
150
147
  }
151
148
  if (this.data.deposit !== undefined) {
152
- obj?.deposit(this.data.deposit.data, passport)
153
- }
154
- if (this.data?.permission_new !== undefined) {
155
- obj?.change_permission(this.data.permission_new);
149
+ const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.data.balance, account, this.data.type_parameter);
150
+ if (coin) {
151
+ const index = this.data.deposit.data?.index ?? 0;
152
+ obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
153
+ for_guard:this.data.deposit.data?.for_guard,
154
+ for_object: this.data.deposit.data?.for_object
155
+ })
156
+ }
156
157
  }
157
158
  if (permission) {
158
159
  permission.launch();
package/src/call.ts CHANGED
@@ -8,19 +8,20 @@
8
8
  import { CallArbitration, CallArbitration_Data } from "./call/arbitration";
9
9
  import { CallDemand, CallDemand_Data } from "./call/demand";
10
10
  import { CallMachine, CallMachine_Data } from "./call/machine";
11
- import { CallPermission, CallPermission_Data } from "./call/permission";
11
+ import { CallEntityPermission, CallEntityPermission_Data } from "./call/entity_permission";
12
12
  import { CallPersonal, CallPersonal_Data } from "./call/personal";
13
13
  import { CallRepository, CallRepository_Data } from "./call/repository";
14
14
  import { CallService, CallService_Data } from "./call/service";
15
15
  import { CallTreasury, CallTreasury_Data } from "./call/treasury";
16
16
  import { CallBase, CallResult, CallWithWitnessParam } from "./call/base";
17
17
  import { CallGuard, CallGuard_Data } from "./call/guard";
18
+ import { CallObjectPermission, CallObjectPermission_Data } from "./call/object_permission";
18
19
 
19
20
 
20
21
  export interface CallObjectData {
21
- type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'Permission';
22
- data: CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallPermission_Data | CallPermission_Data
23
- | CallTreasury_Data | CallService_Data | CallPermission_Data | CallRepository_Data;
22
+ type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'EntityPermission' | 'ObjectPermission';
23
+ data: CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallEntityPermission_Data | CallObjectPermission_Data
24
+ | CallTreasury_Data | CallService_Data | CallRepository_Data;
24
25
  account?: string;
25
26
  witness?: CallWithWitnessParam;
26
27
  }
@@ -64,7 +65,9 @@ function call_object_new (call: CallObjectData) : CallBase | undefined {
64
65
  return new CallRepository(call.data as CallRepository_Data);
65
66
  case 'Personal':
66
67
  return new CallPersonal(call.data as CallPersonal_Data);
67
- case 'Permission':
68
- return new CallPermission(call.data as CallPermission_Data);
68
+ case 'EntityPermission':
69
+ return new CallEntityPermission(call.data as CallEntityPermission_Data);
70
+ case 'ObjectPermission':
71
+ return new CallObjectPermission(call.data as CallObjectPermission_Data);
69
72
  }
70
73
  }
package/src/entity.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { Bcs, Entity, Entity_Info, ERROR, Errors, IsValidAddress, Protocol, TransactionBlock } from "wowok";
2
+ import { CacheName, PERSONAL_RESOURCE_KEY, WowokCache, CachedData} from "./cache";
3
+
4
+ export interface EntityAnswer {
5
+ info?: Entity_Info;
6
+ resource?: string;
7
+ like?: number;
8
+ dislike?: number;
9
+ }
10
+
11
+ export const query_entity_json = async (person_address:string) : Promise<string> => {
12
+ try {
13
+ return JSON.stringify({data:await query_entity(person_address)});
14
+ } catch (e) {
15
+ return JSON.stringify({error:e?.toString()})
16
+ }
17
+ }
18
+
19
+ export const query_entity = async (personal_address:string) : Promise<EntityAnswer | undefined> => {
20
+ if (!IsValidAddress(personal_address)) {
21
+ ERROR(Errors.InvalidParam, 'personal_address - '+personal_address)
22
+ }
23
+
24
+ const cache = WowokCache.Instance().get(CacheName.resource);
25
+
26
+ if (cache) {
27
+ const now = new Date().getTime();
28
+ const data = cache.load(PERSONAL_RESOURCE_KEY(personal_address));
29
+ if (data) {
30
+ const r:CachedData = JSON.parse(data);
31
+ if (r.expire !== 'INFINITE' && r.expire >= now) { //update , INFINITE not supported
32
+ return JSON.parse(r.data) as EntityAnswer
33
+ }
34
+ }
35
+ }
36
+
37
+ const e = await entity(personal_address);
38
+ if (e) {
39
+ if (cache) { // save
40
+ const r:CachedData = {expire:new Date().getTime(), data:JSON.stringify(e)}
41
+ cache.save(PERSONAL_RESOURCE_KEY(personal_address), JSON.stringify(r));
42
+ }
43
+ return e
44
+ }
45
+ }
46
+
47
+ const entity = async (personal_address:string) : Promise<EntityAnswer | undefined> => {
48
+ const txb = new TransactionBlock();
49
+ Entity.From(txb).query_ent(personal_address);
50
+
51
+ const res = await Protocol.Client().devInspectTransactionBlock({sender:personal_address, transactionBlock:txb});
52
+ if (res.results?.length === 1 && res.results[0].returnValues?.length === 1 ) {
53
+ const r = Bcs.getInstance().de_ent(Uint8Array.from(res.results[0].returnValues[0][0]));
54
+ const info = Bcs.getInstance().de_entInfo(Uint8Array.from(r?.avatar));
55
+ const d : EntityAnswer = {resource:r?.resource?.some, like:r?.like, dislike:r?.dislike, info: {
56
+ avatar:info.avatar, name:info.name, twitter:info.twitter, discord:info.discord, homepage:info.homepage, description:info.description
57
+ }};
58
+ return d;
59
+ }
60
+ }
package/src/index.ts CHANGED
@@ -3,10 +3,10 @@ export * from './permission'
3
3
  export * from './events'
4
4
  export * from './cache'
5
5
  export * from './call/base'
6
- export * from './call/permission'
6
+ export * from './call/entity_permission'
7
7
  export * from './call/arbitration'
8
8
  export * from './call/treasury'
9
- export * from './call/permission'
9
+ export * from './call/entity_permission'
10
10
  export * from './call/demand'
11
11
  export * from './call/machine'
12
12
  export * from './call/repository'
package/src/objects.ts CHANGED
@@ -5,20 +5,21 @@
5
5
 
6
6
  import { Protocol, Machine_Node, Machine, Treasury_WithdrawMode, Treasury_Operation,
7
7
  Repository_Type, Repository_Policy_Mode, Repository_Policy, Service_Discount_Type, Service_Sale,
8
- Progress, History, ERROR, Errors, IsValidAddress, Bcs,
8
+ Progress, History, ERROR, Errors, IsValidAddress, Bcs,
9
+ Entity_Info, Tags
9
10
  } from 'wowok';
10
- import {WowokCache, OBJECT_KEY} from './cache'
11
+ import {WowokCache, OBJECT_KEY, CacheExpire, CacheName, CachedData} from './cache'
11
12
 
12
13
  export interface ObjectBase {
13
14
  object: string;
14
15
  type?: string | 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' |
15
- 'Entity' | 'Permission' | 'Resource' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
16
+ 'Entity' | 'Permission' | 'Mark' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
16
17
  'TableItem_DemandPresenter' | 'TableItem_MachineNode' | 'TableItem_ServiceSale' | 'TableItem_TreasuryHistory' | 'TableItem_ArbVote' |
17
- 'TableItem_RepositoryData' | 'TableItem_ResourceMark';
18
+ 'TableItem_RepositoryData' | 'TableItem_MarkGroup' | 'TableItem_MarkTag';
18
19
  type_raw?: string;
19
20
  owner?: any;
20
21
  version?: string;
21
- cache_expire?: number | 'INFINITE';
22
+ cache_expire?: CacheExpire;
22
23
  }
23
24
 
24
25
  export interface ObjectPermission extends ObjectBase {
@@ -220,32 +221,22 @@ export interface ObjectEntity extends ObjectBase {
220
221
  address: string;
221
222
  like: number;
222
223
  dislike: number;
223
-
224
- name?: string;
225
- description?: string;
226
- avatar?: string;
227
- x?: string;
228
- discord?: string;
229
-
230
- homepage?: string;
224
+ info: Entity_Info;
231
225
  resource_object?: string | null;
232
226
  lastActive_digest?: string;
233
227
  }
234
228
 
235
- export interface ObjectResouorce_Tag {
236
- object: string;
237
- nick_name: string;
238
- tags: string[];
229
+ export interface ObjectMark extends ObjectBase {
230
+ group_count: number;
231
+ tag_count: number;
239
232
  }
240
233
 
241
- export interface ObjectResouorce extends ObjectBase {
242
- marks_count: number;
243
- tags: ObjectResouorce_Tag[];
234
+ export interface TableItem_MarkGroup extends ObjectBase {
235
+ group_name: string;
236
+ address: string[];
244
237
  }
245
238
 
246
- export interface TableItem_ResourceMark extends ObjectBase {
247
- mark_name: string;
248
- objects: string[];
239
+ export interface TableItem_MarkTag extends ObjectBase, Tags {
249
240
  }
250
241
 
251
242
  export enum CacheType {
@@ -287,11 +278,6 @@ interface TableItemQuery {
287
278
  key: {type:string, value:unknown};
288
279
  }
289
280
 
290
- export interface CachedData {
291
- expire: number | 'INFINITE';
292
- data: string | any;
293
- }
294
-
295
281
  /* json: ObjectsQuery string */
296
282
  export const query_objects_json = async (json:string) : Promise<string> => {
297
283
  try {
@@ -314,8 +300,8 @@ export const query_table_json = async (json:string) : Promise<string> => {
314
300
 
315
301
  export const query_objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer> => {
316
302
  var ret:ObjectBase[] = []; const pending : string[] = [];
317
- let bCached = true; const time = new Date().getTime();
318
- const cache = WowokCache.Instance().get();
303
+ const time = new Date().getTime();
304
+ const cache = WowokCache.Instance().get(CacheName.object);
319
305
  if (cache) {
320
306
  for (let i = 0; i < query.objects.length; ++i) {
321
307
  try {
@@ -342,10 +328,10 @@ export const query_objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer
342
328
  if (pending.length > 0) {
343
329
  const res = await Protocol.Client().multiGetObjects({ids:[...pending],
344
330
  options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
345
- const now = new Date().getTime();
346
- const cache = WowokCache.Instance().get();
331
+ const cache = WowokCache.Instance().get(CacheName.object);
347
332
 
348
333
  if (cache) {
334
+ const now = new Date().getTime();
349
335
  res.forEach((i) => { // save
350
336
  try {
351
337
  if (i?.data) {
@@ -363,7 +349,7 @@ export const query_objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer
363
349
  return {objects:ret}
364
350
  }
365
351
 
366
- export const query_entity = async (address:string) : Promise<ObjectEntity> => {
352
+ export const queryTableItem_Personal = async (address:string) : Promise<ObjectEntity> => {
367
353
  if (!IsValidAddress(address)) ERROR(Errors.IsValidAddress, 'entity.address')
368
354
  const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().objectEntity(), name:{type:'address', value:address}});
369
355
  return data2object(res?.data) as ObjectEntity
@@ -405,7 +391,7 @@ export const tableItemQuery_RepositoryData = async (repository_object:string | O
405
391
  }
406
392
  return await tableItem({parent:repository_object, key:{type:Protocol.Instance().package('wowok')+'::repository::DataKey', value:{id:address, key:name}}})
407
393
  }
408
- export const tableItemQuery_ResourceMark = async (resource_object:string | ObjectResouorce, name:string) : Promise<ObjectBase> => {
394
+ export const tableItemQuery_ResourceGroup = async (resource_object:string | ObjectMark, name:string) : Promise<ObjectBase> => {
409
395
  return await tableItem(tableItemQuery_byString(resource_object, name))
410
396
  }
411
397
 
@@ -415,7 +401,7 @@ function tableItemQuery_byAddress(parent:string | ObjectDemand | ObjectPermissio
415
401
  }
416
402
  return {parent:parent, key:{type:'address', value:address}};
417
403
  }
418
- function tableItemQuery_byString(parent:string | ObjectMachine | ObjectService | ObjectResouorce, name:string) : TableItemQuery {
404
+ function tableItemQuery_byString(parent:string | ObjectMachine | ObjectService | ObjectMark, name:string) : TableItemQuery {
419
405
  if (typeof(parent) !== 'string') {
420
406
  parent = parent.object;
421
407
  }
@@ -581,11 +567,9 @@ export function data2object(data?:any) : ObjectBase {
581
567
  case 'Resource' :
582
568
  return {
583
569
  object:id, type:type, type_raw:type_raw, owner:owner, version:version,
584
- marks_count:parseInt(content?.marks?.fields?.size),
585
- tags:content?.tags?.map((v:any) => {
586
- return {object:v?.fields?.object, nick_name:v?.fields?.nick, tags:v?.fields?.tags}
587
- })
588
- } as ObjectResouorce;
570
+ group_count:parseInt(content?.marks?.fields?.size),
571
+ tag_count:parseInt(content?.tags?.fields?.size)
572
+ } as ObjectMark;
589
573
  }
590
574
  }
591
575
 
@@ -644,15 +628,19 @@ export function data2object(data?:any) : ObjectBase {
644
628
  return {
645
629
  object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
646
630
  address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
647
- resource_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
648
- homepage:info?.homepage, name:info?.name, avatar:info?.avatar, x:info?.twitter, discord:info?.discord,
649
- description:info?.description
631
+ resource_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
632
+ info : {homepage:info?.homepage, name:info?.name, avatar:info?.avatar, twitter:info?.twitter, discord:info?.discord,
633
+ description:info?.description}
650
634
  } as ObjectEntity;
651
635
  } else if (end.includes('::resource::Addresses>')) {
652
636
  return {
653
- object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
654
- mark_name:content?.name, objects:content?.value?.fields?.addresses
655
- } as TableItem_ResourceMark;
637
+ object:id, type:'TableItem_MarkGroup', type_raw:type_raw, owner:owner, version:version,
638
+ group_name:content?.name, address:content?.value?.fields?.addresses
639
+ } as TableItem_MarkGroup;
640
+ } else if (end.includes('::resource::Tags>')) {
641
+ return {object:id, type:'TableItem_MarkTag', type_raw:type_raw, owner:owner, version:version,
642
+ address:content?.name, nick:content?.value?.fields?.nick, tags:content?.value?.fields?.tags
643
+ } as TableItem_MarkTag;
656
644
  }
657
645
  }
658
646
  }
package/src/permission.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { TransactionBlock, } from 'wowok';
7
- import { Protocol, Bcs, IsValidAddress, Errors, ERROR, Permission, PermissionAnswerItem, PermissionAnswer, BCS} from 'wowok';
7
+ import { Protocol, Bcs, IsValidAddress, Errors, ERROR, Permission, PermissionAnswer, BCS} from 'wowok';
8
8
 
9
9
 
10
10
  export interface PermissionQuery {