Skip to content

Commit

Permalink
Implementing getVoteAccounts rpc method (#47)
Browse files Browse the repository at this point in the history
* Implementing getVoteAccounts rpc method
  • Loading branch information
hoakbuilds committed Jun 3, 2021
1 parent e76b700 commit 43cf099
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 43 deletions.
23 changes: 14 additions & 9 deletions src/Solnet.Examples/SolnetRpcTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ static void Main(string[] args)

//var blockTime = c.GetBlockTime(78561320);

var cn = c.GetClusterNodes();
var bh = c.GetBlockHeight();
Console.WriteLine(bh.Result);
var identity = c.GetIdentity();
Console.WriteLine(identity.Result.Identity);
//var cn = c.GetClusterNodes();
//var bh = c.GetBlockHeight();
//Console.WriteLine(bh.Result);
//var identity = c.GetIdentity();
//Console.WriteLine(identity.Result.Identity);

var inflationGov = c.GetInflationGovernor();
Console.WriteLine(inflationGov.Result.Terminal);
//var inflationGov = c.GetInflationGovernor();
//Console.WriteLine(inflationGov.Result.Terminal);

var inflationRate = c.GetInflationRate();
Console.WriteLine(inflationRate.Result.Total);
//var inflationRate = c.GetInflationRate();
//Console.WriteLine(inflationRate.Result.Total);

var va = c.GetVoteAccounts();

Console.WriteLine(va.Result.Current.Length);
Console.WriteLine(va.Result.Delinquent.Length);

/* Large accounts for Token Mint PubKey
var largeAccounts = c.GetTokenLargestAccounts("7ugkvt26sFjMdiFQFP5AQX8m8UkxWaW7rk2nBk4R6Gf2");
Expand Down
32 changes: 23 additions & 9 deletions src/Solnet.Rpc/IRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public interface IRpcClient

/// <inheritdoc cref="SolanaRpcClient.GetGenesisHashAsync"/>
RequestResult<string> GetGenesisHash();

/// <summary>
/// Gets the identity pubkey for the current node.
/// </summary>
Expand All @@ -119,7 +119,7 @@ public interface IRpcClient

/// <inheritdoc cref="SolanaRpcClient.GetIdentityAsync"/>
RequestResult<NodeIdentity> GetIdentity();

/// <summary>
/// Gets the current inflation governor.
/// </summary>
Expand All @@ -128,7 +128,7 @@ public interface IRpcClient

/// <inheritdoc cref="SolanaRpcClient.GetInflationGovernorAsync"/>
RequestResult<InflationGovernor> GetInflationGovernor();

/// <summary>
/// Gets the specific inflation values for the current epoch.
/// </summary>
Expand All @@ -137,7 +137,7 @@ public interface IRpcClient

/// <inheritdoc cref="SolanaRpcClient.GetInflationRateAsync"/>
RequestResult<InflationRate> GetInflationRate();

/// <summary>
/// Gets the inflation reward for a list of addresses for an epoch.
/// </summary>
Expand Down Expand Up @@ -223,6 +223,15 @@ RequestResult<ResponseValue<TokenAccount[]>> GetTokenAccountsByOwner(
/// <inheritdoc cref="SolanaRpcClient.GetTransactionCountAsync"/>
RequestResult<ulong> GetTransactionCount();

/// <summary>
/// Gets the account info and associated stake for all voting accounts in the current bank.
/// </summary>
/// <returns>A task which may return a request result and information about the vote accounts.</returns>
Task<RequestResult<VoteAccounts>> GetVoteAccountsAsync();

/// <inheritdoc cref="SolanaRpcClient.GetVoteAccountsAsync"/>
RequestResult<VoteAccounts> GetVoteAccounts();

/// <summary>
/// Gets the lowest slot that the node has information about in its ledger.
/// <remarks>
Expand All @@ -245,10 +254,12 @@ RequestResult<ResponseValue<TokenAccount[]>> GetTokenAccountsByOwner(
/// <param name="lamports">The amount of lamports to request.</param>
/// <param name="commitment">The block commitment used to retrieve block hashes and verify success.</param>
/// <returns>A task which may return a request result and the transaction signature of the airdrop, as base-58 encoded string..</returns>
Task<RequestResult<string>> RequestAirdropAsync(string pubKey, ulong lamports, Commitment commitment = Commitment.Finalized);
Task<RequestResult<string>> RequestAirdropAsync(string pubKey, ulong lamports,
Commitment commitment = Commitment.Finalized);

/// <inheritdoc cref="SolanaRpcClient.RequestAirdropAsync"/>
RequestResult<string> RequestAirdrop(string pubKey, ulong lamports, Commitment commitment = Commitment.Finalized);
RequestResult<string> RequestAirdrop(string pubKey, ulong lamports,
Commitment commitment = Commitment.Finalized);

/// <summary>
/// Sends a transaction.
Expand All @@ -258,7 +269,8 @@ RequestResult<ResponseValue<TokenAccount[]>> GetTokenAccountsByOwner(
/// <returns>
/// A task which may return a request result and the first transaction signature embedded in the transaction, as base-58 encoded string.
/// </returns>
Task<RequestResult<string>> SendTransactionAsync(string transaction, BinaryEncoding encoding = BinaryEncoding.Base64);
Task<RequestResult<string>> SendTransactionAsync(string transaction,
BinaryEncoding encoding = BinaryEncoding.Base64);

/// <inheritdoc cref="SolanaRpcClient.SendTransactionAsync"/>
RequestResult<string> SendTransaction(string transaction, BinaryEncoding encoding = BinaryEncoding.Base64);
Expand All @@ -280,10 +292,12 @@ RequestResult<ResponseValue<TokenAccount[]>> GetTokenAccountsByOwner(
/// <returns>
/// A task which may return a request result and the transaction status.
/// </returns>
Task<RequestResult<ResponseValue<SimulationLogs>>> SimulateTransactionAsync(string transaction, BinaryEncoding encoding = BinaryEncoding.Base64);
Task<RequestResult<ResponseValue<SimulationLogs>>> SimulateTransactionAsync(string transaction,
BinaryEncoding encoding = BinaryEncoding.Base64);

/// <inheritdoc cref="SolanaRpcClient.SimulateTransactionAsync"/>
RequestResult<ResponseValue<SimulationLogs>> SimulateTransaction(string transaction, BinaryEncoding encoding = BinaryEncoding.Base64);
RequestResult<ResponseValue<SimulationLogs>> SimulateTransaction(string transaction,
BinaryEncoding encoding = BinaryEncoding.Base64);

/// <summary>
/// Simulate sending a transaction.
Expand Down
71 changes: 71 additions & 0 deletions src/Solnet.Rpc/Models/VoteAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Text.Json.Serialization;

namespace Solnet.Rpc.Models
{
/// <summary>
/// Represents the account info and associated stake for all the voting accounts in the current bank.
/// </summary>
public class VoteAccount
{
/// <summary>
/// The root slot for this vote account.
/// </summary>
public ulong RootSlot { get; set; }

/// <summary>
/// The vote account address, as a base-58 encoded string.
/// </summary>
[JsonPropertyName("votePubkey")]
public string VotePublicKey { get; set; }

/// <summary>
/// The validator identity, as a base-58 encoded string.
/// </summary>
[JsonPropertyName("nodePubkey")]
public string NodePublicKey { get; set; }

/// <summary>
/// The stake, in lamports, delegated to this vote account and active in this epoch.
/// </summary>
public ulong ActivatedStake { get; set; }

/// <summary>
/// Whether the vote account is staked for this epoch.
/// </summary>
public bool EpochVoteAccount { get; set; }

/// <summary>
/// Percentage of rewards payout owed to the vote account.
/// </summary>
public decimal Commission { get; set; }

/// <summary>
/// Most recent slot voted on by this vote account.
/// </summary>
public ulong LastVote { get; set; }

/// <summary>
/// History of how many credits earned by the end of the each epoch.
/// <remarks>
/// Each array contains [epoch, credits, previousCredits];
/// </remarks>
/// </summary>
public ulong[][] EpochCredits { get; set; }
}

/// <summary>
/// Represents the vote accounts.
/// </summary>
public class VoteAccounts
{
/// <summary>
/// Current vote accounts.
/// </summary>
public VoteAccount[] Current { get; set; }

/// <summary>
/// Delinquent vote accounts.
/// </summary>
public VoteAccount[] Delinquent { get; set; }
}
}
Loading

0 comments on commit 43cf099

Please sign in to comment.