ledger

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScriptErrorInsufficientFund  = "INSUFFICIENT_FUND"
	ScriptErrorCompilationFailed = "COMPILATION_FAILED"
	ScriptErrorNoScript          = "NO_SCRIPT"
	ScriptErrorMetadataOverride  = "METADATA_OVERRIDE"
)
View Source
const (
	QueryDefaultPageSize = 15
)
View Source
const ResolverLedgerOptionsKey = `name:"_ledgerResolverLedgerOptions"`
View Source
const ResolverOptionsKey = `group:"_ledgerResolverOptions"`

Variables

View Source
var DefaultContracts = []core.Contract{
	{
		Name:    "default",
		Account: "*",
		Expr: &core.ExprGte{
			Op1: core.VariableExpr{
				Name: "balance",
			},
			Op2: core.ConstantExpr{
				Value: core.NewMonetaryInt(0),
			},
		},
	},
}
View Source
var DefaultResolverOptions = []ResolverOption{
	WithMonitor(&noOpMonitor{}),
}

Functions

func IsConflictError added in v1.0.4

func IsConflictError(err error) bool

func IsInsufficientFundError added in v1.0.4

func IsInsufficientFundError(err error) bool

func IsLockError added in v1.3.0

func IsLockError(err error) bool

func IsNotFoundError added in v1.6.0

func IsNotFoundError(err error) bool

func IsScriptErrorWithCode added in v1.6.0

func IsScriptErrorWithCode(err error, code string) bool

func IsTransactionCommitError added in v1.0.4

func IsTransactionCommitError(err error) bool

func IsValidationError added in v1.0.4

func IsValidationError(err error) bool

func NewCache added in v1.9.0

func NewCache(capacityBytes, maxNumKeys int64, metrics bool) *ristretto.Cache

func NewMachineFromScript added in v1.9.0

func NewMachineFromScript(script string, cache *ristretto.Cache, span trace.Span) (*vm.Machine, error)

func NewNoOpMonitor added in v1.8.0

func NewNoOpMonitor() *noOpMonitor

func ProvideResolverOption

func ProvideResolverOption(provider interface{}) fx.Option

func ResolveModule

func ResolveModule(cacheBytesCapacity, cacheMaxNumKeys int64) fx.Option

func WithPastTimestamps added in v1.7.3

func WithPastTimestamps(l *Ledger)

Types

type AccountsQuery added in v1.8.0

type AccountsQuery struct {
	PageSize     uint
	Offset       uint
	AfterAddress string
	Filters      AccountsQueryFilters
}

func NewAccountsQuery added in v1.8.0

func NewAccountsQuery() *AccountsQuery

func (*AccountsQuery) WithAddressFilter added in v1.8.0

func (a *AccountsQuery) WithAddressFilter(address string) *AccountsQuery

func (*AccountsQuery) WithAfterAddress added in v1.8.0

func (a *AccountsQuery) WithAfterAddress(after string) *AccountsQuery

func (*AccountsQuery) WithBalanceAssetFilter added in v1.10.15

func (a *AccountsQuery) WithBalanceAssetFilter(value string) *AccountsQuery

func (*AccountsQuery) WithBalanceFilter added in v1.8.0

func (a *AccountsQuery) WithBalanceFilter(balance string) *AccountsQuery

func (*AccountsQuery) WithBalanceOperatorFilter added in v1.8.0

func (a *AccountsQuery) WithBalanceOperatorFilter(balanceOperator BalanceOperator) *AccountsQuery

func (*AccountsQuery) WithMetadataFilter added in v1.8.0

func (a *AccountsQuery) WithMetadataFilter(metadata map[string]string) *AccountsQuery

func (*AccountsQuery) WithOffset added in v1.8.0

func (a *AccountsQuery) WithOffset(offset uint) *AccountsQuery

func (*AccountsQuery) WithPageSize added in v1.8.0

func (a *AccountsQuery) WithPageSize(pageSize uint) *AccountsQuery

type AccountsQueryFilters added in v1.8.0

type AccountsQueryFilters struct {
	Address         string
	Balance         string
	BalanceOperator BalanceOperator
	Metadata        map[string]string
	BalanceAsset    string
}

type AggregatedBalancesQuery added in v1.10.4

type AggregatedBalancesQuery struct {
	PageSize     uint
	Offset       uint
	AfterAddress string
	Filters      AggregatedBalancesQueryFilters
}

func NewAggregatedBalancesQuery added in v1.10.4

func NewAggregatedBalancesQuery() *AggregatedBalancesQuery

func (*AggregatedBalancesQuery) WithAddressFilter added in v1.10.4

func (b *AggregatedBalancesQuery) WithAddressFilter(address string) *AggregatedBalancesQuery

func (*AggregatedBalancesQuery) WithAfterAddress added in v1.10.4

func (b *AggregatedBalancesQuery) WithAfterAddress(after string) *AggregatedBalancesQuery

func (*AggregatedBalancesQuery) WithOffset added in v1.10.4

func (b *AggregatedBalancesQuery) WithOffset(offset uint) *AggregatedBalancesQuery

func (*AggregatedBalancesQuery) WithPageSize added in v1.10.4

func (b *AggregatedBalancesQuery) WithPageSize(pageSize uint) *AggregatedBalancesQuery

type AggregatedBalancesQueryFilters added in v1.10.4

type AggregatedBalancesQueryFilters struct {
	AddressRegexp string
}

type BalanceOperator added in v1.8.0

type BalanceOperator string
const (
	BalanceOperatorE   BalanceOperator = "e"
	BalanceOperatorGt  BalanceOperator = "gt"
	BalanceOperatorGte BalanceOperator = "gte"
	BalanceOperatorLt  BalanceOperator = "lt"
	BalanceOperatorLte BalanceOperator = "lte"
	BalanceOperatorNe  BalanceOperator = "ne"

	DefaultBalanceOperator = BalanceOperatorGte
)

func NewBalanceOperator added in v1.8.0

func NewBalanceOperator(s string) (BalanceOperator, bool)

func (BalanceOperator) IsValid added in v1.8.0

func (b BalanceOperator) IsValid() bool

type BalancesQuery added in v1.8.0

type BalancesQuery struct {
	PageSize     uint
	Offset       uint
	AfterAddress string
	Filters      BalancesQueryFilters
}

func NewBalancesQuery added in v1.8.0

func NewBalancesQuery() *BalancesQuery

func (*BalancesQuery) WithAddressFilter added in v1.8.0

func (b *BalancesQuery) WithAddressFilter(address ...string) *BalancesQuery

func (*BalancesQuery) WithAfterAddress added in v1.8.0

func (b *BalancesQuery) WithAfterAddress(after string) *BalancesQuery

func (*BalancesQuery) WithOffset added in v1.8.0

func (b *BalancesQuery) WithOffset(offset uint) *BalancesQuery

func (*BalancesQuery) WithPageSize added in v1.8.0

func (b *BalancesQuery) WithPageSize(pageSize uint) *BalancesQuery

type BalancesQueryFilters added in v1.8.0

type BalancesQueryFilters struct {
	AddressRegexp []string
}

type ConflictError

type ConflictError struct{}

func NewConflictError

func NewConflictError() *ConflictError

func (ConflictError) Error

func (e ConflictError) Error() string

func (ConflictError) Is added in v1.0.4

func (e ConflictError) Is(err error) bool

type InsufficientFundError

type InsufficientFundError struct {
	Asset string
}

func NewInsufficientFundError

func NewInsufficientFundError(asset string) *InsufficientFundError

func (InsufficientFundError) Error

func (e InsufficientFundError) Error() string

func (InsufficientFundError) Is added in v1.0.4

func (e InsufficientFundError) Is(err error) bool

type Ledger

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

func NewLedger

func NewLedger(store Store, monitor Monitor, cache *ristretto.Cache, options ...LedgerOption) (*Ledger, error)

func (*Ledger) Close

func (l *Ledger) Close(ctx context.Context) error

func (*Ledger) CountAccounts added in v1.3.2

func (l *Ledger) CountAccounts(ctx context.Context, a AccountsQuery) (uint64, error)

func (*Ledger) CountTransactions added in v1.3.2

func (l *Ledger) CountTransactions(ctx context.Context, q TransactionsQuery) (uint64, error)

func (*Ledger) ExecuteScript added in v1.9.0

func (l *Ledger) ExecuteScript(ctx context.Context, preview bool, script core.ScriptData) (core.ExpandedTransaction, error)

func (*Ledger) ExecuteTxsData added in v1.9.0

func (l *Ledger) ExecuteTxsData(ctx context.Context, preview, checkBalances bool, txsData ...core.TransactionData) ([]core.ExpandedTransaction, error)

func (*Ledger) GetAccount

func (l *Ledger) GetAccount(ctx context.Context, address string) (*core.AccountWithVolumes, error)

func (*Ledger) GetAccounts added in v1.3.2

func (l *Ledger) GetAccounts(ctx context.Context, a AccountsQuery) (api.Cursor[core.Account], error)

func (*Ledger) GetBalances added in v1.6.0

func (*Ledger) GetBalancesAggregated added in v1.6.0

func (l *Ledger) GetBalancesAggregated(ctx context.Context, q AggregatedBalancesQuery) (core.AssetsBalances, error)

func (*Ledger) GetLedgerStore added in v1.8.0

func (l *Ledger) GetLedgerStore() Store

func (*Ledger) GetLogs added in v1.9.0

func (l *Ledger) GetLogs(ctx context.Context, q *LogsQuery) (api.Cursor[core.Log], error)

func (*Ledger) GetMigrationsInfo added in v1.9.0

func (l *Ledger) GetMigrationsInfo(ctx context.Context) ([]core.MigrationInfo, error)

func (*Ledger) GetTransaction

func (l *Ledger) GetTransaction(ctx context.Context, id uint64) (*core.ExpandedTransaction, error)

func (*Ledger) GetTransactions added in v1.3.2

func (*Ledger) LoadMapping

func (l *Ledger) LoadMapping(ctx context.Context) (*core.Mapping, error)

func (*Ledger) RevertTransaction

func (l *Ledger) RevertTransaction(ctx context.Context, id uint64, checkBalances bool) (*core.ExpandedTransaction, error)

func (*Ledger) SaveMapping

func (l *Ledger) SaveMapping(ctx context.Context, mapping core.Mapping) error

func (*Ledger) SaveMeta

func (l *Ledger) SaveMeta(ctx context.Context, targetType string, targetID interface{}, m core.Metadata) error

func (*Ledger) Stats

func (l *Ledger) Stats(ctx context.Context) (Stats, error)

func (*Ledger) Verify

func (l *Ledger) Verify() error

type LedgerOption added in v1.7.3

type LedgerOption = func(*Ledger)

type LockError added in v1.3.0

type LockError struct {
	Err error
}

func NewLockError added in v1.3.0

func NewLockError(err error) *LockError

func (LockError) Error added in v1.3.0

func (e LockError) Error() string

func (LockError) Is added in v1.3.0

func (e LockError) Is(err error) bool

type LogsQuery added in v1.9.0

type LogsQuery struct {
	AfterID  uint64
	PageSize uint

	Filters LogsQueryFilters
}

func NewLogsQuery added in v1.9.0

func NewLogsQuery() *LogsQuery

func (*LogsQuery) WithAfterID added in v1.9.0

func (l *LogsQuery) WithAfterID(after uint64) *LogsQuery

func (*LogsQuery) WithEndTimeFilter added in v1.9.0

func (l *LogsQuery) WithEndTimeFilter(end time.Time) *LogsQuery

func (*LogsQuery) WithPageSize added in v1.9.0

func (l *LogsQuery) WithPageSize(pageSize uint) *LogsQuery

func (*LogsQuery) WithStartTimeFilter added in v1.9.0

func (l *LogsQuery) WithStartTimeFilter(start time.Time) *LogsQuery

type LogsQueryFilters added in v1.9.0

type LogsQueryFilters struct {
	EndTime   time.Time
	StartTime time.Time
}

type Monitor added in v1.3.0

type Monitor interface {
	CommittedTransactions(ctx context.Context, ledger string, res ...core.ExpandedTransaction)
	SavedMetadata(ctx context.Context, ledger, targetType, id string, metadata core.Metadata)
	UpdatedMapping(ctx context.Context, ledger string, mapping core.Mapping)
	RevertedTransaction(ctx context.Context, ledger string, reverted, revert *core.ExpandedTransaction)
}

type NotFoundError added in v1.6.0

type NotFoundError struct {
	Msg string
}

func NewNotFoundError added in v1.6.0

func NewNotFoundError(msg string) *NotFoundError

func (NotFoundError) Error added in v1.6.0

func (v NotFoundError) Error() string

func (NotFoundError) Is added in v1.6.0

func (v NotFoundError) Is(err error) bool

type ResolveOptionFn

type ResolveOptionFn func(r *Resolver) error

func WithMonitor added in v1.3.0

func WithMonitor(monitor Monitor) ResolveOptionFn

type Resolver

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

func NewResolver

func NewResolver(
	storageFactory storage.Driver[Store],
	ledgerOptions []LedgerOption,
	cacheBytesCapacity, cacheMaxNumKeys int64,
	options ...ResolverOption,
) *Resolver

func (*Resolver) Close added in v1.9.0

func (r *Resolver) Close()

func (*Resolver) GetLedger

func (r *Resolver) GetLedger(ctx context.Context, name string) (*Ledger, error)

type ResolverOption

type ResolverOption interface {
	// contains filtered or unexported methods
}

type ScriptError added in v1.0.5

type ScriptError struct {
	Code    string
	Message string
}

func NewScriptError added in v1.0.5

func NewScriptError(code string, message string) *ScriptError

func (ScriptError) Error added in v1.0.5

func (e ScriptError) Error() string

func (ScriptError) Is added in v1.0.5

func (e ScriptError) Is(err error) bool

type Stats

type Stats struct {
	Transactions uint64 `json:"transactions"`
	Accounts     uint64 `json:"accounts"`
}

type Store added in v1.8.0

type Store interface {
	GetLastTransaction(ctx context.Context) (*core.ExpandedTransaction, error)
	CountTransactions(context.Context, TransactionsQuery) (uint64, error)
	GetTransactions(context.Context, TransactionsQuery) (api.Cursor[core.ExpandedTransaction], error)
	GetTransaction(ctx context.Context, txid uint64) (*core.ExpandedTransaction, error)
	GetAccount(ctx context.Context, accountAddress string) (*core.Account, error)
	GetAssetsVolumes(ctx context.Context, accountAddress string) (core.AssetsVolumes, error)
	GetAccountWithVolumes(ctx context.Context, account string) (*core.AccountWithVolumes, error)
	CountAccounts(context.Context, AccountsQuery) (uint64, error)
	GetAccounts(context.Context, AccountsQuery) (api.Cursor[core.Account], error)
	GetBalances(context.Context, BalancesQuery) (api.Cursor[core.AccountsBalances], error)
	GetBalancesAggregated(context.Context, AggregatedBalancesQuery) (core.AssetsBalances, error)
	GetLastLog(context.Context) (*core.Log, error)
	GetLogs(context.Context, *LogsQuery) (api.Cursor[core.Log], error)
	LoadMapping(context.Context) (*core.Mapping, error)
	GetMigrationsAvailable() ([]core.MigrationInfo, error)
	GetMigrationsDone(context.Context) ([]core.MigrationInfo, error)

	UpdateTransactionMetadata(ctx context.Context, txid uint64, metadata core.Metadata, at time.Time) error
	UpdateAccountMetadata(ctx context.Context, address string, metadata core.Metadata, at time.Time) error
	Commit(ctx context.Context, txs ...core.ExpandedTransaction) error
	SaveMapping(ctx context.Context, m core.Mapping) error
	Name() string
	Initialize(context.Context) (bool, error)
	Close(context.Context) error
}

type TransactionCommitError

type TransactionCommitError struct {
	TXIndex int   `json:"index"`
	Err     error `json:"error"`
}

func NewTransactionCommitError

func NewTransactionCommitError(txIndex int, err error) *TransactionCommitError

func (TransactionCommitError) Error

func (e TransactionCommitError) Error() string

func (TransactionCommitError) Is added in v1.0.4

func (e TransactionCommitError) Is(err error) bool

func (TransactionCommitError) Unwrap added in v1.0.4

func (e TransactionCommitError) Unwrap() error

type TransactionsQuery added in v1.8.0

type TransactionsQuery struct {
	PageSize  uint
	AfterTxID uint64
	Filters   TransactionsQueryFilters
}

func NewTransactionsQuery added in v1.8.0

func NewTransactionsQuery() *TransactionsQuery

func (*TransactionsQuery) WithAccountFilter added in v1.8.0

func (a *TransactionsQuery) WithAccountFilter(account string) *TransactionsQuery

func (*TransactionsQuery) WithAfterTxID added in v1.8.0

func (a *TransactionsQuery) WithAfterTxID(after uint64) *TransactionsQuery

func (*TransactionsQuery) WithDestinationFilter added in v1.8.0

func (a *TransactionsQuery) WithDestinationFilter(dest string) *TransactionsQuery

func (*TransactionsQuery) WithEndTimeFilter added in v1.8.0

func (a *TransactionsQuery) WithEndTimeFilter(end time.Time) *TransactionsQuery

func (*TransactionsQuery) WithMetadataFilter added in v1.8.0

func (a *TransactionsQuery) WithMetadataFilter(metadata map[string]string) *TransactionsQuery

func (*TransactionsQuery) WithPageSize added in v1.8.0

func (a *TransactionsQuery) WithPageSize(pageSize uint) *TransactionsQuery

func (*TransactionsQuery) WithReferenceFilter added in v1.8.0

func (a *TransactionsQuery) WithReferenceFilter(ref string) *TransactionsQuery

func (*TransactionsQuery) WithSourceFilter added in v1.8.0

func (a *TransactionsQuery) WithSourceFilter(source string) *TransactionsQuery

func (*TransactionsQuery) WithStartTimeFilter added in v1.8.0

func (a *TransactionsQuery) WithStartTimeFilter(start time.Time) *TransactionsQuery

type TransactionsQueryFilters added in v1.8.0

type TransactionsQueryFilters struct {
	Reference   string
	Destination string
	Source      string
	Account     string
	EndTime     time.Time
	StartTime   time.Time
	Metadata    map[string]string
}

type TxVolumeAggregator added in v1.9.0

type TxVolumeAggregator struct {
	PreCommitVolumes  core.AccountsAssetsVolumes
	PostCommitVolumes core.AccountsAssetsVolumes
	// contains filtered or unexported fields
}

func (*TxVolumeAggregator) FindInPreviousTxs added in v1.9.0

func (tva *TxVolumeAggregator) FindInPreviousTxs(addr, asset string) *core.Volumes

func (*TxVolumeAggregator) Transfer added in v1.9.0

func (tva *TxVolumeAggregator) Transfer(
	ctx context.Context,
	from, to, asset string,
	amount *core.MonetaryInt,
	accs map[string]*core.AccountWithVolumes,
) error

type ValidationError

type ValidationError struct {
	Msg string
}

func NewValidationError

func NewValidationError(msg string) *ValidationError

func (ValidationError) Error

func (v ValidationError) Error() string

func (ValidationError) Is added in v1.0.4

func (v ValidationError) Is(err error) bool

type VolumeAggregator added in v1.9.0

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

func NewVolumeAggregator added in v1.8.0

func NewVolumeAggregator(l *Ledger) *VolumeAggregator

func (*VolumeAggregator) NextTx added in v1.9.0

func (agg *VolumeAggregator) NextTx() *TxVolumeAggregator

Jump to

Keyboard shortcuts

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