wowok_agent 0.1.7 → 0.1.9

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.7",
3
+ "version": "0.1.9",
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
@@ -240,6 +240,7 @@ export class Account {
240
240
 
241
241
  if (addr && b > BigInt(0)) {
242
242
  if (!token_type || token_type === '0x2::sui::SUI' || token_type === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
243
+ console.log(1)
243
244
  return txb.splitCoins(txb.gas, [balance_required]);
244
245
  } else {
245
246
  const r = await Protocol.Client().getCoins({owner: addr, coinType:token_type});
@@ -1,4 +1,4 @@
1
- import { TransactionBlock, IsValidArgType, } from 'wowok';
1
+ import { TransactionBlock, IsValidArgType, Resource, ResourceObject, } 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';
@@ -118,11 +118,12 @@ export class CallArbitration extends CallBase {
118
118
  }
119
119
  if (!treasury_address || !IsValidAddress(treasury_address)) {
120
120
  const d = (this.data?.fee_treasury as any)?.description ?? '';
121
- withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ?? permission_address, d, permission?undefined:passport);
121
+ withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
122
+ d, permission?undefined:passport);
122
123
  }
123
124
 
124
- obj = Arbitration.New(txb, this.data.type_parameter!, permission ?? permission_address, this.data?.description??'',
125
- BigInt(this.data?.fee ?? 0), withdraw_treasury??treasury_address, permission?undefined:passport);
125
+ obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
126
+ BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
126
127
  } else if (object_address) {
127
128
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
128
129
  obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
package/src/call/base.ts CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { Protocol, TransactionBlock, CallResponse, Guard, TransactionArgument, Entity, IsValidAddress, Resource, TxbObject, TransactionResult, TxbAddress, array_unique, TagName} from 'wowok';
3
+ import { Protocol, TransactionBlock, CallResponse, Guard, TransactionArgument, Entity, IsValidAddress, Resource, TxbObject, TransactionResult, TxbAddress, array_unique, TagName, ResourceObject} from 'wowok';
4
4
  import { PassportObject, Errors, ERROR, Permission,
5
5
  PermissionIndexType, GuardParser, Passport, WitnessFill
6
6
  } from 'wowok';
@@ -46,21 +46,9 @@ export function ResponseData(response: CallResponse | undefined) : ResponseData[
46
46
  return res;
47
47
  }
48
48
 
49
- export const mark_address = async (txb:TransactionBlock, mark:AddressMark, account?:string) => {
50
- const addr = Account.Instance().get_address(account);
51
- if (addr) {
52
- const r = await queryTableItem_Personal({address:addr}); //@ use cache
53
- const resource = r?.mark_object ? Resource.From(txb, r.mark_object) : Resource.From(txb, Entity.From(txb).create_resource2());
54
- resource.add(mark.address, mark.tags, mark.name);
55
- if (!r?.mark_object) {
56
- resource.launch(); // launch new
57
- }
58
- } else {
59
- ERROR(Errors.InvalidParam, 'account - ' + account)
60
- }
61
- }
62
49
  export class CallBase {
63
50
  // operation implementation for a call
51
+ resouceObject:ResourceObject | undefined;
64
52
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
65
53
  constructor () {}
66
54
  // return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
@@ -70,22 +58,16 @@ export class CallBase {
70
58
  async call_with_witness (param: CallWithWitnessParam) : Promise<CallResponse | undefined> {
71
59
  if (param.info.guard.length > 0) { // prepare passport
72
60
  const p: GuardParser | undefined = await GuardParser.Create([...param.info.guard]);
73
- const pair = Account.Instance().get_pair(param.account, true);
74
- if (!pair) ERROR(Errors.Fail, 'account invalid')
75
61
 
76
62
  if (p) {
77
63
  const query = await p.done(param.info.witness);
78
64
  if (query) {
79
65
  const txb = new TransactionBlock();
80
66
  const passport = new Passport(txb, query!);
81
- this.operate(new TransactionBlock(), passport?.get_object(), param?.account)
67
+ await this.operate(new TransactionBlock(), passport?.get_object(), param?.account)
82
68
  passport.destroy();
83
-
84
- return await Protocol.Client().signAndExecuteTransaction({
85
- transaction: txb,
86
- signer: pair!,
87
- options:{showObjectChanges:true},
88
- });
69
+
70
+ return await this.sign_and_commit(txb, param.account);
89
71
  }
90
72
  } else {
91
73
  ERROR(Errors.Fail, 'guard finish_passport')
@@ -96,11 +78,12 @@ export class CallBase {
96
78
  protected async check_permission_and_call (permission:string, permIndex: PermissionIndexType[], guards_needed: string[],
97
79
  checkOwner?:boolean, checkAdmin?:boolean, account?:string) : Promise<CallResult> {
98
80
  var guards : string[] = [];
99
- const pair = Account.Instance().get_pair(account, true);
100
- if (!pair) ERROR(Errors.Fail, 'account invalid')
101
81
 
102
82
  if (permIndex.length > 0 || checkOwner) {
103
- const p = await query_permission({permission_object:permission, address:pair!.toSuiAddress()});
83
+ const addr = Account.Instance().get_address(account);
84
+ if (!addr) ERROR(Errors.InvalidParam, 'check_permission_and_call: account invalid');
85
+
86
+ const p = await query_permission({permission_object:permission, address:addr!});
104
87
  if (checkOwner && !p.owner) ERROR(Errors.noPermission, 'owner');
105
88
  if (checkAdmin && !p.admin) ERROR(Errors.noPermission, 'admin');
106
89
 
@@ -125,14 +108,10 @@ export class CallBase {
125
108
  if (query) {
126
109
  const txb = new TransactionBlock();
127
110
  const passport = new Passport(txb, query!);
128
- this.operate(new TransactionBlock(), passport?.get_object(), account)
111
+ await this.operate(new TransactionBlock(), passport?.get_object(), account)
129
112
  passport.destroy();
130
-
131
- return await Protocol.Client().signAndExecuteTransaction({
132
- transaction: txb,
133
- signer: pair!,
134
- options:{showObjectChanges:true},
135
- });
113
+
114
+ return await this.sign_and_commit(txb, account);
136
115
  }
137
116
  }
138
117
 
@@ -142,20 +121,48 @@ export class CallBase {
142
121
  }
143
122
  }
144
123
  protected async exec (account?:string) : Promise<CallResponse> {
124
+ const txb = new TransactionBlock();
125
+ await this.operate(txb, undefined, account);
126
+ return await this.sign_and_commit(txb, account);
127
+ }
128
+
129
+ protected async new_with_mark(txb:TransactionBlock, object:TxbAddress, named_new?:Namedbject, account?:string, innerTags:string[]=[TagName.Launch]) {
130
+ const tags = named_new?.tags ? array_unique([...named_new.tags, ...innerTags]) : array_unique([...innerTags]);
131
+
132
+ if (!this.resouceObject) {
133
+ const addr = Account.Instance().get_address(account);
134
+ if (addr) {
135
+ const r = await queryTableItem_Personal({address:addr}); //@ use cache
136
+ if (!r?.mark_object) {
137
+ this.resouceObject = Entity.From(txb).create_resource2(); // new
138
+ } else {
139
+ Resource.From(txb, r.mark_object).add(object, tags, named_new?.name);
140
+ return
141
+ }
142
+ } else {
143
+ ERROR(Errors.InvalidParam, 'account - ' + account)
144
+ }
145
+ }
146
+ if (this.resouceObject) {
147
+ Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
148
+ } else {
149
+ ERROR(Errors.Fail, 'invalid personal mark')
150
+ }
151
+ }
152
+
153
+ protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
145
154
  const pair = Account.Instance().get_pair(account, true);
146
155
  if (!pair) ERROR(Errors.Fail, 'account invalid')
147
156
 
148
- const txb = new TransactionBlock();
149
- this.operate(txb, undefined, account);
157
+ if (this.resouceObject) {
158
+ Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
159
+ this.resouceObject = undefined;
160
+ }
161
+
150
162
  return await Protocol.Client().signAndExecuteTransaction({
151
163
  transaction: txb,
152
164
  signer: pair!,
153
165
  options:{showObjectChanges:true},
154
166
  });
155
167
  }
156
-
157
- protected new_with_mark(txb:TransactionBlock, object:TxbAddress, named_new?:Namedbject, account?:string, innerTags:string[]=[TagName.Launch]) {
158
- const tags = named_new?.tags ? array_unique([...named_new.tags, ...innerTags]) : array_unique([...innerTags]);
159
- mark_address(txb, {address:object, name:named_new?.name, tags:tags}, account)
160
- }
161
168
  }
@@ -1,4 +1,4 @@
1
- import { TransactionBlock, IsValidArgType, IsValidCoinType } from 'wowok';
1
+ import { TransactionBlock, IsValidArgType, IsValidCoinType, Resource, ResourceObject } from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
3
  PermissionIndexType, Demand, } from 'wowok';
4
4
  import { query_objects, ObjectDemand } from '../objects';
@@ -1,5 +1,5 @@
1
1
  import { CallBase, CallResult, Namedbject } from "./base";
2
- import { TransactionBlock, CallResponse} from 'wowok';
2
+ import { TransactionBlock, CallResponse, Resource, ResourceObject} from 'wowok';
3
3
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
4
4
  PermissionIndexType, WitnessFill
5
5
  } from 'wowok';
package/src/call/guard.ts CHANGED
@@ -5,7 +5,10 @@
5
5
 
6
6
  import { Bcs, ContextType, ERROR, Errors, IsValidU8, OperatorType, ValueType, GUARD_QUERIES, IsValidAddress,
7
7
  concatenate, TransactionBlock, Protocol, FnCallType, hasDuplicates, insertAtHead, CallResponse,
8
- IsValidDesription} from "wowok";
8
+ IsValidDesription,
9
+ Resource,
10
+ ResourceObject,
11
+ PassportObject} from "wowok";
9
12
  import { Account } from "../account";
10
13
  import { CallBase, CallResult, Namedbject } from "./base";
11
14
 
@@ -32,7 +35,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
32
35
  export interface CallGuard_Data {
33
36
  namedNew?: Namedbject;
34
37
  description: string;
35
- table: GuardConst[]; // data used by multiple logical guard nodes
38
+ table?: GuardConst[]; // data used by multiple logical guard nodes
36
39
  root: GuardNode; // root must return ValueType.TYPE_BOOL
37
40
  }
38
41
  export class CallGuard extends CallBase {
@@ -42,6 +45,10 @@ export class CallGuard extends CallBase {
42
45
  this.data = data;
43
46
  }
44
47
  async call(account?:string) : Promise<CallResult> {
48
+ return await this.exec(account)
49
+ }
50
+
51
+ protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
45
52
  if (!this.data?.root) {
46
53
  ERROR(Errors.InvalidParam, 'guard root node invalid')
47
54
  }
@@ -50,26 +57,25 @@ export class CallGuard extends CallBase {
50
57
  }
51
58
 
52
59
  // check const
53
- this.data.table.forEach(v => {
60
+ this.data?.table?.forEach(v => {
54
61
  if (!IsValidU8(v.identifier) || v.identifier < 1) ERROR(Errors.InvalidParam, 'table.identifer invalid');
55
62
  if (!v.bWitness && v.value === undefined) ERROR(Errors.InvalidParam, 'table.value');
56
63
  })
57
64
 
58
- if (hasDuplicates(this.data.table.map(v => v.identifier))) {
65
+ if (this.data?.table && hasDuplicates(this.data?.table?.map(v => v.identifier))) {
59
66
  ERROR(Errors.InvalidParam, 'table.identifer duplicates')
60
67
  }
61
68
 
62
69
  // check root
63
70
  var output : Uint8Array[]= [];
64
- buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data.table, output);
71
+ buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data?.table ?? [], output);
65
72
  const bytes = (concatenate(Uint8Array, ...output) as Uint8Array);
66
- const txb = new TransactionBlock();
67
73
 
68
74
  const obj = txb.moveCall({
69
75
  target: Protocol.Instance().guardFn('new') as FnCallType,
70
76
  arguments: [txb.pure.string(this.data.description), txb.pure.vector('u8', [].slice.call(bytes.reverse()))],
71
77
  });
72
- this.data.table.forEach((v) => {
78
+ this.data?.table?.forEach((v) => {
73
79
  if (v.bWitness) {
74
80
  const n = new Uint8Array(1); n.set([v.value_type], 0);
75
81
  txb.moveCall({
@@ -90,15 +96,6 @@ export class CallGuard extends CallBase {
90
96
  arguments:[txb.object(obj)]
91
97
  });
92
98
  this.new_with_mark(txb, addr, this.data?.namedNew, account);
93
-
94
- const pair = Account.Instance().get_pair(account, true);
95
- if (!pair) ERROR(Errors.Fail, 'account invalid')
96
-
97
- return await Protocol.Client().signAndExecuteTransaction({
98
- transaction: txb,
99
- signer: pair!,
100
- options:{showObjectChanges:true},
101
- });
102
99
  }
103
100
  }
104
101
 
@@ -1,6 +1,8 @@
1
1
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock,
2
2
  PermissionIndexType, Machine, Machine_Forward, Machine_Node, Deliverable, ParentProgress, Progress, ProgressNext,
3
3
  TxbAddress,
4
+ Resource,
5
+ ResourceObject,
4
6
  } from 'wowok';
5
7
  import { CallBase, CallResult, Namedbject } from "./base";
6
8
  import { Account } from '../account';
@@ -112,7 +114,7 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
112
114
  const d = (this.data?.permission as any)?.description ?? '';
113
115
  permission = Permission.New(txb, d);
114
116
  }
115
- obj = Machine.New(txb, permission ?? permission_address, this.data?.description??'', this.data?.endpoint ?? '', permission?undefined:passport);
117
+ obj = Machine.New(txb, permission ? permission.get_object() : permission_address, this.data?.description??'', this.data?.endpoint ?? '', permission?undefined:passport);
116
118
  } else {
117
119
  if (IsValidAddress(object_address) &&permission_address && IsValidAddress(permission_address)) {
118
120
  obj = Machine.From(txb, permission_address, object_address)
@@ -1,4 +1,4 @@
1
- import { TransactionBlock } from 'wowok';
1
+ import { ResourceObject, TransactionBlock } from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Entity, Entity_Info, TagName, Resource} from 'wowok';
3
3
  import { CallBase, CallResult, Namedbject } from "./base";
4
4
 
@@ -1,4 +1,4 @@
1
- import { TransactionBlock, CallResponse} from 'wowok';
1
+ import { TransactionBlock, CallResponse, Resource, ResourceObject} from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, PermissionIndexType, Repository,
3
3
  Repository_Policy, Repository_Policy_Data, Repository_Policy_Data2, Repository_Policy_Data_Remove,
4
4
  Repository_Policy_Mode, WitnessFill
@@ -59,7 +59,7 @@ export class CallRepository extends CallBase {
59
59
  permission = Permission.New(txb, d);
60
60
  }
61
61
 
62
- obj = Repository.New(txb, permission ?? permission_address, this.data?.description??'', this.data?.mode, permission?undefined:passport)
62
+ obj = Repository.New(txb, permission ? permission.get_object() : permission_address, this.data?.description??'', this.data?.mode, permission?undefined:passport)
63
63
  } else {
64
64
  if (IsValidAddress(object_address) && this.data.permission && IsValidAddress(permission_address)) {
65
65
  obj = Repository.From(txb, permission_address, object_address)
@@ -70,9 +70,6 @@ export class CallRepository extends CallBase {
70
70
  if (this.data?.description !== undefined && object_address) {
71
71
  obj?.set_description(this.data.description, passport);
72
72
  }
73
- if (this.data?.mode !== undefined && object_address) { //@ priority??
74
- obj?.set_policy_mode(this.data.mode, passport)
75
- }
76
73
  if (this.data?.reference !== undefined) {
77
74
  switch (this.data.reference.op) {
78
75
  case 'set':
@@ -126,6 +123,9 @@ export class CallRepository extends CallBase {
126
123
  break;
127
124
  }
128
125
  }
126
+ if (this.data?.mode !== undefined && object_address) { //@ priority??
127
+ obj?.set_policy_mode(this.data.mode, passport)
128
+ }
129
129
  if (permission) {
130
130
  this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
131
131
  }
@@ -1,4 +1,4 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType, TxbAddress, TagName} from 'wowok';
1
+ import { TransactionBlock, CallResponse, IsValidArgType, TxbAddress, TagName, Resource, ResourceObject} from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
3
  PermissionIndexType, BuyRequiredEnum, Customer_RequiredInfo, DicountDispatch, Service, Service_Buy,
4
4
  Service_Guard_Percent, Service_Sale, WithdrawPayee, Treasury, WitnessFill
@@ -95,7 +95,7 @@ export class CallService extends CallBase {
95
95
  if (this.data?.machine !== undefined) {
96
96
  perms.push(PermissionIndex.service_machine)
97
97
  }
98
- if (this.data?.payee_treasury !== undefined && object_address) {
98
+ if (treasury_address !== undefined && object_address) {
99
99
  perms.push(PermissionIndex.service_payee)
100
100
  }
101
101
  if (this.data?.withdraw_guard !== undefined) {
@@ -161,7 +161,8 @@ export class CallService extends CallBase {
161
161
  const d = (this.data?.payee_treasury as any)?.description ?? '';
162
162
  payee = Treasury.New(txb, this.data?.type_parameter!, permission ?? permission_address, d, permission?undefined:passport);
163
163
  }
164
- obj = Service.New(txb, this.data.type_parameter!, permission??permission_address, this.data?.description??'', payee??treasury_address, permission?undefined:passport)
164
+ obj = Service.New(txb, this.data.type_parameter!, permission?permission.get_object():permission_address,
165
+ this.data?.description??'', payee?payee.get_object():treasury_address, permission?undefined:passport)
165
166
  } else {
166
167
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
167
168
  obj = Service.From(txb, this.data.type_parameter, permission_address, object_address)
@@ -1,4 +1,4 @@
1
- import { TransactionBlock, CallResponse, IsValidArgType} from 'wowok';
1
+ import { TransactionBlock, CallResponse, IsValidArgType, Resource, ResourceObject} from 'wowok';
2
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
3
3
  PermissionIndexType, DepositParam, Treasury, Treasury_WithdrawMode, WithdrawParam, WitnessFill
4
4
  } from 'wowok';
@@ -96,7 +96,6 @@ export class CallTreasury extends CallBase {
96
96
  } else {
97
97
  perms.push(PermissionIndex.treasury_withdraw)
98
98
  }
99
-
100
99
  return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
101
100
  }
102
101
  return await this.exec(account);
@@ -111,7 +110,7 @@ export class CallTreasury extends CallBase {
111
110
  const d = (this.data?.permission as any)?.description ?? '';
112
111
  permission = Permission.New(txb, d);
113
112
  }
114
- obj = Treasury.New(txb, this.data.type_parameter!, permission ?? permission_address, this.data?.description??'', permission?undefined:passport)
113
+ obj = Treasury.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'', permission?undefined:passport)
115
114
  } else {
116
115
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
117
116
  obj = Treasury.From(txb, this.data.type_parameter, permission_address, object_address)
@@ -162,11 +161,11 @@ export class CallTreasury extends CallBase {
162
161
  }
163
162
  }
164
163
  if (permission) {
165
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
164
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
166
165
  }
167
166
 
168
167
  if (!object_address) {
169
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
168
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
170
169
  }
171
170
  }
172
171
  }
package/src/call.ts CHANGED
@@ -1,8 +1,7 @@
1
1
 
2
2
  /**
3
3
  * Provide a this interface for AI
4
- * Operation sequence Priority: common operation > Guard change > permission change
5
- * Recommended: Changes to guard and permission are committed on-chain separately to avoid permission dependencies for other operations.
4
+ * Restrictive prioritization, such as setting a deposit first and setting a deposit guard later (only subsequent deposits are affected).
6
5
  */
7
6
 
8
7
  import { CallArbitration, CallArbitration_Data } from "./call/arbitration";
package/src/objects.ts CHANGED
@@ -12,8 +12,8 @@ import {WowokCache, OBJECT_KEY, CacheExpire, CacheName, CachedData} from './cach
12
12
 
13
13
  export interface ObjectBase {
14
14
  object: string;
15
- type?: string | 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' |
16
- 'Personal' | 'Permission' | 'Mark' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
15
+ type?: string | 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' | 'Discount' |
16
+ 'Personal' | 'EntityPermission' | 'PersonalMark' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
17
17
  'TableItem_DemandPresenter' | 'TableItem_MachineNode' | 'TableItem_ServiceSale' | 'TableItem_TreasuryHistory' | 'TableItem_ArbVote' |
18
18
  'TableItem_RepositoryData' | 'TableItem_PersonalMark';
19
19
  type_raw?: string;
@@ -230,7 +230,7 @@ export interface ObjectMark extends ObjectBase {
230
230
  tag_count: number;
231
231
  }
232
232
 
233
- export interface TableItem_MarkTag extends ObjectBase, Tags {
233
+ export interface TableItem_PersonalMark extends ObjectBase, Tags {
234
234
  }
235
235
 
236
236
  export enum CacheType {
@@ -298,10 +298,10 @@ export const query_table_json = async (json:string) : Promise<string> => {
298
298
  }
299
299
 
300
300
  // query personal information; json: ObjectsAnswer; return ObjectPersonal | undefined .
301
- export const query_personal = async (json:string) : Promise<string> => {
301
+ export const query_personal_json = async (json:string) : Promise<string> => {
302
302
  try {
303
303
  const q : PersonalQuery = JSON.parse(json);
304
- return JSON.stringify({data:(await queryTableItem_Personal(q)) ?? ''});
304
+ return JSON.stringify({data:(await queryTableItem_Personal(q) ?? '')});
305
305
  } catch (e) {
306
306
  return JSON.stringify({error:e?.toString()})
307
307
  }
@@ -362,35 +362,34 @@ export const queryTableItem_Personal = async (query:PersonalQuery) : Promise<Obj
362
362
  if (!IsValidAddress(query.address)) ERROR(Errors.IsValidAddress, 'entity.address')
363
363
  const time = new Date().getTime();
364
364
  const cache = WowokCache.Instance().get(CacheName.personal);
365
+
365
366
  if (cache && !query.no_cache) {
366
367
  try {
367
368
  let data = cache.load(OBJECT_KEY(query.address, CacheName.personal))
368
369
 
369
370
  if (data) {
370
371
  const r:CachedData = JSON.parse(data);
371
-
372
372
  if (r?.expire === 'INFINITE' || r.expire <= time) {
373
- const d = data2object(JSON.parse(r.data));
374
- d.cache_expire = r.expire;
375
- return d as ObjectPersonal;
373
+ const d = JSON.parse(r.data) as ObjectPersonal;
374
+ d.cache_expire = r.expire;
375
+ return d;
376
376
  }
377
377
  }
378
378
  } catch (e) {
379
379
  console.log(e)
380
380
  }
381
381
  }
382
- const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().objectEntity(), name:{type:'address', value:query.address}});
383
- if (res?.data) {
384
- const ret = data2object(res?.data) as ObjectPersonal;
382
+ const res = await tableItem(tableItemQuery_byAddress(Protocol.Instance().objectEntity(), query.address));
383
+ if (res.type === 'Personal') {
385
384
  if (cache) {
386
385
  try {
387
386
  const expire = cache.expire_time()+((new Date()).getTime()); // guard & payment immutable
388
- const r:CachedData = {expire:expire, data:JSON.stringify(res.data)}
387
+ const r:CachedData = {expire:expire, data:JSON.stringify(res)}
389
388
  cache.save(OBJECT_KEY(query.address, CacheName.personal), JSON.stringify(r));
390
- ret.cache_expire = expire;
389
+ res.cache_expire = expire;
391
390
  } catch(e) { console.log(e)}
392
391
  }
393
- return ret
392
+ return res as ObjectPersonal;
394
393
  }
395
394
  }
396
395
 
@@ -468,7 +467,7 @@ export function data2object(data?:any) : ObjectBase {
468
467
  if (type) {
469
468
  switch(type) {
470
469
  case 'Permission':
471
- return {object:id, type:type, type_raw:type_raw, owner:owner, version:version,
470
+ return {object:id, type:'EntityPermission', type_raw:type_raw, owner:owner, version:version,
472
471
  builder: content?.builder ??'', admin:content?.admin, description:content?.description??'',
473
472
  entity_count: parseInt(content?.table?.fields?.size),
474
473
  biz_permission:content?.user_define?.fields?.contents?.map((v:any) => {
@@ -605,7 +604,7 @@ export function data2object(data?:any) : ObjectBase {
605
604
  } as ObjectGuard;
606
605
  case 'Resource' :
607
606
  return {
608
- object:id, type:type, type_raw:type_raw, owner:owner, version:version,
607
+ object:id, type:'PersonalMark', type_raw:type_raw, owner:owner, version:version,
609
608
  tag_count:parseInt(content?.tags?.fields?.size)
610
609
  } as ObjectMark;
611
610
  }
@@ -617,35 +616,35 @@ export function data2object(data?:any) : ObjectBase {
617
616
  if(end && Protocol.Instance().hasPackage(end)) {
618
617
  if (end.includes('::demand::Tips>')) {
619
618
  return {
620
- object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
619
+ object:id, type:'TableItem_DemandPresenter', type_raw:type_raw, owner:owner, version:version,
621
620
  service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
622
621
  } as TableItem_DemandPresenter;
623
622
  } else if (end.includes('::machine::NodePair>>>')) {
624
623
  return {
625
- object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
624
+ object:id, type:'TableItem_MachineNode', type_raw:type_raw, owner:owner, version:version,
626
625
  node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
627
626
  } as TableItem_MachineNode;
628
627
  } else if (end.includes('::progress::History>')) {
629
628
  return {
630
- object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
629
+ object:id, type:'TableItem_ProgressHistory', type_raw:type_raw, owner:owner, version:version,
631
630
  history:Progress.DeHistory(content)
632
631
  } as TableItem_ProgressHistory;
633
632
  } else if (end.includes('::service::Sale>')) {
634
633
  return {
635
- object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
634
+ object:id, type:'TableItem_ServiceSale', type_raw:type_raw, owner:owner, version:version,
636
635
  item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
637
636
  endpoint:content?.value?.fields?.endpoint
638
637
  }
639
638
  } as TableItem_ServiceSale;
640
639
  } else if (end.includes('::treasury::Record>')) {
641
640
  return {
642
- object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
641
+ object:id, type:'TableItem_TreasuryHistory', type_raw:type_raw, owner:owner, version:version,
643
642
  id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
644
643
  operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
645
644
  } as TableItem_TreasuryHistory;
646
645
  } else if (end.includes('::arb::Voted>')) {
647
646
  return {
648
- object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
647
+ object:id, type:'TableItem_ArbVote', type_raw:type_raw, owner:owner, version:version,
649
648
  singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
650
649
  weight:content?.value?.fields?.weight
651
650
  } as TableItem_ArbVote;
@@ -664,16 +663,16 @@ export function data2object(data?:any) : ObjectBase {
664
663
  } else if (end.includes('::entity::Ent>')) {
665
664
  const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
666
665
  return {
667
- object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
666
+ object:id, type:'Personal', type_raw:type_raw, owner:owner, version:version,
668
667
  address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
669
668
  mark_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
670
669
  info : {homepage:info?.homepage, name:info?.name, avatar:info?.avatar, twitter:info?.twitter, discord:info?.discord,
671
670
  description:info?.description}
672
671
  } as ObjectPersonal;
673
672
  } else if (end.includes('::resource::Tags>')) {
674
- return {object:id, type:'TableItem_MarkTag', type_raw:type_raw, owner:owner, version:version,
673
+ return {object:id, type:'TableItem_PersonalMark', type_raw:type_raw, owner:owner, version:version,
675
674
  address:content?.name, name:content?.value?.fields?.nick, tags:content?.value?.fields?.tags
676
- } as TableItem_MarkTag;
675
+ } as TableItem_PersonalMark;
677
676
  }
678
677
  }
679
678
  }