meshdb

package
v6.1.1-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDBFilledWithPinnedOrders = errors.New("the database is full of pinned orders; no orders can be removed in order to make space")

Functions

This section is empty.

Types

type MeshDB

type MeshDB struct {
	MiniHeaders *MiniHeadersCollection
	Orders      *OrdersCollection
	// contains filtered or unexported fields
}

MeshDB instantiates the DB connection and creates all the collections used by the application

func New

func New(path string) (*MeshDB, error)

New instantiates a new MeshDB instance

func (*MeshDB) ClearAllMiniHeaders

func (m *MeshDB) ClearAllMiniHeaders() error

ClearAllMiniHeaders removes all stored MiniHeaders from the database.

func (*MeshDB) Close

func (m *MeshDB) Close()

Close closes the database connection

func (*MeshDB) CountPinnedOrders

func (m *MeshDB) CountPinnedOrders() (int, error)

CountPinnedOrders returns the number of pinned orders.

func (*MeshDB) FindAllMiniHeadersSortedByNumber

func (m *MeshDB) FindAllMiniHeadersSortedByNumber() ([]*miniheader.MiniHeader, error)

FindAllMiniHeadersSortedByNumber returns all MiniHeaders sorted by block number

func (*MeshDB) FindLatestMiniHeader

func (m *MeshDB) FindLatestMiniHeader() (*miniheader.MiniHeader, error)

FindLatestMiniHeader returns the latest MiniHeader (i.e. the one with the largest block number), or nil if there are none in the database.

func (*MeshDB) FindOrdersByMakerAddress

func (m *MeshDB) FindOrdersByMakerAddress(makerAddress common.Address) ([]*Order, error)

FindOrdersByMakerAddress finds all orders belonging to a particular maker address

func (*MeshDB) FindOrdersByMakerAddressAndMaxSalt

func (m *MeshDB) FindOrdersByMakerAddressAndMaxSalt(makerAddress common.Address, salt *big.Int) ([]*Order, error)

FindOrdersByMakerAddressAndMaxSalt finds all orders belonging to a particular maker address that also have a salt value less then or equal to X

func (*MeshDB) FindOrdersByMakerAddressTokenAddressAndTokenID

func (m *MeshDB) FindOrdersByMakerAddressTokenAddressAndTokenID(makerAddress, tokenAddress common.Address, tokenID *big.Int) ([]*Order, error)

FindOrdersByMakerAddressTokenAddressAndTokenID finds all orders belonging to a particular maker address where makerAssetData encodes for a particular token contract and optionally a token ID

func (*MeshDB) FindOrdersLastUpdatedBefore

func (m *MeshDB) FindOrdersLastUpdatedBefore(lastUpdated time.Time) ([]*Order, error)

FindOrdersLastUpdatedBefore finds all orders where the LastUpdated time is less than X

func (*MeshDB) FindRemovedOrders

func (m *MeshDB) FindRemovedOrders() ([]*Order, error)

FindRemovedOrders finds all orders that have been flagged for removal

func (*MeshDB) GetMetadata

func (m *MeshDB) GetMetadata() (*Metadata, error)

GetMetadata returns the metadata (or a db.NotFoundError if no metadata has been found).

func (*MeshDB) SaveMetadata

func (m *MeshDB) SaveMetadata(metadata *Metadata) error

SaveMetadata inserts the metadata into the database, overwriting any existing metadata.

func (*MeshDB) TrimOrdersByExpirationTime

func (m *MeshDB) TrimOrdersByExpirationTime(targetMaxOrders int) (newMaxExpirationTime *big.Int, removedOrders []*Order, err error)

TrimOrdersByExpirationTime removes existing orders with the highest expiration time until the number of remaining orders is <= targetMaxOrders. It returns any orders that were removed and the new max expiration time that can be used to eliminate incoming orders that expire too far in the future.

func (*MeshDB) UpdateMetadata

func (m *MeshDB) UpdateMetadata(updater func(oldmetadata Metadata) (newMetadata Metadata)) error

UpdateMetadata updates the metadata in the database via a transaction. It accepts a callback function which will be provided with the old metadata and should return the new metadata to save.

type Metadata

type Metadata struct {
	EthereumChainID                   int
	MaxExpirationTime                 *big.Int
	EthRPCRequestsSentInCurrentUTCDay int
	StartOfCurrentUTCDay              time.Time
}

Metadata is the database representation of MeshDB instance metadata

func (Metadata) ID

func (m Metadata) ID() []byte

ID returns the id used for the metadata collection (one per DB)

type MetadataCollection

type MetadataCollection struct {
	*db.Collection
}

MetadataCollection represents a DB collection used to store instance metadata

type MiniHeadersCollection

type MiniHeadersCollection struct {
	*db.Collection
	// contains filtered or unexported fields
}

MiniHeadersCollection represents a DB collection of mini Ethereum block headers

type Order

type Order struct {
	Hash        common.Hash
	SignedOrder *zeroex.SignedOrder
	// When was this order last validated
	LastUpdated time.Time
	// How much of this order can still be filled
	FillableTakerAssetAmount *big.Int
	// Was this order flagged for removal? Due to the possibility of block-reorgs, instead
	// of immediately removing an order when FillableTakerAssetAmount becomes 0, we instead
	// flag it for removal. After this order isn't updated for X time and has IsRemoved = true,
	// the order can be permanently deleted.
	IsRemoved bool
	// IsPinned indicates whether or not the order is pinned. Pinned orders are
	// not removed from the database unless they become unfillable.
	IsPinned bool
}

Order is the database representation a 0x order along with some relevant metadata

func (Order) ID

func (o Order) ID() []byte

ID returns the Order's ID

type OrdersCollection

type OrdersCollection struct {
	*db.Collection
	MakerAddressAndSaltIndex             *db.Index
	MakerAddressTokenAddressTokenIDIndex *db.Index
	LastUpdatedIndex                     *db.Index
	IsRemovedIndex                       *db.Index
	ExpirationTimeIndex                  *db.Index
}

OrdersCollection represents a DB collection of 0x orders

Jump to

Keyboard shortcuts

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