From ec1e0b53c359200d801fa2042cb6b074a2e3f8a9 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Mon, 16 May 2022 18:13:31 +0100 Subject: [PATCH] Instruction decoder bug fix (#387) * Missing nullcheck from instruction decoder. * Version bump. --- SharedBuildProperties.props | 2 +- src/Solnet.Programs/InstructionDecoder.cs | 44 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/SharedBuildProperties.props b/SharedBuildProperties.props index 16247395..77a61e9d 100644 --- a/SharedBuildProperties.props +++ b/SharedBuildProperties.props @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> Solnet - 6.0.10 + 6.0.11 Copyright 2022 © Solnet blockmountain blockmountain diff --git a/src/Solnet.Programs/InstructionDecoder.cs b/src/Solnet.Programs/InstructionDecoder.cs index 215d8b2c..37d2d130 100644 --- a/src/Solnet.Programs/InstructionDecoder.cs +++ b/src/Solnet.Programs/InstructionDecoder.cs @@ -93,32 +93,34 @@ public static List DecodeInstructions(TransactionMetaInfo tx txMetaInfo.Transaction.Message.AccountKeys.Select(a => new PublicKey(a)).ToList(), instructionInfo.Accounts.Select(instr => (byte)instr).ToArray()); } - - foreach (InnerInstruction innerInstruction in txMetaInfo.Meta.InnerInstructions) + if (txMetaInfo.Meta.InnerInstructions != null) { - if (innerInstruction.Index != i) continue; - - foreach (InstructionInfo innerInstructionInfo in innerInstruction.Instructions) + foreach (InnerInstruction innerInstruction in txMetaInfo.Meta.InnerInstructions) { - DecodedInstruction innerDecodedInstruction = null; - programKey = txMetaInfo.Transaction.Message.AccountKeys[innerInstructionInfo.ProgramIdIndex]; - registered = InstructionDictionary.TryGetValue(programKey, out method); + if (innerInstruction.Index != i) continue; - if (!registered) - { - innerDecodedInstruction = AddUnknownInstruction( - innerInstructionInfo, programKey, txMetaInfo.Transaction.Message.AccountKeys, - txMetaInfo.Transaction.Message.Instructions[i].Accounts); - } - else + foreach (InstructionInfo innerInstructionInfo in innerInstruction.Instructions) { - innerDecodedInstruction = method.Invoke( - Encoders.Base58.DecodeData(innerInstructionInfo.Data), - txMetaInfo.Transaction.Message.AccountKeys.Select(a => new PublicKey(a)).ToList(), - innerInstructionInfo.Accounts.Select(instr => (byte)instr).ToArray()); + DecodedInstruction innerDecodedInstruction = null; + programKey = txMetaInfo.Transaction.Message.AccountKeys[innerInstructionInfo.ProgramIdIndex]; + registered = InstructionDictionary.TryGetValue(programKey, out method); + + if (!registered) + { + innerDecodedInstruction = AddUnknownInstruction( + innerInstructionInfo, programKey, txMetaInfo.Transaction.Message.AccountKeys, + txMetaInfo.Transaction.Message.Instructions[i].Accounts); + } + else + { + innerDecodedInstruction = method.Invoke( + Encoders.Base58.DecodeData(innerInstructionInfo.Data), + txMetaInfo.Transaction.Message.AccountKeys.Select(a => new PublicKey(a)).ToList(), + innerInstructionInfo.Accounts.Select(instr => (byte)instr).ToArray()); + } + if (innerDecodedInstruction != null) + decodedInstruction.InnerInstructions.Add(innerDecodedInstruction); } - if (innerDecodedInstruction != null) - decodedInstruction.InnerInstructions.Add(innerDecodedInstruction); } } if (decodedInstruction != null)