solana_exporter/pkg/rpc/responses.go

89 lines
2.0 KiB
Go
Raw Normal View History

2024-06-14 02:09:39 -07:00
package rpc
2024-10-02 05:47:04 -07:00
import (
"encoding/json"
"fmt"
)
2024-06-14 02:09:39 -07:00
type (
response[T any] struct {
2024-06-14 03:58:32 -07:00
Result T `json:"result"`
Error rpcError `json:"error"`
2024-06-14 02:09:39 -07:00
}
2024-10-02 05:47:04 -07:00
contextualResult[T any] struct {
Value T `json:"value"`
Context struct {
Slot int64 `json:"slot"`
}
}
2024-06-14 02:09:39 -07:00
EpochInfo struct {
// Current absolute slot in epoch
AbsoluteSlot int64 `json:"absoluteSlot"`
// Current block height
BlockHeight int64 `json:"blockHeight"`
// Current epoch number
Epoch int64 `json:"epoch"`
// Current slot relative to the start of the current epoch
SlotIndex int64 `json:"slotIndex"`
// Number of slots in this epoch
SlotsInEpoch int64 `json:"slotsInEpoch"`
2024-06-14 03:58:32 -07:00
// Total number of transactions
2024-06-14 02:09:39 -07:00
TransactionCount int64 `json:"transactionCount"`
}
VoteAccount struct {
ActivatedStake int64 `json:"activatedStake"`
Commission int `json:"commission"`
EpochCredits [][]int `json:"epochCredits"`
EpochVoteAccount bool `json:"epochVoteAccount"`
LastVote int `json:"lastVote"`
NodePubkey string `json:"nodePubkey"`
RootSlot int `json:"rootSlot"`
VotePubkey string `json:"votePubkey"`
}
VoteAccounts struct {
Current []VoteAccount `json:"current"`
Delinquent []VoteAccount `json:"delinquent"`
}
2024-10-02 05:47:04 -07:00
HostProduction struct {
LeaderSlots int64
BlocksProduced int64
2024-06-14 03:58:32 -07:00
}
2024-10-02 05:47:04 -07:00
BlockProductionRange struct {
FirstSlot int64 `json:"firstSlot"`
LastSlot int64 `json:"lastSlot"`
2024-06-14 03:58:32 -07:00
}
2024-10-02 05:47:04 -07:00
BlockProduction struct {
ByIdentity map[string]HostProduction `json:"byIdentity"`
Range BlockProductionRange `json:"range"`
2024-06-14 03:58:32 -07:00
}
2024-10-02 05:47:04 -07:00
)
2024-06-14 03:58:32 -07:00
2024-10-02 05:47:04 -07:00
func (hp *HostProduction) UnmarshalJSON(data []byte) error {
var arr []int64
if err := json.Unmarshal(data, &arr); err != nil {
return err
2024-06-14 02:09:39 -07:00
}
2024-10-01 02:52:02 -07:00
2024-10-02 05:47:04 -07:00
if len(arr) != 2 {
return fmt.Errorf("expected array of 2 integers, got %d", len(arr))
2024-10-01 02:52:02 -07:00
}
2024-10-02 05:47:04 -07:00
hp.LeaderSlots = arr[0]
hp.BlocksProduced = arr[1]
return nil
}
2024-06-14 02:09:39 -07:00
2024-06-14 03:58:32 -07:00
func (r response[T]) getError() rpcError {
2024-06-14 02:09:39 -07:00
return r.Error
}
type HasRPCError interface {
2024-06-14 03:58:32 -07:00
getError() rpcError
2024-06-14 02:09:39 -07:00
}