From b516a2513235e47a8cbc441336cafea1246609b5 Mon Sep 17 00:00:00 2001 From: steveluscher Date: Wed, 23 Mar 2022 21:08:10 -0700 Subject: [PATCH] fix: add TypeScript buffer type to instruction.ts --- web3.js/src/instruction.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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) {