solana

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package solana decodes the accounts and events of the AKT Solana program and attributes program logs.

Index

Constants

This section is empty.

Variables

View Source
var (
	DiscLaunchConfig     = [8]byte{18, 161, 9, 224, 102, 145, 29, 94}
	DiscBridgeConfig     = [8]byte{40, 206, 51, 233, 246, 40, 178, 85}
	DiscTransferStatus   = [8]byte{32, 200, 30, 253, 33, 153, 127, 45}
	DiscTransferResolved = [8]byte{205, 27, 228, 215, 90, 3, 236, 176}
)

Anchor discriminators, checked against contracts/solana/tests/fixtures/deployed-interface.json.

View Source
var (
	// ErrBlockMissing reports a resolution block that the owned node cannot serve.
	ErrBlockMissing = errors.New("resolution evidence unavailable: block missing from owned node history")
	// ErrNotInBlock reports that no transaction of the resolution block proves the resolution.
	ErrNotInBlock = errors.New("resolution evidence unavailable in its block")
	// ErrMultipleInBlock reports more than one transaction proving the resolution; the status account is created once.
	ErrMultipleInBlock = errors.New("multiple resolution transactions in block")
)
View Source
var (
	// ErrUnavailable reports any transport or RPC failure outside getBlock, as in TS.
	ErrUnavailable = errors.New("Solana node is temporarily unavailable") //nolint:staticcheck // verbatim TS text
	// ErrBlockUnavailable reports a getBlock error, a missing block or a malformed one.
	ErrBlockUnavailable = errors.New("resolution evidence unavailable: block missing from owned node history")
)

Functions

func MatchesStatus

func MatchesStatus(ev TransferResolved, st TransferStatus) bool

MatchesStatus reports whether ev carries the identity, proof height, slot and outcome of st.

func PDA

func PDA(program solana.PublicKey, seeds ...[]byte) solana.PublicKey

PDA returns the program address for seeds. It panics when a seed is longer than 32 bytes or there are more than 16 seeds, which are programming errors.

func Resolves

func Resolves(tx Tx, program, address solana.PublicKey, match func(TransferResolved) bool) bool

Resolves reports whether tx proves a resolution: it succeeded, has logs, writes address and one of the TransferResolved events of its program frames satisfies match. Logs that cannot be attributed give no evidence.

func StatusAddress

func StatusAddress(program solana.PublicKey, id sinkid.ID) solana.PublicKey

StatusAddress returns the TransferStatus address ["transfer", SHA256(owner), LE64(height), LE64(sequence)].

Types

type Account

type Account struct {
	Owner      solana.PublicKey
	Executable bool
	Data       []byte
}

Account is an account as getMultipleAccounts returns it.

type BridgeConfig

type BridgeConfig struct {
	LightClientProgram solana.PublicKey
	ChainID            string
}

BridgeConfig is the account at ["bridge"]. The mint policy and usage counters are validated but not kept.

func DecodeBridgeConfig

func DecodeBridgeConfig(data []byte) (BridgeConfig, error)

DecodeBridgeConfig decodes a BridgeConfig account. Trailing bytes are account padding.

type EvidenceIndex

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

EvidenceIndex finds the transaction that resolved a transfer in the block of its resolution slot. Blocks are finalized, so the entries of a slot never change; slots are evicted lowest number first, not by use.

func NewEvidenceIndex

func NewEvidenceIndex(rpc *RPC, program solana.PublicKey, maxSlots int, maxBytes int64) *EvidenceIndex

NewEvidenceIndex returns an index over the blocks rpc serves. It keeps at most maxSlots slots and about maxBytes of entries.

func (*EvidenceIndex) Lookup

func (e *EvidenceIndex) Lookup(
	ctx context.Context,
	slot uint64,
	address solana.PublicKey,
	st TransferStatus,
) (solana.Signature, error)

Lookup returns the signature of the one transaction of slot that resolves st at address.

ErrBlockMissing means the block could not be read; ErrNotInBlock and ErrMultipleInBlock mean the block holds no resolution or several. A cancelled ctx gives ctx.Err() and caches nothing.

type LaunchConfig

type LaunchConfig struct {
	Version           uint8
	Initializer       solana.PublicKey
	Mint              solana.PublicKey
	BridgeEnabled     bool
	InitializedAtSlot uint64
	Bump              uint8
	MintAuthorityBump uint8
}

LaunchConfig is the account at ["config"].

func DecodeLaunchConfig

func DecodeLaunchConfig(data []byte) (LaunchConfig, error)

DecodeLaunchConfig decodes a LaunchConfig account. Trailing bytes are account padding.

type Mint

type Mint struct {
	MintAuthority   *solana.PublicKey
	Supply          uint64
	Decimals        uint8
	Initialized     bool
	FreezeAuthority *solana.PublicKey
}

Mint is an SPL Token mint account.

func DecodeMint

func DecodeMint(data []byte) (Mint, error)

DecodeMint decodes an SPL Token mint account, which is exactly 82 bytes.

type Minted

type Minted struct {
	Amount    uint64
	Recipient solana.PublicKey
}

Minted is an outcome that minted Amount base units to the associated token account of Recipient.

type Outcome

type Outcome struct {
	Minted *Minted
	Voided *VoidReason
}

Outcome is the Borsh enum TransferOutcome; exactly one field is set.

type RPC

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

RPC is a JSON-RPC client for one Solana node. Every read uses finalized commitment.

func NewRPC

func NewRPC(opts RPCOptions) *RPC

NewRPC returns a client with one keep-alive connection pool sized to both concurrency limits.

func (*RPC) BlockTime

func (r *RPC) BlockTime(ctx context.Context, slot uint64) (*int64, error)

BlockTime returns the block time of slot, or nil when the node has none. Known times are cached per slot.

func (*RPC) GenesisHash

func (r *RPC) GenesisHash(ctx context.Context) (string, error)

GenesisHash returns the node's genesis hash.

func (*RPC) MultipleAccounts

func (r *RPC) MultipleAccounts(ctx context.Context, keys []solana.PublicKey) (uint64, []*Account, error)

MultipleAccounts reads up to 100 accounts at finalized commitment; a missing account is nil.

func (*RPC) StreamBlock

func (r *RPC) StreamBlock(ctx context.Context, slot uint64, each func(Tx) error) error

StreamBlock fetches the finalized block at slot and calls each for its transactions in order, decoding one transaction at a time. A getBlock error, a null result or a malformed block gives ErrBlockUnavailable, possibly after some calls to each; an error from each is returned as is.

func (*RPC) Transaction

func (r *RPC) Transaction(ctx context.Context, sig string) (*Tx, error)

Transaction reads a finalized transaction by signature; it returns nil, nil when the node has none.

type RPCOptions

type RPCOptions struct {
	// LegacyRedirects follows the packaged TS global-fetch redirect policy.
	LegacyRedirects bool
	URL             string
	Timeout         time.Duration
	// Concurrency limits concurrent requests other than getBlock.
	Concurrency int
	// BlockConcurrency limits concurrent getBlock requests.
	BlockConcurrency int
	Metrics          *metrics.Metrics
}

RPCOptions configures the Solana JSON-RPC client.

type TransferID

type TransferID struct {
	Owner    []byte
	Height   uint64
	Sequence uint64
}

TransferID is the x/sink record ID as the program stores it.

type TransferResolved

type TransferResolved TransferStatus

TransferResolved is the event a record's resolution emits; it carries the same evidence as TransferStatus.

func DecodeTransferResolved

func DecodeTransferResolved(data []byte) (TransferResolved, error)

DecodeTransferResolved decodes the Anchor event data, discriminator included. The length must be exact.

func ProgramEvents

func ProgramEvents(logs []string, program solana.PublicKey) ([]TransferResolved, error)

ProgramEvents returns the TransferResolved events emitted by program frames, in log order.

Anchor's event parser ignores events emitted inside a CPI, so each "Program data:" line is attributed to the executing frame from the invoke and exit lines instead. Unbalanced logs cannot be attributed and are an error. A later instruction can exhaust the log limit. The runtime then writes `Log truncated` once and keeps logging the messages that still fit, so parsing stops at the first marker: only top-level program frames that closed with success before it count. Data lines with other discriminators are ignored; a TransferResolved that does not decode is an error.

type TransferStatus

type TransferStatus struct {
	ID             TransferID
	ProofHeight    uint64
	ResolvedAtSlot uint64
	Outcome        Outcome
}

TransferStatus is the terminal record at ["transfer", SHA256(owner), LE64(height), LE64(sequence)].

func DecodeTransferStatus

func DecodeTransferStatus(data []byte) (TransferStatus, error)

DecodeTransferStatus decodes a TransferStatus account. Trailing bytes are account padding.

type Tx

type Tx struct {
	Slot       uint64
	Version    string
	Signatures []string
	Failed     bool
	Logs       []string
	HasLogs    bool
	Keys       []solana.PublicKey
	Writable   []bool
}

Tx is a transaction decoded from the JSON encoding. Keys lists the static account keys, then meta.loadedAddresses.writable, then meta.loadedAddresses.readonly; Writable holds one flag per key.

type VoidReason

type VoidReason uint8

VoidReason says why a record was voided.

const (
	// VoidInvalidRecipient means the proven recipient cannot receive AKT.
	VoidInvalidRecipient VoidReason = iota
	// VoidGovernance means Akash governance wrote a void order for the record.
	VoidGovernance
)

Jump to

Keyboard shortcuts

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