simple

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) (any, bool)
	Add(key string, value any)
}

type ConfigProvider

type ConfigProvider interface {
	UnmarshalKey(key string, rawVal any) error
}

type Locker

type Locker interface {
	// Lock locks the token id for the consumer transaction txID on behalf of the given
	// owner (the wallet the tokens are selected for, ownerFilter.ID()).
	// owner lets a Locker implementation apply per-wallet policies such as rate limiting.
	// To deny a lock for policy reasons, return an error wrapping token.SelectorRateLimited:
	// the selector then aborts immediately instead of retrying.
	Lock(ctx context.Context, owner string, id *token2.ID, txID string, reclaim bool) (string, error)
	// UnlockIDs unlocks the passed IDs for the given owner. It returns the list of tokens
	// that were not locked in the first place among those passed.
	UnlockIDs(ctx context.Context, owner string, ids ...*token2.ID) []*token2.ID
	UnlockByTxID(ctx context.Context, txID string)
	IsLocked(id *token2.ID) bool
}

type LockerProvider

type LockerProvider interface {
	New(network, channel, namespace string) (Locker, error)
}

type Manager

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

func NewManager

func NewManager(
	locker Locker,
	newQueryEngine NewQueryEngineFunc,
	numRetry int,
	timeout time.Duration,
	requestCertification bool,
	precision uint64,
) *Manager

func (*Manager) Close

func (m *Manager) Close(txID string) error

func (*Manager) NewSelector

func (m *Manager) NewSelector(id string) (token.Selector, error)

func (*Manager) Unlock

func (m *Manager) Unlock(ctx context.Context, txID string) error

type NewQueryEngineFunc

type NewQueryEngineFunc func() QueryService

type QueryService

type QueryService interface {
	UnspentTokensIterator(ctx context.Context) (*token.UnspentTokensIterator, error)
	UnspentTokensIteratorBy(ctx context.Context, id string, tokenType token2.Type) (driver.UnspentTokensIterator, error)
	GetTokens(ctx context.Context, inputs ...*token2.ID) ([]*token2.Token, error)
}

type SelectorService

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

func NewService

func NewService(lockerProvider LockerProvider, c ConfigProvider, opts ...ratelimit.Option) *SelectorService

NewService returns a SelectorService for the simple driver.

By default, selection is not rate limited. Passing ratelimit options, or enabling the token.selector.rateLimit* configuration keys, meters every selection request per wallet.

func (*SelectorService) SelectorManager

func (s *SelectorService) SelectorManager(tms *token.ManagementService) (token.SelectorManager, error)

func (*SelectorService) Shutdown

func (s *SelectorService) Shutdown()

Shutdown stops all background goroutines for every locker created by this service.

It deliberately leaves the rate limiter alone. Shutdown also runs on routine public-parameter reloads (see token.ManagementServiceProvider.Update), after which the service keeps serving managers: resetting the wallet allowances there would let a throttled client wash out its debt by triggering a reload, and a limiter supplied through ratelimit.WithLimiter belongs to the caller in the first place. The built-in limiter runs no goroutines and prunes its own buckets, so there is nothing to leak.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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