wowok 1.7.13 → 1.7.16
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/dist/arbitration.d.ts.map +1 -1
- package/dist/arbitration.js +21 -32
- package/dist/arbitration.js.map +1 -1
- package/dist/entity.d.ts +1 -0
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +12 -6
- package/dist/entity.js.map +1 -1
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/exception.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -4
- package/dist/guard.js.map +1 -1
- package/dist/payment.d.ts +2 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +2 -2
- package/dist/payment.js.map +1 -1
- package/dist/protocol.d.ts +21 -19
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +211 -58
- package/dist/protocol.js.map +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +5 -6
- package/dist/service.js.map +1 -1
- package/package.json +5 -2
- package/src/arbitration.ts +0 -551
- package/src/demand.ts +0 -300
- package/src/entity.ts +0 -171
- package/src/exception.ts +0 -37
- package/src/guard.ts +0 -810
- package/src/index.ts +0 -40
- package/src/machine.ts +0 -542
- package/src/passport.ts +0 -777
- package/src/payment.ts +0 -94
- package/src/permission.ts +0 -550
- package/src/progress.ts +0 -367
- package/src/protocol.ts +0 -549
- package/src/repository.ts +0 -680
- package/src/resource.ts +0 -155
- package/src/service.ts +0 -1349
- package/src/treasury.ts +0 -425
- package/src/utils.ts +0 -660
- package/src/wowok.ts +0 -70
- package/tsconfig.json +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/webpack.config.cjs +0 -23
package/src/index.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export * from './demand.js'
|
|
2
|
-
export * from './progress.js'
|
|
3
|
-
export * from './utils.js'
|
|
4
|
-
export * from './permission.js'
|
|
5
|
-
export * from './guard.js'
|
|
6
|
-
export * from './repository.js'
|
|
7
|
-
export * from './protocol.js';
|
|
8
|
-
export * from './passport.js'
|
|
9
|
-
export * from './machine.js'
|
|
10
|
-
export * from './service.js'
|
|
11
|
-
export * from './entity.js'
|
|
12
|
-
export * from './wowok.js'
|
|
13
|
-
export * from './resource.js'
|
|
14
|
-
export * from './treasury.js'
|
|
15
|
-
export * from './payment.js'
|
|
16
|
-
export * from './arbitration.js'
|
|
17
|
-
export * from './exception.js'
|
|
18
|
-
|
|
19
|
-
export * as BCS from '@mysten/sui/bcs';
|
|
20
|
-
export * as CLIENT from '@mysten/sui/client';
|
|
21
|
-
export { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
22
|
-
export { SuiClient } from '@mysten/sui/client';
|
|
23
|
-
export { Ed25519Keypair, } from '@mysten/sui/keypairs/ed25519';
|
|
24
|
-
export { fromHex, toHex } from '@mysten/bcs';
|
|
25
|
-
export { decodeSuiPrivateKey, encodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
26
|
-
export * as FAUCET from '@mysten/sui/faucet';
|
|
27
|
-
export { normalizeSuiAddress } from '@mysten/sui/utils'
|
|
28
|
-
export * as RawBCS from '@mysten/bcs'
|
|
29
|
-
|
|
30
|
-
import * as WowokTxn from '@mysten/sui/transactions';
|
|
31
|
-
export type TransactionArgument = WowokTxn.TransactionArgument;
|
|
32
|
-
export type TransactionResult = WowokTxn.TransactionResult;
|
|
33
|
-
export type TransactionObjectArgument = WowokTxn.TransactionObjectArgument;
|
|
34
|
-
import * as WowokClt from '@mysten/sui/client';
|
|
35
|
-
export type ObjectResponse = WowokClt.SuiObjectResponse;
|
|
36
|
-
//export type TransactionBlockResponseOptions = WowokClt.SuiTransactionBlockResponseOptions;
|
|
37
|
-
export type DynamicFieldPage = WowokClt.DynamicFieldPage;
|
|
38
|
-
export type CoinBalance = WowokClt.CoinBalance;
|
|
39
|
-
export type CoinStruct = WowokClt.CoinStruct;
|
|
40
|
-
export type CallResponse = WowokClt.SuiTransactionBlockResponse;
|
package/src/machine.ts
DELETED
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
import { Transaction as TransactionBlock, TransactionObjectArgument, type TransactionResult } from '@mysten/sui/transactions';
|
|
2
|
-
import { Protocol, FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject, MachineAddress, GuardObject, TxbObject, ServiceObject} from './protocol.js';
|
|
3
|
-
import { IsValidInt, array_unique, IsValidArray, IsValidAddress, IsValidName, IsValidName_AllowEmpty,
|
|
4
|
-
IsValidEndpoint, IsValidDesription, IsValidU64,
|
|
5
|
-
IsValidTokenType} from './utils.js'
|
|
6
|
-
import { Permission, PermissionIndexType } from './permission.js';
|
|
7
|
-
import { Errors, ERROR} from './exception.js'
|
|
8
|
-
|
|
9
|
-
export interface ServiceWrap {
|
|
10
|
-
object: ServiceObject,
|
|
11
|
-
pay_token_type: string,
|
|
12
|
-
bRequired?: boolean, // If true, An order at least must be placed from this service provider
|
|
13
|
-
}
|
|
14
|
-
export interface Machine_Forward {
|
|
15
|
-
name: string; // foward name
|
|
16
|
-
namedOperator?: string; // dynamic operator
|
|
17
|
-
permission?: PermissionIndexType; // this.permission-index or named-operator MUST one defined.
|
|
18
|
-
weight?: number;
|
|
19
|
-
guard?: GuardObject;
|
|
20
|
-
suppliers?: ServiceWrap[]; // List of service providers
|
|
21
|
-
}
|
|
22
|
-
export interface Machine_Node_Pair {
|
|
23
|
-
prior_node: string;
|
|
24
|
-
forwards: Machine_Forward[];
|
|
25
|
-
threshold?: number;
|
|
26
|
-
}
|
|
27
|
-
export interface Machine_Node {
|
|
28
|
-
name: string;
|
|
29
|
-
pairs: Machine_Node_Pair[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface QueryGuardParam {
|
|
33
|
-
node: string;
|
|
34
|
-
prior_node: string;
|
|
35
|
-
forward: string;
|
|
36
|
-
txb: TransactionBlock;
|
|
37
|
-
guard: string | null;
|
|
38
|
-
}
|
|
39
|
-
export type OnQueryGuard = (param: QueryGuardParam) => void;
|
|
40
|
-
export class Machine {
|
|
41
|
-
protected txb;
|
|
42
|
-
protected object : TxbObject;
|
|
43
|
-
protected permission: TxbObject;
|
|
44
|
-
|
|
45
|
-
get_object() { return this.object }
|
|
46
|
-
|
|
47
|
-
static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Machine {
|
|
48
|
-
let d = new Machine(txb, permission)
|
|
49
|
-
d.object = Protocol.TXB_OBJECT(txb, object)
|
|
50
|
-
return d
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private constructor(txb:TransactionBlock, permission:PermissionObject) {
|
|
54
|
-
this.txb = txb;
|
|
55
|
-
this.permission = permission;
|
|
56
|
-
this.object = '';
|
|
57
|
-
}
|
|
58
|
-
static New(txb:TransactionBlock, permission:PermissionObject, description:string, endpoint?:string|null|undefined, passport?:PassportObject) : Machine {
|
|
59
|
-
if (!Protocol.IsValidObjects([permission])) {
|
|
60
|
-
ERROR(Errors.IsValidObjects, 'permission')
|
|
61
|
-
}
|
|
62
|
-
if (!IsValidDesription(description)) {
|
|
63
|
-
ERROR(Errors.IsValidDesription)
|
|
64
|
-
}
|
|
65
|
-
if (endpoint && !IsValidEndpoint(endpoint)) {
|
|
66
|
-
ERROR(Errors.IsValidEndpoint)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let m = new Machine(txb, permission);
|
|
70
|
-
let ep = txb.pure.option('string', endpoint ? endpoint : undefined);
|
|
71
|
-
if (passport) {
|
|
72
|
-
m.object = txb.moveCall({
|
|
73
|
-
target:Protocol.Instance().machineFn('new_with_passport') as FnCallType,
|
|
74
|
-
arguments:[passport, txb.pure.string(description), ep, Protocol.TXB_OBJECT(txb, permission)],
|
|
75
|
-
})
|
|
76
|
-
} else {
|
|
77
|
-
m.object = txb.moveCall({
|
|
78
|
-
target:Protocol.Instance().machineFn('new') as FnCallType,
|
|
79
|
-
arguments:[txb.pure.string(description), ep, Protocol.TXB_OBJECT(txb, permission)],
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
return m
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// create new nodes for machine
|
|
86
|
-
add_node(nodes:Machine_Node[], passport?:PassportObject) {
|
|
87
|
-
if (nodes.length === 0) return ;
|
|
88
|
-
|
|
89
|
-
nodes.forEach((node) => {
|
|
90
|
-
if (!IsValidName(node.name)) ERROR(Errors.IsValidName, 'add_node.nodes.name')
|
|
91
|
-
|
|
92
|
-
node.pairs.forEach((p) => {
|
|
93
|
-
if (!IsValidName_AllowEmpty(p.prior_node)) ERROR(Errors.IsValidName_AllowEmpty, 'add_node.nodes.pairs.prior_node')
|
|
94
|
-
|
|
95
|
-
if (p?.threshold && !IsValidInt(p.threshold)) ERROR(Errors.IsValidInt, 'add_node.nodes.pairs.threshold')
|
|
96
|
-
p.forwards.forEach((f) => { Machine.checkValidForward(f) })
|
|
97
|
-
})
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
let new_nodes: TxbObject[] = [];
|
|
101
|
-
nodes.forEach((node) => {
|
|
102
|
-
let n = this.txb.moveCall({
|
|
103
|
-
target:Protocol.Instance().machineFn('node_new') as FnCallType,
|
|
104
|
-
arguments:[this.txb.pure.string(node.name)]
|
|
105
|
-
});
|
|
106
|
-
node.pairs.forEach((pair) => {
|
|
107
|
-
let threshold = this.txb.pure.option('u32', pair?.threshold);
|
|
108
|
-
|
|
109
|
-
pair.forwards.forEach((forward) => {
|
|
110
|
-
this.txb.moveCall({ // add forward
|
|
111
|
-
target:Protocol.Instance().machineFn('forward_add') as FnCallType,
|
|
112
|
-
arguments:[n, this.txb.pure.string(pair.prior_node), this.txb.pure.string(forward.name), threshold, this.forward(forward)]
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
if (pair.forwards.length === 0) {
|
|
116
|
-
this.txb.moveCall({ // add forward
|
|
117
|
-
target:Protocol.Instance().machineFn('forward_add_none') as FnCallType,
|
|
118
|
-
arguments:[n, this.txb.pure.string(pair.prior_node), threshold]
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
new_nodes.push(n);
|
|
123
|
-
});
|
|
124
|
-
this.add_node2(new_nodes, passport)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
forward(forward:Machine_Forward) : TransactionResult {
|
|
128
|
-
let weight = forward?.weight ? forward.weight : 1;
|
|
129
|
-
let f:any;
|
|
130
|
-
|
|
131
|
-
// namedOperator first.
|
|
132
|
-
if (forward?.namedOperator && IsValidName(forward.namedOperator)) {
|
|
133
|
-
if (forward?.guard) {
|
|
134
|
-
f = this.txb.moveCall({
|
|
135
|
-
target:Protocol.Instance().machineFn('forward') as FnCallType,
|
|
136
|
-
arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight), Protocol.TXB_OBJECT(this.txb, forward.guard)]
|
|
137
|
-
});
|
|
138
|
-
} else {
|
|
139
|
-
f = this.txb.moveCall({
|
|
140
|
-
target:Protocol.Instance().machineFn('forward2') as FnCallType,
|
|
141
|
-
arguments:[this.txb.pure.string(forward.namedOperator), this.txb.pure.u16(weight)]
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
} else if (forward?.permission !== undefined && IsValidU64(forward.permission)) {
|
|
145
|
-
if (forward?.guard) {
|
|
146
|
-
f = this.txb.moveCall({
|
|
147
|
-
target:Protocol.Instance().machineFn('forward3') as FnCallType,
|
|
148
|
-
arguments:[this.txb.pure.u64(forward.permission), this.txb.pure.u16(weight), Protocol.TXB_OBJECT(this.txb, forward.guard)]
|
|
149
|
-
});
|
|
150
|
-
} else {
|
|
151
|
-
f = this.txb.moveCall({
|
|
152
|
-
target:Protocol.Instance().machineFn('forward4') as FnCallType,
|
|
153
|
-
arguments:[this.txb.pure.u64(forward.permission), this.txb.pure.u16(weight)]
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
ERROR(Errors.InvalidParam, 'forward')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
forward?.suppliers?.forEach((v) => {
|
|
161
|
-
if (!IsValidTokenType(v.pay_token_type)) {
|
|
162
|
-
ERROR(Errors.IsValidTokenType, 'forward.suppliers:'+v.object);
|
|
163
|
-
}
|
|
164
|
-
this.txb.moveCall({
|
|
165
|
-
target:Protocol.Instance().serviceFn('add_to') as FnCallType,
|
|
166
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, v.object), this.txb.pure.bool(v.bRequired ?? false), f],
|
|
167
|
-
typeArguments:[v.pay_token_type]
|
|
168
|
-
});
|
|
169
|
-
})
|
|
170
|
-
return f
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// move MachineNodeObject to the machine from signer-owned MachineNode object
|
|
174
|
-
add_node2(nodes:TxbObject[], passport?:PassportObject) {
|
|
175
|
-
if (nodes.length === 0) return;
|
|
176
|
-
let n: TransactionObjectArgument[] = nodes.map((v)=>{ return Protocol.TXB_OBJECT(this.txb, v) as any});
|
|
177
|
-
if (passport) {
|
|
178
|
-
this.txb.moveCall({ // add node
|
|
179
|
-
target:Protocol.Instance().machineFn('node_add_with_passport') as FnCallType,
|
|
180
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:n}), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
181
|
-
});
|
|
182
|
-
} else {
|
|
183
|
-
this.txb.moveCall({ // add node
|
|
184
|
-
target:Protocol.Instance().machineFn('node_add') as FnCallType,
|
|
185
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.makeMoveVec({elements:n}), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
fetch_node(node_name:string, passport?:PassportObject) : TxbObject {
|
|
191
|
-
if (!IsValidName(node_name)) {
|
|
192
|
-
ERROR(Errors.IsValidName, 'fetch_node');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (passport) {
|
|
196
|
-
return this.txb.moveCall({
|
|
197
|
-
target:Protocol.Instance().machineFn('node_fetch_with_passport') as FnCallType,
|
|
198
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name),
|
|
199
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
200
|
-
});
|
|
201
|
-
} else {
|
|
202
|
-
return this.txb.moveCall({
|
|
203
|
-
target:Protocol.Instance().machineFn('node_fetch') as FnCallType,
|
|
204
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
rename_node(node_name:string, new_name:string, passport?:PassportObject) {
|
|
209
|
-
if (node_name === new_name) return
|
|
210
|
-
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'rename_node');
|
|
211
|
-
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'rename_node');
|
|
212
|
-
|
|
213
|
-
if (passport) {
|
|
214
|
-
this.txb.moveCall({
|
|
215
|
-
target:Protocol.Instance().machineFn('node_rename_with_passport') as FnCallType,
|
|
216
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
217
|
-
this.txb.pure.string(node_name), this.txb.pure.string(new_name),
|
|
218
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
219
|
-
});
|
|
220
|
-
} else {
|
|
221
|
-
this.txb.moveCall({
|
|
222
|
-
target:Protocol.Instance().machineFn('node_rename') as FnCallType,
|
|
223
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
224
|
-
this.txb.pure.string(node_name), this.txb.pure.string(new_name),
|
|
225
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// move MachineNodeObject from this.object to signer-owned MachineNode object
|
|
231
|
-
remove_node(nodes_name:string[], bTransferMyself:boolean = false, passport?:PassportObject) {
|
|
232
|
-
if (nodes_name.length === 0) return;
|
|
233
|
-
|
|
234
|
-
if (!IsValidArray(nodes_name, IsValidName)) {
|
|
235
|
-
ERROR(Errors.IsValidArray, 'nodes_name')
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (passport) {
|
|
239
|
-
this.txb.moveCall({
|
|
240
|
-
target:Protocol.Instance().machineFn('node_remove_with_passport') as FnCallType,
|
|
241
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
|
|
242
|
-
this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
this.txb.moveCall({
|
|
246
|
-
target:Protocol.Instance().machineFn('node_remove') as FnCallType,
|
|
247
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('string', nodes_name),
|
|
248
|
-
this.txb.pure.bool(bTransferMyself), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
launch() : MachineAddress {
|
|
254
|
-
return this.txb.moveCall({
|
|
255
|
-
target:Protocol.Instance().machineFn('create') as FnCallType,
|
|
256
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
257
|
-
})
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
set_description(description:string, passport?:PassportObject) {
|
|
261
|
-
if (!IsValidDesription(description)) {
|
|
262
|
-
ERROR(Errors.IsValidDesription)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (passport) {
|
|
266
|
-
this.txb.moveCall({
|
|
267
|
-
target:Protocol.Instance().machineFn('description_set_with_passport') as FnCallType,
|
|
268
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
269
|
-
})
|
|
270
|
-
} else {
|
|
271
|
-
this.txb.moveCall({
|
|
272
|
-
target:Protocol.Instance().machineFn('description_set') as FnCallType,
|
|
273
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
add_repository(repository:RepositoryObject, passport?:PassportObject) {
|
|
278
|
-
if (passport) {
|
|
279
|
-
this.txb.moveCall({
|
|
280
|
-
target:Protocol.Instance().machineFn('repository_add_with_passport') as FnCallType,
|
|
281
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
282
|
-
})
|
|
283
|
-
} else {
|
|
284
|
-
this.txb.moveCall({
|
|
285
|
-
target:Protocol.Instance().machineFn('repository_add') as FnCallType,
|
|
286
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, repository), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
287
|
-
})
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
remove_repository(repositories:string[], removeall?:boolean, passport?:PassportObject) {
|
|
292
|
-
if (!removeall && repositories.length===0) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (!IsValidArray(repositories, IsValidAddress)){
|
|
297
|
-
ERROR(Errors.IsValidArray, 'remove_repository')
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (passport) {
|
|
301
|
-
if (removeall) {
|
|
302
|
-
this.txb.moveCall({
|
|
303
|
-
target:Protocol.Instance().machineFn('repository_remove_all_with_passport') as FnCallType,
|
|
304
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
305
|
-
})
|
|
306
|
-
} else {
|
|
307
|
-
this.txb.moveCall({
|
|
308
|
-
target:Protocol.Instance().machineFn('repository_remove_with_passport') as FnCallType,
|
|
309
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(repositories)),
|
|
310
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
311
|
-
})
|
|
312
|
-
}
|
|
313
|
-
} else {
|
|
314
|
-
if (removeall) {
|
|
315
|
-
this.txb.moveCall({
|
|
316
|
-
target:Protocol.Instance().machineFn('repository_remove_all') as FnCallType,
|
|
317
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
318
|
-
})
|
|
319
|
-
} else {
|
|
320
|
-
this.txb.moveCall({
|
|
321
|
-
target:Protocol.Instance().machineFn('repository_remove') as FnCallType,
|
|
322
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.vector('address', array_unique(repositories)),
|
|
323
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
324
|
-
})
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
clone(bLaunch?: boolean, passport?:PassportObject) : MachineObject | MachineAddress {
|
|
330
|
-
let ret: MachineObject | undefined;
|
|
331
|
-
if (passport) {
|
|
332
|
-
ret = this.txb.moveCall({
|
|
333
|
-
target:Protocol.Instance().machineFn('clone_with_passport') as FnCallType,
|
|
334
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
335
|
-
})
|
|
336
|
-
} else {
|
|
337
|
-
ret = this.txb.moveCall({
|
|
338
|
-
target:Protocol.Instance().machineFn('clone') as FnCallType,
|
|
339
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
340
|
-
})
|
|
341
|
-
}
|
|
342
|
-
if (bLaunch) {
|
|
343
|
-
return this.txb.moveCall({
|
|
344
|
-
target:Protocol.Instance().machineFn('create') as FnCallType,
|
|
345
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, ret)],
|
|
346
|
-
})
|
|
347
|
-
} else {
|
|
348
|
-
return ret
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
set_endpoint(endpoint?:string|null|undefined, passport?:PassportObject) {
|
|
353
|
-
if (endpoint && !IsValidEndpoint(endpoint)) {
|
|
354
|
-
ERROR(Errors.IsValidEndpoint)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
let ep = this.txb.pure.option('string', endpoint ? endpoint : undefined) ;
|
|
358
|
-
if (passport) {
|
|
359
|
-
this.txb.moveCall({
|
|
360
|
-
target:Protocol.Instance().machineFn('endpoint_set_with_passport') as FnCallType,
|
|
361
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), ep, Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
362
|
-
})
|
|
363
|
-
} else {
|
|
364
|
-
this.txb.moveCall({
|
|
365
|
-
target:Protocol.Instance().machineFn('endpoint_set') as FnCallType,
|
|
366
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), ep, Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
367
|
-
})
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
pause(bPaused:boolean, passport?:PassportObject) {
|
|
371
|
-
if (passport) {
|
|
372
|
-
this.txb.moveCall({
|
|
373
|
-
target:Protocol.Instance().machineFn('pause_with_passport') as FnCallType,
|
|
374
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bPaused), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
375
|
-
})
|
|
376
|
-
} else {
|
|
377
|
-
this.txb.moveCall({
|
|
378
|
-
target:Protocol.Instance().machineFn('pause') as FnCallType,
|
|
379
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(bPaused), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
380
|
-
})
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
publish(passport?:PassportObject) {
|
|
384
|
-
if (passport) {
|
|
385
|
-
this.txb.moveCall({
|
|
386
|
-
target:Protocol.Instance().machineFn('publish_with_passport') as FnCallType,
|
|
387
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
388
|
-
})
|
|
389
|
-
} else {
|
|
390
|
-
this.txb.moveCall({
|
|
391
|
-
target:Protocol.Instance().machineFn('publish') as FnCallType,
|
|
392
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
393
|
-
})
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
change_permission(new_permission:PermissionObject) {
|
|
398
|
-
if (!Protocol.IsValidObjects([new_permission])){
|
|
399
|
-
ERROR(Errors.IsValidObjects, 'new_permission')
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
this.txb.moveCall({
|
|
403
|
-
target:Protocol.Instance().machineFn('permission_set') as FnCallType,
|
|
404
|
-
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
405
|
-
typeArguments:[]
|
|
406
|
-
})
|
|
407
|
-
this.permission = new_permission;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
add_forward(node_prior:string, node_name:string, foward: Machine_Forward, threshold?:number, old_forward_name?:string, passport?:PassportObject) {
|
|
411
|
-
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'add_forward');
|
|
412
|
-
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'add_forward');
|
|
413
|
-
Machine.checkValidForward(foward);
|
|
414
|
-
|
|
415
|
-
let n : any;
|
|
416
|
-
if (passport) {
|
|
417
|
-
n = this.txb.moveCall({
|
|
418
|
-
target:Protocol.Instance().machineFn('node_fetch_with_passport') as FnCallType,
|
|
419
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
} else {
|
|
423
|
-
n = this.txb.moveCall({
|
|
424
|
-
target:Protocol.Instance().machineFn('node_fetch') as FnCallType,
|
|
425
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
426
|
-
})
|
|
427
|
-
}
|
|
428
|
-
const f = this.forward(foward);
|
|
429
|
-
const t = this.txb.pure.option('u32', threshold ?? undefined);
|
|
430
|
-
this.txb.moveCall({
|
|
431
|
-
target:Protocol.Instance().machineFn('forward_add') as FnCallType,
|
|
432
|
-
arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward.name), t, f],
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
if (old_forward_name && old_forward_name !== foward.name) {
|
|
436
|
-
this.txb.moveCall({
|
|
437
|
-
target:Protocol.Instance().machineFn('forward_remove') as FnCallType,
|
|
438
|
-
arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(old_forward_name)],
|
|
439
|
-
})
|
|
440
|
-
}
|
|
441
|
-
this.add_node2([n], passport);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
remove_pair(node_prior:string, node_name:string, passport?:PassportObject) {
|
|
445
|
-
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'remove_pair');
|
|
446
|
-
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'remove_pair');
|
|
447
|
-
let n : any;
|
|
448
|
-
if (passport) {
|
|
449
|
-
n = this.txb.moveCall({
|
|
450
|
-
target:Protocol.Instance().machineFn('node_fetch_with_passport') as FnCallType,
|
|
451
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
452
|
-
})
|
|
453
|
-
|
|
454
|
-
} else {
|
|
455
|
-
n = this.txb.moveCall({
|
|
456
|
-
target:Protocol.Instance().machineFn('node_fetch') as FnCallType,
|
|
457
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
458
|
-
})
|
|
459
|
-
}
|
|
460
|
-
this.txb.moveCall({
|
|
461
|
-
target:Protocol.Instance().machineFn('pair_remove') as FnCallType,
|
|
462
|
-
arguments:[n, this.txb.pure.string(node_prior)],
|
|
463
|
-
})
|
|
464
|
-
this.add_node2([n], passport);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
remove_forward(node_prior:string, node_name:string, foward_name: string, passport?:PassportObject) {
|
|
468
|
-
if (!IsValidName_AllowEmpty(node_prior)) ERROR(Errors.IsValidName_AllowEmpty, 'remove_forward');
|
|
469
|
-
if (!IsValidName(node_name)) ERROR(Errors.IsValidName, 'remove_forward');
|
|
470
|
-
|
|
471
|
-
let n : any;
|
|
472
|
-
if (passport) {
|
|
473
|
-
n = this.txb.moveCall({
|
|
474
|
-
target:Protocol.Instance().machineFn('node_fetch_with_passport') as FnCallType,
|
|
475
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
476
|
-
})
|
|
477
|
-
|
|
478
|
-
} else {
|
|
479
|
-
n = this.txb.moveCall({
|
|
480
|
-
target:Protocol.Instance().machineFn('node_fetch') as FnCallType,
|
|
481
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(node_name), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
482
|
-
})
|
|
483
|
-
}
|
|
484
|
-
this.txb.moveCall({
|
|
485
|
-
target:Protocol.Instance().machineFn('forward_remove') as FnCallType,
|
|
486
|
-
arguments:[n, this.txb.pure.string(node_prior), this.txb.pure.string(foward_name)],
|
|
487
|
-
})
|
|
488
|
-
this.add_node2([n], passport);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
static rpc_de_nodes(fields: any) : Machine_Node[] {
|
|
492
|
-
const machine_nodes:Machine_Node[] = [];
|
|
493
|
-
fields.forEach((n:any) => {
|
|
494
|
-
machine_nodes.push({name:n.data.content.fields.name, pairs:Machine.rpc_de_pair(n?.data.content.fields.value)});
|
|
495
|
-
});
|
|
496
|
-
return machine_nodes;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
static rpc_de_pair(data:any) : Machine_Node_Pair[] {
|
|
500
|
-
let pairs:Machine_Node_Pair[] = [];
|
|
501
|
-
data.fields.value.fields.contents.forEach((p:any) => {
|
|
502
|
-
let forwards:Machine_Forward[] = [];
|
|
503
|
-
p.fields.value.fields.forwards.fields.contents.forEach((f:any) => {
|
|
504
|
-
let forward_name = f.fields.key;
|
|
505
|
-
let forward_weight = f.fields.value.fields.weight;
|
|
506
|
-
let forward_guard = f.fields.value.fields.guard;
|
|
507
|
-
let forward_namedOperator = f.fields.value.fields.namedOperator;
|
|
508
|
-
let forward_permission_index = f.fields.value.fields.permission_index;
|
|
509
|
-
forwards.push({name:forward_name, namedOperator:forward_namedOperator, permission:forward_permission_index,
|
|
510
|
-
weight:forward_weight, guard:forward_guard?forward_guard:'', suppliers:f.fields.value.fields.suppliers.fields.contents.map((v:any) => {
|
|
511
|
-
return {object:v.fields.key, bRequired:v.fields.value, pay_token_type:''}
|
|
512
|
-
})}); //@ NOTICE...
|
|
513
|
-
});
|
|
514
|
-
pairs.push({prior_node:p.fields.key, threshold:p.fields.value.fields.threshold, forwards:forwards});
|
|
515
|
-
});
|
|
516
|
-
return pairs
|
|
517
|
-
}
|
|
518
|
-
static namedOperators(nodes:Machine_Node[]) : string[] {
|
|
519
|
-
let ret: string[] = [];
|
|
520
|
-
nodes.forEach((v)=> {
|
|
521
|
-
v.pairs.forEach((i) => {
|
|
522
|
-
i.forwards.forEach((k) => {
|
|
523
|
-
if (k?.namedOperator && !ret.find((x)=>x===k.namedOperator)) {
|
|
524
|
-
ret.push(k.namedOperator);
|
|
525
|
-
}
|
|
526
|
-
})
|
|
527
|
-
})
|
|
528
|
-
})
|
|
529
|
-
return ret;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
static checkValidForward(forward:Machine_Forward) {
|
|
533
|
-
if (!IsValidName(forward.name)) ERROR(Errors.IsValidName, `checkValidForward.forward.name ${forward}`)
|
|
534
|
-
if (forward?.namedOperator && !IsValidName_AllowEmpty(forward?.namedOperator)) ERROR(Errors.IsValidName_AllowEmpty, `checkValidForward.forward.namedOperator ${forward}`)
|
|
535
|
-
if (forward?.permission && !Permission.IsValidPermissionIndex(forward?.permission)) ERROR(Errors.IsValidPermissionIndex, `checkValidForward.forward.permission ${forward}`)
|
|
536
|
-
if (!forward?.permission && !forward?.namedOperator) ERROR(Errors.InvalidParam, `checkValidForward.forward permission and namedOperator both empty ${forward}`)
|
|
537
|
-
if (forward?.weight && !IsValidU64(forward.weight)) ERROR(Errors.IsValidU64, `checkValidForward.forward.weight ${forward}`)
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
static INITIAL_NODE_NAME = '';
|
|
541
|
-
static OPERATOR_ORDER_PAYER = 'OrderPayer';
|
|
542
|
-
}
|