Skip to content

Commit

Permalink
Added all commitment parameters to streaming client. (#96)
Browse files Browse the repository at this point in the history
Improved missing documentation related to streaming client and its objects.
Refactored test payloads for streaming client to improve navigation inside project.
Changed visibility in some objects that are unused outside of RPC project.
  • Loading branch information
tiago18c committed Jun 18, 2021
1 parent 386d76a commit f697e90
Show file tree
Hide file tree
Showing 40 changed files with 503 additions and 106 deletions.
38 changes: 38 additions & 0 deletions src/Solnet.Rpc/Cluster.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
namespace Solnet.Rpc
{
/// <summary>
/// Represents the public solana clusters.
/// </summary>
public enum Cluster
{
/// <summary>
/// Devnet serves as a playground for anyone who wants to take Solana for a test drive, as a user, token holder, app developer, or validator.
/// </summary>
/// <remarks>
/// Application developers should target Devnet.
/// Potential validators should first target Devnet.
/// Key points:
/// <list type="bullet">
/// <item>Devnet tokens are not real</item>
/// <item>Devnet includes a token faucet for airdrops for application testing</item>
/// <item>Devnet may be subject to ledger resets</item>
/// <item>Devnet typically runs a newer software version than Mainnet Beta</item>
/// </list>
/// </remarks>
DevNet,

/// <summary>
/// Testnet is where Solana stress tests recent release features on a live cluster, particularly focused on network performance, stability and validator behavior.
/// </summary>
/// <remarks>
/// Tour de SOL initiative runs on Testnet, where malicious behavior and attacks are encouraged on the network to help find and squash bugs or network vulnerabilities.
/// Key points:
/// <list type="bullet">
/// <item>Devnet tokens are not real</item>
/// <item>Devnet includes a token faucet for airdrops for application testing</item>
/// <item>Devnet may be subject to ledger resets</item>
/// <item>Testnet typically runs a newer software release than both Devnet and Mainnet Beta</item>
/// </list>
/// </remarks>
TestNet,

/// <summary>
/// A permissionless, persistent cluster for early token holders and launch partners. Currently, rewards and inflation are disabled.
/// </summary>
/// <remarks>
/// Tokens that are issued on Mainnet Beta are real SOL.
/// </remarks>
MainNet
}
}
26 changes: 25 additions & 1 deletion src/Solnet.Rpc/Core/Http/RequestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,45 @@

namespace Solnet.Rpc.Core.Http
{
/// <summary>
/// Represents the result of a given request.
/// </summary>
/// <typeparam name="T"></typeparam>
public class RequestResult<T>
{

/// <summary>
/// Returns <c>true</c> if the request was succesffully handled and parsed.
/// </summary>
public bool WasSuccessful { get => WasHttpRequestSuccessful && WasRequestSuccessfullyHandled; }

/// <summary>
/// Returns <c>true</c> if the HTTP request was successfull (e.g. Code 200).
/// </summary>
public bool WasHttpRequestSuccessful { get; }

/// <summary>
/// Returns <c>true</c> if the request was successfully handled by the server and no error parameters are found in the result.
/// </summary>
public bool WasRequestSuccessfullyHandled { get; internal set; }

/// <summary>
/// Returns a string with the reason for the error if <see cref="WasSuccessful"/> is <c>false</c>.
/// </summary>
public string Reason { get; internal set; }

/// <summary>
/// Returns the actual result of the request if <see cref="WasSuccessful"/> is <c>true</c>.
/// </summary>
public T Result { get; internal set; }

/// <summary>
/// Returns the <see cref="HttpStatusCode"/> of the request.
/// </summary>
public HttpStatusCode HttpStatusCode { get; }

/// <summary>
/// Returns the error code if one was found in the error object when the server is unable to handle the request.
/// </summary>
public int ServerErrorCode { get; internal set; }

internal RequestResult(HttpResponseMessage resultMsg, T result = default(T))
Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Rpc/Core/Sockets/IWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Solnet.Rpc.Core.Sockets
{
public interface IWebSocket : IDisposable
internal interface IWebSocket : IDisposable
{
WebSocketState State { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Rpc/Core/Sockets/StreamingRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Solnet.Rpc.Core.Sockets
/// <summary>
/// Base streaming Rpc client class that abstracts the websocket handling.
/// </summary>
public abstract class StreamingRpcClient
internal abstract class StreamingRpcClient
{
/// <summary>
/// The web socket client abstraction.
Expand Down
21 changes: 21 additions & 0 deletions src/Solnet.Rpc/Core/Sockets/SubscriptionChannel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
namespace Solnet.Rpc.Core.Sockets
{
/// <summary>
/// Represents the channel of a given subscription.
/// </summary>
public enum SubscriptionChannel
{
/// <summary>
/// Account subscription (<c>accountSubscribe</c>).
/// </summary>
Account,
/// <summary>
/// Logs subscription (<c>logsSubscribe</c>).
/// </summary>
Logs,
/// <summary>
/// Program subscription (<c>programSubscribe</c>).
/// </summary>
Program,
/// <summary>
/// Signature subscription (<c>signatureSubscribe</c>).
/// </summary>
Signature,
/// <summary>
/// Slot subscription (<c>slotSubscribe</c>).
/// </summary>
Slot,
/// <summary>
/// Root subscription (<c>rootSubscribe</c>).
/// </summary>
Root
}
}
5 changes: 4 additions & 1 deletion src/Solnet.Rpc/Core/Sockets/SubscriptionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public abstract class SubscriptionState
/// </summary>
public string LastCode { get; private set; }

private ImmutableList<object> AdditionalParameters { get; }
/// <summary>
/// The collection of parameters that were submitted for this subscription.
/// </summary>
public ImmutableList<object> AdditionalParameters { get; }

/// <summary>
/// Event fired when the state of the subcription changes.
Expand Down
60 changes: 50 additions & 10 deletions src/Solnet.Rpc/IStreamingRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,122 @@ public interface IStreamingRpcClient
/// <summary>
/// Subscribes asynchronously to AccountInfo notifications.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="pubkey">The public key of the account.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
Task<SubscriptionState> SubscribeAccountInfoAsync(string pubkey, Action<SubscriptionState, ResponseValue<AccountInfo>> callback);
Task<SubscriptionState> SubscribeAccountInfoAsync(string pubkey, Action<SubscriptionState, ResponseValue<AccountInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes to the AccountInfo. This is a synchronous and blocking function.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="pubkey">The public key of the account.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object representing the state of the subscription.</returns>
SubscriptionState SubscribeAccountInfo(string pubkey, Action<SubscriptionState, ResponseValue<AccountInfo>> callback);
SubscriptionState SubscribeAccountInfo(string pubkey, Action<SubscriptionState, ResponseValue<AccountInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes asynchronously to the logs notifications that mention a given public key.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="pubkey">The public key to filter by mention.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
Task<SubscriptionState> SubscribeLogInfoAsync(string pubkey, Action<SubscriptionState, ResponseValue<LogInfo>> callback);
Task<SubscriptionState> SubscribeLogInfoAsync(string pubkey, Action<SubscriptionState, ResponseValue<LogInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes asynchronously to the logs notifications.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="subscriptionType">The filter mechanism.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
Task<SubscriptionState> SubscribeLogInfoAsync(LogsSubscriptionType subscriptionType, Action<SubscriptionState, ResponseValue<LogInfo>> callback);
Task<SubscriptionState> SubscribeLogInfoAsync(LogsSubscriptionType subscriptionType, Action<SubscriptionState, ResponseValue<LogInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes to the logs notifications that mention a given public key. This is a synchronous and blocking function.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="pubkey">The public key to filter by mention.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object representing the state of the subscription.</returns>
SubscriptionState SubscribeLogInfo(string pubkey, Action<SubscriptionState, ResponseValue<LogInfo>> callback);
SubscriptionState SubscribeLogInfo(string pubkey, Action<SubscriptionState, ResponseValue<LogInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes to the logs notifications. This is a synchronous and blocking function.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="subscriptionType">The filter mechanism.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object representing the state of the subscription.</returns>
SubscriptionState SubscribeLogInfo(LogsSubscriptionType subscriptionType, Action<SubscriptionState, ResponseValue<LogInfo>> callback);
SubscriptionState SubscribeLogInfo(LogsSubscriptionType subscriptionType, Action<SubscriptionState, ResponseValue<LogInfo>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes asynchronously to a transaction signature to receive notification when the transaction is confirmed.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="transactionSignature">The transaction signature.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
Task<SubscriptionState> SubscribeSignatureAsync(string transactionSignature, Action<SubscriptionState, ResponseValue<ErrorResult>> callback);
Task<SubscriptionState> SubscribeSignatureAsync(string transactionSignature, Action<SubscriptionState, ResponseValue<ErrorResult>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes to a transaction signature to receive notification when the transaction is confirmed. This is a synchronous and blocking function.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="transactionSignature">The transaction signature.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object representing the state of the subscription.</returns>
SubscriptionState SubscribeSignature(string transactionSignature, Action<SubscriptionState, ResponseValue<ErrorResult>> callback);
SubscriptionState SubscribeSignature(string transactionSignature, Action<SubscriptionState, ResponseValue<ErrorResult>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes asynchronously to changes to a given program account data.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="programPubkey">The program pubkey.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
Task<SubscriptionState> SubscribeProgramAsync(string programPubkey, Action<SubscriptionState, ResponseValue<AccountKeyPair>> callback);
Task<SubscriptionState> SubscribeProgramAsync(string programPubkey, Action<SubscriptionState, ResponseValue<AccountKeyPair>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes to changes to a given program account data. This is a synchronous and blocking function.
/// </summary>
/// <remarks>
/// The <c>commitment</c> parameter is optional, the default value <see cref="Commitment.Finalized"/> is not sent.
/// </remarks>
/// <param name="programPubkey">The program pubkey.</param>
/// <param name="callback">The callback to handle data notifications.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object representing the state of the subscription.</returns>
SubscriptionState SubscribeProgram(string programPubkey, Action<SubscriptionState, ResponseValue<AccountKeyPair>> callback);
SubscriptionState SubscribeProgram(string programPubkey, Action<SubscriptionState, ResponseValue<AccountKeyPair>> callback, Commitment commitment = Commitment.Finalized);

/// <summary>
/// Subscribes asynchronously to receive notifications anytime a slot is processed by the validator.
Expand Down
Loading

0 comments on commit f697e90

Please sign in to comment.