ваше сообщение коммита
This commit is contained in:
@@ -195,8 +195,12 @@ router.post('/verify', async (req, res) => {
|
||||
return res.status(401).json({ success: false, error: 'Invalid signature' });
|
||||
}
|
||||
|
||||
// СРАЗУ проверяем наличие админских токенов
|
||||
const adminStatus = await authService.checkAdminTokens(normalizedAddress);
|
||||
logger.info(`[verify] Admin status for ${normalizedAddress}: ${adminStatus}`);
|
||||
|
||||
let userId;
|
||||
let isAdmin = false;
|
||||
let isAdmin = adminStatus;
|
||||
|
||||
// Проверяем, авторизован ли пользователь уже
|
||||
if (req.session.authenticated && req.session.userId) {
|
||||
@@ -214,11 +218,11 @@ router.post('/verify', async (req, res) => {
|
||||
`[verify] Wallet ${normalizedAddress} linked to user ${userId}: already exists`
|
||||
);
|
||||
} else {
|
||||
// Находим или создаем пользователя, если не авторизован
|
||||
const result = await authService.findOrCreateUser(address);
|
||||
// Находим или создаем пользователя с уже известной ролью
|
||||
const result = await authService.findOrCreateUser(address, adminStatus);
|
||||
userId = result.userId;
|
||||
isAdmin = result.isAdmin;
|
||||
logger.info(`[verify] Found or created user ${userId} for wallet ${normalizedAddress}`);
|
||||
logger.info(`[verify] Found or created user ${userId} for wallet ${normalizedAddress} with admin status: ${isAdmin}`);
|
||||
}
|
||||
|
||||
// Сохраняем идентификаторы гостевой сессии
|
||||
@@ -230,14 +234,6 @@ router.post('/verify', async (req, res) => {
|
||||
await identityService.saveIdentity(userId, 'guest', previousGuestId, true);
|
||||
}
|
||||
|
||||
// Проверяем наличие админских токенов
|
||||
const adminStatus = await authService.checkAdminTokens(normalizedAddress);
|
||||
|
||||
if (adminStatus) {
|
||||
await db.getQuery()('UPDATE users SET role = $1 WHERE id = $2', ['admin', userId]);
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
// Обновляем сессию
|
||||
req.session.userId = userId;
|
||||
req.session.authenticated = true;
|
||||
|
||||
@@ -217,10 +217,11 @@ router.post('/get-proposals', async (req, res) => {
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
|
||||
// ABI для чтения предложений (только читаемые поля)
|
||||
// ABI для чтения предложений (используем правильные функции из смарт-контракта)
|
||||
const dleAbi = [
|
||||
"function proposals(uint256) external view returns (uint256 id, string description, uint256 forVotes, uint256 againstVotes, bool executed, uint256 deadline, address initiator, bytes operation)",
|
||||
"function checkProposalResult(uint256 _proposalId) external view returns (bool)",
|
||||
"function getProposalSummary(uint256 _proposalId) external view returns (uint256 id, string memory description, uint256 forVotes, uint256 againstVotes, bool executed, bool canceled, uint256 deadline, address initiator, uint256 governanceChainId, uint256 snapshotTimepoint, uint256[] memory targets)",
|
||||
"function checkProposalResult(uint256 _proposalId) external view returns (bool passed, bool quorumReached)",
|
||||
"function getProposalState(uint256 _proposalId) external view returns (uint8 state)",
|
||||
"event ProposalCreated(uint256 proposalId, address initiator, string description)"
|
||||
];
|
||||
|
||||
@@ -250,8 +251,9 @@ router.post('/get-proposals', async (req, res) => {
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
proposal = await dle.proposals(proposalId);
|
||||
isPassed = await dle.checkProposalResult(proposalId);
|
||||
proposal = await dle.getProposalSummary(proposalId);
|
||||
const result = await dle.checkProposalResult(proposalId);
|
||||
isPassed = result.passed;
|
||||
break; // Успешно прочитали
|
||||
} catch (error) {
|
||||
retryCount++;
|
||||
@@ -264,19 +266,18 @@ router.post('/get-proposals', async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
// governanceChainId не сохраняется в предложении, используем текущую цепочку
|
||||
const governanceChainId = 11155111; // Sepolia chain ID
|
||||
|
||||
console.log(`[Blockchain] Данные предложения ${proposalId}:`, {
|
||||
id: Number(proposal.id),
|
||||
description: proposal.description,
|
||||
forVotes: Number(proposal.forVotes),
|
||||
againstVotes: Number(proposal.againstVotes),
|
||||
executed: proposal.executed,
|
||||
canceled: proposal.canceled,
|
||||
deadline: Number(proposal.deadline),
|
||||
initiator: proposal.initiator,
|
||||
operation: proposal.operation,
|
||||
governanceChainId: Number(governanceChainId)
|
||||
governanceChainId: Number(proposal.governanceChainId),
|
||||
snapshotTimepoint: Number(proposal.snapshotTimepoint),
|
||||
targets: proposal.targets
|
||||
});
|
||||
|
||||
const proposalInfo = {
|
||||
@@ -285,10 +286,12 @@ router.post('/get-proposals', async (req, res) => {
|
||||
forVotes: Number(proposal.forVotes),
|
||||
againstVotes: Number(proposal.againstVotes),
|
||||
executed: proposal.executed,
|
||||
canceled: proposal.canceled,
|
||||
deadline: Number(proposal.deadline),
|
||||
initiator: proposal.initiator,
|
||||
operation: proposal.operation,
|
||||
governanceChainId: Number(governanceChainId),
|
||||
governanceChainId: Number(proposal.governanceChainId),
|
||||
snapshotTimepoint: Number(proposal.snapshotTimepoint),
|
||||
targetChains: proposal.targets.map(chainId => Number(chainId)),
|
||||
isPassed: isPassed,
|
||||
blockNumber: events[i].blockNumber
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user