ваше сообщение коммита
This commit is contained in:
@@ -21,14 +21,21 @@ function generateDLEConstructorArgs(params, chainId = null) {
|
||||
symbol: params.symbol || '',
|
||||
location: params.location || '',
|
||||
coordinates: params.coordinates || '',
|
||||
jurisdiction: params.jurisdiction || 0,
|
||||
okvedCodes: params.okvedCodes || [],
|
||||
kpp: params.kpp ? BigInt(params.kpp) : 0n,
|
||||
quorumPercentage: params.quorumPercentage || 50,
|
||||
initialPartners: params.initialPartners || [],
|
||||
jurisdiction: params.jurisdiction ? BigInt(String(params.jurisdiction)) : 0n,
|
||||
okvedCodes: (params.okvedCodes || params.okved_codes || []).map(code => {
|
||||
// OKVED коды должны оставаться строками, так как в контракте DLE.sol
|
||||
// поле okvedCodes определено как string[], а не uint256[]
|
||||
if (typeof code === 'string') {
|
||||
return code;
|
||||
}
|
||||
return code.toString();
|
||||
}),
|
||||
kpp: params.kpp ? BigInt(String(params.kpp)) : 0n,
|
||||
quorumPercentage: params.quorumPercentage ? BigInt(String(params.quorumPercentage)) : 50n,
|
||||
initialPartners: params.initialPartners || params.initial_partners || [],
|
||||
// Умножаем initialAmounts на 1e18 для конвертации в wei
|
||||
initialAmounts: (params.initialAmounts || []).map(amount => BigInt(amount) * BigInt(1e18)),
|
||||
supportedChainIds: (params.supportedChainIds || []).map(id => BigInt(id))
|
||||
initialAmounts: (params.initialAmounts || params.initial_amounts || []).map(amount => BigInt(String(amount)) * BigInt(1e18)),
|
||||
supportedChainIds: (params.supportedChainIds || params.supported_chain_ids || []).map(id => BigInt(String(id)))
|
||||
};
|
||||
|
||||
// Определяем initializer
|
||||
@@ -92,7 +99,9 @@ function validateConstructorArgs(params) {
|
||||
if (!params.location) errors.push('location не указан');
|
||||
if (!params.coordinates) errors.push('coordinates не указаны');
|
||||
if (!params.jurisdiction) errors.push('jurisdiction не указан');
|
||||
if (!params.okvedCodes || !Array.isArray(params.okvedCodes)) errors.push('okvedCodes не указан или не является массивом');
|
||||
if ((!params.okvedCodes || !Array.isArray(params.okvedCodes)) && (!params.okved_codes || !Array.isArray(params.okved_codes))) {
|
||||
errors.push('okvedCodes не указан или не является массивом');
|
||||
}
|
||||
if (!params.initialPartners || !Array.isArray(params.initialPartners)) errors.push('initialPartners не указан или не является массивом');
|
||||
if (!params.initialAmounts || !Array.isArray(params.initialAmounts)) errors.push('initialAmounts не указан или не является массивом');
|
||||
if (!params.supportedChainIds || !Array.isArray(params.supportedChainIds)) errors.push('supportedChainIds не указан или не является массивом');
|
||||
@@ -134,7 +143,8 @@ function logConstructorArgs(params, context = 'unknown') {
|
||||
console.log(` location: "${params.location}"`);
|
||||
console.log(` coordinates: "${params.coordinates}"`);
|
||||
console.log(` jurisdiction: ${params.jurisdiction}`);
|
||||
console.log(` okvedCodes: [${params.okvedCodes.join(', ')}]`);
|
||||
const okvedCodes = params.okvedCodes || params.okved_codes || [];
|
||||
console.log(` okvedCodes: [${okvedCodes.join(', ')}]`);
|
||||
console.log(` kpp: ${params.kpp}`);
|
||||
console.log(` quorumPercentage: ${params.quorumPercentage}`);
|
||||
console.log(` initialPartners: [${params.initialPartners.join(', ')}]`);
|
||||
|
||||
110
backend/utils/networkLoader.js
Normal file
110
backend/utils/networkLoader.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Утилита для загрузки поддерживаемых сетей из deploy_params
|
||||
* Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
*/
|
||||
|
||||
const DeployParamsService = require('../services/deployParamsService');
|
||||
|
||||
class NetworkLoader {
|
||||
constructor() {
|
||||
this.cache = new Map();
|
||||
this.cacheTimeout = 5 * 60 * 1000; // 5 минут
|
||||
this.fallbackChainIds = [11155111, 421614, 84532, 17000];
|
||||
}
|
||||
|
||||
/**
|
||||
* Общий метод для загрузки данных из deploy_params
|
||||
* @param {string} field - Поле для извлечения
|
||||
* @param {boolean} useCache - Использовать кеш
|
||||
* @returns {Promise<Array|Object>} - Данные из deploy_params
|
||||
*/
|
||||
async _loadFromDatabase(field, useCache = true) {
|
||||
const cacheKey = field;
|
||||
|
||||
// Проверяем кеш
|
||||
if (useCache && this.cache.has(cacheKey)) {
|
||||
const cached = this.cache.get(cacheKey);
|
||||
if (Date.now() - cached.timestamp < this.cacheTimeout) {
|
||||
console.log(`📋 Используем кешированные ${field}`);
|
||||
return cached.data;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const deployParamsService = new DeployParamsService();
|
||||
const latestParams = await deployParamsService.getLatestDeployParams(1);
|
||||
await deployParamsService.close();
|
||||
|
||||
if (latestParams.length > 0) {
|
||||
const params = latestParams[0];
|
||||
let data;
|
||||
|
||||
switch (field) {
|
||||
case 'supportedChainIds':
|
||||
data = params.supportedChainIds || params.supported_chain_ids || [];
|
||||
break;
|
||||
case 'rpcUrls':
|
||||
data = params.rpcUrls || params.rpc_urls || {};
|
||||
break;
|
||||
default:
|
||||
data = params[field] || {};
|
||||
}
|
||||
|
||||
console.log(`✅ Загружены ${field} из deploy_params:`, Array.isArray(data) ? data : Object.keys(data));
|
||||
|
||||
// Кешируем результат
|
||||
this.cache.set(cacheKey, {
|
||||
data: data,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Если нет данных в deploy_params
|
||||
console.log(`⚠️ Нет ${field} в deploy_params`);
|
||||
return field === 'supportedChainIds' ? this.fallbackChainIds : {};
|
||||
} catch (error) {
|
||||
console.error(`❌ Ошибка загрузки ${field}:`, error.message);
|
||||
return field === 'supportedChainIds' ? this.fallbackChainIds : {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить поддерживаемые сети из deploy_params
|
||||
* @param {boolean} useCache - Использовать кеш
|
||||
* @returns {Promise<Array>} - Массив chainId
|
||||
*/
|
||||
async getSupportedChainIds(useCache = true) {
|
||||
return await this._loadFromDatabase('supportedChainIds', useCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить RPC URLs из deploy_params
|
||||
* @param {boolean} useCache - Использовать кеш
|
||||
* @returns {Promise<Object>} - Объект с RPC URLs
|
||||
*/
|
||||
async getRpcUrls(useCache = true) {
|
||||
return await this._loadFromDatabase('rpcUrls', useCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Очистить кеш
|
||||
*/
|
||||
clearCache() {
|
||||
this.cache.clear();
|
||||
console.log('🗑️ Кеш NetworkLoader очищен');
|
||||
}
|
||||
}
|
||||
|
||||
// Создаем singleton
|
||||
const networkLoader = new NetworkLoader();
|
||||
|
||||
module.exports = {
|
||||
NetworkLoader,
|
||||
networkLoader,
|
||||
// Экспортируем методы для удобства
|
||||
getSupportedChainIds: () => networkLoader.getSupportedChainIds(),
|
||||
getRpcUrls: () => networkLoader.getRpcUrls(),
|
||||
clearCache: () => networkLoader.clearCache()
|
||||
};
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
const { ethers } = require('ethers');
|
||||
const { getRpcUrls } = require('./networkLoader');
|
||||
|
||||
class NonceManager {
|
||||
constructor() {
|
||||
@@ -230,31 +231,18 @@ class NonceManager {
|
||||
}
|
||||
|
||||
try {
|
||||
// Получаем RPC из deploy_params (как в deploy-multichain.js)
|
||||
const DeployParamsService = require('../services/deployParamsService');
|
||||
const deployParamsService = new DeployParamsService();
|
||||
// Используем networkLoader для получения RPC URLs
|
||||
const { getRpcUrls } = require('./networkLoader');
|
||||
const rpcUrlsFromLoader = await getRpcUrls();
|
||||
|
||||
// Получаем последние параметры деплоя
|
||||
const latestParams = await deployParamsService.getLatestDeployParams(1);
|
||||
if (latestParams.length > 0) {
|
||||
const params = latestParams[0];
|
||||
const supportedChainIds = params.supported_chain_ids || [];
|
||||
const rpcUrlsFromParams = params.rpc_urls || [];
|
||||
|
||||
// Находим RPC для нужного chainId
|
||||
const chainIndex = supportedChainIds.indexOf(chainId);
|
||||
if (chainIndex !== -1 && rpcUrlsFromParams[chainIndex]) {
|
||||
const deployRpcUrl = rpcUrlsFromParams[chainIndex];
|
||||
if (!rpcUrls.includes(deployRpcUrl)) {
|
||||
rpcUrls.push(deployRpcUrl);
|
||||
console.log(`[NonceManager] ✅ RPC из deploy_params для chainId ${chainId}: ${deployRpcUrl}`);
|
||||
}
|
||||
}
|
||||
// Получаем RPC для конкретного chainId
|
||||
const chainRpcUrl = rpcUrlsFromLoader[chainId] || rpcUrlsFromLoader[chainId.toString()];
|
||||
if (chainRpcUrl && !rpcUrls.includes(chainRpcUrl)) {
|
||||
rpcUrls.push(chainRpcUrl);
|
||||
console.log(`[NonceManager] ✅ RPC из networkLoader для chainId ${chainId}: ${chainRpcUrl}`);
|
||||
}
|
||||
|
||||
await deployParamsService.close();
|
||||
} catch (error) {
|
||||
console.warn(`[NonceManager] deploy_params недоступны для chainId ${chainId}, используем fallback: ${error.message}`);
|
||||
console.warn(`[NonceManager] networkLoader недоступен для chainId ${chainId}, используем fallback: ${error.message}`);
|
||||
}
|
||||
|
||||
// Всегда добавляем fallback RPC для надежности
|
||||
|
||||
Reference in New Issue
Block a user