Разделить среды и закрепить лицензии в HEADER 1.0

This commit is contained in:
AidarKC
2026-12-05 11:42:20 +03:00
parent a64168a748
commit 77c7021aed
89 changed files with 4204 additions and 211 deletions
@@ -1,5 +1,7 @@
import { base64ToBytes } from './crypto-utils.js';
import { unpackCoreContent } from './core-content.js';
import { unpackCoreContent, verifyCoreContentPair } from './core-content.js';
import { parseAns104DataItem } from './ans104-data-item.js';
import { parseServerEnvironment } from './server-environment.js';
import { uploadSignedBlockDataItem } from './turbo-upload-service.js';
import { showToast } from './channels-ux.js';
import { t } from '../i18n/index.js';
@@ -10,10 +12,14 @@ const lastNotice = new Map();
/** После перезапуска браузер повторно получает подписанные bytes с сервера. */
export async function publishPendingBlocks({ ws, login, storagePwd, blockchainName }) {
if (!ws || !login || !storagePwd || !blockchainName || running.has(blockchainName)) return;
running.add(blockchainName);
if (!ws || ws.retired || !login || !storagePwd || !blockchainName) return;
const key = `${ws.url}|${blockchainName}`;
if (running.has(key)) return;
running.add(key);
let keepPolling = false;
try {
const env = parseServerEnvironment(await ws.request('GetServerInfo', {}, 9000));
const generation = ws.connectionGeneration;
const response = await ws.request('BlockPublication', { action: 'list', blockchainName });
if (response.status !== 200) return;
keepPolling = true;
@@ -23,14 +29,17 @@ export async function publishPendingBlocks({ ws, login, storagePwd, blockchainNa
throw new Error('Pending block bytes unavailable or changed');
}
const { contentDataItem, coreDataItem } = unpackCoreContent(base64ToBytes(read.payload.blockBytesB64));
await verifyCoreContentPair(coreDataItem, contentDataItem, parseAns104DataItem(coreDataItem).owner32, env.arweaveAppTag);
if (ws.retired || ws.connectionGeneration !== generation) return;
let uploadError = '';
try {
if (!block.contentConfirmed) await uploadSignedBlockDataItem({ login, storagePwd, bytes: contentDataItem, expectedId: block.contentId });
if (ws.retired || ws.connectionGeneration !== generation) return;
if (!block.coreConfirmed) await uploadSignedBlockDataItem({ login, storagePwd, bytes: coreDataItem, expectedId: block.coreId });
} catch (error) {
uploadError = String(error?.message || error);
const insufficientCredits = /(?:\b402\b|insufficient (?:balance|funds|credits)|not enough (?:balance|funds|credits)|payment required|недостаточно (?:средств|кредитов))/i.test(uploadError);
const noticeKey = `${blockchainName}:${block.blockNumber}`;
const noticeKey = `${key}:${block.blockNumber}`;
if (Date.now() - (lastNotice.get(noticeKey) || 0) >= 30 * 60_000) {
showToast(t(insufficientCredits ? 'block_publication.insufficient_credits' : 'block_publication.upload_failed',
{ number: block.blockNumber }), { kind: 'error', timeoutMs: 7000 });
@@ -47,13 +56,13 @@ export async function publishPendingBlocks({ ws, login, storagePwd, blockchainNa
} catch (error) {
console.warn('Block publication queue unavailable', error);
} finally {
running.delete(blockchainName);
if (keepPolling && !scheduled.has(blockchainName)) {
running.delete(key);
if (!ws.retired && keepPolling && !scheduled.has(key)) {
const timer = globalThis.setTimeout(() => {
scheduled.delete(blockchainName);
scheduled.delete(key);
void publishPendingBlocks({ ws, login, storagePwd, blockchainName });
}, 30_000);
scheduled.set(blockchainName, timer);
scheduled.set(key, timer);
}
}
}