Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 171 additions & 1 deletion packages/gill/src/__tests__/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert";
import { type FullySignedTransaction, getSignatureFromTransaction } from "@solana/kit";

import { getExplorerLink } from "../core";
import { getExplorerLink, getExplorerLinkOrb, getExplorerLinkSolscan, getExplorerLinkSolanafm } from "../core";

describe("getExplorerLink", () => {
test("getExplorerLink returns the base explorer url", () => {
Expand Down Expand Up @@ -140,4 +140,174 @@ describe("getExplorerLink", () => {
"https://explorer.solana.com/tx/2QC8BkDVZgaPHUXG9HuPw7aE5d6kN5DTRXLe2inT1NzurkYTCFhraSEo883CPNe18BZ2peJC1x1nojZ5Jmhs94pL?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899",
);
});

test("getExplorerLink returns the base explorer url with default explorer chosen", () => {
const link = getExplorerLink();
assert.equal(link, "https://explorer.solana.com/");
});

test("getExplorerLinkOrb returns orb explorer url", () => {
const link = getExplorerLinkOrb();
assert.equal(link, "https://orb.helius.dev/");
});

test("getExplorerLinkSolscan returns solscan explorer url", () => {
const link = getExplorerLinkSolscan();
assert.equal(link, "https://solscan.io/");
});

test("getExplorerLinkSolanafm returns solanafm explorer url", () => {
const link = getExplorerLinkSolanafm();
assert.equal(link, "https://solana.fm/");
});

test("getExplorerLinkSolscan works for an address on solscan", () => {
const link = getExplorerLinkSolscan({
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
Comment thread
arihantbansal marked this conversation as resolved.
Outdated
});
assert.equal(link, "https://solscan.io/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8");
});

test("getExplorerLinkOrb works for an address on orb", () => {
const link = getExplorerLinkOrb({
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://orb.helius.dev/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8");
});

test("getExplorerLinkSolanafm works for an address on solanafm", () => {
const link = getExplorerLinkSolanafm({
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solana.fm/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8");
});

test("getExplorerLinkSolscan works for a transaction on solscan", () => {
const link = getExplorerLinkSolscan({
transaction: "2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
});
assert.equal(
link,
"https://solscan.io/tx/2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
);
});

test("getExplorerLinkOrb works for a transaction on orb", () => {
const link = getExplorerLinkOrb({
transaction: "2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
});
assert.equal(
link,
"https://orb.helius.dev/tx/2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
);
});

test("getExplorerLinkSolanafm works for a transaction on solanafm", () => {
const link = getExplorerLinkSolanafm({
transaction: "2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
});
assert.equal(
link,
"https://solana.fm/tx/2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
);
});

test("getExplorerLinkSolscan works for a block on solscan", () => {
const link = getExplorerLinkSolscan({
block: "242233124",
});
assert.equal(link, "https://solscan.io/block/242233124");
});

test("getExplorerLinkOrb works for a block on orb", () => {
const link = getExplorerLinkOrb({
block: "242233124",
});
assert.equal(link, "https://orb.helius.dev/block/242233124");
});

test("getExplorerLinkSolanafm works for a block on solanafm", () => {
const link = getExplorerLinkSolanafm({
block: "242233124",
});
assert.equal(link, "https://solana.fm/block/242233124");
});

test("getExplorerLinkSolscan works with devnet cluster on solscan", () => {
const link = getExplorerLinkSolscan({
cluster: "devnet",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solscan.io/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8?cluster=devnet");
});

test("getExplorerLinkOrb works with testnet cluster on orb", () => {
const link = getExplorerLinkOrb({
cluster: "testnet",
transaction: "2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX",
});
assert.equal(
link,
"https://orb.helius.dev/tx/2YhzivV92fw9oT6RjTBWSdqR8Sc9FTWxzPMwAzeqiWutXfEgiwhXz3iCnayt9P8nmKwwGn2wDYsGRCSdeoxTJCDX?cluster=testnet",
);
});

test("getExplorerLinkSolscan works with localnet on solscan", () => {
const link = getExplorerLinkSolscan({
cluster: "localnet",
transaction: "2QC8BkDVZgaPHUXG9HuPw7aE5d6kN5DTRXLe2inT1NzurkYTCFhraSEo883CPNe18BZ2peJC1x1nojZ5Jmhs94pL",
});
assert.equal(
link,
"https://solscan.io/tx/2QC8BkDVZgaPHUXG9HuPw7aE5d6kN5DTRXLe2inT1NzurkYTCFhraSEo883CPNe18BZ2peJC1x1nojZ5Jmhs94pL?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899",
);
});

test("getExplorerLinkOrb ignores localnet cluster (not supported)", () => {
const link = getExplorerLinkOrb({
cluster: "localnet",
block: "242233124",
});
assert.equal(link, "https://orb.helius.dev/block/242233124");
});

test("getExplorerLinkOrb ignores localhost cluster (not supported)", () => {
const link = getExplorerLinkOrb({
cluster: "localhost",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://orb.helius.dev/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8");
});

test("getExplorerLinkSolanafm works with localhost cluster using localnet-solana", () => {
const link = getExplorerLinkSolanafm({
cluster: "localhost",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solana.fm/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8?cluster=localnet-solana");
});

test("getExplorerLinkSolanafm works with localnet cluster using localnet-solana", () => {
const link = getExplorerLinkSolanafm({
cluster: "localnet",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solana.fm/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8?cluster=localnet-solana");
});

test("getExplorerLinkSolanafm works with devnet cluster using devnet-solana", () => {
const link = getExplorerLinkSolanafm({
cluster: "devnet",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solana.fm/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8?cluster=devnet-solana");
});

test("getExplorerLinkSolanafm works with testnet cluster using testnet-solana", () => {
const link = getExplorerLinkSolanafm({
cluster: "testnet",
address: "dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8",
});
assert.equal(link, "https://solana.fm/address/dDCQNnDmNbFVi8cQhKAgXhyhXeJ625tvwsunRyRc7c8?cluster=testnet-solana");
});
});
97 changes: 95 additions & 2 deletions packages/gill/src/core/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { GetExplorerLinkArgs } from "../types";
import { type GetExplorerLinkArgs } from "../types";

/**
* Craft a Solana Explorer link on any cluster
*/
export function getExplorerLink(props: GetExplorerLinkArgs = {}): string {
let url = new URL("https://explorer.solana.com");
let url = new URL("https://explorer.solana.com/");
Comment thread
arihantbansal marked this conversation as resolved.
Outdated

// default to mainnet / mainnet-beta
if (!props.cluster || props.cluster == "mainnet") props.cluster = "mainnet-beta";
Expand All @@ -29,3 +29,96 @@ export function getExplorerLink(props: GetExplorerLinkArgs = {}): string {

return url.toString();
}

/**
* Craft an Orb Explorer link on any cluster
*/
export function getExplorerLinkOrb(props: GetExplorerLinkArgs = {}): string {
Comment thread
arihantbansal marked this conversation as resolved.
let url = new URL("https://orb.helius.dev/");

// default to mainnet / mainnet-beta
if (!props.cluster || props.cluster == "mainnet") props.cluster = "mainnet-beta";

if ("address" in props) {
url.pathname = `/address/${props.address}`;
} else if ("transaction" in props) {
url.pathname = `/tx/${props.transaction}`;
} else if ("block" in props) {
url.pathname = `/block/${props.block}`;
}

if (props.cluster !== "mainnet-beta") {
// Orb doesn't support localnet/localhost, so we ignore those clusters
if (props.cluster !== "localnet" && props.cluster !== "localhost") {
url.searchParams.set("cluster", props.cluster);
}
}

return url.toString();
}

/**
* Craft a Solscan Explorer link on any cluster
*/
export function getExplorerLinkSolscan(props: GetExplorerLinkArgs = {}): string {
let url = new URL("https://solscan.io/");

// default to mainnet / mainnet-beta
if (!props.cluster || props.cluster == "mainnet") props.cluster = "mainnet-beta";

if ("address" in props) {
url.pathname = `/address/${props.address}`;
} else if ("transaction" in props) {
url.pathname = `/tx/${props.transaction}`;
} else if ("block" in props) {
url.pathname = `/block/${props.block}`;
}

if (props.cluster !== "mainnet-beta") {
if (props.cluster === "localnet" || props.cluster === "localhost") {
// localnet technically isn't a cluster, so requires special handling
url.searchParams.set("cluster", "custom");
url.searchParams.set("customUrl", "http://localhost:8899");
} else {
url.searchParams.set("cluster", props.cluster);
}
}

return url.toString();
}

/**
* Craft a SolanaFM Explorer link on any cluster
* Note: SolanaFM uses different cluster naming conventions
*/
export function getExplorerLinkSolanafm(props: GetExplorerLinkArgs = {}): string {
let url = new URL("https://solana.fm/");

// default to mainnet / mainnet-beta
if (!props.cluster || props.cluster == "mainnet") props.cluster = "mainnet-beta";

if ("address" in props) {
url.pathname = `/address/${props.address}`;
} else if ("transaction" in props) {
url.pathname = `/tx/${props.transaction}`;
} else if ("block" in props) {
url.pathname = `/block/${props.block}`;
}

if (props.cluster !== "mainnet-beta") {
if (props.cluster === "localnet" || props.cluster === "localhost") {
// SolanaFM uses "localnet-solana" instead of custom cluster
url.searchParams.set("cluster", "localnet-solana");
} else if (props.cluster === "devnet") {
// SolanaFM uses "devnet-solana" instead of "devnet"
url.searchParams.set("cluster", "devnet-solana");
} else if (props.cluster === "testnet") {
// SolanaFM uses "testnet-solana" instead of "testnet"
url.searchParams.set("cluster", "testnet-solana");
} else {
url.searchParams.set("cluster", props.cluster);
}
}

return url.toString();
}