util

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package util contains generic functions.

Index

Constants

View Source
const SectionSolpipeHook logger.Section = 1

Variables

View Source
var LoggerBrainSimple = logger.Standard{Category: logger.CategoryTunnel, Section: SectionSolpipeHook, Code: 1}

Functions

func BotPipelineWhiteList

func BotPipelineWhiteList() []sgo.PublicKey

func DownloadCatscopeRustBotDemonstrator

func DownloadCatscopeRustBotDemonstrator(ctx context.Context) (string, error)

DownloadCatscopeRustBotDemonstrator downloads a Noncepad build demonstration web assembly blob

func DownloadSigned

func DownloadSigned(ctx context.Context, url string, armoredKeyring io.Reader) ([]byte, error)

DownloadSigned fetches a PGP clear-signed file from url, verifies its signature against armoredKeyring, and returns the decoded binary payload. The signed message body must be the binary data encoded as standard base64.

func FetchAccount added in v0.4.16

func FetchAccount(ctx context.Context, stateClient state.Client, pubkey sgo.PublicKey) (graph.Account, bool, error)

FetchAccount fetches one already-known account address as a one-shot snapshot: subscribe at depth 1 (graph.Graph.Subscribe's own doc comment: "Depth==1 fetches the root account only" -- no neighbor expansion, which is exactly right for a single leaf address) and cancel the subscription's own context the moment its ack channel fires.

This is deliberately NOT the pattern FetchWalletBalance/ cmd/watchobligations.go's PendingSubscriptionStatus uses. That helper's own doc comment (util/subscribe.go) explains why it leaves a subscription's context alive until the whole fetch is done: an ack only means "registered with the server", not "data has arrived" -- cancelling on ack was tried in this exact codebase before and confirmed (server-side: "grpc client is prematurely dropping") to sometimes cut a subscription off before its account data had actually streamed back. FetchAccount accepts that same tradeoff on purpose, scoped narrowly to a caller that only wants one value and is genuinely done with the subscription immediately after (e.g. answering a single synchronous tool call) -- anything that needs to keep observing an account for further updates should use the quiet-slot pattern instead of this.

func ParsePubkey

func ParsePubkey(data []byte) (sgo.PublicKey, error)

func VerifyDetached

func VerifyDetached(signed io.Reader, sig io.Reader, armoredKeyring io.Reader) error

VerifyDetached checks a detached PGP signature (armored .asc or raw binary .sig) against signed and returns an error if verification fails.

Types

type PendingSubscriptionStatus added in v0.4.16

type PendingSubscriptionStatus struct {
	// contains filtered or unexported fields
}

func CreatePendingSubscriptionList added in v0.4.16

func CreatePendingSubscriptionList(ctx context.Context, g graph.Graph, max int, quietSlots graph.Slot) *PendingSubscriptionStatus

CreatePendingSubscriptionList creates a subscription tracker that reports done only after quietSlots consecutive slot-commits have passed with nothing pending — see PendingSubscriptionStatus.quietSlots.

func (*PendingSubscriptionStatus) Check added in v0.4.16

func (pss *PendingSubscriptionStatus) Check(slot graph.Slot) bool

Check returns true once there have been no pending subscriptions for at least quietSlots consecutive slot-commits. slot is the current commit's slot (as reported by CommitStart).

func (*PendingSubscriptionStatus) Count added in v0.4.16

func (pss *PendingSubscriptionStatus) Count() [3]int

Count returns [count, inFlight, queued] — queued is how many are still sitting in listSub, not yet sent. count should always equal queued+inFlight; a mismatch means the two are out of sync.

func (*PendingSubscriptionStatus) PendingRoots added in v0.4.16

func (pss *PendingSubscriptionStatus) PendingRoots() []sgo.PublicKey

PendingRoots returns the roots currently sent and awaiting ack (a snapshot of listAck), for diagnosing subscriptions that never ack. Non-destructive.

func (*PendingSubscriptionStatus) Subscribe added in v0.4.16

func (pss *PendingSubscriptionStatus) Subscribe(root sgo.PublicKey, weight graph.Weight, depth graph.Depth)

type Pool added in v0.4.7

type Pool[T any] struct {
	// contains filtered or unexported fields
}

func Create added in v0.4.7

func Create[T any](ctx context.Context, workerCount int) (Pool[T], <-chan *PoolResponse[T])

func (Pool[T]) Run added in v0.4.7

func (p Pool[T]) Run(ctx context.Context, callback func() (T, error)) uint64

type PoolResponse added in v0.4.7

type PoolResponse[T any] struct {
	ID      uint64
	Error   error
	Payload T
}

type TokenBalance added in v0.4.16

type TokenBalance struct {
	Mint   sgo.PublicKey
	Amount uint64
	// Decimals is the mint's decimals, resolved via a separate FetchAccount
	// call per unique mint (a token account's own data has no decimals
	// field -- that lives on the mint account, which isn't a graph child
	// of the wallet's depth-2 walk below). DecimalsKnown is false when
	// that resolution failed (mint account not found, or an unexpected
	// data size) -- Decimals is meaningless then, not just "0 decimals".
	Decimals      uint8
	DecimalsKnown bool
}

TokenBalance is one SPL token account found under a wallet.

type WalletBalance added in v0.4.16

type WalletBalance struct {
	Pubkey   sgo.PublicKey
	Slot     graph.Slot
	Lamports uint64
	// Found is false when the root account itself was never observed (no
	// funds, or never initialized) -- Slot/Lamports are meaningless then.
	Found  bool
	Tokens []TokenBalance
}

WalletBalance is a wallet pubkey's live SOL balance plus every SPL token account discovered under it.

func FetchWalletBalance added in v0.4.16

func FetchWalletBalance(ctx context.Context, stateClient state.Client, pubkey sgo.PublicKey) (*WalletBalance, error)

FetchWalletBalance fetches a wallet's live SOL and SPL token balances via a direct graph.Hook subscription (state.Client.Hook + PendingSubscriptionStatus) -- the same pattern prefetch/{solend,kamino,marginfi,jet,drift}/event.go already use for bulk program crawling, applied here to a single wallet's depth-2 neighborhood. Deliberately not state.Client.QuerySingleShot: that helper wrapped the identical underlying Subscribe/ack mechanism but with a fixed, apparently too-aggressive 3-slot quiet window, and was dropped from this codebase after repeated unreliable results in production use (cmd/balance.go, shell/tools.go and prefetch/prompttool.go's wallet-balance tools all used to call it directly).

Source Files

  • fetchaccount.go
  • gpg.go
  • logger.go
  • pool.go
  • subscribe.go
  • util.go
  • walletbalance.go
  • whitelist.go

Jump to

Keyboard shortcuts

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