Skip to content

Commit

Permalink
support versionedTransactions in mocked wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
asktree committed Aug 23, 2023
1 parent 3f78e68 commit 2d5b086
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions components/explorer/tools.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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<TransactionVersion>
>
) {
const SIGNATURE_LENGTH = 64

Expand All @@ -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()
}

0 comments on commit 2d5b086

Please sign in to comment.