Skip to content

Commit

Permalink
Fixed transaction error decoding. (#385)
Browse files Browse the repository at this point in the history
* Fixed transaction error decoding.
Updated transaction and instruction error enums.

* Version bump.
  • Loading branch information
tiago18c authored May 9, 2022
1 parent e973e1a commit afe5c73
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 4 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.9</Version>
<Version>6.0.10</Version>
<Copyright>Copyright 2022 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
1 change: 0 additions & 1 deletion src/Solnet.Rpc/Converters/TransactionErrorJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public override TransactionError Read(ref Utf8JsonReader reader, Type typeToConv

Enum.TryParse(enumValue, ignoreCase: false, out TransactionErrorType errorType);
err.Type = errorType;
reader.Read();
return err;
}

Expand Down
14 changes: 13 additions & 1 deletion src/Solnet.Rpc/Models/InstructionError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ public enum InstructionErrorType
/// <summary>
/// Unsupported sysvar
/// </summary>
UnsupportedSysvar
UnsupportedSysvar,
/// <summary>
/// Illegal account owner.
/// </summary>
IllegalOwner,
/// <summary>
/// Account data allocation exceeded the maximum accounts data size limit.
/// </summary>
MaxAccountsDataSizeExceeded,
/// <summary>
/// Active vote account close.
/// </summary>
ActiveVoteAccountClose
}
}
50 changes: 49 additions & 1 deletion src/Solnet.Rpc/Models/TransactionError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,54 @@ public enum TransactionErrorType
/// <summary>
/// Transaction processing left an account with an outstanding borrowed reference
/// </summary>
AccountBorrowOutstanding
AccountBorrowOutstanding,
/// <summary>
/// Transaction would exceed max Block Cost Limit.
/// </summary>
WouldExceedMaxBlockCostLimit,
/// <summary>
/// Transaction version is unsupported.
/// </summary>
UnsupportedVersion,
/// <summary>
/// Transaction loads a writable account that cannot be written.
/// </summary>
InvalidWritableAccount,
/// <summary>
/// Transaction would exceed max account limit within the block.
/// </summary>
WouldExceedMaxAccountCostLimit,
/// <summary>
/// Transaction would exceed max account data limit within the block.
/// </summary>
WouldExceedMaxAccountDataCostLimit,
/// <summary>
/// Transaction locked too many accounts.
/// </summary>
TooManyAccountLocks,
/// <summary>
/// Address lookup table not found.
/// </summary>
AddressLookupTableNotFound,
/// <summary>
/// Attempted to lookup addresses from an account owned by the wrong program.
/// </summary>
InvalidAddressLookupTableOwner,
/// <summary>
/// Attempted to lookup addresses from an invalid account.
/// </summary>
InvalidAddressLookupTableData,
/// <summary>
/// Address table lookup uses an invalid index.
/// </summary>
InvalidAddressLookupTableIndex,
/// <summary>
/// Transaction leaves an account with a lower balance than rent-exempt minimum.
/// </summary>
InvalidRentPayingAccount,
/// <summary>
/// Transaction would exceed max Vote Cost Limit.
/// </summary>
WouldExceedMaxVoteCostLimit
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getTransaction","params":["3Q9mu4ePvtbtQzY1kpGmaViJKyBev6hgUppyXDF9hKgWHHnecwGLE2pSoFvNUF3h7acKyFwWd65bkwr9A1jN2CdT",{"encoding":"json"}],"jsonrpc":"2.0","id":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"jsonrpc": "2.0",
"result": {
"blockTime": 1651763621,
"meta": {
"err": "InvalidRentPayingAccount",
"fee": 10000,
"innerInstructions": [
{
"index": 1,
"instructions": [
{
"accounts": [ 0, 5 ],
"data": "1111cdZH8j1hhBYm8NusCzRNXkMPywbEQWh7ajL72yunGRac4kvcpsAEk5kwY5LSUdYz9",
"programIdIndex": 6
}
]
},
{
"index": 2,
"instructions": [
{
"accounts": [ 0, 2 ],
"data": "11119EY3pY6ic8YCxcYTfW2d4zG7J1os7p8ArhkwHR6Q1eSYdAYcgk4K5Smo7tPzP39fnM",
"programIdIndex": 6
}
]
}
],
"logMessages": [ "Program 11111111111111111111111111111111 invoke [1]", "Program 11111111111111111111111111111111 success", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw invoke [1]", "Program log: VERSION:\"2.2.4\"", "Program log: GOVERNANCE-INSTRUCTION: CreateProposal { name: \"Test 7\", description_link: \"test\", vote_type: SingleChoice, options: [\"Approve\"], use_deny_option: true }", "Program 11111111111111111111111111111111 invoke [2]", "Program 11111111111111111111111111111111 success", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw consumed 34297 of 1400000 compute units", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw success", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw invoke [1]", "Program log: VERSION:\"2.2.4\"", "Program log: GOVERNANCE-INSTRUCTION: AddSignatory { signatory: H5pamkZhqFna6stoe79SUt71JiTt34GssgtqoztxX6py }", "Program 11111111111111111111111111111111 invoke [2]", "Program 11111111111111111111111111111111 success", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw consumed 33340 of 1365703 compute units", "Program GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw success" ],
"postBalances": [ 9342509480, 0, 0, 2533440, 2853600, 0, 1, 0, 1461600, 2804880, 1141440 ],
"postTokenBalances": [],
"preBalances": [ 9342519480, 0, 0, 2533440, 2853600, 0, 1, 0, 1461600, 2804880, 1141440 ],
"preTokenBalances": [],
"rewards": [],
"status": { "Err": "InvalidRentPayingAccount" }
},
"slot": 132196637,
"transaction": {
"message": {
"accountKeys": [ "H5pamkZhqFna6stoe79SUt71JiTt34GssgtqoztxX6py", "7vESBnyT9te7ttTLsRnyijrtpZuC2EvR8t1ZazNy7Zx1", "3fsZJwjnGCDb2if1tpr1cRptXmwmJdAsRmf8XNJnVi8E", "9cbvyoAYdwM4eBzwDAgXdAWY5gh4StZr7EyJ8RxFZqeh", "FA9Fv1cLSsMcz22DbPJLKLf6onYjoD12gPJ2Fx4UoXk7", "Hup1keWQ661oxKtWukFGsXBE3Q8SxC4FYsS17MeuWuqj", "11111111111111111111111111111111", "37PCL91GdPRpVK22FLXSB25g8zt4Z4g6WF37RfXF3X3S", "4ZBkNCsFDTbi5hLqMGw5AKn54uXPR3P8Hd9QQ8KQfP5A", "61BnDwdR5DytKNHFVuk7HZ8suWRe3BXtJRuehLHrehxV", "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw" ],
"header": {
"numReadonlySignedAccounts": 0,
"numReadonlyUnsignedAccounts": 5,
"numRequiredSignatures": 2
},
"instructions": [
{
"accounts": [ 0, 1 ],
"data": "111184tZdEHhqyZiCTq5hAoWfNkcdCTdrZzybTVBSzbbe5ixfxFZVoqxaC99XuSFxWxM2A",
"programIdIndex": 6
},
{
"accounts": [ 9, 5, 3, 4, 8, 0, 0, 6, 7 ],
"data": "3erv9aqBLnJgmyNgaAc3mBzBdvNmQGZQq7eHW2Y7jWCyVvtM6",
"programIdIndex": 10
},
{
"accounts": [ 5, 4, 0, 2, 0, 6 ],
"data": "3Mh3BFGpuPawx6TNjELPWqRif4Ay9FWmYG3a7qStL8mYu",
"programIdIndex": 10
}
],
"recentBlockhash": "CxCWR5ecPFGjyYU3zsYQy6hHVwdTgzCDSpjxhde76pcW"
},
"signatures": [ "3Q9mu4ePvtbtQzY1kpGmaViJKyBev6hgUppyXDF9hKgWHHnecwGLE2pSoFvNUF3h7acKyFwWd65bkwr9A1jN2CdT", "c9mVsH3N6NjC5QcBP3SFuuvYUYUjuFdVLuQMYces5ffksdodLiRc9GKHEj6TUNFNtYbCFQc8aeY2AMBSNVnmJS7" ]
}
},
"id": 0
}
31 changes: 31 additions & 0 deletions test/Solnet.Rpc.Test/SolanaRpcClientBlockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,37 @@ public void TestGetTransaction()
FinishTest(messageHandlerMock, TestnetUri);
}

[TestMethod]
public void TestGetTransaction2()
{
var responseData = File.ReadAllText("Resources/Http/Transaction/GetTransactionResponse2.json");
var requestData = File.ReadAllText("Resources/Http/Transaction/GetTransactionRequest2.json");
var sentMessage = string.Empty;
var messageHandlerMock = SetupTest(
(s => sentMessage = s), responseData);

var httpClient = new HttpClient(messageHandlerMock.Object)
{
BaseAddress = TestnetUri
};
var sut = new SolanaRpcClient(TestnetUrl, null, httpClient);

var res = sut.GetTransaction("3Q9mu4ePvtbtQzY1kpGmaViJKyBev6hgUppyXDF9hKgWHHnecwGLE2pSoFvNUF3h7acKyFwWd65bkwr9A1jN2CdT");

Assert.AreEqual(requestData, sentMessage);
Assert.IsNotNull(res.Result);

Assert.AreEqual(132196637UL, res.Result.Slot);

Assert.AreEqual(1651763621, res.Result.BlockTime);

TransactionMetaInfo first = res.Result;

Assert.IsNotNull(first.Meta.Error);
Assert.AreEqual(TransactionErrorType.InvalidRentPayingAccount, first.Meta.Error.Type);
FinishTest(messageHandlerMock, TestnetUri);
}

[TestMethod]
public void TestGetTransactionProcessed()
{
Expand Down
6 changes: 6 additions & 0 deletions test/Solnet.Rpc.Test/Solnet.Rpc.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
<None Update="Resources\Http\Transaction\GetTransactionProcessedRequest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Http\Transaction\GetTransactionRequest2.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Http\Transaction\GetTransactionRequest.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -186,6 +189,9 @@
<None Update="Resources\Http\Blocks\GetBlockProductionNoArgsResponse.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Http\Transaction\GetTransactionResponse2.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\Http\Transaction\GetTransactionResponse.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit afe5c73

Please sign in to comment.