From bcb10b0536818a56e7792a22e1977778203cfed1 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sun, 5 Apr 2020 17:23:38 +0800 Subject: [PATCH] Display owner names when known --- explorer/src/components/AccountsCard.tsx | 4 +- explorer/src/utils.ts | 52 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/explorer/src/components/AccountsCard.tsx b/explorer/src/components/AccountsCard.tsx index 4cbb89ae71..6d669994fb 100644 --- a/explorer/src/components/AccountsCard.tsx +++ b/explorer/src/components/AccountsCard.tsx @@ -7,7 +7,7 @@ import { Account, Status } from "../providers/accounts"; -import { assertUnreachable } from "../utils"; +import { assertUnreachable, displayAddress } from "../utils"; import { useCluster } from "../providers/cluster"; import { PublicKey, LAMPORTS_PER_SOL } from "@solana/web3.js"; @@ -138,7 +138,7 @@ const renderAccountRow = (account: Account) => { let owner = "-"; if (account.details) { data = `${account.details.space}`; - owner = `${account.details.owner.toBase58()}`; + owner = displayAddress(account.details.owner); } let balance = "-"; diff --git a/explorer/src/utils.ts b/explorer/src/utils.ts index 1d8d583a67..a1601cc81a 100644 --- a/explorer/src/utils.ts +++ b/explorer/src/utils.ts @@ -1,3 +1,15 @@ +import { + PublicKey, + SystemProgram, + StakeProgram, + VOTE_PROGRAM_ID, + BpfLoader, + SYSVAR_CLOCK_PUBKEY, + SYSVAR_RENT_PUBKEY, + SYSVAR_REWARDS_PUBKEY, + SYSVAR_STAKE_HISTORY_PUBKEY +} from "@solana/web3.js"; + export function findGetParameter(parameterName: string): string | null { let result = null, tmp = []; @@ -34,3 +46,43 @@ export function findPathSegment(pathName: string): string | null { export function assertUnreachable(x: never): never { throw new Error("Unreachable!"); } + +const PROGRAM_IDS = { + Budget1111111111111111111111111111111111111: "Budget Program", + Config1111111111111111111111111111111111111: "Config Program", + Exchange11111111111111111111111111111111111: "Exchange Program", + [StakeProgram.programId.toBase58()]: "Stake Program", + Storage111111111111111111111111111111111111: "Storage Program", + [SystemProgram.programId.toBase58()]: "System Program", + Vest111111111111111111111111111111111111111: "Vest Program", + [VOTE_PROGRAM_ID.toBase58()]: "Vote Program" +}; + +const LOADER_IDS = { + MoveLdr111111111111111111111111111111111111: "Move Loader", + NativeLoader1111111111111111111111111111111: "Native Loader", + [BpfLoader.programId.toBase58()]: "BPF Loader" +}; + +const SYSVAR_IDS = { + Sysvar1111111111111111111111111111111111111: "SYSVAR", + [SYSVAR_CLOCK_PUBKEY.toBase58()]: "SYSVAR_CLOCK", + SysvarEpochSchedu1e111111111111111111111111: "SYSVAR_EPOCH_SCHEDULE", + SysvarFees111111111111111111111111111111111: "SYSVAR_FEES", + SysvarRecentB1ockHashes11111111111111111111: "SYSVAR_RECENT_BLOCKHASHES", + [SYSVAR_RENT_PUBKEY.toBase58()]: "SYSVAR_RENT", + [SYSVAR_REWARDS_PUBKEY.toBase58()]: "SYSVAR_REWARDS", + SysvarS1otHashes111111111111111111111111111: "SYSVAR_SLOT_HASHES", + SysvarS1otHistory11111111111111111111111111: "SYSVAR_SLOT_HISTORY", + [SYSVAR_STAKE_HISTORY_PUBKEY.toBase58()]: "SYSVAR_STAKE_HISTORY" +}; + +export function displayAddress(pubkey: PublicKey): string { + const address = pubkey.toBase58(); + return ( + PROGRAM_IDS[address] || + LOADER_IDS[address] || + SYSVAR_IDS[address] || + address + ); +}