Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer: Display address lookup table instruction type #27106

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
/>
);
}
33 changes: 33 additions & 0 deletions explorer/src/components/instruction/address-lookup-table/types.ts
Original file line number Diff line number Diff line change
@@ -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];
}
6 changes: 5 additions & 1 deletion explorer/src/components/transaction/InstructionsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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} />;
Expand Down