goyser

package module
v0.0.0-...-9d33e1f Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

README

Geyser Yellowstone SDK

GoDoc Go Report Card License

This library contains tooling to interact with Yellowstone Geyser Plugin. Work in progress. 👷

yellowstone

❇️ Contents

🛟 Support

If my work has been useful in building your for-profit services/infra/bots/etc, consider donating at EcrHvqa5Vh4NhR3bitRZVrdcUGr1Z3o6bXHz7xgBU2FB (SOL).

📡 Methods

  • SubscribeAccounts
    • AppendAccounts
    • UnsubscribeAccounts
    • UnsubscribeAccountsByID
    • UnsubscribeAllAccounts
  • SubscribeSlots
    • UnsubscribeSlots
  • SubscribeTransaction
    • UnsubscribeTransaction
  • SubscribeTransactionStatus
    • UnsubscribeTransactionStatus
  • SubscribeBlocks
    • UnsubscribeBlocks
  • SubscribeBlocksMeta
    • UnsubscribeBlocksMeta
  • SubscribeEntry
    • UnsubscribeEntry
  • SubscribeAccountDataSlice
    • UnsubscribeAccountDataSlice

It also contains a feature to convert Goyser types to github.com/gagliardetto/solana-go types :)

💾 Installing

Go 1.22.0 or higher.

go get github.com/weeaa/goyser@latest

💻 Examples

Subscribe to Account

Simple example on how to monitor an account for transactions with explanations.

package main

import (
  "context"
  "github.com/weeaa/goyser"
  "github.com/weeaa/goyser/pb"
  "log"
  "os"
  "time"
)

const subAccount = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"

func main() {
  ctx := context.Background()

  // get the geyser rpc address
  geyserRPC := os.Getenv("GEYSER_RPC")

  // create geyser client
  client, err := goyser.New(ctx, geyserRPC, nil)
  if err != nil {
    log.Fatal(err)
  }

  // create a new subscribe client which is tied, for our example we will name it main
  // the created client is stored in client.Streams
  if err = client.AddStreamClient(ctx, "main"); err != nil {
    log.Fatal(err)
  }

  // get the stream client
  streamClient := client.GetStreamClient("main")
  if streamClient == nil {
    log.Fatal("client does not have a stream named main")
  }

  // subscribe to the account you want to see txns from and set a custom filter name to filter them out later
  if err = streamClient.SubscribeAccounts("accounts", &geyser_pb.SubscribeRequestFilterAccounts{
    Account: []string{subAccount},
  }); err != nil {
    log.Fatal(err)
  }

  // loop through the stream and print the output
  for out := range streamClient.Ch {
    // u can filter the output by checking the filters
    go func() {
      filters := out.GetFilters()
      for _, filter := range filters {
        switch filter {
        case "accounts":
          log.Printf("account filter: %+v", out.GetAccount())
        default:
          log.Printf("unknown filter: %s", filter)
        }
      }
    }()
    break
  }

  time.Sleep(5 * time.Second)

  // unsubscribe from the account
  if err = streamClient.UnsubscribeAccounts("accounts", subAccount); err != nil {
    log.Fatal(err)
  }
}

📃 License

Apache-2.0 License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchConvertBlockHash

func BatchConvertBlockHash(geyserBlocks ...*geyser_pb.SubscribeUpdateBlock) []*rpc.GetBlockResult

func BatchConvertTransaction

func BatchConvertTransaction(geyserTxns ...*geyser_pb.SubscribeUpdateTransaction) []*solana.Transaction

func ConvertBlockHash

func ConvertBlockHash(geyserBlock *geyser_pb.SubscribeUpdateBlock) *rpc.GetBlockResult

ConvertBlockHash converts a Geyser type block to a github.com/gagliardetto/solana-go Solana block.

func ConvertTransaction

func ConvertTransaction(geyserTx *geyser_pb.SubscribeUpdateTransaction) *solana.Transaction

Types

type Client

type Client struct {
	Ctx    context.Context
	Geyser geyser_pb.GeyserClient
	ErrCh  chan error
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, grpcDialURL string, md metadata.MD) (*Client, error)

func (*Client) AddStreamClient

func (c *Client) AddStreamClient(ctx context.Context, streamName string, opts ...grpc.CallOption) error

AddStreamClient creates a new Geyser subscribe stream client.

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetStreamClient

func (c *Client) GetStreamClient(streamName string) *StreamClient

type StreamClient

type StreamClient struct {
	Ctx context.Context

	Ch    chan *geyser_pb.SubscribeUpdate
	ErrCh chan error
	// contains filtered or unexported fields
}

func (*StreamClient) AppendAccounts

func (s *StreamClient) AppendAccounts(filterName string, accounts ...string) error

AppendAccounts appends accounts to an existing subscription and sends the request.

func (*StreamClient) GetAccounts

func (s *StreamClient) GetAccounts(filterName string) []string

func (*StreamClient) Stop

func (s *StreamClient) Stop()

func (*StreamClient) SubscribeAccountDataSlice

func (s *StreamClient) SubscribeAccountDataSlice(req []*geyser_pb.SubscribeRequestAccountsDataSlice) error

SubscribeAccountDataSlice subscribes to account data slice updates.

func (*StreamClient) SubscribeAccounts

func (s *StreamClient) SubscribeAccounts(filterName string, req *geyser_pb.SubscribeRequestFilterAccounts) error

SubscribeAccounts subscribes to account updates. Note: This will overwrite existing subscriptions for the given ID. To add new accounts without overwriting, use AppendAccounts.

func (*StreamClient) SubscribeBlocks

func (s *StreamClient) SubscribeBlocks(filterName string, req *geyser_pb.SubscribeRequestFilterBlocks) error

SubscribeBlocks subscribes to block updates.

func (*StreamClient) SubscribeBlocksMeta

func (s *StreamClient) SubscribeBlocksMeta(filterName string, req *geyser_pb.SubscribeRequestFilterBlocksMeta) error

SubscribeBlocksMeta subscribes to block metadata updates.

func (*StreamClient) SubscribeEntry

func (s *StreamClient) SubscribeEntry(filterName string, req *geyser_pb.SubscribeRequestFilterEntry) error

SubscribeEntry subscribes to entry updates.

func (*StreamClient) SubscribeSlots

func (s *StreamClient) SubscribeSlots(filterName string, req *geyser_pb.SubscribeRequestFilterSlots) error

SubscribeSlots subscribes to slot updates.

func (*StreamClient) SubscribeTransaction

func (s *StreamClient) SubscribeTransaction(filterName string, req *geyser_pb.SubscribeRequestFilterTransactions) error

SubscribeTransaction subscribes to transaction updates.

func (*StreamClient) SubscribeTransactionStatus

func (s *StreamClient) SubscribeTransactionStatus(filterName string, req *geyser_pb.SubscribeRequestFilterTransactions) error

SubscribeTransactionStatus subscribes to transaction status updates.

func (*StreamClient) UnsubscribeAccountDataSlice

func (s *StreamClient) UnsubscribeAccountDataSlice() error

func (*StreamClient) UnsubscribeAccounts

func (s *StreamClient) UnsubscribeAccounts(filterName string, accounts ...string) error

UnsubscribeAccounts unsubscribes specific accounts.

func (*StreamClient) UnsubscribeAccountsByID

func (s *StreamClient) UnsubscribeAccountsByID(filterName string) error

UnsubscribeAccountsByID unsubscribes from account updates by ID.

func (*StreamClient) UnsubscribeAllAccounts

func (s *StreamClient) UnsubscribeAllAccounts(filterName string) error

func (*StreamClient) UnsubscribeBlocks

func (s *StreamClient) UnsubscribeBlocks(filterName string) error

func (*StreamClient) UnsubscribeBlocksMeta

func (s *StreamClient) UnsubscribeBlocksMeta(filterName string) error

func (*StreamClient) UnsubscribeEntry

func (s *StreamClient) UnsubscribeEntry(filterName string) error

func (*StreamClient) UnsubscribeSlots

func (s *StreamClient) UnsubscribeSlots(filterName string) error

UnsubscribeSlots unsubscribes from slot updates.

func (*StreamClient) UnsubscribeTransaction

func (s *StreamClient) UnsubscribeTransaction(filterName string) error

UnsubscribeTransaction unsubscribes from transaction updates.

func (*StreamClient) UnsubscribeTransactionStatus

func (s *StreamClient) UnsubscribeTransactionStatus(filterName string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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