From 2d5b086542ffcaaf9fad8bf30b3285e627d8df99 Mon Sep 17 00:00:00 2001 From: agrippa kellum Date: Wed, 23 Aug 2023 13:57:19 -0400 Subject: [PATCH] support versionedTransactions in mocked wallet --- components/explorer/tools.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/components/explorer/tools.ts b/components/explorer/tools.ts index f5513196b2..33fb61a624 100644 --- a/components/explorer/tools.ts +++ b/components/explorer/tools.ts @@ -1,4 +1,5 @@ -import { PublicKey, Transaction } from '@solana/web3.js' +import { TransactionOrVersionedTransaction } from '@solana/wallet-adapter-base' +import { PublicKey, Transaction, TransactionVersion } from '@solana/web3.js' import { ConnectionContext } from '@utils/connection' import base58 from 'bs58' @@ -30,7 +31,9 @@ export function getExplorerUrl( /// Returns explorer inspector URL for the given transaction export async function getExplorerInspectorUrl( connection: ConnectionContext, - transaction: Transaction + transaction: TransactionOrVersionedTransaction< + ReadonlySet + > ) { const SIGNATURE_LENGTH = 64 @@ -42,12 +45,16 @@ export async function getExplorerInspectorUrl( base58.encode(s.signature ?? Buffer.alloc(SIGNATURE_LENGTH)) ) explorerUrl.searchParams.append('signatures', JSON.stringify(signatures)) - const latestBlockhash = await connection.current.getLatestBlockhash() - transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight - transaction.recentBlockhash = latestBlockhash.blockhash - const message = transaction.serializeMessage() + const message = + transaction instanceof Transaction + ? transaction.serializeMessage() + : transaction.message.serialize() explorerUrl.searchParams.append('message', message.toString('base64')) + if (connection.cluster === 'devnet') { + explorerUrl.searchParams.append('cluster', 'devnet') + } + return explorerUrl.toString() }