diff --git a/web3.js/src/instruction.ts b/web3.js/src/instruction.ts index 4162143939..4097211a50 100644 --- a/web3.js/src/instruction.ts +++ b/web3.js/src/instruction.ts @@ -3,21 +3,28 @@ import * as BufferLayout from '@solana/buffer-layout'; import * as Layout from './layout'; +export interface IInstructionInputData { + readonly instruction: number; +} + /** * @internal */ -export type InstructionType = { +export type InstructionType = { /** The Instruction index (from solana upstream program) */ index: number; /** The BufferLayout to use to build data */ - layout: BufferLayout.Layout; + layout: BufferLayout.Layout; }; /** * Populate a buffer of instruction data using an InstructionType * @internal */ -export function encodeData(type: InstructionType, fields?: any): Buffer { +export function encodeData( + type: InstructionType, + fields?: any, +): Buffer { const allocLength = type.layout.span >= 0 ? type.layout.span : Layout.getAlloc(type, fields); const data = Buffer.alloc(allocLength); @@ -30,8 +37,11 @@ export function encodeData(type: InstructionType, fields?: any): Buffer { * Decode instruction data buffer using an InstructionType * @internal */ -export function decodeData(type: InstructionType, buffer: Buffer): any { - let data; +export function decodeData( + type: InstructionType, + buffer: Buffer, +): TInputData { + let data: TInputData; try { data = type.layout.decode(buffer); } catch (err) {