Skip to content

Commit

Permalink
support versionedTransactions in mocked wallet (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
asktree authored Aug 23, 2023
1 parent 3f78e68 commit de33c9b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 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()
explorerUrl.searchParams.append('message', message.toString('base64'))
const message =
transaction instanceof Transaction
? transaction.serializeMessage().toString('base64')
: Buffer.from(transaction.message.serialize()).toString('base64')
explorerUrl.searchParams.append('message', message)

if (connection.cluster === 'devnet') {
explorerUrl.searchParams.append('cluster', 'devnet')
}

return explorerUrl.toString()
}

1 comment on commit de33c9b

@vercel
Copy link

@vercel vercel bot commented on de33c9b Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.