ledger

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScriptErrorInsufficientFund  = "INSUFFICIENT_FUND"
	ScriptErrorCompilationFailed = "COMPILATION_FAILED"
	ScriptErrorNoScript          = "NO_SCRIPT"
)
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 IsScriptError added in v1.0.5

func IsScriptError(err error) 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 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(name string, store storage.Store, locker Locker, monitor Monitor) (*Ledger, error)

func (*Ledger) Close

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

func (*Ledger) Commit

func (*Ledger) CommitPreview added in v1.1.0

func (*Ledger) CountAccounts added in v1.3.2

func (l *Ledger) CountAccounts(ctx context.Context, m ...query.Modifier) (uint64, error)

func (*Ledger) CountTransactions added in v1.3.2

func (l *Ledger) CountTransactions(ctx context.Context, m ...query.Modifier) (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) FindAccounts

func (l *Ledger) FindAccounts(ctx context.Context, m ...query.Modifier) (sharedapi.Cursor, error)

func (*Ledger) FindTransactions

func (l *Ledger) FindTransactions(ctx context.Context, m ...query.Modifier) (sharedapi.Cursor, error)

func (*Ledger) GetAccount

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

func (*Ledger) GetLastTransaction

func (l *Ledger) GetLastTransaction(ctx context.Context) (core.Transaction, error)

TODO: This is only used for testing I think we should remove this and all related code We don't need any testing logic in the business code.

func (*Ledger) GetTransaction

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

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, []core.Transaction, core.AggregatedVolumes)
	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 core.Transaction, revert core.Transaction)
}

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

func WithStorageDriver added in v1.3.2

func WithStorageDriver(factory storage.Driver) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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