SHA256
UI: добавить просмотр любого PDA
This commit is contained in:
@@ -623,6 +623,38 @@ export async function readShineUserPda({ login, solanaEndpoint }) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function readShineUserPdaByAddress({ pdaAddress, solanaEndpoint }) {
|
||||
const address = String(pdaAddress || '').trim();
|
||||
const endpoint = String(solanaEndpoint || '').trim();
|
||||
if (!address) throw new Error('Не указан адрес PDA');
|
||||
if (!endpoint) throw new Error('Не указан Solana RPC endpoint');
|
||||
const solana = await loadSolanaLib();
|
||||
const connection = new solana.Connection(endpoint, 'confirmed');
|
||||
const accountAddress = new solana.PublicKey(address);
|
||||
const accountInfo = await connection.getAccountInfo(accountAddress, 'confirmed');
|
||||
if (!accountInfo?.data) throw new Error(`PDA не найдена: ${address}`);
|
||||
return {
|
||||
...parseShineUserPda(accountInfo.data),
|
||||
userPda: accountAddress.toBase58(),
|
||||
pdaAddress: accountAddress.toBase58(),
|
||||
endpoint,
|
||||
};
|
||||
}
|
||||
|
||||
export async function readShineUserPdaByRef({ value, solanaEndpoint }) {
|
||||
const ref = String(value || '').trim();
|
||||
if (!ref) throw new Error('Не указан логин или адрес PDA');
|
||||
try {
|
||||
const bytes = base58ToBytes(ref);
|
||||
if (bytes.length === 32) {
|
||||
return await readShineUserPdaByAddress({ pdaAddress: ref, solanaEndpoint });
|
||||
}
|
||||
} catch {
|
||||
// Если это не адрес, читаем как логин.
|
||||
}
|
||||
return readShineUserPda({ login: ref, solanaEndpoint });
|
||||
}
|
||||
|
||||
export async function getShineBlockchainUsage({ login, solanaEndpoint }) {
|
||||
const parsed = await readShineUserPda({ login, solanaEndpoint });
|
||||
const bch = parsed.blockchain;
|
||||
|
||||
Reference in New Issue
Block a user