Explorer: Support additional bpf upgradeable loader instructions (#28342)

This commit is contained in:
Justin Starry 2022-10-11 14:27:58 +08:00 committed by GitHub
parent bcbf4c7fb3
commit 928730ac94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 32 deletions

View File

@ -13,7 +13,9 @@ import { ParsedInfo } from "validators";
import { InstructionCard } from "../InstructionCard";
import { UnknownDetailsCard } from "../UnknownDetailsCard";
import {
CloseInfo,
DeployWithMaxDataLenInfo,
ExtendProgramInfo,
InitializeBufferInfo,
SetAuthorityInfo,
UpgradeInfo,
@ -33,15 +35,16 @@ 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,
@ -49,11 +52,20 @@ export function BpfUpgradeableLoaderDetailsCard(props: DetailsProps) {
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:

View File

@ -1,51 +1,68 @@
/* 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 WriteInfo = Infer<typeof WriteInfo>;
export const WriteInfo = type({
account: PublicKeyFromString,
authority: PublicKeyFromString,
bytes: string(),
offset: number(),
});
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,
});
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,
});
export type UpgradeInfo = Infer<typeof UpgradeInfo>;
export const UpgradeInfo = type({
programDataAccount: PublicKeyFromString,
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<
@ -53,8 +70,10 @@ export type UpgradeableBpfLoaderInstructionType = Infer<
>;
export const UpgradeableBpfLoaderInstructionType = enums([
"initializeBuffer",
"deployWithMaxDataLen",
"setAuthority",
"write",
"finalize",
"deployWithMaxDataLen",
"upgrade",
"setAuthority",
"close",
"extendProgram",
]);