gosol

package module
v0.0.0-...-32000b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 6 Imported by: 0

README

go-sol (WIP)

Simple, Opinionated, Lightweight, GoLang Solana Client

Usage

import (
    "github.com/Dank-del/go-sol"
    "fmt"
)

func main() {
    url := "https://api.devnet.solana.com"
    client := gosol.NewClient(url, nil)
    publicKey := "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg"
    response, err := client.GetAccountBalance(publicKey)
    if err != nil {
        t.Error("Error:", err)
        return
    }
    fmt.Println(response)
}

License

MIT License - see LICENSE for full text

Documentation

Index

Constants

View Source
const (
	// APIVersion is the version of the Solana API.
	APIVersion = "1.0.0"
	// DefaultURL is the devnet URL for the Solana API.
	DevnetURL = "https://api.devnet.solana.com"
	// JSONRPCVersion is the version of the JSON-RPC protocol.
	JSONRPCVersion = "2.0"
)

Variables

View Source
var (
	// DefaultHTTPClient is the default HTTP client for the Solana API.
	DefaultHTTPClient = &http.Client{}
	// DefaultClientOptions is the default options for the Solana API client.
	DefaultClientOptions = &ClientOptions{
		HttpClient: DefaultHTTPClient,
	}
)

Functions

This section is empty.

Types

type AccountInfo

type AccountInfo struct {
	Data       []string `json:"data,omitempty"`
	Executable bool     `json:"executable,omitempty"`
	Lamports   int64    `json:"lamports,omitempty"`
	Owner      string   `json:"owner,omitempty"`
	RentEpoch  int64    `json:"rentEpoch,omitempty"`
	Space      int64    `json:"space,omitempty"`
}

type BlockResult

type BlockResult struct {
	BlockHeight       int64                `json:"blockHeight"`
	BlockTime         interface{}          `json:"blockTime"`
	Blockhash         string               `json:"blockhash"`
	ParentSlot        int64                `json:"parentSlot"`
	PreviousBlockhash string               `json:"previousBlockhash"`
	Transactions      []TransactionElement `json:"transactions"`
}

type Client

type Client struct {
	BaseURL    string
	HttpClient *http.Client
}

Client represents a JSON-RPC client with a base URL.

func NewClient

func NewClient(baseURL string, opts *ClientOptions) *Client

NewClient creates a new JSON-RPC client with the specified base URL.

func (*Client) GetAccountBalance

func (c *Client) GetAccountBalance(publicKey string) (*RPCResponse[Result[int64]], error)

GetAccountBalance retrieves the account balance for a given public key.

func (*Client) GetAccountInfo

func (c *Client) GetAccountInfo(publicKey string) (*RPCResponse[Result[AccountInfo]], error)

func (*Client) GetBlock

func (c *Client) GetBlock(slotNumber int64, getBlockProps *GetBlockProps) (*RPCResponse[Result[BlockResult]], error)

func (*Client) GetBlockHeight

func (c *Client) GetBlockHeight() (*RPCResponse[int64], error)

func (*Client) GetBlockProduction

func (c *Client) GetBlockProduction() (*RPCResponse[Result[GetBlockProdResponse]], error)

GetBlockProduction retrieves the block production information from the Solana RPC endpoint.

type ClientOptions

type ClientOptions struct {
	HttpClient *http.Client
}

type Context

type Context struct {
	APIVersion string `json:"apiVersion,omitempty"`
	Slot       int64  `json:"slot,omitempty"`
}

type GetBlockProdResponse

type GetBlockProdResponse struct {
	ByIdentity map[string][]int64 `json:"byIdentity"`
	Range      *Range             `json:"range"`
}

type GetBlockProps

type GetBlockProps struct {
	Encoding                       string `json:"encoding"`
	MaxSupportedTransactionVersion int64  `json:"maxSupportedTransactionVersion"`
	TransactionDetails             string `json:"transactionDetails"`
	Rewards                        bool   `json:"rewards"`
}
type Header struct {
	NumReadonlySignedAccounts   int64 `json:"numReadonlySignedAccounts"`
	NumReadonlyUnsignedAccounts int64 `json:"numReadonlyUnsignedAccounts"`
	NumRequiredSignatures       int64 `json:"numRequiredSignatures"`
}

type Instruction

type Instruction struct {
	Accounts       []int64 `json:"accounts"`
	Data           string  `json:"data"`
	ProgramIDIndex int64   `json:"programIdIndex"`
}

type Message

type Message struct {
	AccountKeys     []string      `json:"accountKeys"`
	Header          *Header       `json:"header"`
	Instructions    []Instruction `json:"instructions"`
	RecentBlockhash string        `json:"recentBlockhash"`
}

type Meta

type Meta struct {
	Err               interface{}   `json:"err"`
	Fee               int64         `json:"fee"`
	InnerInstructions []interface{} `json:"innerInstructions"`
	LogMessages       []interface{} `json:"logMessages"`
	PostBalances      []int64       `json:"postBalances"`
	PostTokenBalances []interface{} `json:"postTokenBalances"`
	PreBalances       []int64       `json:"preBalances"`
	PreTokenBalances  []interface{} `json:"preTokenBalances"`
	Rewards           interface{}   `json:"rewards"`
	Status            *Status       `json:"status"`
}

type RPCRequest

type RPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      int         `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
}

RPCRequest represents a JSON-RPC request object.

type RPCResponse

type RPCResponse[T any | Result[T] | int64] struct {
	ID      int64  `json:"id,omitempty"`
	Jsonrpc string `json:"jsonrpc,omitempty"`
	Result  T      `json:"result,omitempty"`
}

type Range

type Range struct {
	FirstSlot int64 `json:"firstSlot"`
	LastSlot  int64 `json:"lastSlot"`
}

type Result

type Result[T any] struct {
	Context *Context `json:"context,omitempty"`
	Value   *T       `json:"value,omitempty"`
}

type Status

type Status struct {
	Ok interface{} `json:"Ok"`
}

type TransactionElement

type TransactionElement struct {
	Meta        *Meta                   `json:"meta"`
	Transaction *TransactionTransaction `json:"transaction"`
}

type TransactionTransaction

type TransactionTransaction struct {
	Message    *Message `json:"message"`
	Signatures []string `json:"signatures"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL