diff --git a/packages/solana-contrib/src/transaction/PendingTransaction.ts b/packages/solana-contrib/src/transaction/PendingTransaction.ts index 329ad03a..0c988c56 100644 --- a/packages/solana-contrib/src/transaction/PendingTransaction.ts +++ b/packages/solana-contrib/src/transaction/PendingTransaction.ts @@ -9,6 +9,7 @@ import type { import promiseRetry from "promise-retry"; import type { WrapOptions } from "retry"; +import { generateTXLink } from "../utils/txLink.js"; import { TransactionReceipt } from "./TransactionReceipt.js"; /** @@ -165,6 +166,6 @@ export class PendingTransaction { * @returns */ generateSolanaExplorerLink(cluster: Cluster = "mainnet-beta"): string { - return `https://explorer.solana.com/tx/${this.signature}?cluster=${cluster}`; + return generateTXLink(this.signature, cluster); } } diff --git a/packages/solana-contrib/src/transaction/TransactionReceipt.ts b/packages/solana-contrib/src/transaction/TransactionReceipt.ts index 0d9b5d88..e7f35d5f 100644 --- a/packages/solana-contrib/src/transaction/TransactionReceipt.ts +++ b/packages/solana-contrib/src/transaction/TransactionReceipt.ts @@ -8,6 +8,7 @@ import { default as invariant } from "tiny-invariant"; import type { Event, EventParser } from "../interfaces.js"; import type { PromiseOrValue } from "../utils/misc.js"; import { valueAsPromise } from "../utils/misc.js"; +import { generateTXLink } from "../utils/txLink.js"; import { PendingTransaction } from "./PendingTransaction.js"; import type { TransactionEnvelope } from "./TransactionEnvelope.js"; @@ -19,11 +20,6 @@ export type TransactionLike = | PendingTransaction | TransactionReceipt; -export enum ExplorerType { - SOLANA_EXPLORER = "solana-explorer", - SOLSCAN = "solscan", -} - /** * Confirms a transaction, returning its receipt. * @@ -102,20 +98,6 @@ export class TransactionReceipt { * @returns */ generateSolanaExplorerLink(cluster: Cluster = "mainnet-beta"): string { - return this.generateTXLink(cluster); - } - - generateTXLink( - cluster: Cluster = "mainnet-beta", - explorerType: string = ExplorerType.SOLANA_EXPLORER - ): string { - switch (explorerType) { - case ExplorerType.SOLANA_EXPLORER: - return `https://explorer.solana.com/tx/${this.signature}?cluster=${cluster}`; - case ExplorerType.SOLSCAN: - return `https://solscan.io/tx/${this.signature}?cluster=${cluster}`; - default: - throw new Error(`Explorer type ${explorerType} is not supported.`); - } + return generateTXLink(this.signature, cluster); } } diff --git a/packages/solana-contrib/src/utils/index.ts b/packages/solana-contrib/src/utils/index.ts index 3c64bd05..6ef4e412 100644 --- a/packages/solana-contrib/src/utils/index.ts +++ b/packages/solana-contrib/src/utils/index.ts @@ -6,3 +6,4 @@ export * from "./pubkeyCache.js"; export * from "./publicKey.js"; export * from "./simulateTransactionWithCommitment.js"; export * from "./time.js"; +export * from "./txLink.js"; diff --git a/packages/solana-contrib/src/utils/txLink.ts b/packages/solana-contrib/src/utils/txLink.ts new file mode 100644 index 00000000..00030660 --- /dev/null +++ b/packages/solana-contrib/src/utils/txLink.ts @@ -0,0 +1,21 @@ +import type { Cluster } from "@solana/web3.js"; + +export enum ExplorerType { + SOLANA_EXPLORER = "solana-explorer", + SOLSCAN = "solscan", +} + +export function generateTXLink( + signature: string, + cluster: Cluster = "mainnet-beta", + explorerType: string = ExplorerType.SOLANA_EXPLORER +): string { + switch (explorerType) { + case ExplorerType.SOLANA_EXPLORER: + return `https://explorer.solana.com/tx/${signature}?cluster=${cluster}`; + case ExplorerType.SOLSCAN: + return `https://solscan.io/tx/${signature}?cluster=${cluster}`; + default: + throw new Error(`Explorer type ${explorerType} is not supported.`); + } +}