Explorer: Display address lookup table instruction type (#27106)

This commit is contained in:
Justin Starry 2022-08-12 15:20:33 +01:00 committed by GitHub
parent 5618e9fd07
commit 0e4ce87870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 1 deletions

View File

@ -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
/>
);
}

View File

@ -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];
}

View File

@ -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} />;