Skip to content

Commit

Permalink
Implements remaining RPC method commitment params (#103)
Browse files Browse the repository at this point in the history
Added all remaining commitments.
Fixed several methods mishandling parameters.
Properly implemented sendTransaction and simulateTransaction methods.
Refactored tests into multiple different classes to increase IDE performance.
Increased code coverage (some rpc methods weren't previously covered).
Fixed all remaining xml comments.
  • Loading branch information
tiago18c committed Jun 21, 2021
1 parent 8045297 commit 1896593
Show file tree
Hide file tree
Showing 109 changed files with 3,442 additions and 1,699 deletions.
2 changes: 1 addition & 1 deletion src/Solnet.Examples/SolnetRpcTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void Example(string[] args)
var inflation = c.GetInflationReward(
new List<string> { "25xzEf8cqLLEm2wyZTEBtCDchsUFm3SVESjs6eEFHJWe", "GPQdoUUDQXM1gWgRVwBbYmDqAgxoZN3bhVeKr1P8jd4c" });
Console.WriteLine(inflation.Result.Count);
var res = c.GetLargestAccounts("circulating");
var res = c.GetLargestAccounts(Rpc.Types.AccountFilterType.Circulating);
Console.WriteLine(res.Result.Value.Count);

var accs = c.GetMultipleAccounts(new List<string> { "Bbe9EKucmRtJr2J4dd5Eb5ybQmY7Fm7jYxKXxmmkLFsu", "9we6kjtbcZ2vy3GSLLsZTEhbAqXPTRvEyoxa8wxSqKp5" });
Expand Down
2 changes: 1 addition & 1 deletion src/Solnet.Rpc/Builders/TransactionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TransactionBuilder
private byte[] _serializedMessage;

/// <summary>
/// Initialize the transaction builder.
/// Default constructor that initializes the transaction builder.
/// </summary>
public TransactionBuilder()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Solnet.Rpc/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public static IRpcClient GetClient(Cluster cluster, ILogger logger = null)
{
Cluster.DevNet => RpcDevNet,
Cluster.TestNet => RpcTestNet,
Cluster.MainNet => RpcMainNet,
_ => RpcMainNet,
};

#if DEBUG
logger = logger ?? LoggerFactory.Create(x =>
logger ??= LoggerFactory.Create(x =>
{
x.AddSimpleConsole(o =>
{
Expand Down Expand Up @@ -95,10 +95,10 @@ public static IStreamingRpcClient GetStreamingClient(Cluster cluster, ILogger lo
{
Cluster.DevNet => StreamingRpcDevNet,
Cluster.TestNet => StreamingRpcTestNet,
Cluster.MainNet => StreamingRpcMainNet,
_ => StreamingRpcMainNet,
};
#if DEBUG
logger = logger ?? LoggerFactory.Create(x =>
logger ??= LoggerFactory.Create(x =>
{
x.AddSimpleConsole(o =>
{
Expand Down
125 changes: 125 additions & 0 deletions src/Solnet.Rpc/Core/Http/ConfigObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Solnet.Rpc.Core.Http
{
/// <summary>
/// Helper class that holds a key-value config pair that filters out null values.
/// </summary>
internal class KeyValue : Tuple<string, object>
{
private KeyValue(string item1, object item2) : base(item1, item2)
{
}

internal static KeyValue Create(string key, object value)
{
if(value != null)
{
return new KeyValue(key, value);
}
return null;
}
}

/// <summary>
/// Helper class to create configuration objects with key-value pairs that filters out null values.
/// </summary>
internal static class ConfigObject
{
internal static Dictionary<string, object> Create(KeyValue pair1)
{
if (pair1 != null)
{
return new Dictionary<string, object> { { pair1.Item1, pair1.Item2 } };
}
return null;
}

internal static Dictionary<string, object> Create(KeyValue pair1, KeyValue pair2)
{
var dict = Create(pair1) ?? new Dictionary<string, object>();

if(pair2 != null)
{
dict.Add(pair2.Item1, pair2.Item2);
}

return dict.Count > 0 ? dict : null;
}

internal static Dictionary<string, object> Create(KeyValue pair1, KeyValue pair2, KeyValue pair3)
{
var dict = Create(pair1, pair2) ?? new Dictionary<string, object>();

if(pair3 != null)
{
dict.Add(pair3.Item1, pair3.Item2);
}

return dict.Count > 0 ? dict : null;
}

internal static Dictionary<string, object> Create(KeyValue pair1, KeyValue pair2, KeyValue pair3, KeyValue pair4)
{
var dict = Create(pair1, pair2, pair3) ?? new Dictionary<string, object>();

if(pair4 != null)
{
dict.Add(pair4.Item1, pair4.Item2);
}

return dict.Count > 0 ? dict : null;
}

internal static Dictionary<string, object> Create(KeyValue pair1, KeyValue pair2, KeyValue pair3, KeyValue pair4, KeyValue pair5)
{
var dict = Create(pair1, pair2, pair3, pair4) ?? new Dictionary<string, object>();

if(pair5 != null)
{
dict.Add(pair5.Item1, pair5.Item2);
}

return dict.Count > 0 ? dict : null;
}
}

/// <summary>
/// Helper class that creates a List of parameters and filters out null values.
/// </summary>
internal static class Parameters
{
internal static List<object> Create(object val1)
{
if(val1 != null)
{
return new List<object> { val1 };
}
return null;
}

internal static List<object> Create(object val1, object val2)
{
var list = Create(val1) ?? new List<object>();
if(val2 != null)
{
list.Add(val2);
}
return list.Count > 0 ? list : null;
}

internal static List<object> Create(object val1, object val2, object val3)
{
var list = Create(val1, val2) ?? new List<object>();
if(val3 != null)
{
list.Add(val3);
}
return list.Count > 0 ? list : null;
}
}
}
2 changes: 1 addition & 1 deletion src/Solnet.Rpc/Core/Http/RequestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Solnet.Rpc.Core.Http
/// <summary>
/// Represents the result of a given request.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type of the result.</typeparam>
public class RequestResult<T>
{
/// <summary>
Expand Down
Loading

0 comments on commit 1896593

Please sign in to comment.