Skip to content

Commit

Permalink
Implements Epoch and Fee related methods (#58)
Browse files Browse the repository at this point in the history
* Implementing all Slot related methods and fixing some docs

* Implements fees and epoch rpc methods

* Deleting transaction models file
  • Loading branch information
hoakbuilds committed Jun 5, 2021
1 parent 14d6220 commit a1fb441
Show file tree
Hide file tree
Showing 17 changed files with 509 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Solnet.Rpc/IRpcClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Solnet.Rpc.Core.Http;
using Solnet.Rpc.Messages;
Expand Down Expand Up @@ -207,6 +208,53 @@ public interface IRpcClient
/// <inheritdoc cref="SolanaRpcClient.GetClusterNodesAsync"/>
RequestResult<ClusterNode[]> GetClusterNodes();

/// <summary>
/// Gets information about the current epoch.
/// </summary>
/// <returns>A task which may return a request result and information about the current epoch.</returns>
Task<RequestResult<EpochInfo>> GetEpochInfoAsync();

/// <inheritdoc cref="SolanaRpcClient.GetEpochInfoAsync"/>
RequestResult<EpochInfo> GetEpochInfo();

/// <summary>
/// Gets epoch schedule information from this cluster's genesis config.
/// </summary>
/// <returns>A task which may return a request result and epoch schedule information from this cluster's genesis config.</returns>
Task<RequestResult<EpochScheduleInfo>> GetEpochScheduleAsync();

/// <inheritdoc cref="SolanaRpcClient.GetEpochScheduleAsync"/>
RequestResult<EpochScheduleInfo> GetEpochSchedule();

/// <summary>
/// Gets the fee calculator associated with the query blockhash, or null if the blockhash has expired.
/// </summary>
/// <param name="blockhash">The blockhash to query, as base-58 encoded string.</param>
/// <returns>A task which may return a request result and the fee calculator for the block.</returns>
Task<RequestResult<ResponseValue<FeeCalculatorInfo>>> GetFeeCalculatorForBlockhashAsync(string blockhash);

/// <inheritdoc cref="SolanaRpcClient.GetFeeCalculatorForBlockhashAsync"/>
RequestResult<ResponseValue<FeeCalculatorInfo>> GetFeeCalculatorForBlockhash(string blockhash);

/// <summary>
/// Gets the fee rate governor information from the root bank.
/// </summary>
/// <returns>A task which may return a request result and the fee rate governor.</returns>
Task<RequestResult<ResponseValue<FeeRateGovernorInfo>>> GetFeeRateGovernorAsync();

/// <inheritdoc cref="SolanaRpcClient.GetFeeRateGovernorAsync"/>
RequestResult<ResponseValue<FeeRateGovernorInfo>> GetFeeRateGovernor();

/// <summary>
/// Gets a recent block hash from the ledger, a fee schedule that can be used to compute the
/// cost of submitting a transaction using it, and the last slot in which the blockhash will be valid.
/// </summary>
/// <returns>A task which may return a request result and information about fees.</returns>
Task<RequestResult<ResponseValue<FeesInfo>>> GetFeesAsync();

/// <inheritdoc cref="SolanaRpcClient.GetFeesAsync"/>
RequestResult<ResponseValue<FeesInfo>> GetFees();

/// <summary>
/// Gets a recent block hash.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Solnet.Rpc/Models/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ public class FeeCalculator
public ulong LamportsPerSignature { get; set; }
}

/// <summary>
/// Represents the fee calculator info.
/// </summary>
public class FeeCalculatorInfo
{
/// <summary>
/// The fee calculator info.
/// </summary>
public FeeCalculator FeeCalculator { get; set; }
}

/// <summary>
/// Represents block hash info.
/// </summary>
Expand Down
64 changes: 64 additions & 0 deletions src/Solnet.Rpc/Models/Epoch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace Solnet.Rpc.Models
{
/// <summary>
/// Represents information about the current epoch.
/// </summary>
public class EpochInfo
{
/// <summary>
/// The current slot.
/// </summary>
public ulong AbsoluteSlot { get; set; }

/// <summary>
/// The current block height.
/// </summary>
public ulong BlockHeight { get; set; }

/// <summary>
/// The current epoch.
/// </summary>
public ulong Epoch { get; set; }

/// <summary>
/// The current slot relative to the start of the current epoch.
/// </summary>
public ulong SlotIndex { get; set; }

/// <summary>
/// The number of slots in this epoch
/// </summary>
public ulong SlotsInEpoch { get; set; }
}

/// <summary>
/// Represents information about the epoch schedule.
/// </summary>
public class EpochScheduleInfo
{
/// <summary>
/// The maximum number of slots in each epoch.
/// </summary>
public ulong SlotsPerEpoch { get; set; }

/// <summary>
/// The number of slots before beginning of an epoch to calculate a leader schedule for that epoch.
/// </summary>
public ulong LeaderScheduleSlotOffset { get; set; }

/// <summary>
/// The first normal-length epoch.
/// </summary>
public ulong FirstNormalEpoch { get; set; }

/// <summary>
/// The first normal-length slot.
/// </summary>
public ulong FirstNormalSlot { get; set; }

/// <summary>
/// Whether epochs start short and grow.
/// </summary>
public bool Warmup { get; set; }
}
}
70 changes: 70 additions & 0 deletions src/Solnet.Rpc/Models/Fees.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace Solnet.Rpc.Models
{
/// <summary>
/// Represents the fee rate governor.
/// </summary>
public class FeeRateGovernor
{
/// <summary>
/// Percentage of fees collected to be destroyed.
/// </summary>
public decimal BurnPercent { get; set; }

/// <summary>
/// Highest value LamportsPerSignature can attain for the next slot.
/// </summary>
public ulong MaxLamportsPerSignature { get; set; }

/// <summary>
/// Smallest value LamportsPerSignature can attain for the next slot.
/// </summary>
public ulong MinLamportsPerSignature { get; set; }

/// <summary>
/// Desired fee rate for the cluster.
/// </summary>
public ulong TargetLamportsPerSignature { get; set; }

/// <summary>
/// Desired signature rate for the cluster.
/// </summary>
public ulong TargetSignaturesPerSlot { get; set; }
}

/// <summary>
/// Represents the fee rate governor info.
/// </summary>
public class FeeRateGovernorInfo
{
/// <summary>
/// The fee rate governor.
/// </summary>
public FeeRateGovernor FeeRateGovernor { get; set; }
}

/// <summary>
/// Represents information about the fees.
/// </summary>
public class FeesInfo
{
/// <summary>
/// A block hash as base-58 encoded string.
/// </summary>
public string Blockhash { get; set; }

/// <summary>
/// The fee calculator for this block hash.
/// </summary>
public FeeCalculator FeeCalculator { get; set; }

/// <summary>
/// DEPRECATED - this value is inaccurate and should not be relied upon
/// </summary>
public ulong LastValidSlot { get; set; }

/// <summary>
/// Last block height at which a blockhash will be valid.
/// </summary>
public ulong LastValidBlockHeight { get; set; }
}
}
66 changes: 66 additions & 0 deletions src/Solnet.Rpc/SolanaRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,72 @@ public async Task<RequestResult<ClusterNode[]>> GetClusterNodesAsync()
public RequestResult<ClusterNode[]> GetClusterNodes()
=> GetClusterNodesAsync().Result;

/// <summary>
/// Gets information about the current epoch.
/// </summary>
/// <returns>A task which may return a request result and information about the current epoch.</returns>
public async Task<RequestResult<EpochInfo>> GetEpochInfoAsync()
{
return await SendRequestAsync<EpochInfo>("getEpochInfo");
}

/// <inheritdoc cref="GetEpochInfoAsync"/>
public RequestResult<EpochInfo> GetEpochInfo() => GetEpochInfoAsync().Result;

/// <summary>
/// Gets epoch schedule information from this cluster's genesis config.
/// </summary>
/// <returns>A task which may return a request result and epoch schedule information from this cluster's genesis config.</returns>
public async Task<RequestResult<EpochScheduleInfo>> GetEpochScheduleAsync()
{
return await SendRequestAsync<EpochScheduleInfo>("getEpochSchedule");
}

/// <inheritdoc cref="GetEpochScheduleAsync"/>
public RequestResult<EpochScheduleInfo> GetEpochSchedule() => GetEpochScheduleAsync().Result;

/// <summary>
/// Gets the fee calculator associated with the query blockhash, or null if the blockhash has expired.
/// </summary>
/// <param name="blockhash">The blockhash to query, as base-58 encoded string.</param>
/// <returns>A task which may return a request result and the fee calculator for the block.</returns>
public async Task<RequestResult<ResponseValue<FeeCalculatorInfo>>> GetFeeCalculatorForBlockhashAsync(
string blockhash)
{
return await SendRequestAsync<ResponseValue<FeeCalculatorInfo>>("getFeeCalculatorForBlockhash",
new List<object> {blockhash});
}

/// <inheritdoc cref="GetFeeCalculatorForBlockhashAsync"/>
public RequestResult<ResponseValue<FeeCalculatorInfo>> GetFeeCalculatorForBlockhash(string blockhash) =>
GetFeeCalculatorForBlockhashAsync(blockhash).Result;

/// <summary>
/// Gets the fee rate governor information from the root bank.
/// </summary>
/// <returns>A task which may return a request result and the fee rate governor.</returns>
public async Task<RequestResult<ResponseValue<FeeRateGovernorInfo>>> GetFeeRateGovernorAsync()
{
return await SendRequestAsync<ResponseValue<FeeRateGovernorInfo>>("getFeeRateGovernor");
}

/// <inheritdoc cref="GetFeeRateGovernorAsync"/>
public RequestResult<ResponseValue<FeeRateGovernorInfo>> GetFeeRateGovernor()
=> GetFeeRateGovernorAsync().Result;

/// <summary>
/// Gets a recent block hash from the ledger, a fee schedule that can be used to compute the
/// cost of submitting a transaction using it, and the last slot in which the blockhash will be valid.
/// </summary>
/// <returns>A task which may return a request result and information about fees.</returns>
public async Task<RequestResult<ResponseValue<FeesInfo>>> GetFeesAsync()
{
return await SendRequestAsync<ResponseValue<FeesInfo>>("getFees");
}

/// <inheritdoc cref="GetFeesAsync"/>
public RequestResult<ResponseValue<FeesInfo>> GetFees() => GetFeesAsync().Result;

/// <summary>
/// Gets a recent block hash.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getEpochInfo","jsonrpc":"2.0","id":0}
11 changes: 11 additions & 0 deletions test/Solnet.Rpc.Test/Resources/Http/GetEpochInfoResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"jsonrpc": "2.0",
"result": {
"absoluteSlot": 166598,
"blockHeight": 166500,
"epoch": 27,
"slotIndex": 2790,
"slotsInEpoch": 8192
},
"id": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getEpochSchedule","jsonrpc":"2.0","id":0}
11 changes: 11 additions & 0 deletions test/Solnet.Rpc.Test/Resources/Http/GetEpochScheduleResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"jsonrpc": "2.0",
"result": {
"firstNormalEpoch": 8,
"firstNormalSlot": 8160,
"leaderScheduleSlotOffset": 8192,
"slotsPerEpoch": 8192,
"warmup": true
},
"id": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getFeeCalculatorForBlockhash","params":["GJxqhuxcgfn5Tcj6y3f8X4FeCDd2RQ6SnEMo1AAxrPRZ"],"jsonrpc":"2.0","id":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 221
},
"value": {
"feeCalculator": {
"lamportsPerSignature": 5000
}
}
},
"id": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getFeeRateGovernor","jsonrpc":"2.0","id":0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 54
},
"value": {
"feeRateGovernor": {
"burnPercent": 50,
"maxLamportsPerSignature": 100000,
"minLamportsPerSignature": 5000,
"targetLamportsPerSignature": 10000,
"targetSignaturesPerSlot": 20000
}
}
},
"id": 0
}
1 change: 1 addition & 0 deletions test/Solnet.Rpc.Test/Resources/Http/GetFeesRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method":"getFees","jsonrpc":"2.0","id":0}
17 changes: 17 additions & 0 deletions test/Solnet.Rpc.Test/Resources/Http/GetFeesResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 1
},
"value": {
"blockhash": "CSymwgTNX1j3E4qhKfJAUE41nBWEwXufoYryPbkde5RR",
"feeCalculator": {
"lamportsPerSignature": 5000
},
"lastValidSlot": 297,
"lastValidBlockHeight": 296
}
},
"id": 0
}
Loading

0 comments on commit a1fb441

Please sign in to comment.