ledger

package
v0.0.0-...-fb9541f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ledger provides useful utilities concerning ledgers within paydex, specifically as a central location to store a cached snapshot of the state of both horizon's and paydex-core's views of the ledger. This package is intended to be at the lowest levels of horizon's dependency tree, please keep it free of dependencies to other horizon packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetState

func SetState(next State)

SetState updates the cached snapshot of the ledger state

Types

type HistoryDBSource

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

HistoryDBSource utility struct to pass the SSE update frequency and a function to get the current ledger state.

func NewHistoryDBSource

func NewHistoryDBSource(updateFrequency time.Duration) HistoryDBSource

NewHistoryDBSource constructs a new instance of HistoryDBSource

func (HistoryDBSource) CurrentLedger

func (source HistoryDBSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (HistoryDBSource) NextLedger

func (source HistoryDBSource) NextLedger(currentSequence uint32) chan uint32

NextLedger returns a channel which yields every time there is a new ledger with a sequence number larger than currentSequence.

type Source

type Source interface {
	CurrentLedger() uint32
	NextLedger(currentSequence uint32) chan uint32
}

Source exposes two helpers methods to help you find out the current ledger and yield every time there is a new ledger.

type State

type State struct {
	CoreLatest       int32  `db:"core_latest"`
	HistoryLatest    int32  `db:"history_latest"`
	HistoryElder     int32  `db:"history_elder"`
	ExpHistoryLatest uint32 `db:"exp_history_latest"`
}

State represents a snapshot of both horizon's and paydex-core's view of the ledger.

func CurrentState

func CurrentState() State

CurrentState returns the cached snapshot of ledger state

type TestingSource

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

TestingSource is helper struct which implements the LedgerSource interface.

func NewTestingSource

func NewTestingSource(currentLedger uint32) *TestingSource

NewTestingSource returns a TestingSource.

func (*TestingSource) AddLedger

func (source *TestingSource) AddLedger(nextSequence uint32)

AddLedger adds a new sequence to the newLedgers channel. AddLedger() will block until the new sequence is read

func (*TestingSource) CurrentLedger

func (source *TestingSource) CurrentLedger() uint32

CurrentLedger returns the current ledger.

func (*TestingSource) NextLedger

func (source *TestingSource) NextLedger(currentSequence uint32) chan uint32

NextLedger returns a channel which yields every time there is a new ledger.

func (*TestingSource) TryAddLedger

func (source *TestingSource) TryAddLedger(
	ctx context.Context,
	nextSequence uint32,
	timeout time.Duration,
) bool

TryAddLedger sends a new sequence to the newLedgers channel. TryAddLedger() will block until whichever of the following events occur first: * the given ctx terminates * timeout has elapsed * the new sequence is read from the newLedgers channel TryAddLedger() returns true if the new sequence was read from the newLedgers channel

Jump to

Keyboard shortcuts

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