Explorer: Display address lookup table instruction type (#27106)
This commit is contained in:
parent
5618e9fd07
commit
0e4ce87870
|
@ -0,0 +1,46 @@
|
|||
import React from "react";
|
||||
import { TransactionInstruction, SignatureResult } from "@solana/web3.js";
|
||||
import { InstructionCard } from "./InstructionCard";
|
||||
import { useCluster } from "providers/cluster";
|
||||
import { reportError } from "utils/sentry";
|
||||
import { parseAddressLookupTableInstructionTitle } from "./address-lookup-table/types";
|
||||
|
||||
export function AddressLookupTableDetailsCard({
|
||||
ix,
|
||||
index,
|
||||
result,
|
||||
signature,
|
||||
innerCards,
|
||||
childIndex,
|
||||
}: {
|
||||
ix: TransactionInstruction;
|
||||
index: number;
|
||||
result: SignatureResult;
|
||||
signature: string;
|
||||
innerCards?: JSX.Element[];
|
||||
childIndex?: number;
|
||||
}) {
|
||||
const { url } = useCluster();
|
||||
|
||||
let title;
|
||||
try {
|
||||
title = parseAddressLookupTableInstructionTitle(ix);
|
||||
} catch (error) {
|
||||
reportError(error, {
|
||||
url: url,
|
||||
signature: signature,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<InstructionCard
|
||||
ix={ix}
|
||||
index={index}
|
||||
result={result}
|
||||
title={`Address Lookup Table: ${title || "Unknown"}`}
|
||||
innerCards={innerCards}
|
||||
childIndex={childIndex}
|
||||
defaultRaw
|
||||
/>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import { TransactionInstruction } from "@solana/web3.js";
|
||||
|
||||
export const PROGRAM_IDS: string[] = [
|
||||
"AddressLookupTab1e1111111111111111111111111",
|
||||
];
|
||||
|
||||
const INSTRUCTION_LOOKUP: { [key: number]: string } = {
|
||||
0: "Create Lookup Table",
|
||||
1: "Freeze Lookup Table",
|
||||
2: "Extend Lookup Table",
|
||||
3: "Deactivate Lookup Table",
|
||||
4: "Close Lookup Table",
|
||||
};
|
||||
|
||||
export function isAddressLookupTableInstruction(
|
||||
instruction: TransactionInstruction
|
||||
): boolean {
|
||||
return PROGRAM_IDS.includes(instruction.programId.toBase58());
|
||||
}
|
||||
|
||||
export function parseAddressLookupTableInstructionTitle(
|
||||
instruction: TransactionInstruction
|
||||
): string {
|
||||
const code = instruction.data[0];
|
||||
|
||||
if (!(code in INSTRUCTION_LOOKUP)) {
|
||||
throw new Error(
|
||||
`Unrecognized Address Lookup Table instruction code: ${code}`
|
||||
);
|
||||
}
|
||||
|
||||
return INSTRUCTION_LOOKUP[code];
|
||||
}
|
|
@ -25,6 +25,7 @@ import {
|
|||
SignatureProps,
|
||||
} from "pages/TransactionDetailsPage";
|
||||
import { intoTransactionInstruction } from "utils/tx";
|
||||
import { isAddressLookupTableInstruction } from "components/instruction/address-lookup-table/types";
|
||||
import { isSerumInstruction } from "components/instruction/serum/types";
|
||||
import { isTokenLendingInstruction } from "components/instruction/token-lending/types";
|
||||
import { isTokenSwapInstruction } from "components/instruction/token-swap/types";
|
||||
|
@ -48,6 +49,7 @@ import { useAnchorProgram } from "providers/anchor";
|
|||
import { LoadingCard } from "components/common/LoadingCard";
|
||||
import { ErrorBoundary } from "@sentry/react";
|
||||
import { ComputeBudgetDetailsCard } from "components/instruction/ComputeBudgetDetailsCard";
|
||||
import { AddressLookupTableDetailsCard } from "components/instruction/AddressLookupTableDetailsCard";
|
||||
|
||||
export type InstructionDetailsProps = {
|
||||
tx: ParsedTransaction;
|
||||
|
@ -224,7 +226,9 @@ function InstructionCard({
|
|||
childIndex,
|
||||
};
|
||||
|
||||
if (isBonfidaBotInstruction(transactionIx)) {
|
||||
if (isAddressLookupTableInstruction(transactionIx)) {
|
||||
return <AddressLookupTableDetailsCard key={key} {...props} />;
|
||||
} else if (isBonfidaBotInstruction(transactionIx)) {
|
||||
return <BonfidaBotDetailsCard key={key} {...props} />;
|
||||
} else if (isMangoInstruction(transactionIx)) {
|
||||
return <MangoDetailsCard key={key} {...props} />;
|
||||
|
|
Loading…
Reference in New Issue