Улучшить UI регистрации и связанные сценарии

This commit is contained in:
AidarKC
2026-11-08 18:04:06 +03:00
parent 9405f28525
commit 4068465ee6
66 changed files with 842 additions and 221 deletions
@@ -34,6 +34,9 @@ async function run(){
if(!(['localhost','127.0.0.1'].includes(endpoint.hostname)||endpoint.hostname.endsWith('.devnet.solana.com')))
throw Error('Разрешены только localhost/127.0.0.1 и *.devnet.solana.com; production запрещён');
const type=Number(options.type),minimum=Number(options['min-length']);
// Формат namespace 1.1 хранит валюту явно; создание через legacy tag=7 всегда задаёт SOL.
const currencyCode=Number(options.currency ?? '1');
if(currencyCode!==1)throw Error('Код 2 USDT зарезервирован; создание namespace доступно только в SOL (код 1)');
const fee=BigInt(options['fee-lamports']);
if(![1,2].includes(type) || !Number.isInteger(minimum) || minimum<1 || minimum+1+namespace.length>30 || fee<0n || fee>0xffffffffffffffffn)
throw Error('Некорректные тип, длина или цена');
@@ -71,7 +74,7 @@ async function run(){
{pubkey:programdata,isSigner:false,isWritable:false},
...(serverPda?[{pubkey:serverPda,isSigner:false,isWritable:false}]:[]),
],data:payload});
console.log(JSON.stringify({namespace,type,minimum,fee:fee.toString(),pda:pda.toBase58(),bump,economy:economy.toBase58(),programdata:programdata.toBase58(),mode:options.send?'SEND':'DRY-RUN'},null,2));
console.log(JSON.stringify({namespace,type,minimum,currencyCode,fee:fee.toString(),pda:pda.toBase58(),bump,economy:economy.toBase58(),programdata:programdata.toBase58(),mode:options.send?'SEND':'DRY-RUN'},null,2));
if(!options.send)return;
const signature=await sendAndConfirmTransaction(connection,new Transaction().add(instruction),[wallet],{commitment:'confirmed'});
console.log('Подтверждённая devnet/localnet транзакция:',signature);
@@ -1,11 +1,12 @@
#!/usr/bin/env node
import { readFileSync } from 'node:fs';
// Автономный декодер namespace 1.0 (без RPC и внешних пакетов).
// Автономный декодер namespace 1.0/1.1 (без RPC и внешних пакетов).
export function decodeNamespace(data) {
const b=Buffer.from(data);
if(b.length<13) throw Error('namespace: payload слишком короткий');
if(b[0]!==1 || b[1]!==0) throw Error('namespace: неизвестная версия');
if(b[0]!==1 || ![0,1].includes(b[1])) throw Error('namespace: неизвестная версия');
const minor=b[1];
const type=b[2],minLocalLen=b[3],len=b[4];
if(type!==1 && type!==2)throw Error('namespace: неверный тип');
if(!len || !minLocalLen || len+1+minLocalLen>30) throw Error('namespace: некорректная длина');
@@ -14,6 +15,8 @@ export function decodeNamespace(data) {
const name=b.subarray(p,p+len).toString('utf8');p+=len;
if(!/^[a-z0-9_]+$/.test(name) || Buffer.byteLength(name)!==len) throw Error('namespace: некорректное название');
const fee=b.readBigUInt64LE(p).toString();p+=8;
const currencyCode=minor===1?b[p++]:1;
if(currencyCode!==1) throw Error('namespace: неподдерживаемый код валюты (пока только 1=SOL)');
let registrar=null,serverLogin=null;
if(type===2){
if(p+33>b.length)throw Error('namespace: отсутствуют ключ и логин сервера');
@@ -24,7 +27,7 @@ export function decodeNamespace(data) {
if(!/^[a-z0-9_]+@[a-z0-9_]+$/.test(serverLogin) || Buffer.byteLength(serverLogin)>30)throw Error('namespace: неверный логин сервера');
}
if(p!==b.length) throw Error('namespace: лишние байты запрещены');
return {major:1,minor:0,type,minLocalLen,name,registrationFeeLamports:fee,registrarPubkeyHex:registrar,serverLogin};
return {major:1,minor,type,minLocalLen,name,registrationFeeLamports:fee,currencyCode,registrarPubkeyHex:registrar,serverLogin};
}
if(process.argv[1]?.endsWith('decode-namespace.mjs')){
const data=process.argv[2];