wowok_agent 0.1.9 → 0.1.12

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.9",
3
+ "version": "0.1.12",
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,7 +240,6 @@ 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)
244
243
  return txb.splitCoins(txb.gas, [balance_required]);
245
244
  } else {
246
245
  const r = await Protocol.Client().getCoins({owner: addr, coinType:token_type});
@@ -8,8 +8,7 @@ import { CallBase, CallResult, AddressMark, Namedbject} from "./base";
8
8
  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
- mark?:AddressMark;
12
- type_parameter?: string;
11
+ type_parameter: string;
13
12
  permission_new?: string;
14
13
  description?: string;
15
14
  bPaused?: boolean;
@@ -121,12 +120,13 @@ export class CallArbitration extends CallBase {
121
120
  withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
122
121
  d, permission?undefined:passport);
123
122
  }
124
-
125
123
  obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
126
124
  BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
127
- } else if (object_address) {
125
+ } else {
128
126
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
129
127
  obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
128
+ } else {
129
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
130
130
  }
131
131
  }
132
132
 
@@ -134,9 +134,6 @@ export class CallArbitration extends CallBase {
134
134
  if (this.data?.description !== undefined && object_address) {
135
135
  obj?.set_description(this.data.description, passport);
136
136
  }
137
- if (this.data?.bPaused !== undefined) {
138
- obj?.pause(this.data.bPaused, passport);
139
- }
140
137
  if (this.data?.endpoint !== undefined) {
141
138
  obj?.set_endpoint(this.data.endpoint, passport)
142
139
  }
@@ -146,8 +143,20 @@ export class CallArbitration extends CallBase {
146
143
  if (treasury_address !== undefined && object_address) {
147
144
  obj?.set_withdrawTreasury(treasury_address, passport)
148
145
  }
149
- if (this.data.usage_guard !== undefined) {
150
- obj?.set_guard(this.data.usage_guard, passport)
146
+ if (this.data?.arb_new !== undefined) {
147
+ await this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
148
+ }
149
+ if (this.data?.arb_arbitration !== undefined) {
150
+ obj?.arbitration(this.data.arb_arbitration, passport)
151
+ }
152
+ if (this.data?.arb_vote !== undefined) {
153
+ obj?.vote(this.data.arb_vote, passport)
154
+ }
155
+ if (this.data?.arb_withdraw_fee !== undefined) {
156
+ obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
157
+ }
158
+ if (this.data?.permission_new !== undefined) {
159
+ obj?.change_permission(this.data.permission_new);
151
160
  }
152
161
  if (this.data?.voting_guard !== undefined) {
153
162
  switch (this.data.voting_guard.op) {
@@ -166,32 +175,21 @@ export class CallArbitration extends CallBase {
166
175
  break;
167
176
  }
168
177
  }
169
-
170
- if (this.data?.arb_new !== undefined) {
171
- this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
172
- }
173
- if (this.data?.arb_arbitration !== undefined) {
174
- obj?.arbitration(this.data.arb_arbitration, passport)
175
- }
176
- if (this.data?.arb_vote !== undefined) {
177
- obj?.vote(this.data.arb_vote, passport)
178
- }
179
- if (this.data?.arb_withdraw_fee !== undefined) {
180
- obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
178
+ if (this.data.usage_guard !== undefined) {
179
+ obj?.set_guard(this.data.usage_guard, passport)
181
180
  }
182
- if (this.data?.permission_new !== undefined) {
183
- obj?.change_permission(this.data.permission_new);
181
+ if (this.data?.bPaused !== undefined) {
182
+ obj?.pause(this.data.bPaused, passport);
184
183
  }
185
-
186
184
  if (withdraw_treasury) {
187
- this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
185
+ await this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
188
186
  }
189
187
  if (permission) {
190
- this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
188
+ await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
191
189
  }
192
190
 
193
191
  if (!object_address) {
194
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
192
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
195
193
  }
196
194
  }
197
195
  }
package/src/call/base.ts CHANGED
@@ -6,10 +6,10 @@ import { PassportObject, Errors, ERROR, Permission,
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
- name: string;
12
+ name?: string;
13
13
  tags?: string[];
14
14
  }
15
15
 
@@ -32,11 +32,12 @@ export interface CallWithWitnessParam {
32
32
  }
33
33
  export type CallResult = GuardInfo_forCall | CallResponse | undefined;
34
34
 
35
+
35
36
  export function ResponseData(response: CallResponse | undefined) : ResponseData[] {
36
37
  const res : ResponseData[] = [];
37
38
  response?.objectChanges?.forEach(v => {
38
39
  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;
40
+ const type = raw2type(type_raw);
40
41
  if (type) {
41
42
  res.push({type:type, type_raw:type_raw, object:(v as any)?.objectId, version:(v as any)?.version,
42
43
  owner:(v as any)?.owner, change:v.type
@@ -135,25 +136,22 @@ export class CallBase {
135
136
  const r = await queryTableItem_Personal({address:addr}); //@ use cache
136
137
  if (!r?.mark_object) {
137
138
  this.resouceObject = Entity.From(txb).create_resource2(); // new
139
+ Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
138
140
  } else {
139
141
  Resource.From(txb, r.mark_object).add(object, tags, named_new?.name);
140
- return
141
142
  }
142
143
  } else {
143
144
  ERROR(Errors.InvalidParam, 'account - ' + account)
144
145
  }
145
- }
146
- if (this.resouceObject) {
147
- Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
148
146
  } else {
149
- ERROR(Errors.Fail, 'invalid personal mark')
147
+ Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
150
148
  }
151
149
  }
152
150
 
153
151
  protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
154
152
  const pair = Account.Instance().get_pair(account, true);
155
153
  if (!pair) ERROR(Errors.Fail, 'account invalid')
156
-
154
+
157
155
  if (this.resouceObject) {
158
156
  Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
159
157
  this.resouceObject = undefined;
@@ -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,11 +5,8 @@
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,
9
- Resource,
10
- ResourceObject,
11
- PassportObject} from "wowok";
12
- import { Account } from "../account";
8
+ IsValidDesription, PassportObject,
9
+ IsValidGuardIdentifier} from "wowok";
13
10
  import { CallBase, CallResult, Namedbject } from "./base";
14
11
 
15
12
  export interface GuardConst {
@@ -30,6 +27,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
30
27
  | {calc: OperatorType.TYPE_NUMBER_ADD | OperatorType.TYPE_NUMBER_DEVIDE | OperatorType.TYPE_NUMBER_MOD
31
28
  | OperatorType.TYPE_NUMBER_MULTIPLY | OperatorType.TYPE_NUMBER_SUBTRACT; parameters: GuardNode[];}
32
29
  | {value_type: ValueType; value:any; } // Data
30
+ | {identifier: number} // data from GuardConst
33
31
  | {context: ContextType.TYPE_CLOCK | ContextType.TYPE_GUARD | ContextType.TYPE_SIGNER }; // Data from run-time environment
34
32
 
35
33
  export interface CallGuard_Data {
@@ -70,7 +68,7 @@ export class CallGuard extends CallBase {
70
68
  var output : Uint8Array[]= [];
71
69
  buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data?.table ?? [], output);
72
70
  const bytes = (concatenate(Uint8Array, ...output) as Uint8Array);
73
-
71
+
74
72
  const obj = txb.moveCall({
75
73
  target: Protocol.Instance().guardFn('new') as FnCallType,
76
74
  arguments: [txb.pure.string(this.data.description), txb.pure.vector('u8', [].slice.call(bytes.reverse()))],
@@ -95,7 +93,7 @@ export class CallGuard extends CallBase {
95
93
  target:Protocol.Instance().guardFn("create") as FnCallType,
96
94
  arguments:[txb.object(obj)]
97
95
  });
98
- this.new_with_mark(txb, addr, this.data?.namedNew, account);
96
+ await this.new_with_mark(txb, addr, this.data?.namedNew, account);
99
97
  }
100
98
  }
101
99
 
@@ -110,32 +108,30 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
110
108
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
111
109
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.identifier))
112
110
  } else {
113
- ERROR(Errors.InvalidParam, 'node identifier - ' + node.toString());
111
+ ERROR(Errors.InvalidParam, 'node identifier - ' + JSON.stringify(node));
114
112
  }
115
113
  } else if (node?.query !== undefined) {
116
114
  var q: any[] | undefined;
117
- if (typeof(node.query === 'string')) {
115
+ if (typeof(node.query) === 'string') {
118
116
  q = GUARD_QUERIES.find(v=>v[1] === node.query);
119
- } else if (typeof(node.query === 'number')) {
117
+ } else if (typeof(node.query) === 'number') {
120
118
  q = GUARD_QUERIES.find(v=>v[2] === node.query);
121
119
  }
122
-
123
- if (q) {
124
- checkType(q[4], type_required, node); // Return type checking
125
- if ((q[3]).length === node.parameters.length) {
126
- for (let i = node.parameters.length - 1; i >= 0; --i) { // stack: first in, last out
127
- buildNode(node.parameters[i], q[3][i], table, output); // Recursive check
128
- }
129
- } else {
130
- ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + node.toString())
120
+ if (!q) ERROR(Errors.InvalidParam, 'query invalid - ' + node?.query);
121
+
122
+ checkType(q![4], type_required, node); // Return type checking
123
+ if ((q![3]).length === node.parameters.length) {
124
+ for (let i = node.parameters.length - 1; i >= 0; --i) { // stack: first in, last out
125
+ buildNode(node.parameters[i], q![3][i], table, output); // Recursive check
131
126
  }
132
127
  } else {
133
- ERROR(Errors.InvalidParam, 'node query not found - ' + node.toString());
128
+ ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + JSON.stringify(node))
134
129
  }
135
130
 
131
+ output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE + addr + cmd
136
132
  if (typeof(node.object) === 'string') {
137
133
  if (!IsValidAddress(node.object)) {
138
- ERROR(Errors.InvalidParam, 'node object from address string - ' + node.toString())
134
+ ERROR(Errors.InvalidParam, 'node object from address string - ' + JSON.stringify(node))
139
135
  }
140
136
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
141
137
  output.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, node.object)); // object address
@@ -146,25 +142,26 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
146
142
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
147
143
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.object)); // object id
148
144
  } else {
149
- ERROR(Errors.InvalidParam, 'node object from identifier - ' + node.toString());
145
+ ERROR(Errors.InvalidParam, 'node object from identifier - ' + JSON.stringify(node));
150
146
  }
151
147
  }
148
+ output.push(Bcs.getInstance().ser('u16', q![2])); // cmd(u16)
152
149
  } else if (node?.logic !== undefined) {
153
150
  checkType(ValueType.TYPE_BOOL, type_required, node); // bool
154
151
  switch (node?.logic) {
155
152
  case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
156
- if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+ node.toString());
153
+ if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+ JSON.stringify(node));
157
154
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
158
155
  break;
159
156
  case OperatorType.TYPE_LOGIC_AND:
160
157
  case OperatorType.TYPE_LOGIC_OR:
161
- if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
158
+ if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
162
159
  (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output)); // reserve
163
160
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
164
161
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
165
162
  break;
166
163
  case OperatorType.TYPE_LOGIC_NOT:
167
- if (node.parameters.length !== 1) ERROR(Errors.InvalidParam, 'node logic parameters length must be 1'+ node.toString());
164
+ if (node.parameters.length !== 1) ERROR(Errors.InvalidParam, 'node logic parameters length must be 1'+ JSON.stringify(node));
168
165
  (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output)); // reserve
169
166
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
170
167
  break;
@@ -173,34 +170,34 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
173
170
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
174
171
  case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
175
172
  case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
176
- if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
177
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
173
+ if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
174
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
178
175
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
179
176
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
180
177
  break;
181
178
  case OperatorType.TYPE_LOGIC_EQUAL:
182
- if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
179
+ if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
183
180
  var any_type: any = 'variable';
184
181
  (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, any_type, table, output));
185
182
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
186
183
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
187
184
  break;
188
185
  case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
189
- if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ node.toString());
190
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
186
+ if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
187
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_STRING, table, output));
191
188
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
192
189
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
193
190
  break;
194
191
  }
195
192
  } else if (node?.calc !== undefined) {
196
193
  checkType(ValueType.TYPE_U256, type_required, node);
197
- if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node calc parameters length must >= 2'+ node.toString());
198
- (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output));
194
+ if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node calc parameters length must >= 2'+ JSON.stringify(node));
195
+ (node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
199
196
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.calc)); // TYPE
200
197
  output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
201
198
  } else if (node?.value_type !== undefined) {
202
199
  checkType(node?.value_type, type_required, node);
203
- if (node?.value === undefined) ERROR(Errors.InvalidParam, 'node value undefined - ' + node.toString());
200
+ if (node?.value === undefined) ERROR(Errors.InvalidParam, 'node value undefined - ' + JSON.stringify(node));
204
201
  output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.value_type)); // TYPE
205
202
 
206
203
  if (node.value_type == ValueType.TYPE_STRING || node.value_type === ValueType.TYPE_VEC_U8) {
@@ -223,8 +220,15 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
223
220
  checkType(ValueType.TYPE_ADDRESS, type_required, node);
224
221
  break;
225
222
  }
223
+ } else if (node?.identifier !== undefined) {
224
+ if (!IsValidGuardIdentifier(node.identifier)) ERROR(Errors.IsValidGuardIdentifier, 'node - '+JSON.stringify(node));
225
+ const i = table.find(v => v.identifier === node.identifier);
226
+ if (!i) ERROR(Errors.InvalidParam, 'identifier not found. node - '+JSON.stringify(node));
227
+ checkType(i!.value_type, type_required, node);
228
+ output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
229
+ output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.identifier));
226
230
  } else {
227
- ERROR(Errors.InvalidParam, 'node - ' + node.toString())
231
+ ERROR(Errors.InvalidParam, 'node - ' + JSON.stringify(node))
228
232
  }
229
233
  }
230
234
 
@@ -254,7 +258,7 @@ const checkType = (type: ValueType | ContextType.TYPE_CLOCK | ContextType.TYPE_G
254
258
 
255
259
  if (type !== type_required) {
256
260
  var str = '';
257
- if (node) str = ' - ' + node.toString();
261
+ if (node) str = ' - ' + JSON.stringify(node);
258
262
  ERROR(Errors.InvalidParam, 'checkType: ' + type + ' require type: ' + type_required + str);
259
263
  }
260
264
  }
@@ -30,7 +30,7 @@ export interface CallMachine_Data {
30
30
  progress_next?: {progress:string; data:ProgressNext; deliverable:Deliverable; guard?:string | 'fetch'};
31
31
  }
32
32
  export class CallMachine extends CallBase { //@ todo self-owned node operate
33
- data: CallMachine_Data
33
+ data: CallMachine_Data;
34
34
  constructor(data:CallMachine_Data) {
35
35
  super();
36
36
  this.data = data;
@@ -118,6 +118,8 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
118
118
  } else {
119
119
  if (IsValidAddress(object_address) &&permission_address && IsValidAddress(permission_address)) {
120
120
  obj = Machine.From(txb, permission_address, object_address)
121
+ } else {
122
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
121
123
  }
122
124
  }
123
125
 
@@ -128,15 +130,6 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
128
130
  if (this.data?.endpoint !== undefined && object_address) {
129
131
  obj?.set_endpoint(this.data.endpoint, passport)
130
132
  }
131
- if (this.data?.bPaused !== undefined) {
132
- obj?.pause(this.data.bPaused, passport)
133
- }
134
- if (this.data?.bPublished ) {
135
- obj?.publish(passport)
136
- }
137
- if (this.data?.clone_new && obj) {
138
- this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
139
- }
140
133
 
141
134
  if (this.data?.consensus_repository !== undefined) {
142
135
  switch (this.data.consensus_repository.op) {
@@ -180,7 +173,7 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
180
173
  if (this.data?.progress_new !== undefined) {
181
174
  const addr = Progress?.New(txb, obj?.get_object(), permission??this.data?.permission, this.data?.progress_new.task_address, passport).launch();
182
175
  if (addr) {
183
- 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);
184
177
  }
185
178
  }
186
179
  if (this.data?.progress_context_repository !== undefined) {
@@ -211,11 +204,20 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
211
204
  if (this.data?.progress_next !== undefined) {
212
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)
213
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 !== undefined && obj) {
214
+ await this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
215
+ }
214
216
  if (permission) {
215
- 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);
216
218
  }
217
- if (!this.data.object) {
218
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
219
+ if (!object_address) {
220
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
219
221
  }
220
222
  }
221
223
  }
@@ -1,8 +1,5 @@
1
1
  import { CallBase, CallResult } from "./base";
2
- import { TransactionBlock, CallResponse, Protocol, Demand, DemandObject, Machine, Service, Treasury, Arbitration, Repository} from 'wowok';
3
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
4
- PermissionIndexType, WitnessFill
5
- } from 'wowok';
2
+ import { TransactionBlock, PassportObject, IsValidAddress, Errors, ERROR, Demand, Machine, Service, Treasury, Arbitration, Repository} from 'wowok';
6
3
  import { ObjectArbitration, ObjectDemand, ObjectMachine, ObjectRepository, ObjectService, ObjectTreasury, query_objects } from "../objects";
7
4
 
8
5
  export interface CallObjectPermission_Data {
@@ -1,22 +1,21 @@
1
1
  import { CallBase, CallResult, Namedbject } from "./base";
2
- import { TransactionBlock, CallResponse, Resource, ResourceObject} from 'wowok';
3
- import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
4
- PermissionIndexType, WitnessFill
2
+ import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, BizPermission,
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
- admin?: {op:'add' | 'remove' | 'set', admins:string[]};
9
+ admin?: {op:'add' | 'remove' | 'set', address:string[]};
11
10
  description?: string;
12
11
  permission?: {op:'add entity'; entities:Permission_Entity[]} | {op:'add permission'; permissions:Permission_Index[]}
13
12
  | {op:'remove entity'; addresses:string[]} | {op:'remove permission'; address:string; index:PermissionIndexType[]}
14
13
  | {op:'transfer permission', from_address: string; to_address: string};
15
- biz_permission?: {op:'add'; data: UserDefinedIndex[]} | {op:'remove'; permissions: PermissionIndexType[]};
14
+ biz_permission?: {op:'add'; data: BizPermission[]} | {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,30 +49,16 @@ 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':
70
55
  this.data.biz_permission.data.forEach(v => {
71
- obj?.add_userdefine(v.index, v.name);
56
+ obj?.add_bizPermission(v.index, v.name);
72
57
  })
73
58
  break;
74
59
  case 'remove':
75
60
  this.data.biz_permission.permissions.forEach(v => {
76
- obj?.remove_userdefine(v);
61
+ obj?.remove_bizPermission(v);
77
62
  })
78
63
  break;
79
64
  }
@@ -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.address);
92
+ break;
93
+ case 'remove':
94
+ obj?.remove_admin(this.data.admin.address);
95
+ break;
96
+ case 'set':
97
+ obj?.remove_admin([], true);
98
+ obj?.add_admin(this.data.admin.address);
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
  }
@@ -5,11 +5,12 @@ import { CallBase, CallResult, Namedbject } from "./base";
5
5
  export interface CallPersonal_Data {
6
6
  object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
7
7
  information?: Entity_Info;
8
- transfer_to?: string;
9
8
  mark?: {op:'add'; data:{address:string; name?:string; tags:string[]}[]}
10
9
  | {op:'remove'; data:{address:string; tags:string[]}[]}
11
- | {op:'removeall'; address:string[]};
12
- close?: boolean; // close a personal resource
10
+ | {op:'removeall'; address:string[],}
11
+ | {op:'transfer'; address: string}
12
+ | {op:'destroy';}
13
+ | {op:'replace'; address: string};
13
14
  }
14
15
 
15
16
  export class CallPersonal extends CallBase {
@@ -31,7 +32,7 @@ export class CallPersonal extends CallBase {
31
32
  obj = Resource.From(txb, object_address)
32
33
  }
33
34
 
34
- if (this.data?.close) {
35
+ if (this.data?.mark?.op === 'destroy') {
35
36
  entity.destroy_resource(obj)
36
37
  return ; //@ return
37
38
  }
@@ -60,12 +61,15 @@ export class CallPersonal extends CallBase {
60
61
  break;
61
62
  }
62
63
  }
63
- if (this.data?.transfer_to !== undefined && obj) {
64
- entity.transfer_resource(obj, this.data.transfer_to);
64
+ if (this.data?.mark?.op === 'transfer' && obj && IsValidAddress(this.data.mark.address)) {
65
+ entity.transfer_resource(obj, this.data.mark.address);
66
+ }
67
+ if (this.data?.mark?.op === 'replace' && IsValidAddress(this.data.mark.address)) {
68
+ entity.use_resource(Resource.From(txb, this.data.mark.address));
65
69
  }
66
70
 
67
71
  if (!object_address && obj) {
68
- this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
72
+ await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
69
73
  }
70
74
  }
71
75
  }
@@ -63,6 +63,8 @@ export class CallRepository extends CallBase {
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
 
@@ -87,6 +89,20 @@ export class CallRepository extends CallBase {
87
89
  break;
88
90
  }
89
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
+ }
90
106
  if (this.data?.policy !== undefined) {
91
107
  switch(this.data.policy.op) {
92
108
  case 'set':
@@ -109,28 +125,14 @@ export class CallRepository extends CallBase {
109
125
  break;
110
126
  }
111
127
  }
112
- if (this.data?.data !== undefined) {
113
- switch(this.data.data.op) {
114
- case 'add':
115
- if ((this.data.data?.data as any)?.key !== undefined) {
116
- obj?.add_data(this.data.data.data as Repository_Policy_Data);
117
- } else if ((this.data.data?.data as any)?.address !== undefined) {
118
- obj?.add_data2(this.data.data.data as Repository_Policy_Data2);
119
- }
120
- break;
121
- case 'remove':
122
- obj?.remove(this.data.data.data.address, this.data.data.data.key);
123
- break;
124
- }
125
- }
126
128
  if (this.data?.mode !== undefined && object_address) { //@ priority??
127
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
  };
@@ -10,12 +10,12 @@ 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;
17
17
  gen_discount?: DicountDispatch[];
18
- arbitration?: {op:'set' | 'add'; arbitrations:{address:string, token_type:string}[]}
18
+ arbitration?: {op:'set' | 'add'; arbitrations:{address:string, type_parameter:string}[]}
19
19
  | {op:'removeall'} | {op:'remove', addresses:string[]};
20
20
  buy_guard?: string;
21
21
  endpoint?: string;
@@ -166,6 +166,8 @@ export class CallService extends CallBase {
166
166
  } else {
167
167
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
168
168
  obj = Service.From(txb, this.data.type_parameter, permission_address, object_address)
169
+ } else {
170
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
169
171
  }
170
172
  }
171
173
 
@@ -179,21 +181,12 @@ export class CallService extends CallBase {
179
181
  if (this.data?.endpoint !== undefined) {
180
182
  obj?.set_endpoint(this.data.endpoint, passport)
181
183
  }
182
- if (this.data?.buy_guard !== undefined) {
183
- obj?.set_buy_guard(this.data.buy_guard, passport)
184
- }
185
- if (this.data?.bPaused !== undefined) {
186
- obj?.pause(this.data.bPaused, passport)
187
- }
188
- if (this.data?.bPublished) {
189
- obj?.publish(passport)
190
- }
191
- if (this.data?.clone_new !== undefined && obj) {
192
- 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);
193
- }
194
184
  if (this.data?.machine !== undefined) {
195
185
  obj?.set_machine(this.data.machine, passport)
196
186
  }
187
+ if (this.data?.gen_discount !== undefined) {
188
+ obj?.discount_transfer(this.data.gen_discount, passport)
189
+ }
197
190
  if (this.data?.repository !== undefined) {
198
191
  switch (this.data.repository.op) {
199
192
  case 'add':
@@ -231,11 +224,11 @@ export class CallService extends CallBase {
231
224
  if (this.data?.arbitration !== undefined) {
232
225
  switch(this.data.arbitration.op) {
233
226
  case 'add':
234
- this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.token_type, passport))
227
+ this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.type_parameter, passport))
235
228
  break;
236
229
  case 'set':
237
230
  obj?.remove_arbitration([], true, passport)
238
- this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.token_type, passport))
231
+ this.data.arbitration.arbitrations.forEach(v=>obj?.add_arbitration(v.address, v.type_parameter, passport))
239
232
  break;
240
233
  case 'remove':
241
234
  obj?.remove_arbitration(this.data.arbitration.addresses, false, passport)
@@ -245,51 +238,6 @@ export class CallService extends CallBase {
245
238
  break;
246
239
  }
247
240
  }
248
- if (this.data?.customer_required_info !== undefined) {
249
- if (this.data.customer_required_info.required_info && this.data.customer_required_info.pubkey) {
250
- obj?.set_customer_required(this.data.customer_required_info.pubkey, this.data.customer_required_info.required_info, passport);
251
- } else if (this.data.customer_required_info.pubkey) {
252
- obj?.change_required_pubkey(this.data.customer_required_info.pubkey, passport);
253
- }
254
- }
255
- if (this.data?.refund_guard !== undefined) {
256
- switch(this.data.refund_guard.op) {
257
- case 'add':
258
- obj?.add_refund_guards(this.data.refund_guard.guards, passport)
259
- break;
260
- case 'set':
261
- obj?.remove_refund_guards([], true, passport)
262
- obj?.add_refund_guards(this.data.refund_guard.guards, passport)
263
- break;
264
- case 'remove':
265
- obj?.remove_refund_guards(this.data.refund_guard.addresses, false, passport)
266
- break;
267
- case 'removeall':
268
- obj?.remove_refund_guards([], true, passport)
269
- break;
270
- }
271
- }
272
- if (this.data?.gen_discount !== undefined) {
273
- obj?.discount_transfer(this.data.gen_discount, passport)
274
- }
275
- if (this.data?.withdraw_guard !== undefined) {
276
- switch(this.data.withdraw_guard.op) {
277
- case 'add':
278
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
279
- break;
280
- case 'set':
281
- obj?.remove_withdraw_guards([], true, passport)
282
- obj?.add_withdraw_guards(this.data.withdraw_guard.guards, passport)
283
- break;
284
- case 'remove':
285
- obj?.remove_withdraw_guards(this.data.withdraw_guard.addresses, false, passport)
286
- break;
287
- case 'removeall':
288
- obj?.remove_withdraw_guards([], true, passport)
289
- break;
290
- }
291
- }
292
-
293
241
  if (this.data?.sales !== undefined) {
294
242
  switch(this.data.sales.op) {
295
243
  case 'add':
@@ -311,7 +259,7 @@ export class CallService extends CallBase {
311
259
  //@ crypto tools support
312
260
  const addr = obj.buy(this.data.order_new.buy_items, coin, this.data.order_new.discount,
313
261
  this.data.order_new.machine, this.data.order_new.customer_info_crypto, passport) ;
314
- 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]);
315
263
  }
316
264
  }
317
265
  }
@@ -334,14 +282,67 @@ export class CallService extends CallBase {
334
282
  if (this.data?.order_withdrawl !== undefined && passport) { //@ need withdrawal passport
335
283
  obj?.withdraw(this.data.order_withdrawl.order, this.data.order_withdrawl.data, passport)
336
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
+ }
337
338
  if (payee) {
338
- 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);
339
340
  }
340
341
  if (permission) {
341
- 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);
342
343
  }
343
344
  if (!object_address) {
344
- 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);
345
346
  }
346
347
  }
347
348
  }
@@ -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};
@@ -114,19 +114,34 @@ export class CallTreasury extends CallBase {
114
114
  } else {
115
115
  if (IsValidAddress(object_address) && this.data.type_parameter && permission_address && IsValidAddress(permission_address)) {
116
116
  obj = Treasury.From(txb, this.data.type_parameter, permission_address, object_address)
117
+ } else {
118
+ ERROR(Errors.InvalidParam, 'object or permission address invalid.')
117
119
  }
118
120
  }
119
121
 
120
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
+ }
121
139
  if (this.data?.description !== undefined && object_address) {
122
140
  obj?.set_description(this.data.description, passport);
123
141
  }
124
142
  if (this.data?.deposit_guard !== undefined) {
125
143
  obj?.set_deposit_guard(this.data.deposit_guard, passport);
126
144
  }
127
- if (this.data?.withdraw_mode !== undefined) {
128
- obj?.set_withdraw_mode(this.data.withdraw_mode, passport)
129
- }
130
145
  if (this.data?.withdraw_guard !== undefined) {
131
146
  switch (this.data.withdraw_guard.op) {
132
147
  case 'add':
@@ -144,26 +159,12 @@ export class CallTreasury extends CallBase {
144
159
  break;
145
160
  }
146
161
  }
147
- if (this.data?.withdraw !== undefined) {
148
- obj?.withdraw(this.data.withdraw, passport)
149
- }
150
- if (this.data?.receive !== undefined) {
151
- obj?.receive(this.data.receive.payment, this.data.receive.received_object, passport);
152
- }
153
- if (this.data.deposit !== undefined) {
154
- const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.data.balance, account, this.data.type_parameter);
155
- if (coin) {
156
- const index = this.data.deposit.data?.index ?? 0;
157
- obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.data.remark ??'',
158
- for_guard:this.data.deposit.data?.for_guard,
159
- for_object: this.data.deposit.data?.for_object
160
- })
161
- }
162
+ if (this.data?.withdraw_mode !== undefined) {
163
+ obj?.set_withdraw_mode(this.data.withdraw_mode, passport)
162
164
  }
163
165
  if (permission) {
164
166
  await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
165
167
  }
166
-
167
168
  if (!object_address) {
168
169
  await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
169
170
  }
package/src/call.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  import { CallArbitration, CallArbitration_Data } from "./call/arbitration";
8
8
  import { CallDemand, CallDemand_Data } from "./call/demand";
9
9
  import { CallMachine, CallMachine_Data } from "./call/machine";
10
- import { CallEntityPermission, CallEntityPermission_Data } from "./call/entity_permission";
10
+ import { CallPermission, CallPermission_Data } from "./call/permission";
11
11
  import { CallPersonal, CallPersonal_Data } from "./call/personal";
12
12
  import { CallRepository, CallRepository_Data } from "./call/repository";
13
13
  import { CallService, CallService_Data } from "./call/service";
@@ -16,25 +16,26 @@ import { CallBase, CallResult, CallWithWitnessParam } from "./call/base";
16
16
  import { CallGuard, CallGuard_Data } from "./call/guard";
17
17
  import { CallObjectPermission, CallObjectPermission_Data } from "./call/object_permission";
18
18
 
19
-
20
- export interface CallObjectData {
21
- type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'EntityPermission' | 'ObjectPermission';
22
- data: CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallEntityPermission_Data | CallObjectPermission_Data
23
- | CallTreasury_Data | CallService_Data | CallRepository_Data;
19
+ export type CallObjectType = 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | 'Permission' | 'ObjectPermission';
20
+ export type CallObjectData = CallDemand_Data | CallMachine_Data | CallArbitration_Data | CallPermission_Data | CallObjectPermission_Data
21
+ | CallTreasury_Data | CallService_Data | CallRepository_Data;
22
+ export interface CallObject {
23
+ type: CallObjectType;
24
+ data: CallObjectData;
24
25
  account?: string;
25
26
  witness?: CallWithWitnessParam;
26
27
  }
27
28
 
28
29
  export const call_object_json = async (json: string) : Promise<string> => {
29
30
  try {
30
- const c : CallObjectData = JSON.parse(json);
31
+ const c : CallObject = JSON.parse(json);
31
32
  return JSON.stringify({data:await call_object(c)});
32
33
  } catch (e) {
33
34
  return JSON.stringify({error:e?.toString()})
34
35
  }
35
36
  }
36
37
 
37
- export const call_object = async (call: CallObjectData) : Promise<CallResult> => {
38
+ export const call_object = async (call: CallObject) : Promise<CallResult> => {
38
39
  var obj = call_object_new(call);
39
40
 
40
41
  if (obj) {
@@ -46,7 +47,7 @@ export const call_object = async (call: CallObjectData) : Promise<CallResult> =>
46
47
  }
47
48
  }
48
49
 
49
- function call_object_new (call: CallObjectData) : CallBase | undefined {
50
+ function call_object_new (call: CallObject) : CallBase | undefined {
50
51
  switch (call.type) {
51
52
  case 'Demand':
52
53
  return new CallDemand(call.data as CallDemand_Data);
@@ -64,8 +65,8 @@ function call_object_new (call: CallObjectData) : CallBase | undefined {
64
65
  return new CallRepository(call.data as CallRepository_Data);
65
66
  case 'Personal':
66
67
  return new CallPersonal(call.data as CallPersonal_Data);
67
- case 'EntityPermission':
68
- return new CallEntityPermission(call.data as CallEntityPermission_Data);
68
+ case 'Permission':
69
+ return new CallPermission(call.data as CallPermission_Data);
69
70
  case 'ObjectPermission':
70
71
  return new CallObjectPermission(call.data as CallObjectPermission_Data);
71
72
  }
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' | 'Discount' |
16
- 'Personal' | 'EntityPermission' | 'PersonalMark' | '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;
@@ -456,18 +456,58 @@ const tableItem = async (query:TableItemQuery) : Promise<ObjectBase> => {
456
456
  return data2object(res?.data)
457
457
  }
458
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' || t === 'Arbitration') {
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
+
459
499
  export function data2object(data?:any) : ObjectBase {
460
500
  const content = (data?.content as any)?.fields;
461
501
  const id = data?.objectId ?? (content?.id?.id ?? undefined);
462
502
  const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
463
503
  const version = data?.version ?? undefined;
464
504
  const owner = data?.owner ?? undefined;
465
- const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
505
+ const type:string | undefined = raw2type(type_raw);
466
506
 
467
507
  if (type) {
468
508
  switch(type) {
469
509
  case 'Permission':
470
- return {object:id, type:'EntityPermission', type_raw:type_raw, owner:owner, version:version,
510
+ return {object:id, type:type, type_raw:type_raw, owner:owner, version:version,
471
511
  builder: content?.builder ??'', admin:content?.admin, description:content?.description??'',
472
512
  entity_count: parseInt(content?.table?.fields?.size),
473
513
  biz_permission:content?.user_define?.fields?.contents?.map((v:any) => {
@@ -602,80 +642,68 @@ export function data2object(data?:any) : ObjectBase {
602
642
  return {id:v?.fields?.identifier, bWitness:v?.fields?.bWitness, value:Uint8Array.from(v?.fields?.value)}
603
643
  })
604
644
  } as ObjectGuard;
605
- case 'Resource' :
645
+ case 'PersonalMark' :
606
646
  return {
607
- object:id, type:'PersonalMark', type_raw:type_raw, owner:owner, version:version,
647
+ object:id, type:type, type_raw:type_raw, owner:owner, version:version,
608
648
  tag_count:parseInt(content?.tags?.fields?.size)
609
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;
610
704
  }
611
705
  }
612
-
613
- const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
614
- if (start === 0) {
615
- const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
616
- if(end && Protocol.Instance().hasPackage(end)) {
617
- if (end.includes('::demand::Tips>')) {
618
- return {
619
- object:id, type:'TableItem_DemandPresenter', type_raw:type_raw, owner:owner, version:version,
620
- service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
621
- } as TableItem_DemandPresenter;
622
- } else if (end.includes('::machine::NodePair>>>')) {
623
- return {
624
- object:id, type:'TableItem_MachineNode', type_raw:type_raw, owner:owner, version:version,
625
- node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
626
- } as TableItem_MachineNode;
627
- } else if (end.includes('::progress::History>')) {
628
- return {
629
- object:id, type:'TableItem_ProgressHistory', type_raw:type_raw, owner:owner, version:version,
630
- history:Progress.DeHistory(content)
631
- } as TableItem_ProgressHistory;
632
- } else if (end.includes('::service::Sale>')) {
633
- return {
634
- object:id, type:'TableItem_ServiceSale', type_raw:type_raw, owner:owner, version:version,
635
- item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
636
- endpoint:content?.value?.fields?.endpoint
637
- }
638
- } as TableItem_ServiceSale;
639
- } else if (end.includes('::treasury::Record>')) {
640
- return {
641
- object:id, type:'TableItem_TreasuryHistory', type_raw:type_raw, owner:owner, version:version,
642
- id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
643
- operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
644
- } as TableItem_TreasuryHistory;
645
- } else if (end.includes('::arb::Voted>')) {
646
- return {
647
- object:id, type:'TableItem_ArbVote', type_raw:type_raw, owner:owner, version:version,
648
- singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
649
- weight:content?.value?.fields?.weight
650
- } as TableItem_ArbVote;
651
- } else if (end.includes('::permission::Perm>>')) {
652
- return {
653
- object:id, type:'TableItem_PermissionEntity', type_raw:type_raw, owner:owner, version:version,
654
- entity:content?.name, permission:content?.value?.map((v:any) => {
655
- return {id:v?.fields.index, guard:v?.fields.guard}
656
- })
657
- } as TableItem_PermissionEntity;
658
- } else if (end.includes('::repository::DataKey')) {
659
- return {
660
- object:id, type:'TableItem_RepositoryData', type_raw:type_raw, owner:owner, version:version,
661
- address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
662
- } as TableItem_RepositoryData;
663
- } else if (end.includes('::entity::Ent>')) {
664
- const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
665
- return {
666
- object:id, type:'Personal', type_raw:type_raw, owner:owner, version:version,
667
- address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
668
- mark_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
669
- info : {homepage:info?.homepage, name:info?.name, avatar:info?.avatar, twitter:info?.twitter, discord:info?.discord,
670
- description:info?.description}
671
- } as ObjectPersonal;
672
- } else if (end.includes('::resource::Tags>')) {
673
- return {object:id, type:'TableItem_PersonalMark', type_raw:type_raw, owner:owner, version:version,
674
- address:content?.name, name:content?.value?.fields?.nick, tags:content?.value?.fields?.tags
675
- } as TableItem_PersonalMark;
676
- }
677
- }
678
- }
679
- 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}
680
708
  }
681
709