nonce

package
v0.0.0-...-c6effd4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: MIT Imports: 5 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

Index

Constants

View Source
const (
	EnvironmentInstanceSolanaMainnet = "mainnet"
	EnvironmentInstanceSolanaDevnet  = "devnet"
	EnvironmentInstanceSolanaTestnet = "testnet"
)

Variables

View Source
var (
	ErrNonceNotFound = errors.New("no records could be found")
	ErrInvalidNonce  = errors.New("invalid nonce")
)

Functions

This section is empty.

Types

type Environment

type Environment uint8
const (
	EnvironmentUnknown Environment = iota
	EnvironmentSolana              // Environment instance is the cluster name (ie. mainnet, devnet, testnet, etc)
	EnvironmentCvm                 // Environment instance is the VM public key
)

func (Environment) String

func (e Environment) String() string

type Purpose

type Purpose uint8

Split nonce pool across different use cases. This has an added benefit of:

  • Solving for race conditions without distributed locks.
  • Avoiding different use cases from starving each other and ending up in a deadlocked state. Concretely, it would be really bad if clients could starve internal processes from creating transactions that would allow us to progress and submit existing transactions.
const (
	PurposeUnknown Purpose = iota
	PurposeClientTransaction
	PurposeInternalServerProcess
	PurposeOnDemandTransaction
)

func (Purpose) String

func (p Purpose) String() string

type Record

type Record struct {
	Id uint64

	Address   string
	Authority string
	Blockhash string

	Environment         Environment
	EnvironmentInstance string

	Purpose Purpose
	State   State

	Signature string
}

func (*Record) Clone

func (r *Record) Clone() Record

func (*Record) CopyTo

func (r *Record) CopyTo(dst *Record)

func (*Record) GetPublicKey

func (r *Record) GetPublicKey() (ed25519.PublicKey, error)

func (*Record) Validate

func (v *Record) Validate() error

type State

type State uint8
const (
	StateUnknown   State = iota
	StateReleased        // The nonce is almost ready but we don't know its blockhash yet.
	StateAvailable       // The nonce is available to be used by a payment intent, subscription, or other nonce-related transaction/instruction.
	StateReserved        // The nonce is reserved by a payment intent, subscription, or other nonce-related transaction/instruction.
	StateInvalid         // The nonce account is invalid (e.g. insufficient funds, etc).
)

func (State) String

func (s State) String() string

type Store

type Store interface {
	// Count returns the total count of nonce accounts within an environment instance
	Count(ctx context.Context, env Environment, instance string) (uint64, error)

	// CountByState returns the total count of nonce accounts in the provided state within
	// an environment instance
	CountByState(ctx context.Context, env Environment, instance string, state State) (uint64, error)

	// CountByStateAndPurpose returns the total count of nonce accounts in the provided
	// state and use case within an environment instance
	CountByStateAndPurpose(ctx context.Context, env Environment, instance string, state State, purpose Purpose) (uint64, error)

	// Save creates or updates nonce metadata in the store.
	Save(ctx context.Context, record *Record) error

	// Get finds the nonce record for a given address.
	//
	// Returns ErrNotFound if no record is found.
	Get(ctx context.Context, address string) (*Record, error)

	// GetAllByState returns nonce records in the store for a given confirmation state
	// within an environment intance.
	//
	// Returns ErrNotFound if no records are found.
	GetAllByState(ctx context.Context, env Environment, instance string, state State, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// GetRandomAvailableByPurpose gets a random available nonce for a purpose within
	// an environment instance.
	//
	// Returns ErrNotFound if no records are found.
	GetRandomAvailableByPurpose(ctx context.Context, env Environment, instance string, purpose Purpose) (*Record, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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