Skip to content

Commit

Permalink
Explorer: Support additional bpf upgradeable loader instructions (#28342
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jstarry authored Oct 11, 2022
1 parent bcbf4c7 commit 928730a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { ParsedInfo } from "validators";
import { InstructionCard } from "../InstructionCard";
import { UnknownDetailsCard } from "../UnknownDetailsCard";
import {
CloseInfo,
DeployWithMaxDataLenInfo,
ExtendProgramInfo,
InitializeBufferInfo,
SetAuthorityInfo,
UpgradeInfo,
Expand All @@ -33,27 +35,37 @@ export function BpfUpgradeableLoaderDetailsCard(props: DetailsProps) {
try {
const parsed = create(props.ix.parsed, ParsedInfo);
switch (parsed.type) {
case "initializeBuffer": {
return renderDetails<InitializeBufferInfo>(
props,
parsed,
InitializeBufferInfo
);
}
case "write": {
return renderDetails<WriteInfo>(props, parsed, WriteInfo);
}
case "upgrade": {
return renderDetails<UpgradeInfo>(props, parsed, UpgradeInfo);
}
case "setAuthority": {
return renderDetails<SetAuthorityInfo>(props, parsed, SetAuthorityInfo);
}
case "deployWithMaxDataLen": {
return renderDetails<DeployWithMaxDataLenInfo>(
props,
parsed,
DeployWithMaxDataLenInfo
);
}
case "initializeBuffer": {
return renderDetails<InitializeBufferInfo>(
case "upgrade": {
return renderDetails<UpgradeInfo>(props, parsed, UpgradeInfo);
}
case "setAuthority": {
return renderDetails<SetAuthorityInfo>(props, parsed, SetAuthorityInfo);
}
case "close": {
return renderDetails<CloseInfo>(props, parsed, CloseInfo);
}
case "extendProgram": {
return renderDetails<ExtendProgramInfo>(
props,
parsed,
InitializeBufferInfo
ExtendProgramInfo
);
}
default:
Expand Down
57 changes: 38 additions & 19 deletions explorer/src/components/instruction/bpf-upgradeable-loader/types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
/* eslint-disable @typescript-eslint/no-redeclare */

import { enums, nullable, number, type, string, Infer } from "superstruct";
import { enums, number, type, string, Infer, optional } from "superstruct";
import { PublicKeyFromString } from "validators/pubkey";

export type InitializeBufferInfo = Infer<typeof InitializeBufferInfo>;
export const InitializeBufferInfo = type({
account: PublicKeyFromString,
authority: PublicKeyFromString,
});

export type WriteInfo = Infer<typeof WriteInfo>;
export const WriteInfo = type({
offset: number(),
bytes: string(),
account: PublicKeyFromString,
authority: PublicKeyFromString,
bytes: string(),
offset: number(),
});

export type InitializeBufferInfo = Infer<typeof InitializeBufferInfo>;
export const InitializeBufferInfo = type({
account: PublicKeyFromString,
export type DeployWithMaxDataLenInfo = Infer<typeof DeployWithMaxDataLenInfo>;
export const DeployWithMaxDataLenInfo = type({
maxDataLen: number(),
payerAccount: PublicKeyFromString,
programDataAccount: PublicKeyFromString,
programAccount: PublicKeyFromString,
bufferAccount: PublicKeyFromString,
rentSysvar: PublicKeyFromString,
clockSysvar: PublicKeyFromString,
systemProgram: PublicKeyFromString,
authority: PublicKeyFromString,
});

Expand All @@ -23,38 +36,44 @@ export const UpgradeInfo = type({
programAccount: PublicKeyFromString,
bufferAccount: PublicKeyFromString,
spillAccount: PublicKeyFromString,
authority: PublicKeyFromString,
rentSysvar: PublicKeyFromString,
clockSysvar: PublicKeyFromString,
authority: PublicKeyFromString,
});

export type SetAuthorityInfo = Infer<typeof SetAuthorityInfo>;
export const SetAuthorityInfo = type({
account: PublicKeyFromString,
authority: PublicKeyFromString,
newAuthority: nullable(PublicKeyFromString),
newAuthority: optional(PublicKeyFromString),
});

export type DeployWithMaxDataLenInfo = Infer<typeof DeployWithMaxDataLenInfo>;
export const DeployWithMaxDataLenInfo = type({
export type CloseInfo = Infer<typeof CloseInfo>;
export const CloseInfo = type({
account: PublicKeyFromString,
recipient: PublicKeyFromString,
authority: PublicKeyFromString,
programAccount: optional(PublicKeyFromString),
});

export type ExtendProgramInfo = Infer<typeof ExtendProgramInfo>;
export const ExtendProgramInfo = type({
additionalBytes: number(),
programDataAccount: PublicKeyFromString,
programAccount: PublicKeyFromString,
payerAccount: PublicKeyFromString,
bufferAccount: PublicKeyFromString,
authority: PublicKeyFromString,
rentSysvar: PublicKeyFromString,
clockSysvar: PublicKeyFromString,
systemProgram: PublicKeyFromString,
maxDataLen: number(),
systemProgram: optional(PublicKeyFromString),
payerAccount: optional(PublicKeyFromString),
});

export type UpgradeableBpfLoaderInstructionType = Infer<
typeof UpgradeableBpfLoaderInstructionType
>;
export const UpgradeableBpfLoaderInstructionType = enums([
"initializeBuffer",
"write",
"deployWithMaxDataLen",
"upgrade",
"setAuthority",
"write",
"finalize",
"close",
"extendProgram",
]);

1 comment on commit 928730a

@denispalab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for explorer ready!

✅ Preview
https://explorer-65jp55xee-solana-labs.vercel.app

Built with commit 928730a.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.