@digicatapult/sqnc-process-management 2.2.131 → 2.2.132
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/build/index.js +95 -0
- package/build/index.js.map +1 -0
- package/build/lib/process/__tests__/unit.test.js +191 -0
- package/build/lib/process/__tests__/unit.test.js.map +1 -0
- package/build/lib/process/api.js +206 -0
- package/build/lib/process/api.js.map +1 -0
- package/build/lib/process/constants.js +5 -0
- package/build/lib/process/constants.js.map +1 -0
- package/build/{src/lib → lib}/process/hex.js +4 -2
- package/build/lib/process/hex.js.map +1 -0
- package/build/lib/process/index.js +304 -0
- package/build/lib/process/index.js.map +1 -0
- package/build/{src/lib → lib}/types/error.js +9 -6
- package/build/lib/types/error.js.map +1 -0
- package/build/lib/types/polkadot.d.js +2 -0
- package/build/lib/types/polkadot.d.js.map +1 -0
- package/build/lib/types/process.d.js +2 -0
- package/build/lib/types/process.d.js.map +1 -0
- package/build/lib/types/validation.js +179 -0
- package/build/lib/types/validation.js.map +1 -0
- package/build/lib/utils/polkadot.js +26 -0
- package/build/lib/utils/polkadot.js.map +1 -0
- package/build/version.js +5 -0
- package/build/version.js.map +1 -0
- package/package.json +12 -10
- package/build/package.json +0 -65
- package/build/src/index.d.ts +0 -2
- package/build/src/index.js +0 -127
- package/build/src/lib/process/_tests_/unit.test.d.ts +0 -1
- package/build/src/lib/process/_tests_/unit.test.js +0 -112
- package/build/src/lib/process/api.d.ts +0 -10
- package/build/src/lib/process/api.js +0 -193
- package/build/src/lib/process/constants.d.ts +0 -3
- package/build/src/lib/process/constants.js +0 -3
- package/build/src/lib/process/hex.d.ts +0 -2
- package/build/src/lib/process/index.d.ts +0 -22
- package/build/src/lib/process/index.js +0 -311
- package/build/src/lib/types/error.d.ts +0 -14
- package/build/src/lib/types/validation.d.ts +0 -3592
- package/build/src/lib/types/validation.js +0 -128
- package/build/src/lib/utils/polkadot.d.ts +0 -6
- package/build/src/lib/utils/polkadot.js +0 -28
- package/build/src/version.d.ts +0 -2
- package/build/src/version.js +0 -3
- package/build/tests/fixtures/processes.d.ts +0 -281
- package/build/tests/fixtures/processes.js +0 -1066
- package/build/tests/fixtures/programs.d.ts +0 -14
- package/build/tests/fixtures/programs.js +0 -211
- package/build/tests/helpers/containers.d.ts +0 -7
- package/build/tests/helpers/containers.js +0 -40
- package/build/tests/helpers/substrateHelper.d.ts +0 -2
- package/build/tests/helpers/substrateHelper.js +0 -100
- package/build/tests/integration/command-functions.test.d.ts +0 -1
- package/build/tests/integration/command-functions.test.js +0 -414
- package/build/tests/integration/without-manual-seal.test.d.ts +0 -1
- package/build/tests/integration/without-manual-seal.test.js +0 -52
- package/build/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
env.stack.push({
|
|
23
|
+
value: value,
|
|
24
|
+
dispose: dispose,
|
|
25
|
+
async: async
|
|
26
|
+
});
|
|
27
|
+
} else if (async) {
|
|
28
|
+
env.stack.push({
|
|
29
|
+
async: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function _ts_dispose_resources(env) {
|
|
35
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
40
|
+
function fail(e) {
|
|
41
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
42
|
+
env.hasError = true;
|
|
43
|
+
}
|
|
44
|
+
var r, s = 0;
|
|
45
|
+
function next() {
|
|
46
|
+
while(r = env.stack.pop()){
|
|
47
|
+
try {
|
|
48
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
49
|
+
if (r.dispose) {
|
|
50
|
+
var result = r.dispose.call(r.value);
|
|
51
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
52
|
+
fail(e);
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
} else s |= 1;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
})(env);
|
|
65
|
+
}
|
|
66
|
+
import { createNodeApi } from '../utils/polkadot.js';
|
|
67
|
+
import { createProcessTransaction, disableProcessTransaction, getVersion, getProcess } from './api.js';
|
|
68
|
+
import { utf8ToHex } from './hex.js';
|
|
69
|
+
import { processValidation, simpleProcesssValidation } from '../types/validation.js';
|
|
70
|
+
import { CliInputParseError, DisableError, ProgramError, VersionError } from '../types/error.js';
|
|
71
|
+
import { ZodError } from 'zod';
|
|
72
|
+
export const defaultOptions = {
|
|
73
|
+
API_HOST: 'localhost',
|
|
74
|
+
API_PORT: 9944,
|
|
75
|
+
USER_URI: '//Alice'
|
|
76
|
+
};
|
|
77
|
+
const textify = (obj)=>{
|
|
78
|
+
return JSON.stringify(obj, (_key, val)=>{
|
|
79
|
+
// convert snake case to camel case
|
|
80
|
+
if (val && typeof val === 'object') {
|
|
81
|
+
return Object.fromEntries(Object.entries(val).map(([k, v])=>{
|
|
82
|
+
return [
|
|
83
|
+
[
|
|
84
|
+
...k
|
|
85
|
+
].map((c, i)=>k[i - 1] === '_' ? c.toUpperCase() : c).filter((c)=>c != '_').join(''),
|
|
86
|
+
v
|
|
87
|
+
];
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
if (typeof val === 'number') return val.toString();
|
|
91
|
+
return val;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
export const sanitizeInput = (data)=>{
|
|
95
|
+
try {
|
|
96
|
+
return {
|
|
97
|
+
type: 'ok',
|
|
98
|
+
result: simpleProcesssValidation.parse(JSON.parse(data))
|
|
99
|
+
};
|
|
100
|
+
} catch (err) {
|
|
101
|
+
if (err instanceof Error) {
|
|
102
|
+
return {
|
|
103
|
+
type: 'error',
|
|
104
|
+
error: new CliInputParseError(err),
|
|
105
|
+
message: err.message
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const loadProcesses = async ({ data, options, dryRun, verbose })=>{
|
|
112
|
+
const env = {
|
|
113
|
+
stack: [],
|
|
114
|
+
error: void 0,
|
|
115
|
+
hasError: false
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
const parsedRes = sanitizeInput(data);
|
|
119
|
+
if (parsedRes.type === 'error') {
|
|
120
|
+
return parsedRes;
|
|
121
|
+
}
|
|
122
|
+
const processes = parsedRes.result;
|
|
123
|
+
const processTxs = new Map();
|
|
124
|
+
const polkadot = _ts_add_disposable_resource(env, await createNodeApi(options), true);
|
|
125
|
+
for (const process of processes){
|
|
126
|
+
const { waitForFinalised } = await createProcess(process, dryRun, polkadot, options, verbose);
|
|
127
|
+
processTxs.set(process.name, waitForFinalised);
|
|
128
|
+
}
|
|
129
|
+
await Promise.all(processTxs.values());
|
|
130
|
+
const result = {};
|
|
131
|
+
let successCount = 0;
|
|
132
|
+
for (const [key, processTxProm] of processTxs){
|
|
133
|
+
let response = await processTxProm;
|
|
134
|
+
result[key] = response;
|
|
135
|
+
if (response.type === 'ok') {
|
|
136
|
+
successCount = successCount + 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// calculate the result and successCount
|
|
140
|
+
return {
|
|
141
|
+
type: 'ok',
|
|
142
|
+
result,
|
|
143
|
+
message: `Successfully loaded ${successCount}/${processes.length} processes`
|
|
144
|
+
};
|
|
145
|
+
} catch (e) {
|
|
146
|
+
env.error = e;
|
|
147
|
+
env.hasError = true;
|
|
148
|
+
} finally{
|
|
149
|
+
const result = _ts_dispose_resources(env);
|
|
150
|
+
if (result) await result;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
export const listTransforming = (res, options)=>{
|
|
154
|
+
let processes;
|
|
155
|
+
if (options.active) {
|
|
156
|
+
processes = res.filter(({ status })=>status === 'Enabled');
|
|
157
|
+
} else if (options.disabled) {
|
|
158
|
+
processes = res.filter(({ status })=>status === 'Disabled');
|
|
159
|
+
} else {
|
|
160
|
+
processes = res;
|
|
161
|
+
}
|
|
162
|
+
if (options.raw) {
|
|
163
|
+
return processes.map(({ name, program, ...p })=>({
|
|
164
|
+
name: utf8ToHex(name),
|
|
165
|
+
...options.verbose ? {
|
|
166
|
+
program
|
|
167
|
+
} : {},
|
|
168
|
+
...p
|
|
169
|
+
}));
|
|
170
|
+
} else {
|
|
171
|
+
return processes.map((p)=>{
|
|
172
|
+
return {
|
|
173
|
+
name: p.name,
|
|
174
|
+
version: p.version,
|
|
175
|
+
status: p.status,
|
|
176
|
+
...options.verbose ? {
|
|
177
|
+
program: p.program
|
|
178
|
+
} : {}
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
export const handleVerbose = (res, verbose)=>{
|
|
184
|
+
if (verbose) {
|
|
185
|
+
return res;
|
|
186
|
+
}
|
|
187
|
+
const { program, ...rest } = res;
|
|
188
|
+
return rest;
|
|
189
|
+
};
|
|
190
|
+
export const createProcess = async (processRaw, dryRun = false, polkadot, options = defaultOptions, verbose = false)=>{
|
|
191
|
+
const handleErr = (err)=>{
|
|
192
|
+
// err is basically from errors.ts or any exception
|
|
193
|
+
// process errors will contain specific messages and/or process
|
|
194
|
+
// Promise<Process.Result> is in try {} and any exception is in catch {}
|
|
195
|
+
if (err instanceof ProgramError || err instanceof VersionError || err instanceof ZodError) {
|
|
196
|
+
const result = {
|
|
197
|
+
type: 'error',
|
|
198
|
+
error: err,
|
|
199
|
+
message: err.message
|
|
200
|
+
};
|
|
201
|
+
return {
|
|
202
|
+
waitForFinalised: Promise.resolve(result)
|
|
203
|
+
};
|
|
204
|
+
} else if (err instanceof Error) {
|
|
205
|
+
const result = {
|
|
206
|
+
type: 'error',
|
|
207
|
+
error: err,
|
|
208
|
+
message: 'An unknown error occurred'
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
waitForFinalised: Promise.resolve(result)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
throw err;
|
|
215
|
+
};
|
|
216
|
+
try {
|
|
217
|
+
const { name, version, program } = processValidation.parse(processRaw);
|
|
218
|
+
const processId = utf8ToHex(name);
|
|
219
|
+
const currentVersion = await getVersion(polkadot, processId);
|
|
220
|
+
const expectedVersion = currentVersion + 1;
|
|
221
|
+
if (version > expectedVersion || version < currentVersion) throw new VersionError(version, expectedVersion, name);
|
|
222
|
+
if (version === currentVersion) {
|
|
223
|
+
const process = await getProcess(polkadot, processId, version);
|
|
224
|
+
if (program.length !== process.program.length) throw new ProgramError('existing: programs are different lengths', process);
|
|
225
|
+
if (!program.every((step, i)=>textify(step) === textify(process.program[i]))) throw new ProgramError('existing: program steps did not match', process);
|
|
226
|
+
return {
|
|
227
|
+
waitForFinalised: Promise.resolve({
|
|
228
|
+
type: 'ok',
|
|
229
|
+
message: `Skipping: process ${name} is already created.`,
|
|
230
|
+
result: handleVerbose({
|
|
231
|
+
name,
|
|
232
|
+
version,
|
|
233
|
+
program,
|
|
234
|
+
status: process.status
|
|
235
|
+
}, verbose)
|
|
236
|
+
})
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (dryRun) return {
|
|
240
|
+
waitForFinalised: Promise.resolve({
|
|
241
|
+
type: 'ok',
|
|
242
|
+
message: 'Dry run: transaction has not been created',
|
|
243
|
+
result: handleVerbose({
|
|
244
|
+
name,
|
|
245
|
+
version,
|
|
246
|
+
program,
|
|
247
|
+
status: 'Enabled (dry-run)'
|
|
248
|
+
}, verbose)
|
|
249
|
+
})
|
|
250
|
+
};
|
|
251
|
+
const createProcessTx = await createProcessTransaction(polkadot, processId, program, options);
|
|
252
|
+
return {
|
|
253
|
+
waitForFinalised: createProcessTx.waitForFinal.then((process)=>{
|
|
254
|
+
const result = {
|
|
255
|
+
type: 'ok',
|
|
256
|
+
message: `Transaction for new process ${name} has been successfully submitted`,
|
|
257
|
+
result: handleVerbose(process, verbose)
|
|
258
|
+
};
|
|
259
|
+
return result;
|
|
260
|
+
}).catch((err)=>handleErr(err).waitForFinalised)
|
|
261
|
+
};
|
|
262
|
+
} catch (err) {
|
|
263
|
+
return handleErr(err);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
export const disableProcess = async (name, processVersion, dryRun = false, options = defaultOptions)=>{
|
|
267
|
+
const env = {
|
|
268
|
+
stack: [],
|
|
269
|
+
error: void 0,
|
|
270
|
+
hasError: false
|
|
271
|
+
};
|
|
272
|
+
try {
|
|
273
|
+
const processId = utf8ToHex(name);
|
|
274
|
+
const polkadot = _ts_add_disposable_resource(env, await createNodeApi(options), true);
|
|
275
|
+
const currentProcess = await getProcess(polkadot, processId, processVersion);
|
|
276
|
+
if (currentProcess.status === 'Disabled') {
|
|
277
|
+
throw new DisableError(`${name} with version ${processVersion} doesn't exist or is already disabled`);
|
|
278
|
+
}
|
|
279
|
+
if (dryRun) {
|
|
280
|
+
return {
|
|
281
|
+
type: 'ok',
|
|
282
|
+
message: `This will DISABLE the following process ${name}`,
|
|
283
|
+
result: {
|
|
284
|
+
name,
|
|
285
|
+
version: processVersion,
|
|
286
|
+
status: 'Disabled (dry-run)'
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
type: 'ok',
|
|
292
|
+
message: 'Process has been disabled',
|
|
293
|
+
result: await disableProcessTransaction(polkadot, processId, processVersion, options)
|
|
294
|
+
};
|
|
295
|
+
} catch (e) {
|
|
296
|
+
env.error = e;
|
|
297
|
+
env.hasError = true;
|
|
298
|
+
} finally{
|
|
299
|
+
const result = _ts_dispose_resources(env);
|
|
300
|
+
if (result) await result;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/process/index.ts"],"sourcesContent":["import { createNodeApi } from '../utils/polkadot.js'\nimport { createProcessTransaction, disableProcessTransaction, getVersion, getProcess } from './api.js'\nimport { utf8ToHex } from './hex.js'\nimport { processValidation, simpleProcesssValidation } from '../types/validation.js'\nimport { CliInputParseError, DisableError, ProgramError, VersionError } from '../types/error.js'\nimport { ZodError } from 'zod'\n\nexport const defaultOptions: Polkadot.Options = {\n API_HOST: 'localhost',\n API_PORT: 9944,\n USER_URI: '//Alice',\n}\n\nconst textify = (obj: Process.ProgramStep): string => {\n return JSON.stringify(obj, (_key, val) => {\n // convert snake case to camel case\n if (val && typeof val === 'object') {\n return Object.fromEntries(\n Object.entries(val).map(([k, v]) => {\n return [\n [...k]\n .map((c, i) => (k[i - 1] === '_' ? c.toUpperCase() : c))\n .filter((c) => c != '_')\n .join(''),\n v,\n ]\n })\n )\n }\n if (typeof val === 'number') return val.toString()\n return val\n })\n}\n\nexport const sanitizeInput = (data: string): Process.Result<{ name: string }[], CliInputParseError> => {\n try {\n return {\n type: 'ok',\n result: simpleProcesssValidation.parse(JSON.parse(data)),\n }\n } catch (err) {\n if (err instanceof Error) {\n return {\n type: 'error',\n error: new CliInputParseError(err),\n message: err.message,\n }\n }\n throw err\n }\n}\n\nexport const loadProcesses = async ({\n data,\n options,\n dryRun,\n verbose,\n}: {\n data: string\n options: Polkadot.Options\n dryRun?: boolean\n verbose?: boolean\n}): Promise<Process.Response> => {\n const parsedRes = sanitizeInput(data)\n if (parsedRes.type === 'error') {\n return parsedRes\n }\n const processes = parsedRes.result\n\n const processTxs: Map<string, Promise<Process.ProcessResponse>> = new Map()\n await using polkadot = await createNodeApi(options)\n for (const process of processes) {\n const { waitForFinalised } = await createProcess(process, dryRun, polkadot, options, verbose)\n processTxs.set(process.name, waitForFinalised)\n }\n await Promise.all(processTxs.values())\n\n const result: { [key: string]: Process.ProcessResponse } = {}\n let successCount = 0\n for (const [key, processTxProm] of processTxs) {\n let response = await processTxProm\n result[key] = response\n if (response.type === 'ok') {\n successCount = successCount + 1\n }\n }\n\n // calculate the result and successCount\n\n return {\n type: 'ok',\n result,\n message: `Successfully loaded ${successCount}/${processes.length} processes`,\n }\n}\n\nexport const listTransforming = (res: Process.RawPayload[], options: Process.CLIOptions) => {\n let processes: Process.RawPayload[]\n if (options.active) {\n processes = res.filter(({ status }) => status === 'Enabled')\n } else if (options.disabled) {\n processes = res.filter(({ status }) => status === 'Disabled')\n } else {\n processes = res\n }\n\n if (options.raw) {\n return processes.map(({ name, program, ...p }) => ({\n name: utf8ToHex(name),\n ...(options.verbose ? { program } : {}),\n ...p,\n }))\n } else {\n return processes.map((p) => {\n return {\n name: p.name,\n version: p.version,\n status: p.status,\n ...(options.verbose ? { program: p.program } : {}),\n }\n })\n }\n}\n\nexport const handleVerbose = (res: Process.Payload, verbose: boolean): Process.Payload => {\n if (verbose) {\n return res\n }\n const { program, ...rest } = res\n return rest\n}\n\nexport const createProcess = async (\n processRaw: Process.CliProcessInput,\n dryRun: boolean = false,\n polkadot: Polkadot.Polkadot,\n options: Polkadot.Options = defaultOptions,\n verbose: boolean = false\n): Promise<{\n waitForFinalised: Promise<Process.ProcessResponse>\n}> => {\n const handleErr = (err: unknown) => {\n // err is basically from errors.ts or any exception\n // process errors will contain specific messages and/or process\n // Promise<Process.Result> is in try {} and any exception is in catch {}\n if (err instanceof ProgramError || err instanceof VersionError || err instanceof ZodError) {\n const result: Process.ProcessResponse = {\n type: 'error' as 'error',\n error: err,\n message: err.message,\n }\n return {\n waitForFinalised: Promise.resolve(result),\n }\n } else if (err instanceof Error) {\n const result: Process.ProcessResponse = {\n type: 'error' as 'error',\n error: err,\n message: 'An unknown error occurred',\n }\n return {\n waitForFinalised: Promise.resolve(result),\n }\n }\n throw err\n }\n\n try {\n const { name, version, program } = processValidation.parse(processRaw)\n\n const processId = utf8ToHex(name)\n const currentVersion: number = await getVersion(polkadot, processId)\n const expectedVersion: number = currentVersion + 1\n\n if (version > expectedVersion || version < currentVersion) throw new VersionError(version, expectedVersion, name)\n\n if (version === currentVersion) {\n const process = await getProcess(polkadot, processId, version)\n\n if (program.length !== process.program.length)\n throw new ProgramError('existing: programs are different lengths', process)\n\n if (!program.every((step, i) => textify(step) === textify(process.program[i])))\n throw new ProgramError('existing: program steps did not match', process)\n\n return {\n waitForFinalised: Promise.resolve({\n type: 'ok',\n message: `Skipping: process ${name} is already created.`,\n result: handleVerbose(\n {\n name,\n version,\n program,\n status: process.status,\n },\n verbose\n ),\n }),\n }\n }\n\n if (dryRun)\n return {\n waitForFinalised: Promise.resolve({\n type: 'ok',\n message: 'Dry run: transaction has not been created',\n result: handleVerbose(\n {\n name,\n version,\n program,\n status: 'Enabled (dry-run)',\n },\n verbose\n ),\n }),\n }\n\n const createProcessTx = await createProcessTransaction(polkadot, processId, program, options)\n return {\n waitForFinalised: createProcessTx.waitForFinal\n .then((process) => {\n const result: Process.ProcessResponse = {\n type: 'ok',\n message: `Transaction for new process ${name} has been successfully submitted`,\n result: handleVerbose(process, verbose),\n }\n return result\n })\n .catch((err) => handleErr(err).waitForFinalised),\n }\n } catch (err) {\n return handleErr(err)\n }\n}\n\nexport const disableProcess = async (\n name: string,\n processVersion: number,\n dryRun: boolean = false,\n options: Polkadot.Options = defaultOptions\n): Promise<Process.ProcessResponse> => {\n const processId = utf8ToHex(name)\n\n await using polkadot = await createNodeApi(options)\n const currentProcess: Process.Payload = await getProcess(polkadot, processId, processVersion)\n\n if (currentProcess.status === 'Disabled') {\n throw new DisableError(`${name} with version ${processVersion} doesn't exist or is already disabled`)\n }\n\n if (dryRun) {\n return {\n type: 'ok',\n message: `This will DISABLE the following process ${name}`,\n result: {\n name,\n version: processVersion,\n status: 'Disabled (dry-run)',\n },\n }\n }\n\n return {\n type: 'ok',\n message: 'Process has been disabled',\n result: await disableProcessTransaction(polkadot, processId, processVersion, options),\n }\n}\n"],"names":["createNodeApi","createProcessTransaction","disableProcessTransaction","getVersion","getProcess","utf8ToHex","processValidation","simpleProcesssValidation","CliInputParseError","DisableError","ProgramError","VersionError","ZodError","defaultOptions","API_HOST","API_PORT","USER_URI","textify","obj","JSON","stringify","_key","val","Object","fromEntries","entries","map","k","v","c","i","toUpperCase","filter","join","toString","sanitizeInput","data","type","result","parse","err","Error","error","message","loadProcesses","options","dryRun","verbose","parsedRes","processes","processTxs","Map","polkadot","process","waitForFinalised","createProcess","set","name","Promise","all","values","successCount","key","processTxProm","response","length","listTransforming","res","active","status","disabled","raw","program","p","version","handleVerbose","rest","processRaw","handleErr","resolve","processId","currentVersion","expectedVersion","every","step","createProcessTx","waitForFinal","then","catch","disableProcess","processVersion","currentProcess"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAEc,KAAK,gCAAgC,CAAC;oBAC9EnB,QAAQqC,cAActB,SAASN;gBACjC;gBACA,OAAOT;YACT,GACCkD,KAAK,CAAC,CAAChD,MAAQsC,UAAUtC,KAAKc,gBAAgB;QACnD;IACF,EAAE,OAAOd,KAAK;QACZ,OAAOsC,UAAUtC;IACnB;AACF,EAAC;AAED,OAAO,MAAMiD,iBAAiB,OAC5BhC,MACAiC,gBACA5C,SAAkB,KAAK,EACvBD,UAA4BhC,cAAc;;;;;;;QAE1C,MAAMmE,YAAY3E,UAAUoD;cAEhBL,4CAAW,MAAMpD,cAAc6C;QAC3C,MAAM8C,iBAAkC,MAAMvF,WAAWgD,UAAU4B,WAAWU;QAE9E,IAAIC,eAAetB,MAAM,KAAK,YAAY;YACxC,MAAM,IAAI5D,aAAa,GAAGgD,KAAK,cAAc,EAAEiC,eAAe,qCAAqC,CAAC;QACtG;QAEA,IAAI5C,QAAQ;YACV,OAAO;gBACLT,MAAM;gBACNM,SAAS,CAAC,wCAAwC,EAAEc,MAAM;gBAC1DnB,QAAQ;oBACNmB;oBACAiB,SAASgB;oBACTrB,QAAQ;gBACV;YACF;QACF;QAEA,OAAO;YACLhC,MAAM;YACNM,SAAS;YACTL,QAAQ,MAAMpC,0BAA0BkD,UAAU4B,WAAWU,gBAAgB7C;QAC/E;;;;;;;;AACF,EAAC"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
export class DisableError extends Error {
|
|
2
|
-
constructor(m)
|
|
2
|
+
constructor(m){
|
|
3
3
|
super(m);
|
|
4
4
|
Object.setPrototypeOf(this, DisableError.prototype);
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export class VersionError extends Error {
|
|
8
|
-
constructor(version, expected, name)
|
|
8
|
+
constructor(version, expected, name){
|
|
9
9
|
super(`Process version ${version} is invalid. If you are trying to create a new version of process ${name} version should be ${expected}`);
|
|
10
10
|
Object.setPrototypeOf(this, VersionError.prototype);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export class CliInputParseError extends Error {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.baseError = baseError;
|
|
14
|
+
baseError;
|
|
15
|
+
constructor(baseError){
|
|
16
|
+
super(`Error parsing input: ${baseError.message}`), this.baseError = baseError;
|
|
17
17
|
Object.setPrototypeOf(this, CliInputParseError.prototype);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
export class ProgramError extends Error {
|
|
21
|
-
|
|
21
|
+
process;
|
|
22
|
+
constructor(m, process){
|
|
22
23
|
super(m);
|
|
23
24
|
this.process = process;
|
|
24
25
|
Object.setPrototypeOf(this, ProgramError.prototype);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/error.ts"],"sourcesContent":["export class DisableError extends Error {\n constructor(m: string) {\n super(m)\n Object.setPrototypeOf(this, DisableError.prototype)\n }\n}\n\nexport class VersionError extends Error {\n constructor(version: number, expected: number, name: string) {\n super(\n `Process version ${version} is invalid. If you are trying to create a new version of process ${name} version should be ${expected}`\n )\n Object.setPrototypeOf(this, VersionError.prototype)\n }\n}\n\nexport class CliInputParseError extends Error {\n constructor(public baseError: Error) {\n super(`Error parsing input: ${baseError.message}`)\n Object.setPrototypeOf(this, CliInputParseError.prototype)\n }\n}\n\nexport class ProgramError extends Error {\n process?: Process.Payload\n constructor(m: string, process?: Process.Payload) {\n super(m)\n this.process = process\n Object.setPrototypeOf(this, ProgramError.prototype)\n }\n}\n"],"names":["DisableError","Error","constructor","m","Object","setPrototypeOf","prototype","VersionError","version","expected","name","CliInputParseError","baseError","message","ProgramError","process"],"mappings":"AAAA,OAAO,MAAMA,qBAAqBC;IAChCC,YAAYC,CAAS,CAAE;QACrB,KAAK,CAACA;QACNC,OAAOC,cAAc,CAAC,IAAI,EAAEL,aAAaM,SAAS;IACpD;AACF;AAEA,OAAO,MAAMC,qBAAqBN;IAChCC,YAAYM,OAAe,EAAEC,QAAgB,EAAEC,IAAY,CAAE;QAC3D,KAAK,CACH,CAAC,gBAAgB,EAAEF,QAAQ,kEAAkE,EAAEE,KAAK,mBAAmB,EAAED,UAAU;QAErIL,OAAOC,cAAc,CAAC,IAAI,EAAEE,aAAaD,SAAS;IACpD;AACF;AAEA,OAAO,MAAMK,2BAA2BV;;IACtCC,YAAY,AAAOU,SAAgB,CAAE;QACnC,KAAK,CAAC,CAAC,qBAAqB,EAAEA,UAAUC,OAAO,EAAE,QADhCD,YAAAA;QAEjBR,OAAOC,cAAc,CAAC,IAAI,EAAEM,mBAAmBL,SAAS;IAC1D;AACF;AAEA,OAAO,MAAMQ,qBAAqBb;IAChCc,QAAyB;IACzBb,YAAYC,CAAS,EAAEY,OAAyB,CAAE;QAChD,KAAK,CAACZ;QACN,IAAI,CAACY,OAAO,GAAGA;QACfX,OAAOC,cAAc,CAAC,IAAI,EAAES,aAAaR,SAAS;IACpD;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/polkadot.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/process.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Constants } from '../process/constants.js';
|
|
3
|
+
const tokenMetadataKey = z.string();
|
|
4
|
+
const tokenId = z.number();
|
|
5
|
+
const file = z.string();
|
|
6
|
+
const metadataValue = z.union([
|
|
7
|
+
z.object({
|
|
8
|
+
File: file
|
|
9
|
+
}),
|
|
10
|
+
z.object({
|
|
11
|
+
Literal: z.string()
|
|
12
|
+
}),
|
|
13
|
+
z.object({
|
|
14
|
+
TokenId: tokenId
|
|
15
|
+
}),
|
|
16
|
+
z.object({
|
|
17
|
+
None: z.null()
|
|
18
|
+
})
|
|
19
|
+
]);
|
|
20
|
+
const metadataValueType = z.enum([
|
|
21
|
+
'File',
|
|
22
|
+
'Literal',
|
|
23
|
+
'TokenId',
|
|
24
|
+
'None'
|
|
25
|
+
]);
|
|
26
|
+
const role = z.string();
|
|
27
|
+
const binaryOperator = z.enum([
|
|
28
|
+
'Identity',
|
|
29
|
+
'TransferL',
|
|
30
|
+
'TransferR',
|
|
31
|
+
'NotL',
|
|
32
|
+
'NotR',
|
|
33
|
+
'And',
|
|
34
|
+
'Nand',
|
|
35
|
+
'Or',
|
|
36
|
+
'Nor',
|
|
37
|
+
'Xor',
|
|
38
|
+
'Xnor',
|
|
39
|
+
'ImplicationL',
|
|
40
|
+
'ImplicationR',
|
|
41
|
+
'InhibitionL',
|
|
42
|
+
'InhibitionR'
|
|
43
|
+
]);
|
|
44
|
+
const senderHasInputRole = z.object({
|
|
45
|
+
index: z.number(),
|
|
46
|
+
role_key: role
|
|
47
|
+
});
|
|
48
|
+
const senderHasOutputRole = z.object({
|
|
49
|
+
index: z.number(),
|
|
50
|
+
role_key: role
|
|
51
|
+
});
|
|
52
|
+
const outputHasRole = z.object({
|
|
53
|
+
index: z.number(),
|
|
54
|
+
role_key: role
|
|
55
|
+
});
|
|
56
|
+
const outputHasMetadata = z.object({
|
|
57
|
+
index: z.number(),
|
|
58
|
+
metadata_key: tokenMetadataKey
|
|
59
|
+
});
|
|
60
|
+
const inputHasRole = z.object({
|
|
61
|
+
index: z.number(),
|
|
62
|
+
role_key: role
|
|
63
|
+
});
|
|
64
|
+
const inputHasMetadata = z.object({
|
|
65
|
+
index: z.number(),
|
|
66
|
+
metadata_key: tokenMetadataKey
|
|
67
|
+
});
|
|
68
|
+
const matchInputOutputRole = z.object({
|
|
69
|
+
input_index: z.number(),
|
|
70
|
+
input_role_key: role,
|
|
71
|
+
output_index: z.number(),
|
|
72
|
+
output_role_key: role
|
|
73
|
+
});
|
|
74
|
+
const matchInputOutputMetadataValue = z.object({
|
|
75
|
+
input_index: z.number(),
|
|
76
|
+
input_metadata_key: tokenMetadataKey,
|
|
77
|
+
output_index: z.number(),
|
|
78
|
+
output_metadata_key: tokenMetadataKey
|
|
79
|
+
});
|
|
80
|
+
const matchInputIdOutputMetadataValue = z.object({
|
|
81
|
+
input_index: z.number(),
|
|
82
|
+
output_index: z.number(),
|
|
83
|
+
output_metadata_key: tokenMetadataKey
|
|
84
|
+
});
|
|
85
|
+
const fixedNumberOfInputs = z.object({
|
|
86
|
+
num_inputs: z.number()
|
|
87
|
+
});
|
|
88
|
+
const fixedNumberOfOutputs = z.object({
|
|
89
|
+
num_outputs: z.number()
|
|
90
|
+
});
|
|
91
|
+
const fixedInputMetadataValue = z.object({
|
|
92
|
+
index: z.number(),
|
|
93
|
+
metadata_key: tokenMetadataKey,
|
|
94
|
+
metadata_value: metadataValue
|
|
95
|
+
});
|
|
96
|
+
const fixedOutputMetadataValue = z.object({
|
|
97
|
+
index: z.number(),
|
|
98
|
+
metadata_key: tokenMetadataKey,
|
|
99
|
+
metadata_value: metadataValue
|
|
100
|
+
});
|
|
101
|
+
const fixedInputMetadataValueType = z.object({
|
|
102
|
+
index: z.number(),
|
|
103
|
+
metadata_key: tokenMetadataKey,
|
|
104
|
+
metadata_value_type: metadataValueType
|
|
105
|
+
});
|
|
106
|
+
const fixedOutputMetadataValueType = z.object({
|
|
107
|
+
index: z.number(),
|
|
108
|
+
metadata_key: tokenMetadataKey,
|
|
109
|
+
metadata_value_type: metadataValueType
|
|
110
|
+
});
|
|
111
|
+
export const restrictionValidation = z.union([
|
|
112
|
+
z.literal('None'),
|
|
113
|
+
z.literal('Fail'),
|
|
114
|
+
z.object({
|
|
115
|
+
SenderHasInputRole: senderHasInputRole
|
|
116
|
+
}).strict(),
|
|
117
|
+
z.object({
|
|
118
|
+
SenderHasOutputRole: senderHasOutputRole
|
|
119
|
+
}).strict(),
|
|
120
|
+
z.object({
|
|
121
|
+
OutputHasRole: outputHasRole
|
|
122
|
+
}).strict(),
|
|
123
|
+
z.object({
|
|
124
|
+
OutputHasMetadata: outputHasMetadata
|
|
125
|
+
}).strict(),
|
|
126
|
+
z.object({
|
|
127
|
+
InputHasRole: inputHasRole
|
|
128
|
+
}).strict(),
|
|
129
|
+
z.object({
|
|
130
|
+
InputHasMetadata: inputHasMetadata
|
|
131
|
+
}).strict(),
|
|
132
|
+
z.object({
|
|
133
|
+
MatchInputOutputRole: matchInputOutputRole
|
|
134
|
+
}).strict(),
|
|
135
|
+
z.object({
|
|
136
|
+
MatchInputOutputMetadataValue: matchInputOutputMetadataValue
|
|
137
|
+
}).strict(),
|
|
138
|
+
z.object({
|
|
139
|
+
MatchInputIdOutputMetadataValue: matchInputIdOutputMetadataValue
|
|
140
|
+
}).strict(),
|
|
141
|
+
z.object({
|
|
142
|
+
FixedNumberOfInputs: fixedNumberOfInputs
|
|
143
|
+
}).strict(),
|
|
144
|
+
z.object({
|
|
145
|
+
FixedNumberOfOutputs: fixedNumberOfOutputs
|
|
146
|
+
}).strict(),
|
|
147
|
+
z.object({
|
|
148
|
+
FixedInputMetadataValue: fixedInputMetadataValue
|
|
149
|
+
}).strict(),
|
|
150
|
+
z.object({
|
|
151
|
+
FixedOutputMetadataValue: fixedOutputMetadataValue
|
|
152
|
+
}).strict(),
|
|
153
|
+
z.object({
|
|
154
|
+
FixedInputMetadataValueType: fixedInputMetadataValueType
|
|
155
|
+
}).strict(),
|
|
156
|
+
z.object({
|
|
157
|
+
FixedOutputMetadataValueType: fixedOutputMetadataValueType
|
|
158
|
+
}).strict()
|
|
159
|
+
]);
|
|
160
|
+
export const stepValidation = z.union([
|
|
161
|
+
z.object({
|
|
162
|
+
Op: binaryOperator
|
|
163
|
+
}),
|
|
164
|
+
z.object({
|
|
165
|
+
Restriction: restrictionValidation
|
|
166
|
+
})
|
|
167
|
+
]);
|
|
168
|
+
export const programValidation = z.array(stepValidation);
|
|
169
|
+
export const processValidation = z.object({
|
|
170
|
+
name: z.string().max(Constants.PROCESS_ID_LENGTH),
|
|
171
|
+
version: z.number(),
|
|
172
|
+
program: programValidation
|
|
173
|
+
});
|
|
174
|
+
export const simpleProcesssValidation = z.array(z.object({
|
|
175
|
+
name: z.string()
|
|
176
|
+
}).passthrough());
|
|
177
|
+
export const processesValidation = z.array(processValidation);
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/types/validation.ts"],"sourcesContent":["import { z } from 'zod'\nimport { Constants } from '../process/constants.js'\n\nconst tokenMetadataKey = z.string()\nconst tokenId = z.number()\nconst file = z.string()\nconst metadataValue = z.union([\n z.object({ File: file }),\n z.object({ Literal: z.string() }),\n z.object({ TokenId: tokenId }),\n z.object({ None: z.null() }),\n])\nconst metadataValueType = z.enum(['File', 'Literal', 'TokenId', 'None'])\nconst role = z.string()\n\nconst binaryOperator = z.enum([\n 'Identity',\n 'TransferL',\n 'TransferR',\n 'NotL',\n 'NotR',\n 'And',\n 'Nand',\n 'Or',\n 'Nor',\n 'Xor',\n 'Xnor',\n 'ImplicationL',\n 'ImplicationR',\n 'InhibitionL',\n 'InhibitionR',\n])\n\nconst senderHasInputRole = z.object({\n index: z.number(),\n role_key: role,\n})\n\nconst senderHasOutputRole = z.object({\n index: z.number(),\n role_key: role,\n})\n\nconst outputHasRole = z.object({\n index: z.number(),\n role_key: role,\n})\n\nconst outputHasMetadata = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n})\n\nconst inputHasRole = z.object({\n index: z.number(),\n role_key: role,\n})\n\nconst inputHasMetadata = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n})\n\nconst matchInputOutputRole = z.object({\n input_index: z.number(),\n input_role_key: role,\n output_index: z.number(),\n output_role_key: role,\n})\n\nconst matchInputOutputMetadataValue = z.object({\n input_index: z.number(),\n input_metadata_key: tokenMetadataKey,\n output_index: z.number(),\n output_metadata_key: tokenMetadataKey,\n})\n\nconst matchInputIdOutputMetadataValue = z.object({\n input_index: z.number(),\n output_index: z.number(),\n output_metadata_key: tokenMetadataKey,\n})\n\nconst fixedNumberOfInputs = z.object({\n num_inputs: z.number(),\n})\n\nconst fixedNumberOfOutputs = z.object({\n num_outputs: z.number(),\n})\n\nconst fixedInputMetadataValue = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n metadata_value: metadataValue,\n})\n\nconst fixedOutputMetadataValue = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n metadata_value: metadataValue,\n})\n\nconst fixedInputMetadataValueType = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n metadata_value_type: metadataValueType,\n})\n\nconst fixedOutputMetadataValueType = z.object({\n index: z.number(),\n metadata_key: tokenMetadataKey,\n metadata_value_type: metadataValueType,\n})\n\nexport const restrictionValidation = z.union([\n z.literal('None'),\n z.literal('Fail'),\n z.object({ SenderHasInputRole: senderHasInputRole }).strict(),\n z.object({ SenderHasOutputRole: senderHasOutputRole }).strict(),\n z.object({ OutputHasRole: outputHasRole }).strict(),\n z.object({ OutputHasMetadata: outputHasMetadata }).strict(),\n z.object({ InputHasRole: inputHasRole }).strict(),\n z.object({ InputHasMetadata: inputHasMetadata }).strict(),\n z.object({ MatchInputOutputRole: matchInputOutputRole }).strict(),\n z.object({ MatchInputOutputMetadataValue: matchInputOutputMetadataValue }).strict(),\n z.object({ MatchInputIdOutputMetadataValue: matchInputIdOutputMetadataValue }).strict(),\n z.object({ FixedNumberOfInputs: fixedNumberOfInputs }).strict(),\n z.object({ FixedNumberOfOutputs: fixedNumberOfOutputs }).strict(),\n z.object({ FixedInputMetadataValue: fixedInputMetadataValue }).strict(),\n z.object({ FixedOutputMetadataValue: fixedOutputMetadataValue }).strict(),\n z.object({ FixedInputMetadataValueType: fixedInputMetadataValueType }).strict(),\n z.object({ FixedOutputMetadataValueType: fixedOutputMetadataValueType }).strict(),\n])\n\nexport const stepValidation = z.union([\n z.object({ Op: binaryOperator }),\n z.object({ Restriction: restrictionValidation }),\n])\n\nexport const programValidation = z.array(stepValidation)\n\nexport const processValidation = z.object({\n name: z.string().max(Constants.PROCESS_ID_LENGTH),\n version: z.number(),\n program: programValidation,\n})\n\nexport const simpleProcesssValidation = z.array(z.object({ name: z.string() }).passthrough())\n\nexport const processesValidation = z.array(processValidation)\n\nexport type ValidationRestriction = z.infer<typeof restrictionValidation>\nexport type ValidationProgramStep = z.infer<typeof stepValidation>\nexport type ValidationProgram = z.infer<typeof programValidation>\nexport type ValidationProcess = z.infer<typeof processValidation>\nexport type ValidationProcesses = z.infer<typeof processesValidation>\n"],"names":["z","Constants","tokenMetadataKey","string","tokenId","number","file","metadataValue","union","object","File","Literal","TokenId","None","null","metadataValueType","enum","role","binaryOperator","senderHasInputRole","index","role_key","senderHasOutputRole","outputHasRole","outputHasMetadata","metadata_key","inputHasRole","inputHasMetadata","matchInputOutputRole","input_index","input_role_key","output_index","output_role_key","matchInputOutputMetadataValue","input_metadata_key","output_metadata_key","matchInputIdOutputMetadataValue","fixedNumberOfInputs","num_inputs","fixedNumberOfOutputs","num_outputs","fixedInputMetadataValue","metadata_value","fixedOutputMetadataValue","fixedInputMetadataValueType","metadata_value_type","fixedOutputMetadataValueType","restrictionValidation","literal","SenderHasInputRole","strict","SenderHasOutputRole","OutputHasRole","OutputHasMetadata","InputHasRole","InputHasMetadata","MatchInputOutputRole","MatchInputOutputMetadataValue","MatchInputIdOutputMetadataValue","FixedNumberOfInputs","FixedNumberOfOutputs","FixedInputMetadataValue","FixedOutputMetadataValue","FixedInputMetadataValueType","FixedOutputMetadataValueType","stepValidation","Op","Restriction","programValidation","array","processValidation","name","max","PROCESS_ID_LENGTH","version","program","simpleProcesssValidation","passthrough","processesValidation"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AACvB,SAASC,SAAS,QAAQ,0BAAyB;AAEnD,MAAMC,mBAAmBF,EAAEG,MAAM;AACjC,MAAMC,UAAUJ,EAAEK,MAAM;AACxB,MAAMC,OAAON,EAAEG,MAAM;AACrB,MAAMI,gBAAgBP,EAAEQ,KAAK,CAAC;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AAMC,sBAAsB9E,EAAEqE,KAAK,CAACC,mBAAkB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
|
|
2
|
+
export const createNodeApi = async (options)=>{
|
|
3
|
+
const provider = new WsProvider(`ws://${options.API_HOST}:${options.API_PORT}`);
|
|
4
|
+
const api = new ApiPromise({
|
|
5
|
+
provider
|
|
6
|
+
});
|
|
7
|
+
api.isReadyOrError.catch(()=>{}) // prevent unhandled promise rejection errors
|
|
8
|
+
;
|
|
9
|
+
await api.isReady;
|
|
10
|
+
api.on('error', (err)=>{
|
|
11
|
+
const msg = err.message || JSON.stringify(err);
|
|
12
|
+
console.log(`Error from substrate node connection. Error was ${msg}`);
|
|
13
|
+
return msg;
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
api,
|
|
17
|
+
keyring: new Keyring({
|
|
18
|
+
type: 'sr25519'
|
|
19
|
+
}),
|
|
20
|
+
[Symbol.asyncDispose]: async ()=>{
|
|
21
|
+
await api.disconnect();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=polkadot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/utils/polkadot.ts"],"sourcesContent":["import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'\n\nexport const createNodeApi = async (options: Polkadot.Options) => {\n const provider = new WsProvider(`ws://${options.API_HOST}:${options.API_PORT}`)\n const api = new ApiPromise({ provider })\n\n api.isReadyOrError.catch(() => {}) // prevent unhandled promise rejection errors\n\n await api.isReady\n\n api.on('error', (err: { message?: string }): string => {\n const msg = err.message || JSON.stringify(err)\n console.log(`Error from substrate node connection. Error was ${msg}`)\n\n return msg\n })\n\n return {\n api,\n keyring: new Keyring({ type: 'sr25519' }),\n [Symbol.asyncDispose]: async () => {\n await api.disconnect()\n },\n }\n}\n"],"names":["ApiPromise","WsProvider","Keyring","createNodeApi","options","provider","API_HOST","API_PORT","api","isReadyOrError","catch","isReady","on","err","msg","message","JSON","stringify","console","log","keyring","type","Symbol","asyncDispose","disconnect"],"mappings":"AAAA,SAASA,UAAU,EAAEC,UAAU,EAAEC,OAAO,QAAQ,gBAAe;AAE/D,OAAO,MAAMC,gBAAgB,OAAOC;IAClC,MAAMC,WAAW,IAAIJ,WAAW,CAAC,KAAK,EAAEG,QAAQE,QAAQ,CAAC,CAAC,EAAEF,QAAQG,QAAQ,EAAE;IAC9E,MAAMC,MAAM,IAAIR,WAAW;QAAEK;IAAS;IAEtCG,IAAIC,cAAc,CAACC,KAAK,CAAC,KAAO,GAAG,6CAA6C;;IAEhF,MAAMF,IAAIG,OAAO;IAEjBH,IAAII,EAAE,CAAC,SAAS,CAACC;QACf,MAAMC,MAAMD,IAAIE,OAAO,IAAIC,KAAKC,SAAS,CAACJ;QAC1CK,QAAQC,GAAG,CAAC,CAAC,gDAAgD,EAAEL,KAAK;QAEpE,OAAOA;IACT;IAEA,OAAO;QACLN;QACAY,SAAS,IAAIlB,QAAQ;YAAEmB,MAAM;QAAU;QACvC,CAACC,OAAOC,YAAY,CAAC,EAAE;YACrB,MAAMf,IAAIgB,UAAU;QACtB;IACF;AACF,EAAC"}
|
package/build/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["import packageJson from '../package.json' assert { type: 'json' }\nconst { version } = packageJson\nexport default version"],"names":["packageJson","version"],"mappings":"AAAA,OAAOA,iBAAiB,kBAAyC;AACjE,MAAM,EAAEC,OAAO,EAAE,GAAGD;AACpB,eAAeC,QAAO"}
|