ledger

package
v1.7.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 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 ResolverOptionsKey = `group:"_ledgerResolverOptions"`

Variables

View Source
var DefaultContracts = []core.Contract{
	{
		Expr: &core.ExprGte{
			Op1: core.VariableExpr{
				Name: "balance",
			},
			Op2: core.ConstantExpr{
				Value: float64(0),
			},
		},
		Account: "*",
	},
}
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 NoLockModule added in v1.3.0

func NoLockModule() fx.Option

func ProvideResolverOption

func ProvideResolverOption(provider interface{}) fx.Option

func ResolveModule

func ResolveModule() fx.Option

Types

type CommitResult added in v1.6.0

type CommitResult struct {
	PreCommitVolumes      core.AccountsAssetsVolumes
	PostCommitVolumes     core.AccountsAssetsVolumes
	GeneratedTransactions []core.Transaction
	GeneratedLogs         []core.Log
}

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 storage.Store, locker Locker, monitor Monitor) (*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 storage.AccountsQuery) (uint64, error)

func (*Ledger) CountTransactions added in v1.3.2

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

func (*Ledger) Execute

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

func (*Ledger) ExecutePreview added in v1.1.0

func (l *Ledger) ExecutePreview(ctx context.Context, script core.Script) (*core.Transaction, 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 (*Ledger) GetBalances added in v1.6.0

func (*Ledger) GetBalancesAggregated added in v1.6.0

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

func (*Ledger) GetTransaction

func (l *Ledger) GetTransaction(ctx context.Context, id uint64) (*core.Transaction, 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) (*core.Transaction, 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 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(context.Context, string, *CommitResult)
	SavedMetadata(ctx context.Context, ledger string, targetType string, id string, metadata core.Metadata)
	UpdatedMapping(context.Context, string, core.Mapping)
	RevertedTransaction(ctx context.Context, ledger string, reverted, revert *core.Transaction)
}

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, 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 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 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