SHA256
UI/Channels: вкладки по тапу + CreateChannel fallback для legacy формата
This commit is contained in:
@@ -456,6 +456,31 @@ function makeCreateChannelBodyBytes({
|
||||
);
|
||||
}
|
||||
|
||||
function makeCreateChannelBodyBytesLegacy({
|
||||
lineCode,
|
||||
prevLineNumber,
|
||||
prevLineHashHex,
|
||||
thisLineNumber,
|
||||
channelName,
|
||||
}) {
|
||||
const check = validateChannelDisplayName(channelName);
|
||||
if (!check.ok) throw new Error(channelNameErrorText(check.code));
|
||||
const cleanName = check.normalized;
|
||||
const nameBytes = utf8Bytes(cleanName);
|
||||
if (nameBytes.length < 1 || nameBytes.length > 255) {
|
||||
throw new Error('Channel name must be 1..255 bytes');
|
||||
}
|
||||
|
||||
return concatBytes(
|
||||
int32Bytes(lineCode),
|
||||
int32Bytes(prevLineNumber),
|
||||
hexToBytes(normalizeHex32(prevLineHashHex)),
|
||||
int32Bytes(thisLineNumber),
|
||||
int8Byte(nameBytes.length),
|
||||
nameBytes,
|
||||
);
|
||||
}
|
||||
|
||||
function makeTextPostBodyBytes({ lineCode, prevLineNumber, prevLineHashHex, thisLineNumber, text }) {
|
||||
const message = String(text || '').trim();
|
||||
if (!message) throw new Error('Message text is required');
|
||||
@@ -1075,23 +1100,51 @@ export class AuthService {
|
||||
thisLineNumber = createdChannels.length + 1;
|
||||
}
|
||||
|
||||
const payload = await this.addBlockSigned({
|
||||
login: cleanLogin,
|
||||
storagePwd,
|
||||
msgType: MSG_TYPE_TECH,
|
||||
msgSubType: MSG_SUBTYPE_TECH_CREATE_CHANNEL,
|
||||
msgVersion: CREATE_CHANNEL_BODY_VERSION,
|
||||
bodyBytes: makeCreateChannelBodyBytes({
|
||||
lineCode: 0,
|
||||
prevLineNumber,
|
||||
prevLineHashHex,
|
||||
thisLineNumber,
|
||||
channelName: cleanChannelName,
|
||||
channelDescription: cleanChannelDescription,
|
||||
channelType: typeCode,
|
||||
channelTypeVersion: typeVersion,
|
||||
}),
|
||||
});
|
||||
let payload;
|
||||
try {
|
||||
payload = await this.addBlockSigned({
|
||||
login: cleanLogin,
|
||||
storagePwd,
|
||||
msgType: MSG_TYPE_TECH,
|
||||
msgSubType: MSG_SUBTYPE_TECH_CREATE_CHANNEL,
|
||||
msgVersion: CREATE_CHANNEL_BODY_VERSION,
|
||||
bodyBytes: makeCreateChannelBodyBytes({
|
||||
lineCode: 0,
|
||||
prevLineNumber,
|
||||
prevLineHashHex,
|
||||
thisLineNumber,
|
||||
channelName: cleanChannelName,
|
||||
channelDescription: cleanChannelDescription,
|
||||
channelType: typeCode,
|
||||
channelTypeVersion: typeVersion,
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
const rawCode = String(error?.code || '').toUpperCase();
|
||||
const rawText = String(error?.message || '').toLowerCase();
|
||||
const isLegacyFormatMismatch = (
|
||||
rawCode === 'BAD_BLOCK_FORMAT' ||
|
||||
rawText.includes('bad_block_format') ||
|
||||
rawText.includes('некорректный формат блока')
|
||||
);
|
||||
if (!isLegacyFormatMismatch) throw error;
|
||||
|
||||
// Совместимость со старыми серверами, где CreateChannel body без description/type.
|
||||
payload = await this.addBlockSigned({
|
||||
login: cleanLogin,
|
||||
storagePwd,
|
||||
msgType: MSG_TYPE_TECH,
|
||||
msgSubType: MSG_SUBTYPE_TECH_CREATE_CHANNEL,
|
||||
msgVersion: CREATE_CHANNEL_BODY_VERSION,
|
||||
bodyBytes: makeCreateChannelBodyBytesLegacy({
|
||||
lineCode: 0,
|
||||
prevLineNumber,
|
||||
prevLineHashHex,
|
||||
thisLineNumber,
|
||||
channelName: cleanChannelName,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
const selector = {
|
||||
ownerBlockchainName: blockchainName,
|
||||
|
||||
Reference in New Issue
Block a user