github.com/gagliardetto/solana-go@v1.11.0/rpc/getVoteAccounts.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rpc 16 17 import ( 18 "context" 19 20 "github.com/gagliardetto/solana-go" 21 ) 22 23 type GetVoteAccountsOpts struct { 24 Commitment CommitmentType `json:"commitment,omitempty"` 25 26 // (optional) Only return results for this validator vote address. 27 VotePubkey *solana.PublicKey `json:"votePubkey,omitempty"` 28 29 // (optional) Do not filter out delinquent validators with no stake. 30 KeepUnstakedDelinquents *bool `json:"keepUnstakedDelinquents,omitempty"` 31 32 // (optional) Specify the number of slots behind the tip that 33 // a validator must fall to be considered delinquent. 34 // NOTE: For the sake of consistency between ecosystem products, 35 // it is not recommended that this argument be specified. 36 DelinquentSlotDistance *uint64 `json:"delinquentSlotDistance,omitempty"` 37 } 38 39 // GetVoteAccounts returns the account info and associated 40 // stake for all the voting accounts in the current bank. 41 func (cl *Client) GetVoteAccounts( 42 ctx context.Context, 43 opts *GetVoteAccountsOpts, 44 ) (out *GetVoteAccountsResult, err error) { 45 params := []interface{}{} 46 if opts != nil { 47 obj := M{} 48 if opts.Commitment != "" { 49 obj["commitment"] = string(opts.Commitment) 50 } 51 if opts.VotePubkey != nil { 52 obj["votePubkey"] = opts.VotePubkey.String() 53 } 54 if opts.KeepUnstakedDelinquents != nil { 55 obj["keepUnstakedDelinquents"] = opts.KeepUnstakedDelinquents 56 } 57 if opts.DelinquentSlotDistance != nil { 58 obj["delinquentSlotDistance"] = opts.DelinquentSlotDistance 59 } 60 if len(obj) > 0 { 61 params = append(params, obj) 62 } 63 } 64 err = cl.rpcClient.CallForInto(ctx, &out, "getVoteAccounts", params) 65 return 66 } 67 68 type GetVoteAccountsResult struct { 69 Current []VoteAccountsResult `json:"current"` 70 Delinquent []VoteAccountsResult `json:"delinquent"` 71 } 72 73 type VoteAccountsResult struct { 74 // Vote account address. 75 VotePubkey solana.PublicKey `json:"votePubkey,omitempty"` 76 77 // Validator identity. 78 NodePubkey solana.PublicKey `json:"nodePubkey,omitempty"` 79 80 // The stake, in lamports, delegated to this vote account and active in this epoch. 81 ActivatedStake uint64 `json:"activatedStake,omitempty"` 82 83 // Whether the vote account is staked for this epoch. 84 EpochVoteAccount bool `json:"epochVoteAccount,omitempty"` 85 86 // Percentage (0-100) of rewards payout owed to the vote account. 87 Commission uint8 `json:"commission,omitempty"` 88 89 // Most recent slot voted on by this vote account. 90 LastVote uint64 `json:"lastVote,omitempty"` 91 92 RootSlot uint64 `json:"rootSlot,omitempty"` // 93 94 // History of how many credits earned by the end of each epoch, 95 // as an array of arrays containing: [epoch, credits, previousCredits] 96 EpochCredits [][]int64 `json:"epochCredits,omitempty"` 97 }