solana-framework
Version:
solana-framework is solana uni-tools for typescript
49 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Explorer = void 0;
class Explorer {
}
exports.Explorer = Explorer;
Explorer.tx = (id = "", cluster) => {
return getExplorerLink("tx", id, cluster);
};
Explorer.address = (id = "", cluster) => {
return getExplorerLink("address", id, cluster);
};
Explorer.block = (id = "", cluster) => {
return getExplorerLink("block", id, cluster);
};
const getExplorerLink = (linkType, id, cluster = "devnet") => {
const searchParams = {};
if (cluster !== "mainnet-beta") {
if (cluster === "localnet") {
// localnet technically isn't a cluster, so requires special handling
searchParams["cluster"] = "custom";
searchParams["customUrl"] = "http://localhost:8899";
}
else {
searchParams["cluster"] = cluster;
}
}
let baseUrl = "https://explorer.solana.com";
if (linkType === "address") {
baseUrl = `${baseUrl}/address/${id}`;
}
if (linkType === "transaction" || linkType === "tx") {
baseUrl = `${baseUrl}/tx/${id}`;
}
if (linkType === "block") {
baseUrl = `${baseUrl}/block/${id}`;
}
return encodeURL(baseUrl, searchParams);
};
const encodeURL = (baseUrl, searchParams) => {
// This was a little new to me, but it's the
// recommended way to build URLs with query params
// (and also means you don't have to do any encoding)
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
const url = new URL(baseUrl);
url.search = new URLSearchParams(searchParams).toString();
return url.toString();
};
//# sourceMappingURL=Explorer.js.map