Skip to content

Commit

Permalink
Add stackHeight to the instruction type
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Jun 27, 2024
1 parent f1baa9e commit 05a31bf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 92 deletions.
2 changes: 2 additions & 0 deletions packages/rpc-api/src/__typetests__/get-block-type-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ async () => {
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>[];
}>[];
logMessages: readonly string[] | null;
Expand Down Expand Up @@ -736,6 +737,7 @@ async () => {
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>[];
}>[];
logMessages: readonly string[] | null;
Expand Down
3 changes: 3 additions & 0 deletions packages/rpc-api/src/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type TransactionInstruction = Readonly<{
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>;

type TransactionJson = Readonly<{
Expand All @@ -92,6 +93,7 @@ type PartiallyDecodedTransactionInstruction = Readonly<{
accounts: readonly Address[];
data: Base58EncodedBytes;
programId: Address;
stackHeight?: number;
}>;

type ParsedTransactionInstruction = Readonly<{
Expand All @@ -101,6 +103,7 @@ type ParsedTransactionInstruction = Readonly<{
};
program: string;
programId: Address;
stackHeight?: number;
}>;

type TransactionJsonParsed = Readonly<{
Expand Down
104 changes: 12 additions & 92 deletions packages/rpc-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {
AllowedNumericKeypaths,
getDefaultParamsTransformerForSolanaRpc,
getDefaultResponseTransformerForSolanaRpc,
innerInstructionsConfigs,
jsonParsedAccountsConfigs,
jsonParsedTokenAccountsConfigs,
KEYPATH_WILDCARD,
messageConfig,
ParamsTransformerConfig,
} from '@solana/rpc-transformers';

Expand Down Expand Up @@ -223,70 +225,15 @@ function getAllowedNumericKeypaths(): AllowedNumericKeypaths<RpcApi<SolanaRpcApi
'decimals',
],
['transactions', KEYPATH_WILDCARD, 'meta', 'rewards', KEYPATH_WILDCARD, 'commission'],
['transactions', KEYPATH_WILDCARD, 'meta', 'innerInstructions', KEYPATH_WILDCARD, 'index'],
[
...innerInstructionsConfigs.map(c => [
'transactions',
KEYPATH_WILDCARD,
'meta',
'innerInstructions',
KEYPATH_WILDCARD,
'instructions',
KEYPATH_WILDCARD,
'programIdIndex',
],
[
'transactions',
KEYPATH_WILDCARD,
'meta',
'innerInstructions',
KEYPATH_WILDCARD,
'instructions',
KEYPATH_WILDCARD,
'accounts',
KEYPATH_WILDCARD,
],
[
'transactions',
KEYPATH_WILDCARD,
'transaction',
'message',
'addressTableLookups',
KEYPATH_WILDCARD,
'writableIndexes',
KEYPATH_WILDCARD,
],
[
'transactions',
KEYPATH_WILDCARD,
'transaction',
'message',
'addressTableLookups',
KEYPATH_WILDCARD,
'readonlyIndexes',
KEYPATH_WILDCARD,
],
[
'transactions',
KEYPATH_WILDCARD,
'transaction',
'message',
'instructions',
KEYPATH_WILDCARD,
'programIdIndex',
],
[
'transactions',
KEYPATH_WILDCARD,
'transaction',
'message',
'instructions',
KEYPATH_WILDCARD,
'accounts',
KEYPATH_WILDCARD,
],
['transactions', KEYPATH_WILDCARD, 'transaction', 'message', 'header', 'numReadonlySignedAccounts'],
['transactions', KEYPATH_WILDCARD, 'transaction', 'message', 'header', 'numReadonlyUnsignedAccounts'],
['transactions', KEYPATH_WILDCARD, 'transaction', 'message', 'header', 'numRequiredSignatures'],
...c,
]),
...messageConfig.map(c => ['transactions', KEYPATH_WILDCARD, 'transaction', 'message', ...c] as const),
['rewards', KEYPATH_WILDCARD, 'commission'],
],
getBlockTime: [[]],
Expand Down Expand Up @@ -333,45 +280,18 @@ function getAllowedNumericKeypaths(): AllowedNumericKeypaths<RpcApi<SolanaRpcApi
['meta', 'postTokenBalances', KEYPATH_WILDCARD, 'accountIndex'],
['meta', 'postTokenBalances', KEYPATH_WILDCARD, 'uiTokenAmount', 'decimals'],
['meta', 'rewards', KEYPATH_WILDCARD, 'commission'],
['meta', 'innerInstructions', KEYPATH_WILDCARD, 'index'],
['meta', 'innerInstructions', KEYPATH_WILDCARD, 'instructions', KEYPATH_WILDCARD, 'programIdIndex'],
[
'meta',
'innerInstructions',
KEYPATH_WILDCARD,
'instructions',
KEYPATH_WILDCARD,
'accounts',
KEYPATH_WILDCARD,
],
[
'transaction',
'message',
'addressTableLookups',
KEYPATH_WILDCARD,
'writableIndexes',
KEYPATH_WILDCARD,
],
[
'transaction',
'message',
'addressTableLookups',
KEYPATH_WILDCARD,
'readonlyIndexes',
KEYPATH_WILDCARD,
],
['transaction', 'message', 'instructions', KEYPATH_WILDCARD, 'programIdIndex'],
['transaction', 'message', 'instructions', KEYPATH_WILDCARD, 'accounts', KEYPATH_WILDCARD],
['transaction', 'message', 'header', 'numReadonlySignedAccounts'],
['transaction', 'message', 'header', 'numReadonlyUnsignedAccounts'],
['transaction', 'message', 'header', 'numRequiredSignatures'],
...innerInstructionsConfigs.map(c => ['meta', 'innerInstructions', KEYPATH_WILDCARD, ...c]),
...messageConfig.map(c => ['transaction', 'message', ...c] as const),
],
getVersion: [['feature-set']],
getVoteAccounts: [
['current', KEYPATH_WILDCARD, 'commission'],
['delinquent', KEYPATH_WILDCARD, 'commission'],
],
simulateTransaction: jsonParsedAccountsConfigs.map(c => ['value', 'accounts', KEYPATH_WILDCARD, ...c]),
simulateTransaction: [
...jsonParsedAccountsConfigs.map(c => ['value', 'accounts', KEYPATH_WILDCARD, ...c]),
...innerInstructionsConfigs.map(c => ['value', 'innerInstructions', KEYPATH_WILDCARD, ...c]),
],
};
}
return memoizedKeypaths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ type ExpectedMetaForFullBase58 = {
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>[];
}>[];
logMessages: readonly string[] | null;
Expand Down Expand Up @@ -990,6 +991,7 @@ type ExpectedMetaForFullBase64 = {
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>[];
}>[];
logMessages: readonly string[] | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ export const jsonParsedAccountsConfigs = [
['data', 'parsed', 'info', 'commission'],
['data', 'parsed', 'info', 'votes', KEYPATH_WILDCARD, 'confirmationCount'],
];
const instructionConfig = [['accounts', KEYPATH_WILDCARD], ['programIdIndex'], ['stackHeight']];
export const innerInstructionsConfigs = [
['index'],
...instructionConfig.map(c => ['instructions', KEYPATH_WILDCARD, ...c]),
];
export const messageConfig = [
['addressTableLookups', KEYPATH_WILDCARD, 'writableIndexes', KEYPATH_WILDCARD],
['addressTableLookups', KEYPATH_WILDCARD, 'readonlyIndexes', KEYPATH_WILDCARD],
...instructionConfig.map(c => ['instructions', KEYPATH_WILDCARD, ...c]),
['header', 'numReadonlySignedAccounts'],
['header', 'numReadonlyUnsignedAccounts'],
['header', 'numRequiredSignatures'],
] as const;
3 changes: 3 additions & 0 deletions packages/rpc-types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ type ParsedTransactionInstruction = Readonly<{
};
program: string;
programId: Address;
stackHeight?: number;
}>;

type PartiallyDecodedTransactionInstruction = Readonly<{
accounts: readonly Address[];
data: Base58EncodedBytes;
programId: Address;
stackHeight?: number;
}>;

type ReturnData = {
Expand All @@ -44,6 +46,7 @@ type TransactionInstruction = Readonly<{
accounts: readonly number[];
data: Base58EncodedBytes;
programIdIndex: number;
stackHeight?: number;
}>;

type TransactionParsedAccountLegacy = Readonly<{
Expand Down

0 comments on commit 05a31bf

Please sign in to comment.