paths

package
v0.0.0-...-4fa8e69 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package paths provides utilities and facilities for payment paths as needed by horizon. Most importantly, it provides the Finder interface, allowing for pluggable path finding back ends.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRateLimitExceeded indicates that the Finder is not able to fulfill the request due to rate limits.
	ErrRateLimitExceeded = errors.New("Rate limit exceeded")
)

Functions

This section is empty.

Types

type Finder

type Finder interface {
	// Find returns a list of payment paths and the most recent ledger
	// for a Query of a maximum length `maxLength`. The payment paths
	// are accurate and consistent with the returned ledger sequence number
	Find(ctx context.Context, q Query, maxLength uint) ([]Path, uint32, error)
	// FindFixedPaths return a list of payment paths the most recent ledger
	// Each of the payment paths start by spending `amountToSpend` of `sourceAsset` and end
	// with delivering a positive amount of `destinationAsset`.
	// The payment paths are accurate and consistent with the returned ledger sequence number
	FindFixedPaths(
		ctx context.Context,
		sourceAsset xdr.Asset,
		amountToSpend xdr.Int64,
		destinationAssets []xdr.Asset,
		maxLength uint,
	) ([]Path, uint32, error)
}

Finder finds paths.

type MockFinder

type MockFinder struct {
	mock.Mock
}

MockFinder is a mock implementation of the Finder interface

func (*MockFinder) Find

func (m *MockFinder) Find(ctx context.Context, q Query, maxLength uint) ([]Path, uint32, error)

func (*MockFinder) FindFixedPaths

func (m *MockFinder) FindFixedPaths(
	ctx context.Context,
	sourceAsset xdr.Asset,
	amountToSpend xdr.Int64,
	destinationAssets []xdr.Asset,
	maxLength uint,
) ([]Path, uint32, error)

type Path

type Path struct {
	Path              []string
	Source            string
	SourceAmount      xdr.Int64
	Destination       string
	DestinationAmount xdr.Int64
}

Path is the result returned by a path finder and is tied to the DestinationAmount used in the input query

type Query

type Query struct {
	DestinationAsset    xdr.Asset
	DestinationAmount   xdr.Int64
	SourceAssets        []xdr.Asset
	SourceAssetBalances []xdr.Int64
	// if ValidateSourceBalance is true then we won't consider payment paths
	// which require a source asset amount which exceeds the balance present in `SourceAssetBalances`
	ValidateSourceBalance bool
	SourceAccount         *xdr.AccountId
}

Query is a query for paths

type RateLimitedFinder

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

RateLimitedFinder is a Finder implementation which limits the number of path finding requests.

func NewRateLimitedFinder

func NewRateLimitedFinder(finder Finder, limit uint) *RateLimitedFinder

NewRateLimitedFinder constructs a new RateLimitedFinder which enforces a per second limit on path finding requests.

func (*RateLimitedFinder) Find

func (f *RateLimitedFinder) Find(ctx context.Context, q Query, maxLength uint) ([]Path, uint32, error)

Find implements the Finder interface and returns ErrRateLimitExceeded if the RateLimitedFinder is unable to complete the request due to rate limits.

func (*RateLimitedFinder) FindFixedPaths

func (f *RateLimitedFinder) FindFixedPaths(
	ctx context.Context,
	sourceAsset xdr.Asset,
	amountToSpend xdr.Int64,
	destinationAssets []xdr.Asset,
	maxLength uint,
) ([]Path, uint32, error)

FindFixedPaths implements the Finder interface and returns ErrRateLimitExceeded if the RateLimitedFinder is unable to complete the request due to rate limits.

func (*RateLimitedFinder) Limit

func (f *RateLimitedFinder) Limit() int

Limit returns the per second limit of path finding requests.

Jump to

Keyboard shortcuts

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