Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch the instruction discriminant to be 4 bytes #5

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -33,7 +33,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const CLOSE_DISCRIMINATOR = 5;

export function getCloseDiscriminatorBytes() {
return getU8Encoder().encode(CLOSE_DISCRIMINATOR);
return getU32Encoder().encode(CLOSE_DISCRIMINATOR);
}

export type CloseInstruction<
Expand Down Expand Up @@ -72,13 +72,13 @@ export type CloseInstructionDataArgs = {};

export function getCloseInstructionDataEncoder(): Encoder<CloseInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
getStructEncoder([['discriminator', getU32Encoder()]]),
(value) => ({ ...value, discriminator: CLOSE_DISCRIMINATOR })
);
}

export function getCloseInstructionDataDecoder(): Decoder<CloseInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
return getStructDecoder([['discriminator', getU32Decoder()]]);
}

export function getCloseInstructionDataCodec(): Codec<
Expand Down
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/deployWithMaxDataLen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU32Decoder,
getU32Encoder,
getU64Decoder,
getU64Encoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -36,7 +36,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR = 2;

export function getDeployWithMaxDataLenDiscriminatorBytes() {
return getU8Encoder().encode(DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR);
return getU32Encoder().encode(DEPLOY_WITH_MAX_DATA_LEN_DISCRIMINATOR);
}

export type DeployWithMaxDataLenInstruction<
Expand Down Expand Up @@ -102,7 +102,7 @@ export type DeployWithMaxDataLenInstructionDataArgs = {
export function getDeployWithMaxDataLenInstructionDataEncoder(): Encoder<DeployWithMaxDataLenInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['discriminator', getU32Encoder()],
['maxDataLen', getU64Encoder()],
]),
(value) => ({
Expand All @@ -114,7 +114,7 @@ export function getDeployWithMaxDataLenInstructionDataEncoder(): Encoder<DeployW

export function getDeployWithMaxDataLenInstructionDataDecoder(): Decoder<DeployWithMaxDataLenInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['discriminator', getU32Decoder()],
['maxDataLen', getU64Decoder()],
]);
}
Expand Down
8 changes: 3 additions & 5 deletions clients/js/src/generated/instructions/extendProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
getStructEncoder,
getU32Decoder,
getU32Encoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -35,7 +33,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const EXTEND_PROGRAM_DISCRIMINATOR = 6;

export function getExtendProgramDiscriminatorBytes() {
return getU8Encoder().encode(EXTEND_PROGRAM_DISCRIMINATOR);
return getU32Encoder().encode(EXTEND_PROGRAM_DISCRIMINATOR);
}

export type ExtendProgramInstruction<
Expand Down Expand Up @@ -76,7 +74,7 @@ export type ExtendProgramInstructionDataArgs = { additionalBytes: number };
export function getExtendProgramInstructionDataEncoder(): Encoder<ExtendProgramInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['discriminator', getU32Encoder()],
['additionalBytes', getU32Encoder()],
]),
(value) => ({ ...value, discriminator: EXTEND_PROGRAM_DISCRIMINATOR })
Expand All @@ -85,7 +83,7 @@ export function getExtendProgramInstructionDataEncoder(): Encoder<ExtendProgramI

export function getExtendProgramInstructionDataDecoder(): Decoder<ExtendProgramInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['discriminator', getU32Decoder()],
['additionalBytes', getU32Decoder()],
]);
}
Expand Down
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/initializeBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -30,7 +30,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const INITIALIZE_BUFFER_DISCRIMINATOR = 0;

export function getInitializeBufferDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_BUFFER_DISCRIMINATOR);
return getU32Encoder().encode(INITIALIZE_BUFFER_DISCRIMINATOR);
}

export type InitializeBufferInstruction<
Expand Down Expand Up @@ -58,13 +58,13 @@ export type InitializeBufferInstructionDataArgs = {};

export function getInitializeBufferInstructionDataEncoder(): Encoder<InitializeBufferInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
getStructEncoder([['discriminator', getU32Encoder()]]),
(value) => ({ ...value, discriminator: INITIALIZE_BUFFER_DISCRIMINATOR })
);
}

export function getInitializeBufferInstructionDataDecoder(): Decoder<InitializeBufferInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
return getStructDecoder([['discriminator', getU32Decoder()]]);
}

export function getInitializeBufferInstructionDataCodec(): Codec<
Expand Down
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/setAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -33,7 +33,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const SET_AUTHORITY_DISCRIMINATOR = 4;

export function getSetAuthorityDiscriminatorBytes() {
return getU8Encoder().encode(SET_AUTHORITY_DISCRIMINATOR);
return getU32Encoder().encode(SET_AUTHORITY_DISCRIMINATOR);
}

export type SetAuthorityInstruction<
Expand Down Expand Up @@ -68,13 +68,13 @@ export type SetAuthorityInstructionDataArgs = {};

export function getSetAuthorityInstructionDataEncoder(): Encoder<SetAuthorityInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
getStructEncoder([['discriminator', getU32Encoder()]]),
(value) => ({ ...value, discriminator: SET_AUTHORITY_DISCRIMINATOR })
);
}

export function getSetAuthorityInstructionDataDecoder(): Decoder<SetAuthorityInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
return getStructDecoder([['discriminator', getU32Decoder()]]);
}

export function getSetAuthorityInstructionDataCodec(): Codec<
Expand Down
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/setAuthorityChecked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -32,7 +32,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const SET_AUTHORITY_CHECKED_DISCRIMINATOR = 7;

export function getSetAuthorityCheckedDiscriminatorBytes() {
return getU8Encoder().encode(SET_AUTHORITY_CHECKED_DISCRIMINATOR);
return getU32Encoder().encode(SET_AUTHORITY_CHECKED_DISCRIMINATOR);
}

export type SetAuthorityCheckedInstruction<
Expand Down Expand Up @@ -68,7 +68,7 @@ export type SetAuthorityCheckedInstructionDataArgs = {};

export function getSetAuthorityCheckedInstructionDataEncoder(): Encoder<SetAuthorityCheckedInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
getStructEncoder([['discriminator', getU32Encoder()]]),
(value) => ({
...value,
discriminator: SET_AUTHORITY_CHECKED_DISCRIMINATOR,
Expand All @@ -77,7 +77,7 @@ export function getSetAuthorityCheckedInstructionDataEncoder(): Encoder<SetAutho
}

export function getSetAuthorityCheckedInstructionDataDecoder(): Decoder<SetAuthorityCheckedInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
return getStructDecoder([['discriminator', getU32Decoder()]]);
}

export function getSetAuthorityCheckedInstructionDataCodec(): Codec<
Expand Down
10 changes: 5 additions & 5 deletions clients/js/src/generated/instructions/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
getU32Decoder,
getU32Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -33,7 +33,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const UPGRADE_DISCRIMINATOR = 3;

export function getUpgradeDiscriminatorBytes() {
return getU8Encoder().encode(UPGRADE_DISCRIMINATOR);
return getU32Encoder().encode(UPGRADE_DISCRIMINATOR);
}

export type UpgradeInstruction<
Expand Down Expand Up @@ -86,13 +86,13 @@ export type UpgradeInstructionDataArgs = {};

export function getUpgradeInstructionDataEncoder(): Encoder<UpgradeInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
getStructEncoder([['discriminator', getU32Encoder()]]),
(value) => ({ ...value, discriminator: UPGRADE_DISCRIMINATOR })
);
}

export function getUpgradeInstructionDataDecoder(): Decoder<UpgradeInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
return getStructDecoder([['discriminator', getU32Decoder()]]);
}

export function getUpgradeInstructionDataCodec(): Codec<
Expand Down
8 changes: 3 additions & 5 deletions clients/js/src/generated/instructions/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
getStructEncoder,
getU32Decoder,
getU32Encoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
Expand All @@ -39,7 +37,7 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const WRITE_DISCRIMINATOR = 1;

export function getWriteDiscriminatorBytes() {
return getU8Encoder().encode(WRITE_DISCRIMINATOR);
return getU32Encoder().encode(WRITE_DISCRIMINATOR);
}

export type WriteInstruction<
Expand Down Expand Up @@ -76,7 +74,7 @@ export type WriteInstructionDataArgs = {
export function getWriteInstructionDataEncoder(): Encoder<WriteInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['discriminator', getU32Encoder()],
['offset', getU32Encoder()],
['bytes', addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())],
]),
Expand All @@ -86,7 +84,7 @@ export function getWriteInstructionDataEncoder(): Encoder<WriteInstructionDataAr

export function getWriteInstructionDataDecoder(): Decoder<WriteInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['discriminator', getU32Decoder()],
['offset', getU32Decoder()],
['bytes', addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())],
]);
Expand Down
18 changes: 9 additions & 9 deletions clients/js/src/generated/programs/loaderV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {
containsBytes,
getU8Encoder,
getU32Encoder,
type Address,
type ReadonlyUint8Array,
} from '@solana/web3.js';
Expand Down Expand Up @@ -41,28 +41,28 @@ export function identifyLoaderV3Instruction(
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array
): LoaderV3Instruction {
const data = 'data' in instruction ? instruction.data : instruction;
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
if (containsBytes(data, getU32Encoder().encode(0), 0)) {
return LoaderV3Instruction.InitializeBuffer;
}
if (containsBytes(data, getU8Encoder().encode(1), 0)) {
if (containsBytes(data, getU32Encoder().encode(1), 0)) {
return LoaderV3Instruction.Write;
}
if (containsBytes(data, getU8Encoder().encode(2), 0)) {
if (containsBytes(data, getU32Encoder().encode(2), 0)) {
return LoaderV3Instruction.DeployWithMaxDataLen;
}
if (containsBytes(data, getU8Encoder().encode(3), 0)) {
if (containsBytes(data, getU32Encoder().encode(3), 0)) {
return LoaderV3Instruction.Upgrade;
}
if (containsBytes(data, getU8Encoder().encode(4), 0)) {
if (containsBytes(data, getU32Encoder().encode(4), 0)) {
return LoaderV3Instruction.SetAuthority;
}
if (containsBytes(data, getU8Encoder().encode(5), 0)) {
if (containsBytes(data, getU32Encoder().encode(5), 0)) {
return LoaderV3Instruction.Close;
}
if (containsBytes(data, getU8Encoder().encode(6), 0)) {
if (containsBytes(data, getU32Encoder().encode(6), 0)) {
return LoaderV3Instruction.ExtendProgram;
}
if (containsBytes(data, getU8Encoder().encode(7), 0)) {
if (containsBytes(data, getU32Encoder().encode(7), 0)) {
return LoaderV3Instruction.SetAuthorityChecked;
}
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/generated/instructions/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Close {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct CloseInstructionData {
discriminator: u8,
discriminator: u32,
}

impl CloseInstructionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl DeployWithMaxDataLen {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct DeployWithMaxDataLenInstructionData {
discriminator: u8,
discriminator: u32,
}

impl DeployWithMaxDataLenInstructionData {
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/generated/instructions/extend_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ExtendProgram {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct ExtendProgramInstructionData {
discriminator: u8,
discriminator: u32,
}

impl ExtendProgramInstructionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl InitializeBuffer {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct InitializeBufferInstructionData {
discriminator: u8,
discriminator: u32,
}

impl InitializeBufferInstructionData {
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/generated/instructions/set_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl SetAuthority {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct SetAuthorityInstructionData {
discriminator: u8,
discriminator: u32,
}

impl SetAuthorityInstructionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl SetAuthorityChecked {

#[derive(BorshDeserialize, BorshSerialize)]
pub struct SetAuthorityCheckedInstructionData {
discriminator: u8,
discriminator: u32,
}

impl SetAuthorityCheckedInstructionData {
Expand Down
Loading
Loading