wowok_agent 0.1.11 → 0.1.13
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 +51 -55
- package/src/call/arbitration.ts +24 -35
- package/src/call/base.ts +2 -1
- package/src/call/demand.ts +10 -10
- package/src/call/guard.ts +26 -19
- package/src/call/machine.ts +23 -28
- package/src/call/object_permission.ts +1 -4
- package/src/call/permission.ts +24 -23
- package/src/call/personal.ts +11 -6
- package/src/call/repository.ts +18 -16
- package/src/call/service.ts +71 -70
- package/src/call/treasury.ts +13 -12
- package/src/call.ts +10 -9
- package/src/objects.ts +1 -1
- package/src/permission.ts +1 -3
- package/src/private_info.ts +217 -0
package/package.json
CHANGED
package/src/account.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface AccountData_Show {
|
|
|
15
15
|
address: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const Account_FileName = 'wowok.dat';
|
|
19
|
-
const Account_Key = 'wowok-
|
|
18
|
+
const Account_FileName = 'wowok.acc.dat';
|
|
19
|
+
const Account_Key = 'wowok-acc-v1';
|
|
20
20
|
|
|
21
21
|
export class Account {
|
|
22
22
|
constructor(storage: 'File' | 'Explorer' = 'File') {
|
|
@@ -32,64 +32,61 @@ export class Account {
|
|
|
32
32
|
|
|
33
33
|
private storage: 'File' | 'Explorer' = 'File';
|
|
34
34
|
|
|
35
|
-
private _add(buffer:string | null | undefined, name:string, bDefault?: boolean) : AccountData[] {
|
|
35
|
+
private _add(buffer:string | null | undefined, name:string, bDefault?: boolean) : AccountData[] | undefined {
|
|
36
36
|
var data : AccountData[] | undefined;
|
|
37
37
|
var key = '0x'+toHEX(decodeSuiPrivateKey(Ed25519Keypair.generate().getSecretKey()).secretKey);
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
40
|
if (buffer) {
|
|
41
|
-
data = JSON.parse(buffer) as AccountData[];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
data = JSON.parse(buffer) as AccountData[];
|
|
42
|
+
if (data) {
|
|
43
|
+
const f = data.find(v => v.name === name);
|
|
44
|
+
if (f) {
|
|
45
|
+
f.default = bDefault;
|
|
46
|
+
} else {
|
|
47
|
+
if (bDefault) {
|
|
48
|
+
data.forEach(v => v.default = false)
|
|
49
|
+
}
|
|
50
|
+
data.push({name:name, key:key, default:bDefault})
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
data = [{name:name, key:key, default:bDefault}];
|
|
52
54
|
}
|
|
53
|
-
data
|
|
55
|
+
return data
|
|
54
56
|
}
|
|
55
|
-
}
|
|
56
|
-
data = [{name:name, key:key, default:bDefault}];
|
|
57
|
-
}
|
|
58
|
-
return data
|
|
57
|
+
} catch(e) { console.log(e) }
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
private _default(buffer:string | null | undefined) : AccountData | undefined {
|
|
62
61
|
var data : AccountData[] | undefined;
|
|
63
62
|
try {
|
|
64
63
|
if (buffer) {
|
|
65
|
-
data = JSON.parse(buffer) as AccountData[];
|
|
64
|
+
data = JSON.parse(buffer) as AccountData[];
|
|
65
|
+
if (data) {
|
|
66
|
+
const f = data.find(v => v.default);
|
|
67
|
+
if (f) {
|
|
68
|
+
return f
|
|
69
|
+
}
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
} catch(e) { console.log(e) }
|
|
68
|
-
|
|
69
|
-
if (data) {
|
|
70
|
-
const f = data.find(v => v.default);
|
|
71
|
-
if (f) {
|
|
72
|
-
return f
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
73
|
}
|
|
76
74
|
private _get(buffer:string | null | undefined, name?:string, bNotFoundReturnDefault?:boolean) : AccountData | undefined {
|
|
77
75
|
var data : AccountData[] | undefined;
|
|
78
76
|
try {
|
|
79
77
|
if (buffer) {
|
|
80
|
-
data = JSON.parse(buffer) as AccountData[];
|
|
78
|
+
data = JSON.parse(buffer) as AccountData[];
|
|
79
|
+
if (data) {
|
|
80
|
+
const f = data.find(v => v.name === name);
|
|
81
|
+
if (f) {
|
|
82
|
+
return f
|
|
83
|
+
}
|
|
84
|
+
if (bNotFoundReturnDefault) {
|
|
85
|
+
return data.find(v => v.default)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
89
|
} catch(e) { console.log(e) }
|
|
83
|
-
|
|
84
|
-
if (data) {
|
|
85
|
-
const f = data.find(v => v.name === name);
|
|
86
|
-
if (f) {
|
|
87
|
-
return f
|
|
88
|
-
}
|
|
89
|
-
if (bNotFoundReturnDefault) {
|
|
90
|
-
return data.find(v => v.default)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
90
|
}
|
|
94
91
|
private _rename(buffer:string | null | undefined, oldName:string, newName:string, bSwapIfExisted:boolean=true) : AccountData[] | undefined {
|
|
95
92
|
var data : AccountData[] | undefined;
|
|
@@ -97,25 +94,24 @@ export class Account {
|
|
|
97
94
|
if (buffer) {
|
|
98
95
|
data = JSON.parse(buffer) as AccountData[];
|
|
99
96
|
}
|
|
100
|
-
} catch(e) { console.log(e) }
|
|
101
|
-
|
|
102
|
-
if (data) {
|
|
103
|
-
const f1 = data.find(v => v.name === oldName);
|
|
104
|
-
if (!f1) return undefined;
|
|
105
97
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
98
|
+
if (data) {
|
|
99
|
+
const f1 = data.find(v => v.name === oldName);
|
|
100
|
+
if (!f1) return undefined;
|
|
101
|
+
|
|
102
|
+
const f2 = data.find(v => v.name === newName);
|
|
103
|
+
if (f2) {
|
|
104
|
+
if (bSwapIfExisted) {
|
|
105
|
+
f1.name = newName;
|
|
106
|
+
f2.name = oldName;
|
|
107
|
+
return data
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
109
110
|
f1.name = newName;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
f1.name = newName;
|
|
115
|
-
return data;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return undefined
|
|
111
|
+
return data;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} catch(e) { console.log(e) }
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
set_storage(storage: 'File' | 'Explorer' = 'File') {
|
package/src/call/arbitration.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { TransactionBlock, IsValidArgType,
|
|
2
|
-
|
|
3
|
-
Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee, WitnessFill
|
|
1
|
+
import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
|
|
2
|
+
PermissionIndexType, Treasury, Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee,
|
|
4
3
|
} from 'wowok';
|
|
5
4
|
import { query_objects, ObjectArbitration, } from '../objects';
|
|
6
|
-
import { CallBase, CallResult,
|
|
5
|
+
import { CallBase, CallResult, Namedbject} from "./base";
|
|
7
6
|
|
|
8
7
|
export interface CallArbitration_Data {
|
|
8
|
+
type_parameter: string;
|
|
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;
|
|
13
|
-
permission_new?: string;
|
|
14
11
|
description?: string;
|
|
15
|
-
bPaused?: boolean;
|
|
16
12
|
endpoint?: string;
|
|
17
13
|
fee?: string;
|
|
18
14
|
fee_treasury?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
19
|
-
usage_guard?: string;
|
|
20
|
-
voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
|
|
21
15
|
arb_new?: {data: Dispute; guard?:string | 'fetch'; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
|
|
22
16
|
arb_withdraw_fee?: {arb:string; data:WithdrawFee};
|
|
23
17
|
arb_vote?: Vote;
|
|
24
18
|
arb_arbitration?: Feedback;
|
|
19
|
+
usage_guard?: string;
|
|
20
|
+
voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
|
|
21
|
+
bPaused?: boolean;
|
|
25
22
|
}
|
|
23
|
+
|
|
26
24
|
export class CallArbitration extends CallBase {
|
|
27
25
|
data: CallArbitration_Data;
|
|
28
26
|
constructor (data: CallArbitration_Data) {
|
|
@@ -45,9 +43,6 @@ export class CallArbitration extends CallBase {
|
|
|
45
43
|
if (!this.data?.object) {
|
|
46
44
|
perms.push(PermissionIndex.arbitration)
|
|
47
45
|
}
|
|
48
|
-
if (this.data?.permission_new !== undefined) {
|
|
49
|
-
checkOwner = true;
|
|
50
|
-
}
|
|
51
46
|
if (this.data?.description !== undefined && object_address) {
|
|
52
47
|
perms.push(PermissionIndex.arbitration_description)
|
|
53
48
|
}
|
|
@@ -121,10 +116,9 @@ export class CallArbitration extends CallBase {
|
|
|
121
116
|
withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
|
|
122
117
|
d, permission?undefined:passport);
|
|
123
118
|
}
|
|
124
|
-
|
|
125
119
|
obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
|
|
126
120
|
BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
|
|
127
|
-
} else
|
|
121
|
+
} else {
|
|
128
122
|
if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
|
|
129
123
|
obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
130
124
|
} else {
|
|
@@ -136,9 +130,6 @@ export class CallArbitration extends CallBase {
|
|
|
136
130
|
if (this.data?.description !== undefined && object_address) {
|
|
137
131
|
obj?.set_description(this.data.description, passport);
|
|
138
132
|
}
|
|
139
|
-
if (this.data?.bPaused !== undefined) {
|
|
140
|
-
obj?.pause(this.data.bPaused, passport);
|
|
141
|
-
}
|
|
142
133
|
if (this.data?.endpoint !== undefined) {
|
|
143
134
|
obj?.set_endpoint(this.data.endpoint, passport)
|
|
144
135
|
}
|
|
@@ -148,8 +139,17 @@ export class CallArbitration extends CallBase {
|
|
|
148
139
|
if (treasury_address !== undefined && object_address) {
|
|
149
140
|
obj?.set_withdrawTreasury(treasury_address, passport)
|
|
150
141
|
}
|
|
151
|
-
if (this.data
|
|
152
|
-
obj?.
|
|
142
|
+
if (this.data?.arb_new !== undefined) {
|
|
143
|
+
await this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
|
|
144
|
+
}
|
|
145
|
+
if (this.data?.arb_arbitration !== undefined) {
|
|
146
|
+
obj?.arbitration(this.data.arb_arbitration, passport)
|
|
147
|
+
}
|
|
148
|
+
if (this.data?.arb_vote !== undefined) {
|
|
149
|
+
obj?.vote(this.data.arb_vote, passport)
|
|
150
|
+
}
|
|
151
|
+
if (this.data?.arb_withdraw_fee !== undefined) {
|
|
152
|
+
obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
|
|
153
153
|
}
|
|
154
154
|
if (this.data?.voting_guard !== undefined) {
|
|
155
155
|
switch (this.data.voting_guard.op) {
|
|
@@ -168,23 +168,12 @@ export class CallArbitration extends CallBase {
|
|
|
168
168
|
break;
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
await this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
|
|
174
|
-
}
|
|
175
|
-
if (this.data?.arb_arbitration !== undefined) {
|
|
176
|
-
obj?.arbitration(this.data.arb_arbitration, passport)
|
|
177
|
-
}
|
|
178
|
-
if (this.data?.arb_vote !== undefined) {
|
|
179
|
-
obj?.vote(this.data.arb_vote, passport)
|
|
180
|
-
}
|
|
181
|
-
if (this.data?.arb_withdraw_fee !== undefined) {
|
|
182
|
-
obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
|
|
171
|
+
if (this.data.usage_guard !== undefined) {
|
|
172
|
+
obj?.set_guard(this.data.usage_guard, passport)
|
|
183
173
|
}
|
|
184
|
-
if (this.data?.
|
|
185
|
-
obj?.
|
|
174
|
+
if (this.data?.bPaused !== undefined) {
|
|
175
|
+
obj?.pause(this.data.bPaused, passport);
|
|
186
176
|
}
|
|
187
|
-
|
|
188
177
|
if (withdraw_treasury) {
|
|
189
178
|
await this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
|
|
190
179
|
}
|
package/src/call/base.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Account } from '../account';
|
|
|
9
9
|
import { ObjectBase, queryTableItem_Personal, raw2type} from '../objects';
|
|
10
10
|
|
|
11
11
|
export interface Namedbject {
|
|
12
|
-
name
|
|
12
|
+
name?: string;
|
|
13
13
|
tags?: string[];
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -32,6 +32,7 @@ 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 => {
|
package/src/call/demand.ts
CHANGED
|
@@ -5,18 +5,18 @@ import { query_objects, ObjectDemand } from '../objects';
|
|
|
5
5
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
6
6
|
import { Account } from '../account';
|
|
7
7
|
|
|
8
|
+
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
8
9
|
export interface CallDemand_Data {
|
|
10
|
+
type_parameter: string;
|
|
9
11
|
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
10
12
|
permission?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
11
|
-
type_parameter: string;
|
|
12
|
-
guard?: {address:string; service_id_in_guard?:number};
|
|
13
13
|
description?: string;
|
|
14
14
|
time_expire?: {op: 'duration'; minutes:number} | {op:'set'; time:number};
|
|
15
|
-
bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'
|
|
15
|
+
bounty?: {op:'add'; object:{address:string}|{balance:string|number}} | {op:'reward'; service:string} | {op:'refund'} ;
|
|
16
16
|
present?: {service: string | number; recommend_words:string; service_pay_type:string, guard?:string | 'fetch'}; // guard is the present guard of Demand
|
|
17
|
-
|
|
18
|
-
refund?: boolean;
|
|
17
|
+
guard?: {address:string; service_id_in_guard?:number};
|
|
19
18
|
}
|
|
19
|
+
|
|
20
20
|
export class CallDemand extends CallBase {
|
|
21
21
|
data: CallDemand_Data;
|
|
22
22
|
constructor(data: CallDemand_Data) {
|
|
@@ -46,10 +46,10 @@ export class CallDemand extends CallBase {
|
|
|
46
46
|
if (this.data?.guard !== undefined) {
|
|
47
47
|
perms.push(PermissionIndex.demand_guard)
|
|
48
48
|
}
|
|
49
|
-
if (this.data?.
|
|
49
|
+
if (this.data?.bounty?.op === 'reward') {
|
|
50
50
|
perms.push(PermissionIndex.demand_yes)
|
|
51
51
|
}
|
|
52
|
-
if (this.data?.refund) {
|
|
52
|
+
if (this.data?.bounty?.op === 'refund') {
|
|
53
53
|
perms.push(PermissionIndex.demand_refund)
|
|
54
54
|
}
|
|
55
55
|
if (this.data?.present?.guard !== undefined) {
|
|
@@ -121,11 +121,11 @@ export class CallDemand extends CallBase {
|
|
|
121
121
|
const r = await Account.Instance().get_coin_object(txb, (this.data.bounty.object as any)?.balance, account, this.data.type_parameter);
|
|
122
122
|
if (r) obj.deposit(r)
|
|
123
123
|
}
|
|
124
|
-
} else if (this.data.bounty.op === 'refund') {
|
|
125
|
-
obj?.refund(passport);
|
|
126
124
|
} else if (this.data.bounty.op === 'reward') {
|
|
127
125
|
obj?.yes(this.data.bounty.service, passport);
|
|
128
|
-
}
|
|
126
|
+
} else if (this.data.bounty.op === 'refund') {
|
|
127
|
+
obj?.refund(passport);
|
|
128
|
+
}
|
|
129
129
|
}
|
|
130
130
|
if (this.data?.present !== undefined) {
|
|
131
131
|
//@ demand guard and its passport, if set
|
package/src/call/guard.ts
CHANGED
|
@@ -5,7 +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, PassportObject
|
|
8
|
+
IsValidDesription, PassportObject,
|
|
9
|
+
IsValidGuardIdentifier} from "wowok";
|
|
9
10
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
10
11
|
|
|
11
12
|
export interface GuardConst {
|
|
@@ -26,6 +27,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
|
|
|
26
27
|
| {calc: OperatorType.TYPE_NUMBER_ADD | OperatorType.TYPE_NUMBER_DEVIDE | OperatorType.TYPE_NUMBER_MOD
|
|
27
28
|
| OperatorType.TYPE_NUMBER_MULTIPLY | OperatorType.TYPE_NUMBER_SUBTRACT; parameters: GuardNode[];}
|
|
28
29
|
| {value_type: ValueType; value:any; } // Data
|
|
30
|
+
| {identifier: number} // data from GuardConst
|
|
29
31
|
| {context: ContextType.TYPE_CLOCK | ContextType.TYPE_GUARD | ContextType.TYPE_SIGNER }; // Data from run-time environment
|
|
30
32
|
|
|
31
33
|
export interface CallGuard_Data {
|
|
@@ -74,7 +76,6 @@ export class CallGuard extends CallBase {
|
|
|
74
76
|
this.data?.table?.forEach((v) => {
|
|
75
77
|
if (v.bWitness) {
|
|
76
78
|
const n = new Uint8Array(1); n.set([v.value_type], 0);
|
|
77
|
-
console.log(n)
|
|
78
79
|
txb.moveCall({
|
|
79
80
|
target:Protocol.Instance().guardFn("constant_add") as FnCallType,
|
|
80
81
|
arguments:[txb.object(obj), txb.pure.u8(v.identifier), txb.pure.bool(true), txb.pure.vector('u8', [].slice.call(n)), txb.pure.bool(false)]
|
|
@@ -107,13 +108,13 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
107
108
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
|
|
108
109
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.identifier))
|
|
109
110
|
} else {
|
|
110
|
-
ERROR(Errors.InvalidParam, 'node identifier - ' +
|
|
111
|
+
ERROR(Errors.InvalidParam, 'node identifier - ' + JSON.stringify(node));
|
|
111
112
|
}
|
|
112
113
|
} else if (node?.query !== undefined) {
|
|
113
114
|
var q: any[] | undefined;
|
|
114
|
-
if (typeof(node.query === 'string')
|
|
115
|
+
if (typeof(node.query) === 'string') {
|
|
115
116
|
q = GUARD_QUERIES.find(v=>v[1] === node.query);
|
|
116
|
-
} else if (typeof(node.query === 'number')
|
|
117
|
+
} else if (typeof(node.query) === 'number') {
|
|
117
118
|
q = GUARD_QUERIES.find(v=>v[2] === node.query);
|
|
118
119
|
}
|
|
119
120
|
if (!q) ERROR(Errors.InvalidParam, 'query invalid - ' + node?.query);
|
|
@@ -124,13 +125,13 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
124
125
|
buildNode(node.parameters[i], q![3][i], table, output); // Recursive check
|
|
125
126
|
}
|
|
126
127
|
} else {
|
|
127
|
-
ERROR(Errors.InvalidParam, 'node query parameters length not match - ' +
|
|
128
|
+
ERROR(Errors.InvalidParam, 'node query parameters length not match - ' + JSON.stringify(node))
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, OperatorType.TYPE_QUERY)); // QUERY TYPE + addr + cmd
|
|
131
132
|
if (typeof(node.object) === 'string') {
|
|
132
133
|
if (!IsValidAddress(node.object)) {
|
|
133
|
-
ERROR(Errors.InvalidParam, 'node object from address string - ' +
|
|
134
|
+
ERROR(Errors.InvalidParam, 'node object from address string - ' + JSON.stringify(node))
|
|
134
135
|
}
|
|
135
136
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ValueType.TYPE_ADDRESS));
|
|
136
137
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, node.object)); // object address
|
|
@@ -141,7 +142,7 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
141
142
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, ContextType.TYPE_CONSTANT));
|
|
142
143
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.object)); // object id
|
|
143
144
|
} else {
|
|
144
|
-
ERROR(Errors.InvalidParam, 'node object from identifier - ' +
|
|
145
|
+
ERROR(Errors.InvalidParam, 'node object from identifier - ' + JSON.stringify(node));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
output.push(Bcs.getInstance().ser('u16', q![2])); // cmd(u16)
|
|
@@ -149,18 +150,18 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
149
150
|
checkType(ValueType.TYPE_BOOL, type_required, node); // bool
|
|
150
151
|
switch (node?.logic) {
|
|
151
152
|
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
152
|
-
if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+
|
|
153
|
+
if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+ JSON.stringify(node));
|
|
153
154
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
154
155
|
break;
|
|
155
156
|
case OperatorType.TYPE_LOGIC_AND:
|
|
156
157
|
case OperatorType.TYPE_LOGIC_OR:
|
|
157
|
-
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+
|
|
158
|
+
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
|
|
158
159
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output)); // reserve
|
|
159
160
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
160
161
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
161
162
|
break;
|
|
162
163
|
case OperatorType.TYPE_LOGIC_NOT:
|
|
163
|
-
if (node.parameters.length !== 1) ERROR(Errors.InvalidParam, 'node logic parameters length must be 1'+
|
|
164
|
+
if (node.parameters.length !== 1) ERROR(Errors.InvalidParam, 'node logic parameters length must be 1'+ JSON.stringify(node));
|
|
164
165
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_BOOL, table, output)); // reserve
|
|
165
166
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
166
167
|
break;
|
|
@@ -169,20 +170,20 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
169
170
|
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
170
171
|
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
171
172
|
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
172
|
-
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+
|
|
173
|
+
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
|
|
173
174
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
|
|
174
175
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
175
176
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
176
177
|
break;
|
|
177
178
|
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
178
|
-
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+
|
|
179
|
+
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
|
|
179
180
|
var any_type: any = 'variable';
|
|
180
181
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, any_type, table, output));
|
|
181
182
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
182
183
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
183
184
|
break;
|
|
184
185
|
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
185
|
-
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+
|
|
186
|
+
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
|
|
186
187
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, ValueType.TYPE_STRING, table, output));
|
|
187
188
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
188
189
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
@@ -190,13 +191,13 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
190
191
|
}
|
|
191
192
|
} else if (node?.calc !== undefined) {
|
|
192
193
|
checkType(ValueType.TYPE_U256, type_required, node);
|
|
193
|
-
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node calc parameters length must >= 2'+
|
|
194
|
+
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node calc parameters length must >= 2'+ JSON.stringify(node));
|
|
194
195
|
(node.parameters as GuardNode[]).reverse().forEach(v => buildNode(v, 'number', table, output));
|
|
195
196
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.calc)); // TYPE
|
|
196
197
|
output.push((Bcs.getInstance().ser(ValueType.TYPE_U8, node.parameters.length)));
|
|
197
198
|
} else if (node?.value_type !== undefined) {
|
|
198
199
|
checkType(node?.value_type, type_required, node);
|
|
199
|
-
if (node?.value === undefined) ERROR(Errors.InvalidParam, 'node value undefined - ' +
|
|
200
|
+
if (node?.value === undefined) ERROR(Errors.InvalidParam, 'node value undefined - ' + JSON.stringify(node));
|
|
200
201
|
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.value_type)); // TYPE
|
|
201
202
|
|
|
202
203
|
if (node.value_type == ValueType.TYPE_STRING || node.value_type === ValueType.TYPE_VEC_U8) {
|
|
@@ -219,8 +220,15 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
219
220
|
checkType(ValueType.TYPE_ADDRESS, type_required, node);
|
|
220
221
|
break;
|
|
221
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));
|
|
222
230
|
} else {
|
|
223
|
-
ERROR(Errors.InvalidParam, 'node - ' +
|
|
231
|
+
ERROR(Errors.InvalidParam, 'node - ' + JSON.stringify(node))
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
234
|
|
|
@@ -250,8 +258,7 @@ const checkType = (type: ValueType | ContextType.TYPE_CLOCK | ContextType.TYPE_G
|
|
|
250
258
|
|
|
251
259
|
if (type !== type_required) {
|
|
252
260
|
var str = '';
|
|
253
|
-
if (node) str = ' - ' +
|
|
254
|
-
console.log(node)
|
|
261
|
+
if (node) str = ' - ' + JSON.stringify(node);
|
|
255
262
|
ERROR(Errors.InvalidParam, 'checkType: ' + type + ' require type: ' + type_required + str);
|
|
256
263
|
}
|
|
257
264
|
}
|
package/src/call/machine.ts
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock,
|
|
1
|
+
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, TransactionBlock, TxbAddress,
|
|
2
2
|
PermissionIndexType, Machine, Machine_Forward, Machine_Node, Deliverable, ParentProgress, Progress, ProgressNext,
|
|
3
|
-
TxbAddress,
|
|
4
|
-
Resource,
|
|
5
|
-
ResourceObject,
|
|
6
3
|
} from 'wowok';
|
|
7
4
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
8
5
|
import { Account } from '../account';
|
|
9
6
|
|
|
7
|
+
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
10
8
|
export interface CallMachine_Data {
|
|
11
9
|
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
12
10
|
permission?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
13
|
-
bPaused?: boolean;
|
|
14
|
-
bPublished?: boolean;
|
|
15
|
-
consensus_repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
|
|
16
11
|
description?: string;
|
|
17
12
|
endpoint?: string;
|
|
18
|
-
|
|
13
|
+
consensus_repository?: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
|
|
19
14
|
nodes?: {op: 'add'; data: Machine_Node[]} | {op: 'remove'; names: string[], bTransferMyself?:boolean}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
| {op:'rename node'; data:{old:string; new:string}[]} | {op:'add from myself'; addresses: string[]}
|
|
16
|
+
| {op:'remove pair'; pairs: {prior_node_name:string; node_name:string}[]}
|
|
17
|
+
| {op:'add forward'; data: {prior_node_name:string; node_name:string; forward:Machine_Forward; threshold?:number; old_need_remove?:string}[]}
|
|
18
|
+
| {op:'remove forward'; data:{prior_node_name:string; node_name:string; forward_name:string}[]}
|
|
19
|
+
bPublished?: boolean;
|
|
24
20
|
progress_new?: {task_address?:string; namedNew?: Namedbject};
|
|
25
21
|
progress_context_repository?: {progress:string; repository:string};
|
|
22
|
+
progress_namedOperator?: {progress:string; data:{name:string, operator:string[]}[]};
|
|
26
23
|
progress_parent?: {progress:string, parent?:ParentProgress};
|
|
27
24
|
progress_task?: {progress:string; task:string};
|
|
28
|
-
progress_namedOperator?: {progress:string; data:{name:string, operator:string[]}[]};
|
|
29
25
|
progress_hold?: {progress:string; data:ProgressNext; bHold:boolean; adminUnhold?:boolean};
|
|
30
26
|
progress_next?: {progress:string; data:ProgressNext; deliverable:Deliverable; guard?:string | 'fetch'};
|
|
27
|
+
bPaused?: boolean;
|
|
28
|
+
clone_new?: {namedNew: Namedbject/*, description?:string*/};
|
|
31
29
|
}
|
|
32
30
|
export class CallMachine extends CallBase { //@ todo self-owned node operate
|
|
33
|
-
data: CallMachine_Data
|
|
31
|
+
data: CallMachine_Data;
|
|
34
32
|
constructor(data:CallMachine_Data) {
|
|
35
33
|
super();
|
|
36
34
|
this.data = data;
|
|
@@ -48,24 +46,18 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
|
|
|
48
46
|
if (this.data?.description !== undefined && object_address) {
|
|
49
47
|
perms.push(PermissionIndex.machine_description)
|
|
50
48
|
}
|
|
51
|
-
if (this.data?.bPaused !== undefined) {
|
|
52
|
-
perms.push(PermissionIndex.machine_pause)
|
|
53
|
-
}
|
|
54
|
-
if (this.data?.bPublished) { // publish is an irreversible one-time operation
|
|
55
|
-
perms.push(PermissionIndex.machine_publish)
|
|
56
|
-
}
|
|
57
49
|
if (this.data?.endpoint !== undefined && object_address) {
|
|
58
50
|
perms.push(PermissionIndex.machine_endpoint)
|
|
59
51
|
}
|
|
60
52
|
if (this.data?.consensus_repository !== undefined) {
|
|
61
53
|
perms.push(PermissionIndex.machine_repository)
|
|
62
54
|
}
|
|
63
|
-
if (this.data?.clone_new !== undefined) {
|
|
64
|
-
perms.push(PermissionIndex.machine_clone)
|
|
65
|
-
}
|
|
66
55
|
if (this.data?.nodes !== undefined) {
|
|
67
56
|
perms.push(PermissionIndex.machine_node)
|
|
68
57
|
}
|
|
58
|
+
if (this.data?.bPublished) { // publish is an irreversible one-time operation
|
|
59
|
+
perms.push(PermissionIndex.machine_publish)
|
|
60
|
+
}
|
|
69
61
|
if (this.data?.progress_new !== undefined) {
|
|
70
62
|
perms.push(PermissionIndex.progress)
|
|
71
63
|
}
|
|
@@ -86,6 +78,9 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
|
|
|
86
78
|
perms.push(PermissionIndex.progress_unhold)
|
|
87
79
|
}
|
|
88
80
|
}
|
|
81
|
+
if (this.data?.bPaused !== undefined) {
|
|
82
|
+
perms.push(PermissionIndex.machine_pause)
|
|
83
|
+
}
|
|
89
84
|
if (this.data?.progress_next?.guard !== undefined) {
|
|
90
85
|
if (IsValidAddress(this.data?.progress_next?.guard)) {
|
|
91
86
|
guards.push(this.data?.progress_next?.guard)
|
|
@@ -170,6 +165,9 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
|
|
|
170
165
|
break;
|
|
171
166
|
}
|
|
172
167
|
}
|
|
168
|
+
if (this.data?.bPublished ) {
|
|
169
|
+
obj?.publish(passport)
|
|
170
|
+
}
|
|
173
171
|
if (this.data?.progress_new !== undefined) {
|
|
174
172
|
const addr = Progress?.New(txb, obj?.get_object(), permission??this.data?.permission, this.data?.progress_new.task_address, passport).launch();
|
|
175
173
|
if (addr) {
|
|
@@ -207,16 +205,13 @@ export class CallMachine extends CallBase { //@ todo self-owned node operate
|
|
|
207
205
|
if (this.data?.bPaused !== undefined) {
|
|
208
206
|
obj?.pause(this.data.bPaused, passport)
|
|
209
207
|
}
|
|
210
|
-
if (this.data?.
|
|
211
|
-
obj?.publish(passport)
|
|
212
|
-
}
|
|
213
|
-
if (this.data?.clone_new && obj) {
|
|
208
|
+
if (this.data?.clone_new !== undefined && obj) {
|
|
214
209
|
await this.new_with_mark(txb, obj?.clone(true, passport) as TxbAddress, (this.data?.clone_new as any)?.namedNew, account);
|
|
215
210
|
}
|
|
216
211
|
if (permission) {
|
|
217
212
|
await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
|
|
218
213
|
}
|
|
219
|
-
if (!
|
|
214
|
+
if (!object_address) {
|
|
220
215
|
await this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
|
|
221
216
|
}
|
|
222
217
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { CallBase, CallResult } from "./base";
|
|
2
|
-
import { TransactionBlock,
|
|
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 {
|