@coopenomics/parser 2025.11.12-alpha-1 → 2025.11.13-alpha-3
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/index.cjs +172 -2
- package/dist/index.mjs +172 -2
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const mongodb = require('mongodb');
|
|
|
6
6
|
const dotenv = require('dotenv');
|
|
7
7
|
const eosioShipReader = require('@blockmatic/eosio-ship-reader');
|
|
8
8
|
const fetch = require('node-fetch');
|
|
9
|
+
const cooptypes = require('cooptypes');
|
|
9
10
|
const Redis = require('ioredis');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
@@ -282,7 +283,7 @@ FORK detected at block: ${block_num}`);
|
|
|
282
283
|
console.log("\u041F\u043E\u0434\u043F\u0438\u0441\u043A\u0430 \u043D\u0430 \u0444\u043E\u0440\u043A\u0438 \u0430\u043A\u0442\u0438\u0432\u0438\u0440\u043E\u0432\u0430\u043D\u0430");
|
|
283
284
|
}
|
|
284
285
|
|
|
285
|
-
const getInfo = () => fetch__default(`${eosioApi}/v1/chain/get_info`).then((res) => res.json());
|
|
286
|
+
const getInfo$1 = () => fetch__default(`${eosioApi}/v1/chain/get_info`).then((res) => res.json());
|
|
286
287
|
function fetchAbi(account_name) {
|
|
287
288
|
return fetch__default(`${eosioApi}/v1/chain/get_abi`, {
|
|
288
289
|
method: "POST",
|
|
@@ -306,14 +307,183 @@ function extractTablesFromAbi(abi) {
|
|
|
306
307
|
return abi.tables.map((table) => table.name);
|
|
307
308
|
}
|
|
308
309
|
|
|
310
|
+
async function getTableRows(code, scope, table, limit = 1e3) {
|
|
311
|
+
const response = await fetch__default(`${eosioApi}/v1/chain/get_table_rows`, {
|
|
312
|
+
method: "POST",
|
|
313
|
+
headers: {
|
|
314
|
+
"Content-Type": "application/json"
|
|
315
|
+
},
|
|
316
|
+
body: JSON.stringify({
|
|
317
|
+
json: true,
|
|
318
|
+
code,
|
|
319
|
+
scope,
|
|
320
|
+
table,
|
|
321
|
+
limit
|
|
322
|
+
})
|
|
323
|
+
});
|
|
324
|
+
const result = await response.json();
|
|
325
|
+
return result.rows || [];
|
|
326
|
+
}
|
|
327
|
+
async function getInfo() {
|
|
328
|
+
const response = await fetch__default(`${eosioApi}/v1/chain/get_info`);
|
|
329
|
+
return response.json();
|
|
330
|
+
}
|
|
331
|
+
async function checkCooperativeExists(db, coopname) {
|
|
332
|
+
try {
|
|
333
|
+
const cooperative = await db.getDelta({
|
|
334
|
+
"code": cooptypes.RegistratorContract.contractName.production,
|
|
335
|
+
"scope": cooptypes.RegistratorContract.contractName.production,
|
|
336
|
+
"table": cooptypes.RegistratorContract.Tables.Cooperatives.tableName,
|
|
337
|
+
"value.username": coopname
|
|
338
|
+
});
|
|
339
|
+
if (!cooperative)
|
|
340
|
+
return false;
|
|
341
|
+
const soviet = await db.getDelta({
|
|
342
|
+
"code": cooptypes.SovietContract.contractName.production,
|
|
343
|
+
"scope": coopname,
|
|
344
|
+
"table": cooptypes.SovietContract.Tables.Boards.tableName,
|
|
345
|
+
"value.type": "soviet"
|
|
346
|
+
});
|
|
347
|
+
return !!soviet;
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430:", error);
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async function checkTemplatesExist(db) {
|
|
354
|
+
try {
|
|
355
|
+
const drafts = await db.getDelta({
|
|
356
|
+
code: cooptypes.DraftContract.contractName.production,
|
|
357
|
+
scope: cooptypes.DraftContract.contractName.production,
|
|
358
|
+
table: cooptypes.DraftContract.Tables.Drafts.tableName
|
|
359
|
+
});
|
|
360
|
+
return !!drafts;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432:", error);
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function loadCooperativeFromBlockchain(db, coopname, block_num) {
|
|
367
|
+
console.log(`\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430...`);
|
|
368
|
+
const cooperatives = await getTableRows(cooptypes.RegistratorContract.contractName.production, cooptypes.RegistratorContract.contractName.production, cooptypes.RegistratorContract.Tables.Cooperatives.tableName);
|
|
369
|
+
const cooperative = cooperatives.find((row) => row.username === coopname);
|
|
370
|
+
if (!cooperative) {
|
|
371
|
+
throw new Error(`\u041A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432 ${coopname} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435`);
|
|
372
|
+
}
|
|
373
|
+
const cooperativeDelta = {
|
|
374
|
+
code: cooptypes.RegistratorContract.contractName.production,
|
|
375
|
+
scope: cooptypes.RegistratorContract.contractName.production,
|
|
376
|
+
table: cooptypes.RegistratorContract.Tables.Cooperatives.tableName,
|
|
377
|
+
primary_key: cooperative.username,
|
|
378
|
+
// username - это primary_key для cooperatives
|
|
379
|
+
value: cooperative,
|
|
380
|
+
block_num,
|
|
381
|
+
present: "1"
|
|
382
|
+
};
|
|
383
|
+
await db.saveDeltaToDB(cooperativeDelta);
|
|
384
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u044B`);
|
|
385
|
+
const boards = await getTableRows(cooptypes.SovietContract.contractName.production, coopname, cooptypes.SovietContract.Tables.Boards.tableName);
|
|
386
|
+
const soviet = boards.find((row) => row.type === "soviet");
|
|
387
|
+
if (!soviet) {
|
|
388
|
+
throw new Error(`\u0421\u043E\u0432\u0435\u0442 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435`);
|
|
389
|
+
}
|
|
390
|
+
const sovietDelta = {
|
|
391
|
+
code: cooptypes.SovietContract.contractName.production,
|
|
392
|
+
scope: coopname,
|
|
393
|
+
table: cooptypes.SovietContract.Tables.Boards.tableName,
|
|
394
|
+
primary_key: String(soviet.id),
|
|
395
|
+
// id - это primary_key для boards
|
|
396
|
+
value: soviet,
|
|
397
|
+
block_num,
|
|
398
|
+
present: "1"
|
|
399
|
+
};
|
|
400
|
+
await db.saveDeltaToDB(sovietDelta);
|
|
401
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u0441\u043E\u0432\u0435\u0442\u0430 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u044B`);
|
|
402
|
+
}
|
|
403
|
+
async function loadTemplatesFromBlockchain(db, block_num) {
|
|
404
|
+
console.log("\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430...");
|
|
405
|
+
const drafts = await getTableRows(cooptypes.DraftContract.contractName.production, cooptypes.DraftContract.contractName.production, cooptypes.DraftContract.Tables.Drafts.tableName);
|
|
406
|
+
if (drafts.length === 0) {
|
|
407
|
+
console.log("\u26A0 \u0428\u0430\u0431\u043B\u043E\u043D\u044B \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
for (const draft of drafts) {
|
|
411
|
+
const draftDelta = {
|
|
412
|
+
code: cooptypes.DraftContract.contractName.production,
|
|
413
|
+
scope: cooptypes.DraftContract.contractName.production,
|
|
414
|
+
table: cooptypes.DraftContract.Tables.Drafts.tableName,
|
|
415
|
+
primary_key: String(draft.registry_id),
|
|
416
|
+
// registry_id - это primary_key для drafts
|
|
417
|
+
value: draft,
|
|
418
|
+
block_num,
|
|
419
|
+
present: "1"
|
|
420
|
+
};
|
|
421
|
+
await db.saveDeltaToDB(draftDelta);
|
|
422
|
+
}
|
|
423
|
+
console.log(`\u2713 \u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u043E ${drafts.length} \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432`);
|
|
424
|
+
const translations = await getTableRows("draft", "draft", "translations");
|
|
425
|
+
if (translations.length === 0) {
|
|
426
|
+
console.log("\u26A0 \u041F\u0435\u0440\u0435\u0432\u043E\u0434\u044B \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
for (const translation of translations) {
|
|
430
|
+
const translationDelta = {
|
|
431
|
+
code: cooptypes.DraftContract.contractName.production,
|
|
432
|
+
scope: cooptypes.DraftContract.contractName.production,
|
|
433
|
+
table: cooptypes.DraftContract.Tables.Translations.tableName,
|
|
434
|
+
primary_key: String(translation.id),
|
|
435
|
+
// id - это primary_key для translations
|
|
436
|
+
value: translation,
|
|
437
|
+
block_num,
|
|
438
|
+
present: "1"
|
|
439
|
+
};
|
|
440
|
+
await db.saveDeltaToDB(translationDelta);
|
|
441
|
+
}
|
|
442
|
+
console.log(`\u2713 \u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u043E ${translations.length} \u043F\u0435\u0440\u0435\u0432\u043E\u0434\u043E\u0432 \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432`);
|
|
443
|
+
}
|
|
444
|
+
async function initializeFromBlockchain(db) {
|
|
445
|
+
const coopname = process.env.COOPNAME;
|
|
446
|
+
if (!coopname) {
|
|
447
|
+
console.log("\u26A0 COOPNAME \u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D \u0432 .env, \u043F\u0440\u043E\u043F\u0443\u0441\u043A\u0430\u0435\u043C \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044E");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
451
|
+
console.log("\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E\u0441\u0442\u0438 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043D\u043D\u044B\u0445");
|
|
452
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
453
|
+
const info = await getInfo();
|
|
454
|
+
const currentBlock = Number(info.head_block_num);
|
|
455
|
+
const cooperativeExists = await checkCooperativeExists(db, coopname);
|
|
456
|
+
const templatesExist = await checkTemplatesExist(db);
|
|
457
|
+
if (cooperativeExists && templatesExist) {
|
|
458
|
+
console.log("\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 \u0438 \u0448\u0430\u0431\u043B\u043E\u043D\u044B \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442 \u0432 \u0431\u0430\u0437\u0435");
|
|
459
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
console.log(`\u041D\u0430\u0447\u0438\u043D\u0430\u0435\u043C \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044E \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430 (\u0431\u043B\u043E\u043A ${currentBlock})...`);
|
|
463
|
+
if (!cooperativeExists) {
|
|
464
|
+
await loadCooperativeFromBlockchain(db, coopname, currentBlock);
|
|
465
|
+
} else {
|
|
466
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442`);
|
|
467
|
+
}
|
|
468
|
+
if (!templatesExist) {
|
|
469
|
+
await loadTemplatesFromBlockchain(db, currentBlock);
|
|
470
|
+
} else {
|
|
471
|
+
console.log("\u2713 \u0428\u0430\u0431\u043B\u043E\u043D\u044B \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442");
|
|
472
|
+
}
|
|
473
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
474
|
+
console.log("\u2713 \u0418\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E");
|
|
475
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
476
|
+
}
|
|
477
|
+
|
|
309
478
|
const actions_whitelist = () => subsribedActions;
|
|
310
479
|
console.log("Actions whitelist (auto-generated from subscribedContracts):", subsribedActions);
|
|
311
480
|
async function loadReader(db) {
|
|
312
481
|
let currentBlock = await db.getCurrentBlock();
|
|
313
|
-
const info = await getInfo();
|
|
482
|
+
const info = await getInfo$1();
|
|
314
483
|
if (Number(startBlock) === 1) {
|
|
315
484
|
if (currentBlock === 0) {
|
|
316
485
|
currentBlock = Number(info.head_block_num);
|
|
486
|
+
await initializeFromBlockchain(db);
|
|
317
487
|
}
|
|
318
488
|
} else {
|
|
319
489
|
currentBlock = Number(startBlock);
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { MongoClient } from 'mongodb';
|
|
|
4
4
|
import dotenv from 'dotenv';
|
|
5
5
|
import { createEosioShipReader } from '@blockmatic/eosio-ship-reader';
|
|
6
6
|
import fetch from 'node-fetch';
|
|
7
|
+
import { RegistratorContract, SovietContract, DraftContract } from 'cooptypes';
|
|
7
8
|
import Redis from 'ioredis';
|
|
8
9
|
|
|
9
10
|
dotenv.config();
|
|
@@ -273,7 +274,7 @@ FORK detected at block: ${block_num}`);
|
|
|
273
274
|
console.log("\u041F\u043E\u0434\u043F\u0438\u0441\u043A\u0430 \u043D\u0430 \u0444\u043E\u0440\u043A\u0438 \u0430\u043A\u0442\u0438\u0432\u0438\u0440\u043E\u0432\u0430\u043D\u0430");
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
const getInfo = () => fetch(`${eosioApi}/v1/chain/get_info`).then((res) => res.json());
|
|
277
|
+
const getInfo$1 = () => fetch(`${eosioApi}/v1/chain/get_info`).then((res) => res.json());
|
|
277
278
|
function fetchAbi(account_name) {
|
|
278
279
|
return fetch(`${eosioApi}/v1/chain/get_abi`, {
|
|
279
280
|
method: "POST",
|
|
@@ -297,14 +298,183 @@ function extractTablesFromAbi(abi) {
|
|
|
297
298
|
return abi.tables.map((table) => table.name);
|
|
298
299
|
}
|
|
299
300
|
|
|
301
|
+
async function getTableRows(code, scope, table, limit = 1e3) {
|
|
302
|
+
const response = await fetch(`${eosioApi}/v1/chain/get_table_rows`, {
|
|
303
|
+
method: "POST",
|
|
304
|
+
headers: {
|
|
305
|
+
"Content-Type": "application/json"
|
|
306
|
+
},
|
|
307
|
+
body: JSON.stringify({
|
|
308
|
+
json: true,
|
|
309
|
+
code,
|
|
310
|
+
scope,
|
|
311
|
+
table,
|
|
312
|
+
limit
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
const result = await response.json();
|
|
316
|
+
return result.rows || [];
|
|
317
|
+
}
|
|
318
|
+
async function getInfo() {
|
|
319
|
+
const response = await fetch(`${eosioApi}/v1/chain/get_info`);
|
|
320
|
+
return response.json();
|
|
321
|
+
}
|
|
322
|
+
async function checkCooperativeExists(db, coopname) {
|
|
323
|
+
try {
|
|
324
|
+
const cooperative = await db.getDelta({
|
|
325
|
+
"code": RegistratorContract.contractName.production,
|
|
326
|
+
"scope": RegistratorContract.contractName.production,
|
|
327
|
+
"table": RegistratorContract.Tables.Cooperatives.tableName,
|
|
328
|
+
"value.username": coopname
|
|
329
|
+
});
|
|
330
|
+
if (!cooperative)
|
|
331
|
+
return false;
|
|
332
|
+
const soviet = await db.getDelta({
|
|
333
|
+
"code": SovietContract.contractName.production,
|
|
334
|
+
"scope": coopname,
|
|
335
|
+
"table": SovietContract.Tables.Boards.tableName,
|
|
336
|
+
"value.type": "soviet"
|
|
337
|
+
});
|
|
338
|
+
return !!soviet;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u0434\u0430\u043D\u043D\u044B\u0445 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430:", error);
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async function checkTemplatesExist(db) {
|
|
345
|
+
try {
|
|
346
|
+
const drafts = await db.getDelta({
|
|
347
|
+
code: DraftContract.contractName.production,
|
|
348
|
+
scope: DraftContract.contractName.production,
|
|
349
|
+
table: DraftContract.Tables.Drafts.tableName
|
|
350
|
+
});
|
|
351
|
+
return !!drafts;
|
|
352
|
+
} catch (error) {
|
|
353
|
+
console.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432:", error);
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async function loadCooperativeFromBlockchain(db, coopname, block_num) {
|
|
358
|
+
console.log(`\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430...`);
|
|
359
|
+
const cooperatives = await getTableRows(RegistratorContract.contractName.production, RegistratorContract.contractName.production, RegistratorContract.Tables.Cooperatives.tableName);
|
|
360
|
+
const cooperative = cooperatives.find((row) => row.username === coopname);
|
|
361
|
+
if (!cooperative) {
|
|
362
|
+
throw new Error(`\u041A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432 ${coopname} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435`);
|
|
363
|
+
}
|
|
364
|
+
const cooperativeDelta = {
|
|
365
|
+
code: RegistratorContract.contractName.production,
|
|
366
|
+
scope: RegistratorContract.contractName.production,
|
|
367
|
+
table: RegistratorContract.Tables.Cooperatives.tableName,
|
|
368
|
+
primary_key: cooperative.username,
|
|
369
|
+
// username - это primary_key для cooperatives
|
|
370
|
+
value: cooperative,
|
|
371
|
+
block_num,
|
|
372
|
+
present: "1"
|
|
373
|
+
};
|
|
374
|
+
await db.saveDeltaToDB(cooperativeDelta);
|
|
375
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u044B`);
|
|
376
|
+
const boards = await getTableRows(SovietContract.contractName.production, coopname, SovietContract.Tables.Boards.tableName);
|
|
377
|
+
const soviet = boards.find((row) => row.type === "soviet");
|
|
378
|
+
if (!soviet) {
|
|
379
|
+
throw new Error(`\u0421\u043E\u0432\u0435\u0442 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435`);
|
|
380
|
+
}
|
|
381
|
+
const sovietDelta = {
|
|
382
|
+
code: SovietContract.contractName.production,
|
|
383
|
+
scope: coopname,
|
|
384
|
+
table: SovietContract.Tables.Boards.tableName,
|
|
385
|
+
primary_key: String(soviet.id),
|
|
386
|
+
// id - это primary_key для boards
|
|
387
|
+
value: soviet,
|
|
388
|
+
block_num,
|
|
389
|
+
present: "1"
|
|
390
|
+
};
|
|
391
|
+
await db.saveDeltaToDB(sovietDelta);
|
|
392
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u0441\u043E\u0432\u0435\u0442\u0430 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u044B`);
|
|
393
|
+
}
|
|
394
|
+
async function loadTemplatesFromBlockchain(db, block_num) {
|
|
395
|
+
console.log("\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430...");
|
|
396
|
+
const drafts = await getTableRows(DraftContract.contractName.production, DraftContract.contractName.production, DraftContract.Tables.Drafts.tableName);
|
|
397
|
+
if (drafts.length === 0) {
|
|
398
|
+
console.log("\u26A0 \u0428\u0430\u0431\u043B\u043E\u043D\u044B \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435");
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
for (const draft of drafts) {
|
|
402
|
+
const draftDelta = {
|
|
403
|
+
code: DraftContract.contractName.production,
|
|
404
|
+
scope: DraftContract.contractName.production,
|
|
405
|
+
table: DraftContract.Tables.Drafts.tableName,
|
|
406
|
+
primary_key: String(draft.registry_id),
|
|
407
|
+
// registry_id - это primary_key для drafts
|
|
408
|
+
value: draft,
|
|
409
|
+
block_num,
|
|
410
|
+
present: "1"
|
|
411
|
+
};
|
|
412
|
+
await db.saveDeltaToDB(draftDelta);
|
|
413
|
+
}
|
|
414
|
+
console.log(`\u2713 \u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u043E ${drafts.length} \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432`);
|
|
415
|
+
const translations = await getTableRows("draft", "draft", "translations");
|
|
416
|
+
if (translations.length === 0) {
|
|
417
|
+
console.log("\u26A0 \u041F\u0435\u0440\u0435\u0432\u043E\u0434\u044B \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u044B \u0432 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0435");
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
for (const translation of translations) {
|
|
421
|
+
const translationDelta = {
|
|
422
|
+
code: DraftContract.contractName.production,
|
|
423
|
+
scope: DraftContract.contractName.production,
|
|
424
|
+
table: DraftContract.Tables.Translations.tableName,
|
|
425
|
+
primary_key: String(translation.id),
|
|
426
|
+
// id - это primary_key для translations
|
|
427
|
+
value: translation,
|
|
428
|
+
block_num,
|
|
429
|
+
present: "1"
|
|
430
|
+
};
|
|
431
|
+
await db.saveDeltaToDB(translationDelta);
|
|
432
|
+
}
|
|
433
|
+
console.log(`\u2713 \u0417\u0430\u0433\u0440\u0443\u0436\u0435\u043D\u043E ${translations.length} \u043F\u0435\u0440\u0435\u0432\u043E\u0434\u043E\u0432 \u0448\u0430\u0431\u043B\u043E\u043D\u043E\u0432`);
|
|
434
|
+
}
|
|
435
|
+
async function initializeFromBlockchain(db) {
|
|
436
|
+
const coopname = process.env.COOPNAME;
|
|
437
|
+
if (!coopname) {
|
|
438
|
+
console.log("\u26A0 COOPNAME \u043D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D \u0432 .env, \u043F\u0440\u043E\u043F\u0443\u0441\u043A\u0430\u0435\u043C \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044E");
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
442
|
+
console.log("\u041F\u0440\u043E\u0432\u0435\u0440\u043A\u0430 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E\u0441\u0442\u0438 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043D\u043D\u044B\u0445");
|
|
443
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
444
|
+
const info = await getInfo();
|
|
445
|
+
const currentBlock = Number(info.head_block_num);
|
|
446
|
+
const cooperativeExists = await checkCooperativeExists(db, coopname);
|
|
447
|
+
const templatesExist = await checkTemplatesExist(db);
|
|
448
|
+
if (cooperativeExists && templatesExist) {
|
|
449
|
+
console.log("\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 \u0438 \u0448\u0430\u0431\u043B\u043E\u043D\u044B \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442 \u0432 \u0431\u0430\u0437\u0435");
|
|
450
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
console.log(`\u041D\u0430\u0447\u0438\u043D\u0430\u0435\u043C \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044E \u0438\u0437 \u0431\u043B\u043E\u043A\u0447\u0435\u0439\u043D\u0430 (\u0431\u043B\u043E\u043A ${currentBlock})...`);
|
|
454
|
+
if (!cooperativeExists) {
|
|
455
|
+
await loadCooperativeFromBlockchain(db, coopname, currentBlock);
|
|
456
|
+
} else {
|
|
457
|
+
console.log(`\u2713 \u0414\u0430\u043D\u043D\u044B\u0435 \u043A\u043E\u043E\u043F\u0435\u0440\u0430\u0442\u0438\u0432\u0430 ${coopname} \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442`);
|
|
458
|
+
}
|
|
459
|
+
if (!templatesExist) {
|
|
460
|
+
await loadTemplatesFromBlockchain(db, currentBlock);
|
|
461
|
+
} else {
|
|
462
|
+
console.log("\u2713 \u0428\u0430\u0431\u043B\u043E\u043D\u044B \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u043E\u0432 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0442");
|
|
463
|
+
}
|
|
464
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
465
|
+
console.log("\u2713 \u0418\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E");
|
|
466
|
+
console.log("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");
|
|
467
|
+
}
|
|
468
|
+
|
|
300
469
|
const actions_whitelist = () => subsribedActions;
|
|
301
470
|
console.log("Actions whitelist (auto-generated from subscribedContracts):", subsribedActions);
|
|
302
471
|
async function loadReader(db) {
|
|
303
472
|
let currentBlock = await db.getCurrentBlock();
|
|
304
|
-
const info = await getInfo();
|
|
473
|
+
const info = await getInfo$1();
|
|
305
474
|
if (Number(startBlock) === 1) {
|
|
306
475
|
if (currentBlock === 0) {
|
|
307
476
|
currentBlock = Number(info.head_block_num);
|
|
477
|
+
await initializeFromBlockchain(db);
|
|
308
478
|
}
|
|
309
479
|
} else {
|
|
310
480
|
currentBlock = Number(startBlock);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopenomics/parser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2025.11.
|
|
4
|
+
"version": "2025.11.13-alpha-3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.0.6",
|
|
7
7
|
"description": "",
|
|
@@ -54,9 +54,11 @@
|
|
|
54
54
|
"@blockmatic/eosio-ship-reader": "^1.2.0",
|
|
55
55
|
"@types/express": "^4.17.21",
|
|
56
56
|
"@types/ws": "^8.5.13",
|
|
57
|
+
"cooptypes": "2025.11.13-alpha-3",
|
|
57
58
|
"dotenv": "^16.4.5",
|
|
58
59
|
"dotenv-expand": "^11.0.6",
|
|
59
60
|
"eosjs": "^22.1.0",
|
|
61
|
+
"eosjs-api": "^7.0.4",
|
|
60
62
|
"express": "^4.19.2",
|
|
61
63
|
"express-async-errors": "^3.1.1",
|
|
62
64
|
"ioredis": "^5.4.1",
|
|
@@ -85,5 +87,5 @@
|
|
|
85
87
|
"vite": "^5.2.10",
|
|
86
88
|
"vitest": "^1.5.2"
|
|
87
89
|
},
|
|
88
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "dab94657557e501109b96a18e0e00db0c00d111e"
|
|
89
91
|
}
|