Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solana-contrib: Refactor generateTXLink #675

Merged
merged 13 commits into from Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/solana-contrib/src/transaction/PendingTransaction.ts
@@ -1,6 +1,5 @@
import type {
BlockhashWithExpiryBlockHeight,
Cluster,
Connection,
Finality,
SignatureResult,
Expand Down Expand Up @@ -158,13 +157,4 @@ export class PendingTransaction {

return this.signature;
}

/**
* Generates a link to view this {@link PendingTransaction} on the official Solana explorer.
* @param network
* @returns
*/
generateSolanaExplorerLink(cluster: Cluster = "mainnet-beta"): string {
return `https://explorer.solana.com/tx/${this.signature}?cluster=${cluster}`;
}
michaelhly marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 0 additions & 29 deletions packages/solana-contrib/src/transaction/TransactionReceipt.ts
@@ -1,5 +1,4 @@
import type {
Cluster,
TransactionResponse,
TransactionSignature,
} from "@solana/web3.js";
Expand All @@ -19,11 +18,6 @@ export type TransactionLike =
| PendingTransaction
| TransactionReceipt;

export enum ExplorerType {
SOLANA_EXPLORER = "solana-explorer",
SOLSCAN = "solscan",
}

/**
* Confirms a transaction, returning its receipt.
*
Expand Down Expand Up @@ -95,27 +89,4 @@ export class TransactionReceipt {
invariant(amtStr, "no amount");
return parseInt(amtStr);
}

/**
* Generates a link to view this {@link TransactionReceipt} on the official Solana explorer.
* @param network
* @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.`);
}
}
michaelhly marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions packages/solana-contrib/src/utils/index.ts
Expand Up @@ -6,3 +6,4 @@ export * from "./pubkeyCache.js";
export * from "./publicKey.js";
export * from "./simulateTransactionWithCommitment.js";
export * from "./time.js";
export * from "./txLink.js";
31 changes: 31 additions & 0 deletions packages/solana-contrib/src/utils/txLink.ts
@@ -0,0 +1,31 @@
import { Cluster } from "@solana/web3.js";

import { PendingTransaction } from "../transaction/PendingTransaction";
import { TransactionReceipt } from "../transaction/TransactionReceipt";

export enum ExplorerType {
SOLANA_EXPLORER = "solana-explorer",
SOLSCAN = "solscan",
}

export function generateSolanaExplorerLink(
tx: PendingTransaction | TransactionReceipt,
cluster: Cluster = "mainnet-beta"
): string {
return generateTXLink(tx, cluster);
}
michaelhly marked this conversation as resolved.
Show resolved Hide resolved

export function generateTXLink(
tx: PendingTransaction | TransactionReceipt,
michaelhly marked this conversation as resolved.
Show resolved Hide resolved
cluster: Cluster = "mainnet-beta",
explorerType: string = ExplorerType.SOLANA_EXPLORER
): string {
switch (explorerType) {
case ExplorerType.SOLANA_EXPLORER:
return `https://explorer.solana.com/tx/${tx.signature}?cluster=${cluster}`;
case ExplorerType.SOLSCAN:
return `https://solscan.io/tx/${tx.signature}?cluster=${cluster}`;
default:
throw new Error(`Explorer type ${explorerType} is not supported.`);
}
}