wowok_agent 0.1.7 → 0.1.11

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.11",
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",
@@ -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';
@@ -9,7 +9,7 @@ export interface CallArbitration_Data {
9
9
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
10
10
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
11
11
  mark?:AddressMark;
12
- type_parameter?: string;
12
+ type_parameter: string;
13
13
  permission_new?: string;
14
14
  description?: string;
15
15
  bPaused?: boolean;
@@ -118,14 +118,17 @@ 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)
130
+ } else {
131
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
129
132
  }
130
133
  }
131
134
 
@@ -167,7 +170,7 @@ export class CallArbitration extends CallBase {
167
170
  }
168
171
 
169
172
  if (this.data?.arb_new !== undefined) {
170
- this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
173
+ await this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
171
174
  }
172
175
  if (this.data?.arb_arbitration !== undefined) {
173
176
  obj?.arbitration(this.data.arb_arbitration, passport)
@@ -183,14 +186,14 @@ export class CallArbitration extends CallBase {
183
186
  }
184
187
 
185
188
  if (withdraw_treasury) {
186
- this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
189
+ await this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
187
190
  }
188
191
  if (permission) {
189
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
192
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
190
193
  }
191
194
 
192
195
  if (!object_address) {
193
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
196
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
194
197
  }
195
198
  }
196
199
  }
package/src/call/base.ts CHANGED
@@ -1,12 +1,12 @@
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';
7
7
  import { query_permission } from '../permission';
8
8
  import { Account } from '../account';
9
- import { ObjectBase, queryTableItem_Personal} from '../objects';
9
+ import { ObjectBase, queryTableItem_Personal, raw2type} from '../objects';
10
10
 
11
11
  export interface Namedbject {
12
12
  name: string;
@@ -36,7 +36,7 @@ export function ResponseData(response: CallResponse | undefined) : ResponseData[
36
36
  const res : ResponseData[] = [];
37
37
  response?.objectChanges?.forEach(v => {
38
38
  const type_raw: string | undefined = (v as any)?.objectType;
39
- const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
39
+ const type = raw2type(type_raw);
40
40
  if (type) {
41
41
  res.push({type:type, type_raw:type_raw, object:(v as any)?.objectId, version:(v as any)?.version,
42
42
  owner:(v as any)?.owner, change:v.type
@@ -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,45 @@ 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
+ Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
139
+ } else {
140
+ Resource.From(txb, r.mark_object).add(object, tags, named_new?.name);
141
+ }
142
+ } else {
143
+ ERROR(Errors.InvalidParam, 'account - ' + account)
144
+ }
145
+ } else {
146
+ Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
147
+ }
148
+ }
149
+
150
+ protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
145
151
  const pair = Account.Instance().get_pair(account, true);
146
152
  if (!pair) ERROR(Errors.Fail, 'account invalid')
147
-
148
- const txb = new TransactionBlock();
149
- this.operate(txb, undefined, account);
153
+
154
+ if (this.resouceObject) {
155
+ Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
156
+ this.resouceObject = undefined;
157
+ }
158
+
150
159
  return await Protocol.Client().signAndExecuteTransaction({
151
160
  transaction: txb,
152
161
  signer: pair!,
153
162
  options:{showObjectChanges:true},
154
163
  });
155
164
  }
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
165
  }
@@ -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';
@@ -8,8 +8,7 @@ import { Account } from '../account';
8
8
  export interface CallDemand_Data {
9
9
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
10
10
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
11
-
12
- type_parameter?: string;
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};
@@ -98,6 +97,8 @@ export class CallDemand extends CallBase {
98
97
  } else {
99
98
  if (IsValidAddress(object_address) && this.data.type_parameter && this.data.permission && IsValidAddress(permission_address)) {
100
99
  obj = Demand.From(txb, this.data.type_parameter, permission_address, object_address)
100
+ } else {
101
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
101
102
  }
102
103
  }
103
104
 
@@ -134,10 +135,10 @@ export class CallDemand extends CallBase {
134
135
  obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined, passport)
135
136
  }
136
137
  if (permission) {
137
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
138
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
138
139
  }
139
140
  if (!this.data.object) {
140
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
141
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
141
142
  }
142
143
  }
143
144
  }
package/src/call/guard.ts CHANGED
@@ -5,8 +5,7 @@
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";
9
- import { Account } from "../account";
8
+ IsValidDesription, PassportObject} from "wowok";
10
9
  import { CallBase, CallResult, Namedbject } from "./base";
11
10
 
12
11
  export interface GuardConst {
@@ -32,7 +31,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
32
31
  export interface CallGuard_Data {
33
32
  namedNew?: Namedbject;
34
33
  description: string;
35
- table: GuardConst[]; // data used by multiple logical guard nodes
34
+ table?: GuardConst[]; // data used by multiple logical guard nodes
36
35
  root: GuardNode; // root must return ValueType.TYPE_BOOL
37
36
  }
38
37
  export class CallGuard extends CallBase {
@@ -42,6 +41,10 @@ export class CallGuard extends CallBase {
42
41
  this.data = data;
43
42
  }
44
43
  async call(account?:string) : Promise<CallResult> {
44
+ return await this.exec(account)
45
+ }
46
+
47
+ protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
45
48
  if (!this.data?.root) {
46
49
  ERROR(Errors.InvalidParam, 'guard root node invalid')
47
50
  }
@@ -50,28 +53,28 @@ export class CallGuard extends CallBase {
50
53
  }
51
54
 
52
55
  // check const
53
- this.data.table.forEach(v => {
56
+ this.data?.table?.forEach(v => {
54
57
  if (!IsValidU8(v.identifier) || v.identifier < 1) ERROR(Errors.InvalidParam, 'table.identifer invalid');
55
58
  if (!v.bWitness && v.value === undefined) ERROR(Errors.InvalidParam, 'table.value');
56
59
  })
57
60
 
58
- if (hasDuplicates(this.data.table.map(v => v.identifier))) {
61
+ if (this.data?.table && hasDuplicates(this.data?.table?.map(v => v.identifier))) {
59
62
  ERROR(Errors.InvalidParam, 'table.identifer duplicates')
60
63
  }
61
64
 
62
65
  // check root
63
66
  var output : Uint8Array[]= [];
64
- buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data.table, output);
67
+ buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data?.table ?? [], output);
65
68
  const bytes = (concatenate(Uint8Array, ...output) as Uint8Array);
66
- const txb = new TransactionBlock();
67
-
69
+
68
70
  const obj = txb.moveCall({
69
71
  target: Protocol.Instance().guardFn('new') as FnCallType,
70
72
  arguments: [txb.pure.string(this.data.description), txb.pure.vector('u8', [].slice.call(bytes.reverse()))],
71
73
  });
72
- this.data.table.forEach((v) => {
74
+ this.data?.table?.forEach((v) => {
73
75
  if (v.bWitness) {
74
76
  const n = new Uint8Array(1); n.set([v.value_type], 0);
77
+ console.log(n)
75
78
  txb.moveCall({
76
79
  target:Protocol.Instance().guardFn("constant_add") as FnCallType,
77
80
  arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(true), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
@@ -89,16 +92,7 @@ export class CallGuard extends CallBase {
89
92
  target:Protocol.Instance().guardFn("create") as FnCallType,
90
93
  arguments:[txb.object(obj)]
91
94
  });
92
- 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
- });
95
+ await this.new_with_mark(txb, addr, this.data?.namedNew, account);
102
96
  }
103
97
  }
104
98
 
@@ -122,20 +116,18 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
122
116
  } else if (typeof(node.query === 'number')) {
123
117
  q = GUARD_QUERIES.find(v=>v[2] === node.query);
124
118
  }
125
-
126
- if (q) {
127
- checkType(q[4], type_required, node); // Return type checking
128
- if ((q[3]).length === node.parameters.length) {
129
- for (let i = node.parameters.length - 1; i >= 0; --i) { // stack: first in, last out
130
- buildNode(node.parameters[i], q[3][i], table, output); // Recursive check
131
- }
132
- } else {
133
- ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + node.toString())
119
+ if (!q) ERROR(Errors.InvalidParam, 'query invalid - ' + node?.query);
120
+
121
+ checkType(q![4], type_required, node); // Return type checking
122
+ if ((q![3]).length === node.parameters.length) {
123
+ for (let i = node.parameters.length - 1; i >= 0; --i) { // stack: first in, last out
124
+ buildNode(node.parameters[i], q![3][i], table, output); // Recursive check
134
125
  }
135
126
  } else {
136
- ERROR(Errors.InvalidParam, 'node query not found - ' + node.toString());
127
+ ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + node.toString())
137
128
  }
138
129
 
130
+ output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE + addr + cmd
139
131
  if (typeof(node.object) === 'string') {
140
132
  if (!IsValidAddress(node.object)) {
141
133
  ERROR(Errors.InvalidParam, 'node object from address string - ' + node.toString())
@@ -152,6 +144,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
152
144
  ERROR(Errors.InvalidParam, 'node object from identifier - ' + node.toString());
153
145
  }
154
146
  }
147
+ output.push(Bcs.getInstance().ser('u16', q![2])); // cmd(u16)
155
148
  } else if (node?.logic !== undefined) {
156
149
  checkType(ValueType.TYPE_BOOL, type_required, node); // bool
157
150
  switch (node?.logic) {
@@ -177,7 +170,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
177
170
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
178
171
  case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
179
172
  if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
180
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
173
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
181
174
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
182
175
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
183
176
  break;
@@ -190,7 +183,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
190
183
  break;
191
184
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
192
185
  if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
193
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
186
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_STRING, table, output));
194
187
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
195
188
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
196
189
  break;
@@ -198,7 +191,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
198
191
  } else if (node?.calc !== undefined) {
199
192
  checkType(ValueType.TYPE_U256, type_required, node);
200
193
  if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node calc parameters length must >= 2'+ node.toString());
201
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
194
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
202
195
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.calc)); // TYPE
203
196
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
204
197
  } else if (node?.value_type !== undefined) {
@@ -258,6 +251,7 @@ const checkType = (type: ValueType | ContextType.TYPE_CLOCK | ContextType.TYPE_G
258
251
  if (type !== type_required) {
259
252
  var str = '';
260
253
  if (node) str = ' - ' + node.toString();
254
+ console.log(node)
261
255
  ERROR(Errors.InvalidParam, 'checkType: ' + type + ' require type: ' + type_required + str);
262
256
  }
263
257
  }
@@ -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,10 +114,12 @@ 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)
121
+ } else {
122
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
119
123
  }
120
124
  }
121
125
 
@@ -126,15 +130,6 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
126
130
  if (this.data?.endpoint !== undefined && object_address) {
127
131
  obj?.set_endpoint(this.data.endpoint, passport)
128
132
  }
129
- if (this.data?.bPaused !== undefined) {
130
- obj?.pause(this.data.bPaused, passport)
131
- }
132
- if (this.data?.bPublished ) {
133
- obj?.publish(passport)
134
- }
135
- if (this.data?.clone_new && obj) {
136
- this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
137
- }
138
133
 
139
134
  if (this.data?.consensus_repository !== undefined) {
140
135
  switch (this.data.consensus_repository.op) {
@@ -178,7 +173,7 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
178
173
  if (this.data?.progress_new !== undefined) {
179
174
  const addr = Progress?.New(txb, obj?.get_object(), permission??this.data?.permission, this.data?.progress_new.task_address, passport).launch();
180
175
  if (addr) {
181
- this.new_with_mark(txb, addr, this.data?.progress_new?.namedNew, account);
176
+ await this.new_with_mark(txb, addr, this.data?.progress_new?.namedNew, account);
182
177
  }
183
178
  }
184
179
  if (this.data?.progress_context_repository !== undefined) {
@@ -209,11 +204,20 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
209
204
  if (this.data?.progress_next !== undefined) {
210
205
  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)
211
206
  }
207
+ if (this.data?.bPaused !== undefined) {
208
+ obj?.pause(this.data.bPaused, passport)
209
+ }
210
+ if (this.data?.bPublished ) {
211
+ obj?.publish(passport)
212
+ }
213
+ if (this.data?.clone_new && obj) {
214
+ await this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
215
+ }
212
216
  if (permission) {
213
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
217
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
214
218
  }
215
219
  if (!this.data.object) {
216
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
220
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
217
221
  }
218
222
  }
219
223
  }
@@ -1,10 +1,9 @@
1
1
  import { CallBase, CallResult, Namedbject } from "./base";
2
- import { TransactionBlock, CallResponse} from 'wowok';
3
2
  import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
4
- PermissionIndexType, WitnessFill
3
+ PermissionIndexType, TransactionBlock
5
4
  } from 'wowok';
6
5
 
7
- export interface CallEntityPermission_Data {
6
+ export interface CallPermission_Data {
8
7
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
9
8
  builder?: string;
10
9
  admin?: {op:'add' | 'remove' | 'set', admins:string[]};
@@ -14,9 +13,9 @@ export interface CallEntityPermission_Data {
14
13
  | {op:'transfer permission', from_address: string; to_address: string};
15
14
  biz_permission?: {op:'add'; data: UserDefinedIndex[]} | {op:'remove'; permissions: PermissionIndexType[]};
16
15
  }
17
- export class CallEntityPermission extends CallBase {
18
- data: CallEntityPermission_Data;
19
- constructor(data:CallEntityPermission_Data) {
16
+ export class CallPermission extends CallBase {
17
+ data: CallPermission_Data;
18
+ constructor(data:CallPermission_Data) {
20
19
  super();
21
20
  this.data = data;
22
21
  }
@@ -50,20 +49,6 @@ export class CallEntityPermission extends CallBase {
50
49
  }
51
50
 
52
51
  if (obj) {
53
- if (this.data?.admin !== undefined) {
54
- switch(this.data.admin.op) {
55
- case 'add':
56
- obj?.add_admin(this.data.admin.admins);
57
- break;
58
- case 'remove':
59
- obj?.remove_admin(this.data.admin.admins);
60
- break;
61
- case 'set':
62
- obj?.remove_admin([], true);
63
- obj?.add_admin(this.data.admin.admins);
64
- break
65
- }
66
- }
67
52
  if (this.data?.biz_permission !== undefined) { // High priority operate
68
53
  switch(this.data.biz_permission.op) {
69
54
  case 'add':
@@ -100,12 +85,25 @@ export class CallEntityPermission extends CallBase {
100
85
  break;
101
86
  }
102
87
  }
103
-
88
+ if (this.data?.admin !== undefined) {
89
+ switch(this.data.admin.op) {
90
+ case 'add':
91
+ obj?.add_admin(this.data.admin.admins);
92
+ break;
93
+ case 'remove':
94
+ obj?.remove_admin(this.data.admin.admins);
95
+ break;
96
+ case 'set':
97
+ obj?.remove_admin([], true);
98
+ obj?.add_admin(this.data.admin.admins);
99
+ break
100
+ }
101
+ }
104
102
  if (this.data?.builder !== undefined ) {
105
103
  obj?.change_owner(this.data.builder);
106
104
  }
107
105
  if (!object_address) {
108
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
106
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
109
107
  }
110
108
  }
111
109
  }
@@ -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
 
@@ -65,7 +65,7 @@ export class CallPersonal extends CallBase {
65
65
  }
66
66
 
67
67
  if (!object_address && obj) {
68
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
68
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
69
69
  }
70
70
  }
71
71
  }
@@ -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,10 +59,12 @@ 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)
66
+ } else {
67
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
66
68
  }
67
69
  }
68
70
 
@@ -70,9 +72,6 @@ export class CallRepository extends CallBase {
70
72
  if (this.data?.description !== undefined && object_address) {
71
73
  obj?.set_description(this.data.description, passport);
72
74
  }
73
- if (this.data?.mode !== undefined && object_address) { //@ priority??
74
- obj?.set_policy_mode(this.data.mode, passport)
75
- }
76
75
  if (this.data?.reference !== undefined) {
77
76
  switch (this.data.reference.op) {
78
77
  case 'set':
@@ -90,6 +89,20 @@ export class CallRepository extends CallBase {
90
89
  break;
91
90
  }
92
91
  }
92
+ if (this.data?.data !== undefined) {
93
+ switch(this.data.data.op) {
94
+ case 'add':
95
+ if ((this.data.data?.data as any)?.key !== undefined) {
96
+ obj?.add_data(this.data.data.data as Repository_Policy_Data);
97
+ } else if ((this.data.data?.data as any)?.address !== undefined) {
98
+ obj?.add_data2(this.data.data.data as Repository_Policy_Data2);
99
+ }
100
+ break;
101
+ case 'remove':
102
+ obj?.remove(this.data.data.data.address, this.data.data.data.key);
103
+ break;
104
+ }
105
+ }
93
106
  if (this.data?.policy !== undefined) {
94
107
  switch(this.data.policy.op) {
95
108
  case 'set':
@@ -112,25 +125,14 @@ export class CallRepository extends CallBase {
112
125
  break;
113
126
  }
114
127
  }
115
- if (this.data?.data !== undefined) {
116
- switch(this.data.data.op) {
117
- case 'add':
118
- if ((this.data.data?.data as any)?.key !== undefined) {
119
- obj?.add_data(this.data.data.data as Repository_Policy_Data);
120
- } else if ((this.data.data?.data as any)?.address !== undefined) {
121
- obj?.add_data2(this.data.data.data as Repository_Policy_Data2);
122
- }
123
- break;
124
- case 'remove':
125
- obj?.remove(this.data.data.data.address, this.data.data.data.key);
126
- break;
127
- }
128
+ if (this.data?.mode !== undefined && object_address) { //@ priority??
129
+ obj?.set_policy_mode(this.data.mode, passport)
128
130
  }
129
131
  if (permission) {
130
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
132
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
131
133
  }
132
134
  if (!this.data.object) {
133
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
135
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
134
136
  }
135
137
  }
136
138
  };
@@ -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
@@ -10,7 +10,7 @@ import { Account } from '../account';
10
10
  export interface CallService_Data {
11
11
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
12
12
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
13
- type_parameter?: string;
13
+ type_parameter: string;
14
14
  bPaused?: boolean;
15
15
  bPublished?: boolean;
16
16
  description?: string;
@@ -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,10 +161,13 @@ 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)
169
+ } else {
170
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
168
171
  }
169
172
  }
170
173
 
@@ -178,18 +181,6 @@ export class CallService extends CallBase {
178
181
  if (this.data?.endpoint !== undefined) {
179
182
  obj?.set_endpoint(this.data.endpoint, passport)
180
183
  }
181
- if (this.data?.buy_guard !== undefined) {
182
- obj?.set_buy_guard(this.data.buy_guard, passport)
183
- }
184
- if (this.data?.bPaused !== undefined) {
185
- obj?.pause(this.data.bPaused, passport)
186
- }
187
- if (this.data?.bPublished) {
188
- obj?.publish(passport)
189
- }
190
- if (this.data?.clone_new !== undefined && obj) {
191
- this.new_with_mark(txb, obj.clone(this.data.clone_new?.token_type_new, true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
192
- }
193
184
  if (this.data?.machine !== undefined) {
194
185
  obj?.set_machine(this.data.machine, passport)
195
186
  }
@@ -244,51 +235,9 @@ export class CallService extends CallBase {
244
235
  break;
245
236
  }
246
237
  }
247
- if (this.data?.customer_required_info !== undefined) {
248
- if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
249
- obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, passport);
250
- } else if (this.data.customer_required_info.pubkey) {
251
- obj?.change_required_pubkey(this.data.customer_required_info.pubkey, passport);
252
- }
253
- }
254
- if (this.data?.refund_guard !== undefined) {
255
- switch(this.data.refund_guard.op) {
256
- case 'add':
257
- obj?.add_refund_guards(this.data.refund_guard.guards, passport)
258
- break;
259
- case 'set':
260
- obj?.remove_refund_guards([], true, passport)
261
- obj?.add_refund_guards(this.data.refund_guard.guards, passport)
262
- break;
263
- case 'remove':
264
- obj?.remove_refund_guards(this.data.refund_guard.addresses, false, passport)
265
- break;
266
- case 'removeall':
267
- obj?.remove_refund_guards([], true, passport)
268
- break;
269
- }
270
- }
271
238
  if (this.data?.gen_discount !== undefined) {
272
239
  obj?.discount_transfer(this.data.gen_discount, passport)
273
240
  }
274
- if (this.data?.withdraw_guard !== undefined) {
275
- switch(this.data.withdraw_guard.op) {
276
- case 'add':
277
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
278
- break;
279
- case 'set':
280
- obj?.remove_withdraw_guards([], true, passport)
281
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
282
- break;
283
- case 'remove':
284
- obj?.remove_withdraw_guards(this.data.withdraw_guard.addresses, false, passport)
285
- break;
286
- case 'removeall':
287
- obj?.remove_withdraw_guards([], true, passport)
288
- break;
289
- }
290
- }
291
-
292
241
  if (this.data?.sales !== undefined) {
293
242
  switch(this.data.sales.op) {
294
243
  case 'add':
@@ -310,7 +259,7 @@ export class CallService extends CallBase {
310
259
  //@ crypto tools support
311
260
  const addr = obj.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount,
312
261
  this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport) ;
313
- this.new_with_mark(txb, addr, (this.data?.order_new as any)?.namedNew, account, [TagName.Launch, TagName.Order]);
262
+ await this.new_with_mark(txb, addr, (this.data?.order_new as any)?.namedNew, account, [TagName.Launch, TagName.Order]);
314
263
  }
315
264
  }
316
265
  }
@@ -333,14 +282,67 @@ export class CallService extends CallBase {
333
282
  if (this.data?.order_withdrawl !== undefined && passport) { //@ need withdrawal passport
334
283
  obj?.withdraw(this.data.order_withdrawl.order, this.data.order_withdrawl.data, passport)
335
284
  }
285
+ if (this.data?.customer_required_info !== undefined) {
286
+ if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
287
+ obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, passport);
288
+ } else if (this.data.customer_required_info.pubkey) {
289
+ obj?.change_required_pubkey(this.data.customer_required_info.pubkey, passport);
290
+ }
291
+ }
292
+ if (this.data?.withdraw_guard !== undefined) {
293
+ switch(this.data.withdraw_guard.op) {
294
+ case 'add':
295
+ obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
296
+ break;
297
+ case 'set':
298
+ obj?.remove_withdraw_guards([], true, passport)
299
+ obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
300
+ break;
301
+ case 'remove':
302
+ obj?.remove_withdraw_guards(this.data.withdraw_guard.addresses, false, passport)
303
+ break;
304
+ case 'removeall':
305
+ obj?.remove_withdraw_guards([], true, passport)
306
+ break;
307
+ }
308
+ }
309
+ if (this.data?.refund_guard !== undefined) {
310
+ switch(this.data.refund_guard.op) {
311
+ case 'add':
312
+ obj?.add_refund_guards(this.data.refund_guard.guards, passport)
313
+ break;
314
+ case 'set':
315
+ obj?.remove_refund_guards([], true, passport)
316
+ obj?.add_refund_guards(this.data.refund_guard.guards, passport)
317
+ break;
318
+ case 'remove':
319
+ obj?.remove_refund_guards(this.data.refund_guard.addresses, false, passport)
320
+ break;
321
+ case 'removeall':
322
+ obj?.remove_refund_guards([], true, passport)
323
+ break;
324
+ }
325
+ }
326
+ if (this.data?.buy_guard !== undefined) {
327
+ obj?.set_buy_guard(this.data.buy_guard, passport)
328
+ }
329
+ if (this.data?.bPaused !== undefined) {
330
+ obj?.pause(this.data.bPaused, passport)
331
+ }
332
+ if (this.data?.bPublished) {
333
+ obj?.publish(passport)
334
+ }
335
+ if (this.data?.clone_new !== undefined && obj) {
336
+ await this.new_with_mark(txb, obj.clone(this.data.clone_new?.token_type_new, true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
337
+ }
336
338
  if (payee) {
337
- this.new_with_mark(txb, payee.launch(), (this.data?.payee_treasury as any)?.namedNew, account);
339
+ await this.new_with_mark(txb, payee.launch(), (this.data?.payee_treasury as any)?.namedNew, account);
338
340
  }
339
341
  if (permission) {
340
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
342
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
341
343
  }
342
344
  if (!object_address) {
343
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
345
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
344
346
  }
345
347
  }
346
348
  }
@@ -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';
@@ -9,10 +9,10 @@ import { Account } from '../account';
9
9
  export interface CallTreasury_Data {
10
10
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
11
11
  permission?: {address:string} | {namedNew: Namedbject, description?:string};
12
- type_parameter?: string;
12
+ type_parameter: string;
13
13
  description?: string;
14
14
  withdraw_mode?: Treasury_WithdrawMode;
15
- withdraw_guard?: {op:'add' | 'set'; data:{guard:string, amount:string}[]} | {op:'remove', guards:string[]} | {op:'removeall'};
15
+ withdraw_guard?: {op:'add' | 'set'; data:{guard:string, amount:string|number}[]} | {op:'remove', guards:string[]} | {op:'removeall'};
16
16
  deposit_guard?: string;
17
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};
@@ -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,23 +110,38 @@ 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)
117
+ } else {
118
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
118
119
  }
119
120
  }
120
121
 
121
122
  if (obj) {
123
+ if (this.data.deposit !== undefined) {
124
+ const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.data.balance, account, this.data.type_parameter);
125
+ if (coin) {
126
+ const index = this.data.deposit.data?.index ?? 0;
127
+ obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
128
+ for_guard:this.data.deposit.data?.for_guard,
129
+ for_object: this.data.deposit.data?.for_object
130
+ })
131
+ }
132
+ }
133
+ if (this.data?.withdraw !== undefined) {
134
+ obj?.withdraw(this.data.withdraw, passport)
135
+ }
136
+ if (this.data?.receive !== undefined) {
137
+ obj?.receive(this.data.receive.payment, this.data.receive.received_object, passport);
138
+ }
122
139
  if (this.data?.description !== undefined && object_address) {
123
140
  obj?.set_description(this.data.description, passport);
124
141
  }
125
142
  if (this.data?.deposit_guard !== undefined) {
126
143
  obj?.set_deposit_guard(this.data.deposit_guard, passport);
127
144
  }
128
- if (this.data?.withdraw_mode !== undefined) {
129
- obj?.set_withdraw_mode(this.data.withdraw_mode, passport)
130
- }
131
145
  if (this.data?.withdraw_guard !== undefined) {
132
146
  switch (this.data.withdraw_guard.op) {
133
147
  case 'add':
@@ -145,28 +159,14 @@ export class CallTreasury extends CallBase {
145
159
  break;
146
160
  }
147
161
  }
148
- if (this.data?.withdraw !== undefined) {
149
- obj?.withdraw(this.data.withdraw, passport)
150
- }
151
- if (this.data?.receive !== undefined) {
152
- obj?.receive(this.data.receive.payment, this.data.receive.received_object, passport);
153
- }
154
- if (this.data.deposit !== undefined) {
155
- const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.data.balance, account, this.data.type_parameter);
156
- if (coin) {
157
- const index = this.data.deposit.data?.index ?? 0;
158
- obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
159
- for_guard:this.data.deposit.data?.for_guard,
160
- for_object: this.data.deposit.data?.for_object
161
- })
162
- }
162
+ if (this.data?.withdraw_mode !== undefined) {
163
+ obj?.set_withdraw_mode(this.data.withdraw_mode, passport)
163
164
  }
164
165
  if (permission) {
165
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
166
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
166
167
  }
167
-
168
168
  if (!object_address) {
169
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
169
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
170
170
  }
171
171
  }
172
172
  }
package/src/call.ts CHANGED
@@ -1,14 +1,13 @@
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";
9
8
  import { CallDemand, CallDemand_Data } from "./call/demand";
10
9
  import { CallMachine, CallMachine_Data } from "./call/machine";
11
- import { CallEntityPermission, CallEntityPermission_Data } from "./call/entity_permission";
10
+ import { CallPermission, CallPermission_Data } from "./call/permission";
12
11
  import { CallPersonal, CallPersonal_Data } from "./call/personal";
13
12
  import { CallRepository, CallRepository_Data } from "./call/repository";
14
13
  import { CallService, CallService_Data } from "./call/service";
@@ -19,8 +18,8 @@ import { CallObjectPermission, CallObjectPermission_Data } from "./call/object_p
19
18
 
20
19
 
21
20
  export interface CallObjectData {
22
- type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'EntityPermission' | 'ObjectPermission';
23
- data: CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallEntityPermission_Data | CallObjectPermission_Data
21
+ type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'Permission' | 'ObjectPermission';
22
+ data: CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallPermission_Data | CallObjectPermission_Data
24
23
  | CallTreasury_Data | CallService_Data | CallRepository_Data;
25
24
  account?: string;
26
25
  witness?: CallWithWitnessParam;
@@ -65,8 +64,8 @@ function call_object_new (call: CallObjectData) : CallBase | undefined {
65
64
  return new CallRepository(call.data as CallRepository_Data);
66
65
  case 'Personal':
67
66
  return new CallPersonal(call.data as CallPersonal_Data);
68
- case 'EntityPermission':
69
- return new CallEntityPermission(call.data as CallEntityPermission_Data);
67
+ case 'Permission':
68
+ return new CallPermission(call.data as CallPermission_Data);
70
69
  case 'ObjectPermission':
71
70
  return new CallObjectPermission(call.data as CallObjectPermission_Data);
72
71
  }
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/entity_permission'
6
+ export * from './call/permission'
7
7
  export * from './call/arbitration'
8
8
  export * from './call/treasury'
9
- export * from './call/entity_permission'
9
+ export * from './call/object_permission'
10
10
  export * from './call/demand'
11
11
  export * from './call/machine'
12
12
  export * from './call/repository'
@@ -15,3 +15,4 @@ export * from './call/guard'
15
15
  export * from './call/personal'
16
16
  export * from './account'
17
17
  export * from './call'
18
+ export * as WOWOK from 'wowok';
package/src/objects.ts CHANGED
@@ -5,17 +5,17 @@
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,
9
- Entity_Info, Tags
10
- } from 'wowok';
8
+ Progress, History, ERROR, Errors, IsValidAddress, Bcs, Entity_Info, Tags } from 'wowok';
11
9
  import {WowokCache, OBJECT_KEY, CacheExpire, CacheName, CachedData} from './cache'
12
10
 
13
- export interface ObjectBase {
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' |
11
+ export type ObjectBaseType = 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' | 'Discount' |
12
+ 'Personal' | 'Permission' | 'PersonalMark' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
17
13
  'TableItem_DemandPresenter' | 'TableItem_MachineNode' | 'TableItem_ServiceSale' | 'TableItem_TreasuryHistory' | 'TableItem_ArbVote' |
18
14
  'TableItem_RepositoryData' | 'TableItem_PersonalMark';
15
+
16
+ export interface ObjectBase {
17
+ object: string;
18
+ type?: ObjectBaseType;
19
19
  type_raw?: string;
20
20
  owner?: any;
21
21
  version?: 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
 
@@ -457,13 +456,53 @@ const tableItem = async (query:TableItemQuery) : Promise<ObjectBase> => {
457
456
  return data2object(res?.data)
458
457
  }
459
458
 
459
+ export function raw2type(type_raw:string | undefined) : ObjectBaseType | undefined {
460
+ if (!type_raw) return undefined;
461
+
462
+ const t = Protocol.Instance().object_name_from_type_repr(type_raw);
463
+ if (t === 'Permission' || t === 'Demand' || t === 'Machine' || t === 'Progress' || t === 'Order' || t === 'Service' ||
464
+ t === 'Treasury' || t === 'Arb' || t === 'Repository' || t === 'Payment' || t === 'Discount' || t === 'Guard') {
465
+ return t
466
+ } else if (t === 'Resource') {
467
+ return 'PersonalMark';
468
+ }
469
+ const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
470
+ if (start === 0) {
471
+ const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
472
+ if(end && Protocol.Instance().hasPackage(end)) {
473
+ if (end.includes('::demand::Tips>')) {
474
+ return 'TableItem_DemandPresenter';
475
+ } else if (end.includes('::machine::NodePair>>>')) {
476
+ return 'TableItem_MachineNode';
477
+ } else if (end.includes('::progress::History>')) {
478
+ return 'TableItem_ProgressHistory';
479
+ } else if (end.includes('::service::Sale>')) {
480
+ return 'TableItem_ServiceSale';
481
+ } else if (end.includes('::treasury::Record>')) {
482
+ return 'TableItem_TreasuryHistory';
483
+ } else if (end.includes('::arb::Voted>')) {
484
+ return 'TableItem_ArbVote';
485
+ } else if (end.includes('::permission::Perm>>')) {
486
+ return 'TableItem_PermissionEntity';
487
+ } else if (end.includes('::repository::DataKey')) {
488
+ return 'TableItem_RepositoryData';
489
+ } else if (end.includes('::entity::Ent>')) {
490
+ return 'Personal';
491
+ } else if (end.includes('::resource::Tags>')) {
492
+ return 'TableItem_PersonalMark';
493
+ }
494
+ }
495
+ }
496
+ return undefined;
497
+ }
498
+
460
499
  export function data2object(data?:any) : ObjectBase {
461
500
  const content = (data?.content as any)?.fields;
462
501
  const id = data?.objectId ?? (content?.id?.id ?? undefined);
463
502
  const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
464
503
  const version = data?.version ?? undefined;
465
504
  const owner = data?.owner ?? undefined;
466
- const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
505
+ const type:string | undefined = raw2type(type_raw);
467
506
 
468
507
  if (type) {
469
508
  switch(type) {
@@ -603,80 +642,68 @@ export function data2object(data?:any) : ObjectBase {
603
642
  return {id:v?.fields?.identifier, bWitness:v?.fields?.bWitness, value:Uint8Array.from(v?.fields?.value)}
604
643
  })
605
644
  } as ObjectGuard;
606
- case 'Resource' :
645
+ case 'PersonalMark' :
607
646
  return {
608
647
  object:id, type:type, type_raw:type_raw, owner:owner, version:version,
609
648
  tag_count:parseInt(content?.tags?.fields?.size)
610
649
  } as ObjectMark;
650
+ case 'TableItem_DemandPresenter':
651
+ return {
652
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
653
+ service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
654
+ } as TableItem_DemandPresenter;
655
+ case 'TableItem_ProgressHistory':
656
+ return {
657
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
658
+ history:Progress.DeHistory(content)
659
+ } as TableItem_ProgressHistory;
660
+ case 'TableItem_ServiceSale':
661
+ return {
662
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
663
+ item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
664
+ endpoint:content?.value?.fields?.endpoint
665
+ }
666
+ } as TableItem_ServiceSale;
667
+ case 'TableItem_TreasuryHistory':
668
+ return {
669
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
670
+ id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
671
+ operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
672
+ } as TableItem_TreasuryHistory;
673
+ case 'TableItem_ArbVote':
674
+ return {
675
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
676
+ singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
677
+ weight:content?.value?.fields?.weight
678
+ } as TableItem_ArbVote;
679
+ case 'TableItem_PermissionEntity':
680
+ return {
681
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
682
+ entity:content?.name, permission:content?.value?.map((v:any) => {
683
+ return {id:v?.fields.index, guard:v?.fields.guard}
684
+ })
685
+ } as TableItem_PermissionEntity;
686
+ case 'TableItem_RepositoryData':
687
+ return {
688
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
689
+ address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
690
+ } as TableItem_RepositoryData;
691
+ case 'Personal':
692
+ const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
693
+ return {
694
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
695
+ address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
696
+ mark_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
697
+ info : {homepage:info?.homepage, name:info?.name, avatar:info?.avatar, twitter:info?.twitter, discord:info?.discord,
698
+ description:info?.description}
699
+ } as ObjectPersonal;
700
+ case 'TableItem_PersonalMark':
701
+ return {object:id, type:type, type_raw:type_raw, owner:owner, version:version,
702
+ address:content?.name, name:content?.value?.fields?.nick, tags:content?.value?.fields?.tags
703
+ } as TableItem_PersonalMark;
611
704
  }
612
705
  }
613
-
614
- const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
615
- if (start === 0) {
616
- const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
617
- if(end && Protocol.Instance().hasPackage(end)) {
618
- if (end.includes('::demand::Tips>')) {
619
- return {
620
- object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
621
- service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
622
- } as TableItem_DemandPresenter;
623
- } else if (end.includes('::machine::NodePair>>>')) {
624
- return {
625
- object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
626
- node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
627
- } as TableItem_MachineNode;
628
- } else if (end.includes('::progress::History>')) {
629
- return {
630
- object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
631
- history:Progress.DeHistory(content)
632
- } as TableItem_ProgressHistory;
633
- } else if (end.includes('::service::Sale>')) {
634
- return {
635
- object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
636
- item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
637
- endpoint:content?.value?.fields?.endpoint
638
- }
639
- } as TableItem_ServiceSale;
640
- } else if (end.includes('::treasury::Record>')) {
641
- return {
642
- object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
643
- id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
644
- operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
645
- } as TableItem_TreasuryHistory;
646
- } else if (end.includes('::arb::Voted>')) {
647
- return {
648
- object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
649
- singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
650
- weight:content?.value?.fields?.weight
651
- } as TableItem_ArbVote;
652
- } else if (end.includes('::permission::Perm>>')) {
653
- return {
654
- object:id, type:'TableItem_PermissionEntity', type_raw:type_raw, owner:owner, version:version,
655
- entity:content?.name, permission:content?.value?.map((v:any) => {
656
- return {id:v?.fields.index, guard:v?.fields.guard}
657
- })
658
- } as TableItem_PermissionEntity;
659
- } else if (end.includes('::repository::DataKey')) {
660
- return {
661
- object:id, type:'TableItem_RepositoryData', type_raw:type_raw, owner:owner, version:version,
662
- address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
663
- } as TableItem_RepositoryData;
664
- } else if (end.includes('::entity::Ent>')) {
665
- const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
666
- return {
667
- object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
668
- address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
669
- mark_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
670
- info : {homepage:info?.homepage, name:info?.name, avatar:info?.avatar, twitter:info?.twitter, discord:info?.discord,
671
- description:info?.description}
672
- } as ObjectPersonal;
673
- } else if (end.includes('::resource::Tags>')) {
674
- return {object:id, type:'TableItem_MarkTag', type_raw:type_raw, owner:owner, version:version,
675
- address:content?.name, name:content?.value?.fields?.nick, tags:content?.value?.fields?.tags
676
- } as TableItem_MarkTag;
677
- }
678
- }
679
- }
680
- return {object:id, type:type, type_raw:type_raw, owner:owner, version:version}
706
+
707
+ return {object:id, type:undefined, type_raw:type_raw, owner:owner, version:version}
681
708
  }
682
709