Skip to content

Commit

Permalink
Instruction decoder bug fix (#387)
Browse files Browse the repository at this point in the history
* Missing nullcheck from instruction decoder.

* Version bump.
  • Loading branch information
tiago18c authored May 16, 2022
1 parent af768ca commit ec1e0b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion SharedBuildProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Solnet</Product>
<Version>6.0.10</Version>
<Version>6.0.11</Version>
<Copyright>Copyright 2022 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
44 changes: 23 additions & 21 deletions src/Solnet.Programs/InstructionDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,34 @@ public static List<DecodedInstruction> 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)
Expand Down

0 comments on commit ec1e0b5

Please sign in to comment.