Display owner names when known

This commit is contained in:
Justin Starry 2020-04-05 17:23:38 +08:00 committed by Michael Vines
parent 35814e77cb
commit bcb10b0536
2 changed files with 54 additions and 2 deletions

View File

@ -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 = "-";

View File

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