Skip to content

Commit

Permalink
Bumping solnet version, removing wrappers, fixing bug parsing tx erro…
Browse files Browse the repository at this point in the history
…rs and changes to optimize ser/des (#60)
  • Loading branch information
hoakbuilds authored Nov 24, 2021
1 parent 1b2ec84 commit 75bb6e8
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 57 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.Serum</Product>
<Version>1.0.5</Version>
<Version>1.0.6</Version>
<Copyright>Copyright 2021 &#169; Solnet</Copyright>
<Authors>blockmountain</Authors>
<PublisherName>blockmountain</PublisherName>
Expand Down
6 changes: 3 additions & 3 deletions Solnet.Serum.Examples/Solnet.Serum.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Solnet.Rpc" Version="0.4.11" />
<PackageReference Include="Solnet.Wallet" Version="0.4.11" />
<PackageReference Include="Solnet.KeyStore" Version="0.4.11" />
<PackageReference Include="Solnet.Rpc" Version="0.4.14" />
<PackageReference Include="Solnet.Wallet" Version="0.4.14" />
<PackageReference Include="Solnet.KeyStore" Version="0.4.14" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Solnet.Serum.Examples/SubscribeEventQueue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Solnet.Rpc;
using Solnet.Programs.Models;
using Solnet.Rpc.Core.Sockets;
using Solnet.Serum.Models;
using Solnet.Wallet;
Expand Down
1 change: 1 addition & 0 deletions Solnet.Serum.Examples/SubscribeOpenOrders.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Serum.Models;
using System;
Expand Down
1 change: 1 addition & 0 deletions Solnet.Serum.Examples/SubscribeOrderBook.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// unset

using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Serum.Models;
using System;
Expand Down
1 change: 1 addition & 0 deletions Solnet.Serum.Test/MarketManagerStreamingTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Serum.Models;
using Solnet.Wallet;
Expand Down
5 changes: 3 additions & 2 deletions Solnet.Serum.Test/MarketManagerTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Moq;
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Rpc.Core.Http;
using Solnet.Rpc.Core.Sockets;
using Solnet.Rpc.Messages;
using Solnet.Rpc.Models;
using Solnet.Rpc.Types;
using Solnet.Serum.Models;
using Solnet.Wallet;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -64,7 +64,8 @@ protected void MockGetAccountInfoAsync(Mock<IRpcClient> rpcMock, string address,
rpcMock
.Setup(s => s.GetAccountInfoAsync(
It.Is<string>(s1 => s1 == address),
It.Is<Commitment>(c => c == commitment)))
It.Is<Commitment>(c => c == commitment),
It.IsAny<BinaryEncoding>()))
.Callback(() => { })
.ReturnsAsync(new RequestResult<ResponseValue<AccountInfo>>(
new HttpResponseMessage(HttpStatusCode.OK),
Expand Down
3 changes: 1 addition & 2 deletions Solnet.Serum.Test/SerumClientStreamingTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Rpc.Core.Sockets;
using Solnet.Rpc.Messages;
using Solnet.Rpc.Models;
using Solnet.Rpc.Types;
using Solnet.Serum.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.WebSockets;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;

namespace Solnet.Serum.Test
{
Expand Down
3 changes: 2 additions & 1 deletion Solnet.Serum.Test/SerumClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private static Mock<IRpcClient> SetupGetAccountInfo(string responseContent, stri
rpcMock
.Setup(s => s.GetAccountInfoAsync(
It.Is<string>(s1 => s1 == address),
It.Is<Commitment>(c => c == commitment)))
It.Is<Commitment>(c => c == commitment),
It.IsAny<BinaryEncoding>()))
.ReturnsAsync(new RequestResult<ResponseValue<AccountInfo>>(
new HttpResponseMessage(HttpStatusCode.OK),
JsonSerializer.Deserialize<ResponseValue<AccountInfo>>(responseContent, JsonSerializerOptions))
Expand Down
1 change: 1 addition & 0 deletions Solnet.Serum/ISerumClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Rpc.Types;
using Solnet.Serum.Models;
Expand Down
21 changes: 9 additions & 12 deletions Solnet.Serum/MarketManager.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Microsoft.Extensions.Logging;
using Solnet.Programs;
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Rpc.Builders;
using Solnet.Rpc.Core.Http;
using Solnet.Rpc.Core.Sockets;
using Solnet.Rpc.Messages;
using Solnet.Rpc.Models;
using Solnet.Rpc.Types;
using Solnet.Rpc.Utilities;
using Solnet.Serum.Models;
using Solnet.Wallet;
using System;
Expand All @@ -16,7 +16,6 @@
using System.Numerics;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;

namespace Solnet.Serum
Expand Down Expand Up @@ -952,16 +951,14 @@ private async Task<SignatureConfirmation> SendTransactionAndSubscribeSignature(b

if (req.ServerErrorCode != 0)
{
if (req.ErrorData != null)
{
bool exists = req.ErrorData.TryGetValue("data", out object value);
if (!exists) return sigConf;
string elem = ((JsonElement)value).ToString();
if (elem == null) return sigConf;
SimulationLogs simulationLogs =
JsonSerializer.Deserialize<SimulationLogs>(elem, _jsonSerializerOptions);
sigConf.ChangeState(simulationLogs);
}
object value = null;
var exists = req.ErrorData?.TryGetValue("data", out value) ?? false;
if (!exists) return sigConf;
var elem = ((JsonElement)value).ToString();
if (elem == null) return sigConf;
var simulationLogs =
JsonSerializer.Deserialize<SimulationLogs>(elem, _jsonSerializerOptions);
sigConf.ChangeState(simulationLogs);

return sigConf;
}
Expand Down
4 changes: 2 additions & 2 deletions Solnet.Serum/Models/SlabLeafNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public class SlabLeafNode : SlabNode
/// <returns>The SlabNode structure.</returns>
public static new SlabLeafNode Deserialize(ReadOnlySpan<byte> data)
{
Span<byte> key = data.GetSpan(SlabNode.Layout.KeyOffset, Layout.KeyLength);
ulong price = ((ReadOnlySpan<byte>)key).GetU64(Layout.PriceOffset);
ReadOnlySpan<byte> key = data.GetSpan(SlabNode.Layout.KeyOffset, Layout.KeyLength);
ulong price = key.GetU64(Layout.PriceOffset);

return new SlabLeafNode
{
Expand Down
2 changes: 1 addition & 1 deletion Solnet.Serum/Models/SlabNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static SlabNode Deserialize(ReadOnlySpan<byte> data)
if (tag is (byte)NodeType.Uninitialized or (byte)NodeType.LastFreeNode or (byte)NodeType.FreeNode)
return null;

Span<byte> blob = data.GetSpan(Layout.BlobOffset, Layout.BlobSpanLength);
ReadOnlySpan<byte> blob = data.GetSpan(Layout.BlobOffset, Layout.BlobSpanLength);

return tag switch
{
Expand Down
29 changes: 0 additions & 29 deletions Solnet.Serum/Models/Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,6 @@

namespace Solnet.Serum.Models
{
/// <summary>
/// Wraps a subscription with a generic type to hold either order book or trade events.
/// </summary>
public class Subscription
{
/// <summary>
/// The address associated with this data.
/// </summary>
public PublicKey Address;

/// <summary>
/// The underlying subscription state.
/// </summary>
public SubscriptionState SubscriptionState;
}

/// <summary>
/// Wraps the base subscription to have the underlying data of the subscription, which is sometimes needed to perform
/// some logic before returning data to the subscription caller.
/// </summary>
/// <typeparam name="T">The type of the subscription.</typeparam>
internal class SubscriptionWrapper<T> : Subscription
{
/// <summary>
/// The underlying data.
/// </summary>
public T Data;
}

/// <summary>
/// Wraps the base request result and subscription state, provides an event handler to be notified when the given signature
/// is <see cref="Commitment.Confirmed"/>, with additional information in the context of the transaction and the execution of it's instructions.
Expand Down
1 change: 1 addition & 0 deletions Solnet.Serum/SerumClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Solnet.Programs;
using Solnet.Programs.Models;
using Solnet.Rpc;
using Solnet.Rpc.Core.Http;
using Solnet.Rpc.Core.Sockets;
Expand Down
6 changes: 3 additions & 3 deletions Solnet.Serum/Solnet.Serum.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0.0" />
<PackageReference Include="Solnet.Programs" Version="0.4.11" />
<PackageReference Include="Solnet.Rpc" Version="0.4.11" />
<PackageReference Include="Solnet.Wallet" Version="0.4.11" />
<PackageReference Include="Solnet.Programs" Version="0.4.14" />
<PackageReference Include="Solnet.Rpc" Version="0.4.14" />
<PackageReference Include="Solnet.Wallet" Version="0.4.14" />
</ItemGroup>


Expand Down

0 comments on commit 75bb6e8

Please sign in to comment.