nonce

package
v1.10.19 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

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
	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.
	StateReserved        // The nonce is reserved by a payment intent, subscription, or other nonce-related transaction.
	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.
	Count(ctx context.Context) (uint64, error)

	// CountByState returns the total count of nonce accounts in the provided state.
	CountByState(ctx context.Context, state State) (uint64, error)

	// CountByStateAndPurpose returns the total count of nonce accounts in the provided
	// state and use case
	CountByStateAndPurpose(ctx context.Context, 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.
	//
	// Returns ErrNotFound if no records are found.
	GetAllByState(ctx context.Context, state State, cursor query.Cursor, limit uint64, direction query.Ordering) ([]*Record, error)

	// GetRandomAvailableByPurpose gets a random available nonce for a purpose.
	//
	// Returns ErrNotFound if no records are found.
	GetRandomAvailableByPurpose(ctx context.Context, 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