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: Add details page for address lookup table accounts (solana-…
- Loading branch information
1 parent
4d7fd2d
commit 716577f
Showing
5 changed files
with
198 additions
and
7 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
explorer/src/components/account/address-lookup-table/AddressLookupTableAccountSection.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,84 @@ | ||
import React from "react"; | ||
import { TableCardBody } from "components/common/TableCardBody"; | ||
import { SolBalance } from "utils"; | ||
import { Account, useFetchAccountInfo } from "providers/accounts"; | ||
import { Address } from "components/common/Address"; | ||
import { AddressLookupTableAccount } from "@solana/web3.js"; | ||
import { Slot } from "components/common/Slot"; | ||
|
||
export function AddressLookupTableAccountSection({ | ||
account, | ||
data, | ||
}: { | ||
account: Account; | ||
data: Uint8Array; | ||
}) { | ||
const lookupTableAccount = React.useMemo(() => { | ||
return new AddressLookupTableAccount({ | ||
key: account.pubkey, | ||
state: AddressLookupTableAccount.deserialize(data), | ||
}); | ||
}, [account, data]); | ||
const refresh = useFetchAccountInfo(); | ||
return ( | ||
<div className="card"> | ||
<div className="card-header"> | ||
<h3 className="card-header-title mb-0 d-flex align-items-center"> | ||
Address Lookup Table Account | ||
</h3> | ||
<button | ||
className="btn btn-white btn-sm" | ||
onClick={() => refresh(account.pubkey)} | ||
> | ||
<span className="fe fe-refresh-cw me-2"></span> | ||
Refresh | ||
</button> | ||
</div> | ||
|
||
<TableCardBody> | ||
<tr> | ||
<td>Address</td> | ||
<td className="text-lg-end"> | ||
<Address pubkey={account.pubkey} alignRight raw /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Balance (SOL)</td> | ||
<td className="text-lg-end text-uppercase"> | ||
<SolBalance lamports={account.lamports || 0} /> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Activation Status</td> | ||
<td className="text-lg-end text-uppercase"> | ||
{lookupTableAccount.isActive() ? "Active" : "Deactivated"} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Last Extended Slot</td> | ||
<td className="text-lg-end"> | ||
{lookupTableAccount.state.lastExtendedSlot === 0 ? ( | ||
"None (Empty)" | ||
) : ( | ||
<Slot slot={lookupTableAccount.state.lastExtendedSlot} link /> | ||
)} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Authority</td> | ||
<td className="text-lg-end"> | ||
{lookupTableAccount.state.authority === undefined ? ( | ||
"None (Frozen)" | ||
) : ( | ||
<Address | ||
pubkey={lookupTableAccount.state.authority} | ||
alignRight | ||
link | ||
/> | ||
)} | ||
</td> | ||
</tr> | ||
</TableCardBody> | ||
</div> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
explorer/src/components/account/address-lookup-table/LookupTableEntriesCard.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,60 @@ | ||
import React from "react"; | ||
|
||
import { AddressLookupTableAccount, PublicKey } from "@solana/web3.js"; | ||
import { Address } from "components/common/Address"; | ||
|
||
export function LookupTableEntriesCard({ | ||
lookupTableAccountData, | ||
}: { | ||
lookupTableAccountData: Uint8Array; | ||
}) { | ||
const lookupTableState = React.useMemo(() => { | ||
return AddressLookupTableAccount.deserialize(lookupTableAccountData); | ||
}, [lookupTableAccountData]); | ||
|
||
return ( | ||
<div className="card"> | ||
<div className="card-header"> | ||
<div className="row align-items-center"> | ||
<div className="col"> | ||
<h3 className="card-header-title">Lookup Table Entries</h3> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div className="table-responsive mb-0"> | ||
<table className="table table-sm table-nowrap card-table"> | ||
<thead> | ||
<tr> | ||
<th className="w-1 text-muted">Index</th> | ||
<th className="text-muted">Address</th> | ||
</tr> | ||
</thead> | ||
<tbody className="list"> | ||
{lookupTableState.addresses.length > 0 && | ||
lookupTableState.addresses.map((entry: PublicKey, index) => { | ||
return renderRow(entry, index); | ||
})} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
{lookupTableState.addresses.length === 0 && ( | ||
<div className="card-footer"> | ||
<div className="text-muted text-center">No entries found</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
const renderRow = (entry: PublicKey, index: number) => { | ||
return ( | ||
<tr key={index}> | ||
<td className="w-1 font-monospace">{index}</td> | ||
<td className="font-monospace"> | ||
<Address pubkey={entry} link /> | ||
</td> | ||
</tr> | ||
); | ||
}; |
13 changes: 13 additions & 0 deletions
13
explorer/src/components/account/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,13 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
|
||
const PROGRAM_ID: string = "AddressLookupTab1e1111111111111111111111111"; | ||
|
||
export function isAddressLookupTableAccount( | ||
accountOwner: PublicKey, | ||
accountData: Uint8Array | ||
): boolean { | ||
if (accountOwner.toBase58() !== PROGRAM_ID) return false; | ||
if (!accountData || accountData.length === 0) return false; | ||
const LOOKUP_TABLE_ACCOUNT_TYPE = 1; | ||
return accountData[0] === LOOKUP_TABLE_ACCOUNT_TYPE; | ||
} |
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
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