wowok_agent 0.1.9 → 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 +1 -1
- package/src/account.ts +0 -1
- package/src/call/arbitration.ts +7 -5
- package/src/call/base.ts +5 -8
- package/src/call/demand.ts +5 -4
- package/src/call/guard.ts +17 -20
- package/src/call/machine.ts +14 -12
- package/src/call/{entity_permission.ts → permission.ts} +20 -22
- package/src/call/personal.ts +1 -1
- package/src/call/repository.ts +18 -16
- package/src/call/service.ts +60 -59
- package/src/call/treasury.ts +22 -21
- package/src/call.ts +5 -5
- package/src/index.ts +3 -2
- package/src/objects.ts +107 -79
package/package.json
CHANGED
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});
|
package/src/call/arbitration.ts
CHANGED
|
@@ -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
|
|
12
|
+
type_parameter: string;
|
|
13
13
|
permission_new?: string;
|
|
14
14
|
description?: string;
|
|
15
15
|
bPaused?: boolean;
|
|
@@ -127,6 +127,8 @@ export class CallArbitration extends CallBase {
|
|
|
127
127
|
} else if (object_address) {
|
|
128
128
|
if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
|
|
129
129
|
obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
130
|
+
} else {
|
|
131
|
+
ERROR(Errors.InvalidParam, 'object or permission address invalid.')
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -168,7 +170,7 @@ export class CallArbitration extends CallBase {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
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);
|
|
173
|
+
await this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
|
|
172
174
|
}
|
|
173
175
|
if (this.data?.arb_arbitration !== undefined) {
|
|
174
176
|
obj?.arbitration(this.data.arb_arbitration, passport)
|
|
@@ -184,14 +186,14 @@ export class CallArbitration extends CallBase {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
if (withdraw_treasury) {
|
|
187
|
-
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);
|
|
188
190
|
}
|
|
189
191
|
if (permission) {
|
|
190
|
-
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);
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
if (!object_address) {
|
|
194
|
-
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);
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
}
|
package/src/call/base.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
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
|
|
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
|
|
@@ -135,25 +135,22 @@ export class CallBase {
|
|
|
135
135
|
const r = await queryTableItem_Personal({address:addr}); //@ use cache
|
|
136
136
|
if (!r?.mark_object) {
|
|
137
137
|
this.resouceObject = Entity.From(txb).create_resource2(); // new
|
|
138
|
+
Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
|
|
138
139
|
} else {
|
|
139
140
|
Resource.From(txb, r.mark_object).add(object, tags, named_new?.name);
|
|
140
|
-
return
|
|
141
141
|
}
|
|
142
142
|
} else {
|
|
143
143
|
ERROR(Errors.InvalidParam, 'account - ' + account)
|
|
144
144
|
}
|
|
145
|
-
}
|
|
146
|
-
if (this.resouceObject) {
|
|
147
|
-
Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
|
|
148
145
|
} else {
|
|
149
|
-
|
|
146
|
+
Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
|
|
153
150
|
protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
|
|
154
151
|
const pair = Account.Instance().get_pair(account, true);
|
|
155
152
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
156
|
-
|
|
153
|
+
|
|
157
154
|
if (this.resouceObject) {
|
|
158
155
|
Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
|
|
159
156
|
this.resouceObject = undefined;
|
package/src/call/demand.ts
CHANGED
|
@@ -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,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,
|
|
9
|
-
Resource,
|
|
10
|
-
ResourceObject,
|
|
11
|
-
PassportObject} from "wowok";
|
|
12
|
-
import { Account } from "../account";
|
|
8
|
+
IsValidDesription, PassportObject} from "wowok";
|
|
13
9
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
14
10
|
|
|
15
11
|
export interface GuardConst {
|
|
@@ -70,7 +66,7 @@ export class CallGuard extends CallBase {
|
|
|
70
66
|
var output : Uint8Array[]= [];
|
|
71
67
|
buildNode(this.data.root!, ValueType.TYPE_BOOL, this.data?.table ?? [], output);
|
|
72
68
|
const bytes = (concatenate(Uint8Array, ...output) as Uint8Array);
|
|
73
|
-
|
|
69
|
+
|
|
74
70
|
const obj = txb.moveCall({
|
|
75
71
|
target: Protocol.Instance().guardFn('new') as FnCallType,
|
|
76
72
|
arguments: [txb.pure.string(this.data.description), txb.pure.vector('u8', [].slice.call(bytes.reverse()))],
|
|
@@ -78,6 +74,7 @@ export class CallGuard extends CallBase {
|
|
|
78
74
|
this.data?.table?.forEach((v) => {
|
|
79
75
|
if (v.bWitness) {
|
|
80
76
|
const n = new Uint8Array(1); n.set([v.value_type], 0);
|
|
77
|
+
console.log(n)
|
|
81
78
|
txb.moveCall({
|
|
82
79
|
target:Protocol.Instance().guardFn("constant_add") as FnCallType,
|
|
83
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)]
|
|
@@ -95,7 +92,7 @@ export class CallGuard extends CallBase {
|
|
|
95
92
|
target:Protocol.Instance().guardFn("create") as FnCallType,
|
|
96
93
|
arguments:[txb.object(obj)]
|
|
97
94
|
});
|
|
98
|
-
this.new_with_mark(txb, addr, this.data?.namedNew, account);
|
|
95
|
+
await this.new_with_mark(txb, addr, this.data?.namedNew, account);
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
|
|
@@ -119,20 +116,18 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
119
116
|
} else if (typeof(node.query === 'number')) {
|
|
120
117
|
q = GUARD_QUERIES.find(v=>v[2] === node.query);
|
|
121
118
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
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
|
|
131
125
|
}
|
|
132
126
|
} else {
|
|
133
|
-
ERROR(Errors.InvalidParam, 'node query not
|
|
127
|
+
ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + node.toString())
|
|
134
128
|
}
|
|
135
129
|
|
|
130
|
+
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE + addr + cmd
|
|
136
131
|
if (typeof(node.object) === 'string') {
|
|
137
132
|
if (!IsValidAddress(node.object)) {
|
|
138
133
|
ERROR(Errors.InvalidParam, 'node object from address string - ' + node.toString())
|
|
@@ -149,6 +144,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
149
144
|
ERROR(Errors.InvalidParam, 'node object from identifier - ' + node.toString());
|
|
150
145
|
}
|
|
151
146
|
}
|
|
147
|
+
output.push(Bcs.getInstance().ser('u16', q![2])); // cmd(u16)
|
|
152
148
|
} else if (node?.logic !== undefined) {
|
|
153
149
|
checkType(ValueType.TYPE_BOOL, type_required, node); // bool
|
|
154
150
|
switch (node?.logic) {
|
|
@@ -174,7 +170,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
174
170
|
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
175
171
|
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
176
172
|
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,
|
|
173
|
+
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
|
|
178
174
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
179
175
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
180
176
|
break;
|
|
@@ -187,7 +183,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
187
183
|
break;
|
|
188
184
|
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
189
185
|
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.
|
|
186
|
+
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_STRING, table, output));
|
|
191
187
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
192
188
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
193
189
|
break;
|
|
@@ -195,7 +191,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
195
191
|
} else if (node?.calc !== undefined) {
|
|
196
192
|
checkType(ValueType.TYPE_U256, type_required, node);
|
|
197
193
|
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,
|
|
194
|
+
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
|
|
199
195
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.calc)); // TYPE
|
|
200
196
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
201
197
|
} else if (node?.value_type !== undefined) {
|
|
@@ -255,6 +251,7 @@ const checkType = (type: ValueType | ContextType.TYPE_CLOCK | ContextType.TYPE_G
|
|
|
255
251
|
if (type !== type_required) {
|
|
256
252
|
var str = '';
|
|
257
253
|
if (node) str = ' - ' + node.toString();
|
|
254
|
+
console.log(node)
|
|
258
255
|
ERROR(Errors.InvalidParam, 'checkType: ' + type + ' require type: ' + type_required + str);
|
|
259
256
|
}
|
|
260
257
|
}
|
package/src/call/machine.ts
CHANGED
|
@@ -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 && 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
219
|
if (!this.data.object) {
|
|
218
|
-
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);
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
2
|
-
import { TransactionBlock, CallResponse, Resource, ResourceObject} from 'wowok';
|
|
3
2
|
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
|
|
4
|
-
PermissionIndexType,
|
|
3
|
+
PermissionIndexType, TransactionBlock
|
|
5
4
|
} from 'wowok';
|
|
6
5
|
|
|
7
|
-
export interface
|
|
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
|
|
18
|
-
data:
|
|
19
|
-
constructor(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
|
}
|
package/src/call/personal.ts
CHANGED
|
@@ -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
|
}
|
package/src/call/repository.ts
CHANGED
|
@@ -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
|
};
|
package/src/call/service.ts
CHANGED
|
@@ -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
|
|
13
|
+
type_parameter: string;
|
|
14
14
|
bPaused?: boolean;
|
|
15
15
|
bPublished?: boolean;
|
|
16
16
|
description?: 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,18 +181,6 @@ 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
|
}
|
|
@@ -245,51 +235,9 @@ export class CallService extends CallBase {
|
|
|
245
235
|
break;
|
|
246
236
|
}
|
|
247
237
|
}
|
|
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
238
|
if (this.data?.gen_discount !== undefined) {
|
|
273
239
|
obj?.discount_transfer(this.data.gen_discount, passport)
|
|
274
240
|
}
|
|
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
|
}
|
package/src/call/treasury.ts
CHANGED
|
@@ -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
|
|
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?.
|
|
148
|
-
obj?.
|
|
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 {
|
|
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";
|
|
@@ -18,8 +18,8 @@ import { CallObjectPermission, CallObjectPermission_Data } from "./call/object_p
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
export interface CallObjectData {
|
|
21
|
-
type: 'Demand' | 'Service' | 'Machine' | 'Treasury' | 'Arbitration' | 'Guard' | 'Repository' | 'Personal' | '
|
|
22
|
-
data: CallDemand_Data | CallMachine_Data | CallArbitration_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
|
|
23
23
|
| CallTreasury_Data | CallService_Data | CallRepository_Data;
|
|
24
24
|
account?: string;
|
|
25
25
|
witness?: CallWithWitnessParam;
|
|
@@ -64,8 +64,8 @@ function call_object_new (call: CallObjectData) : CallBase | undefined {
|
|
|
64
64
|
return new CallRepository(call.data as CallRepository_Data);
|
|
65
65
|
case 'Personal':
|
|
66
66
|
return new CallPersonal(call.data as CallPersonal_Data);
|
|
67
|
-
case '
|
|
68
|
-
return new
|
|
67
|
+
case 'Permission':
|
|
68
|
+
return new CallPermission(call.data as CallPermission_Data);
|
|
69
69
|
case 'ObjectPermission':
|
|
70
70
|
return new CallObjectPermission(call.data as CallObjectPermission_Data);
|
|
71
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/
|
|
6
|
+
export * from './call/permission'
|
|
7
7
|
export * from './call/arbitration'
|
|
8
8
|
export * from './call/treasury'
|
|
9
|
-
export * from './call/
|
|
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
|
|
14
|
-
|
|
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') {
|
|
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 =
|
|
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:
|
|
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 '
|
|
645
|
+
case 'PersonalMark' :
|
|
606
646
|
return {
|
|
607
|
-
object:id, type:
|
|
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
|
-
|
|
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
|
|