forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explorer: Display address lookup table instruction type (solana-labs#…
- Loading branch information
1 parent
030d3e3
commit 8153b2e
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
explorer/src/components/instruction/AddressLookupTableDetailsCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
explorer/src/components/instruction/address-lookup-table/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters