ledger

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 14 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{
	WithLocker(NewInMemoryLocker()),
	WithMonitor(&noOpMonitor{}),
}
View Source
var NoOpLocker = LockerFn(func(ctx context.Context, name string) (Unlock, error) {
	return func(ctx context.Context) {}, nil
})

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 MemoryLockModule added in v1.3.0

func MemoryLockModule() fx.Option

func NewNoOpMonitor added in v1.8.0

func NewNoOpMonitor() *noOpMonitor

func NewVolumeAggregator added in v1.8.0

func NewVolumeAggregator(store Store) *volumeAggregator

func NoLockModule added in v1.3.0

func NoLockModule() fx.Option

func ProvideResolverOption

func ProvideResolverOption(provider interface{}) fx.Option

func ResolveModule

func ResolveModule() 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) 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
}

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"

	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 CommitResult added in v1.6.0

type CommitResult struct {
	PreCommitVolumes      core.AccountsAssetsVolumes
	PostCommitVolumes     core.AccountsAssetsVolumes
	GeneratedTransactions []core.ExpandedTransaction
}

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 InMemoryLocker

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

func NewInMemoryLocker

func NewInMemoryLocker() *InMemoryLocker

func (*InMemoryLocker) Lock

func (d *InMemoryLocker) Lock(ctx context.Context, ledger string) (Unlock, error)

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,
	locker Locker,
	monitor Monitor,
	options ...LedgerOption,
) (*Ledger, error)

func (*Ledger) Close

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

func (*Ledger) Commit

func (l *Ledger) Commit(ctx context.Context, txsData []core.TransactionData) (*CommitResult, error)

func (*Ledger) CommitPreview added in v1.1.0

func (l *Ledger) CommitPreview(ctx context.Context, txsData []core.TransactionData) (*CommitResult, 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) Execute

func (l *Ledger) Execute(ctx context.Context, script core.Script) (*core.ExpandedTransaction, error)

func (*Ledger) ExecutePreview added in v1.1.0

func (l *Ledger) ExecutePreview(ctx context.Context, script core.Script) (*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) (sharedapi.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 BalancesQuery) (core.AssetsBalances, error)

func (*Ledger) GetLedgerStore added in v1.8.0

func (l *Ledger) GetLedgerStore() Store

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) ProcessTx added in v1.8.0

func (l *Ledger) ProcessTx(ctx context.Context, ts []core.TransactionData) (*CommitResult, error)

func (*Ledger) RevertTransaction

func (l *Ledger) RevertTransaction(ctx context.Context, id uint64) (*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 Locker

type Locker interface {
	Lock(ctx context.Context, name string) (Unlock, error)
}

type LockerFn added in v1.3.0

type LockerFn func(ctx context.Context, name string) (Unlock, error)

func (LockerFn) Lock added in v1.3.0

func (fn LockerFn) Lock(ctx context.Context, name string) (Unlock, error)

type Monitor added in v1.3.0

type Monitor interface {
	CommittedTransactions(ctx context.Context, ledger string, res *CommitResult)
	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 WithLocker

func WithLocker(locker Locker) ResolveOptionFn

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,
	options ...ResolverOption,
) *Resolver

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) (sharedapi.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)
	GetVolumes(ctx context.Context, accountAddress, asset string) (core.Volumes, error)
	CountAccounts(context.Context, AccountsQuery) (uint64, error)
	GetAccounts(context.Context, AccountsQuery) (sharedapi.Cursor[core.Account], error)
	GetBalances(context.Context, BalancesQuery) (sharedapi.Cursor[core.AccountsBalances], error)
	GetBalancesAggregated(context.Context, BalancesQuery) (core.AssetsBalances, error)
	LastLog(ctx context.Context) (*core.Log, error)
	Logs(ctx context.Context) ([]core.Log, error)
	LoadMapping(ctx context.Context) (*core.Mapping, error)

	UpdateTransactionMetadata(ctx context.Context, id uint64, metadata core.Metadata, at time.Time) error
	UpdateAccountMetadata(ctx context.Context, id 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 Unlock

type Unlock func(ctx context.Context)

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

Jump to

Keyboard shortcuts

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