inmemory

package
v0.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMarketNotExist is thrown when a market is not found
	ErrMarketNotExist = errors.New("market does not exists")
	// ErrMarketsNotFound is thrown when there is no market associated to a given quote asset
	ErrMarketsNotFound = errors.New("no markets found for the given address")
	// ErrTradesNotFound is thrown when there is no trades associated to a given trade or swap ID
	ErrTradesNotFound = errors.New("no trades found for the given tradeID/SwapID")
	// ErrAlreadyLocked is thrown when trying to lock an already locked wallet
	ErrAlreadyLocked = errors.New("wallet is already locked")
	// ErrAlreadyUnlocked is thrown when trying to lunock an already unlocked wallet
	ErrAlreadyUnlocked = errors.New("wallet is already unlocked")
	// ErrWalletNotExist is thrown when mnemonic is not found
	ErrWalletNotExist = errors.New("wallet does not exist")
	// ErrWalletAlreadyExist is thrown when trying to create a new mnemonic if another one already exists
	ErrWalletAlreadyExist = errors.New("wallet already initialized with mnemonic")
	// ErrMustBeLocked is thrown when trying to change the passphrase with an unlocked wallet
	ErrMustBeLocked = errors.New("wallet must be locked to perform this operation")
	// ErrMustBeUnlocked is thrown when trying to make an operation that requires the wallet to be unlocked
	ErrMustBeUnlocked = errors.New("wallet must be unlocked to perform this operation")
	// ErrAccountNotExist is thrown when account is not found
	ErrAccountNotExist = errors.New("account does not exist")
)

Functions

func NewMarketRepositoryImpl

func NewMarketRepositoryImpl(dbManager *DbManager) domain.MarketRepository

NewMemoryMarketRepository returns a new empty MarketRepositoryImpl

func NewTradeRepositoryImpl

func NewTradeRepositoryImpl(db *DbManager) domain.TradeRepository

NewTradeRepositoryImpl returns a new empty TradeRepositoryImpl

func NewUnspentRepositoryImpl

func NewUnspentRepositoryImpl(db *DbManager) domain.UnspentRepository

NewUnspentRepositoryImpl returns a new empty MarketRepositoryImpl

func NewVaultRepositoryImpl

func NewVaultRepositoryImpl(db *DbManager) domain.VaultRepository

NewVaultRepositoryImpl returns a new empty VaultRepositoryImpl

Types

type DbManager added in v0.1.0

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

func NewDbManager added in v0.1.0

func NewDbManager() *DbManager

func (*DbManager) NewPricesTransaction added in v0.1.0

func (db *DbManager) NewPricesTransaction() ports.Transaction

func (*DbManager) NewTransaction added in v0.1.0

func (db *DbManager) NewTransaction() ports.Transaction

func (*DbManager) NewUnspentsTransaction added in v0.1.0

func (db *DbManager) NewUnspentsTransaction() ports.Transaction

func (*DbManager) RunPricesTransaction added in v0.1.0

func (db *DbManager) RunPricesTransaction(
	ctx context.Context,
	readOnly bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

func (*DbManager) RunTransaction added in v0.1.0

func (db *DbManager) RunTransaction(
	ctx context.Context,
	_ bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

func (*DbManager) RunUnspentsTransaction added in v0.1.0

func (db *DbManager) RunUnspentsTransaction(
	ctx context.Context,
	readOnly bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

type InmemoryTx added in v0.1.0

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

func (*InmemoryTx) Commit added in v0.1.0

func (tx *InmemoryTx) Commit() error

func (*InmemoryTx) Discard added in v0.1.0

func (tx *InmemoryTx) Discard()

type MarketRepositoryImpl

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

MarketRepositoryImpl represents an in memory storage

func (MarketRepositoryImpl) CloseMarket

func (r MarketRepositoryImpl) CloseMarket(_ context.Context, quoteAsset string) error

CloseMarket makes a market found with the given quote asset hash as NOT available for trading

func (MarketRepositoryImpl) GetAllMarkets

func (r MarketRepositoryImpl) GetAllMarkets(_ context.Context) ([]domain.Market, error)

GetAllMarkets returns all the markets either tradable or not.

func (MarketRepositoryImpl) GetLatestMarket

func (r MarketRepositoryImpl) GetLatestMarket(_ context.Context) (market *domain.Market, accountIndex int, err error)

GetLatestMarket returns the latest stored market (either funded or not)

func (MarketRepositoryImpl) GetMarketByAccount added in v0.1.0

func (r MarketRepositoryImpl) GetMarketByAccount(_ context.Context, accountIndex int) (*domain.Market, error)

GetMarketByAccount return the market for the account index given as parameter

func (MarketRepositoryImpl) GetMarketByAsset

func (r MarketRepositoryImpl) GetMarketByAsset(_ context.Context, quoteAsset string) (market *domain.Market, accountIndex int, err error)

GetMarketByAsset returns a funded market using the quote asset hash

func (MarketRepositoryImpl) GetOrCreateMarket

func (r MarketRepositoryImpl) GetOrCreateMarket(_ context.Context, accountIndex int) (market *domain.Market, err error)

GetOrCreateMarket gets a market with a given account index. If not found, a new entry is inserted

func (MarketRepositoryImpl) GetTradableMarkets

func (r MarketRepositoryImpl) GetTradableMarkets(_ context.Context) (tradableMarkets []domain.Market, err error)

GetTradableMarkets returns all the markets available for trading

func (MarketRepositoryImpl) OpenMarket

func (r MarketRepositoryImpl) OpenMarket(_ context.Context, quoteAsset string) error

OpenMarket makes a market found with the given quote asset hash as available for trading

func (MarketRepositoryImpl) UpdateMarket

func (r MarketRepositoryImpl) UpdateMarket(
	_ context.Context,
	accountIndex int,
	updateFn func(m *domain.Market) (*domain.Market, error),
) error

UpdateMarket updates data to a market identified by the account index passing an update function

func (*MarketRepositoryImpl) UpdatePrices added in v0.1.0

func (r *MarketRepositoryImpl) UpdatePrices(_ context.Context, accountIndex int, prices domain.Prices) error

type TradeRepositoryImpl

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

TradeRepositoryImpl represents an in memory storage

func (TradeRepositoryImpl) GetAllTrades

func (r TradeRepositoryImpl) GetAllTrades(_ context.Context) ([]*domain.Trade, error)

GetAllTrades returns all the trades processed by the daemon

func (TradeRepositoryImpl) GetAllTradesByMarket

func (r TradeRepositoryImpl) GetAllTradesByMarket(_ context.Context, marketQuoteAsset string) ([]*domain.Trade, error)

GetAllTradesByMarket returns all the trades processed for the given market

func (TradeRepositoryImpl) GetAllTradesByTrader

func (r TradeRepositoryImpl) GetAllTradesByTrader(_ context.Context, traderID string) ([]*domain.Trade, error)

GetAllTradesByTrader returns all the trades processed for the given trader

func (TradeRepositoryImpl) GetCompletedTradesByMarket added in v0.1.0

func (r TradeRepositoryImpl) GetCompletedTradesByMarket(ctx context.Context, marketQuoteAsset string) ([]*domain.Trade, error)

GetCompletedTradesByMarket returns the copmpleted trades for a given quote asset

func (TradeRepositoryImpl) GetOrCreateTrade

func (r TradeRepositoryImpl) GetOrCreateTrade(_ context.Context, tradeID *uuid.UUID) (*domain.Trade, error)

GetOrCreateTrade gets a trade with a given swapID that can be either a request, accept, or complete ID. They all identify the same Trade. If not found, a new entry is inserted

func (TradeRepositoryImpl) GetTradeBySwapAcceptID

func (r TradeRepositoryImpl) GetTradeBySwapAcceptID(_ context.Context, swapAcceptID string) (*domain.Trade, error)

GetTradeBySwapAcceptID returns the trade idetified by the swap accept message's id

func (TradeRepositoryImpl) GetTradeByTxID added in v0.1.2

func (r TradeRepositoryImpl) GetTradeByTxID(
	ctx context.Context,
	txID string,
) (*domain.Trade, error)

func (TradeRepositoryImpl) UpdateTrade

func (r TradeRepositoryImpl) UpdateTrade(
	ctx context.Context,
	tradeID *uuid.UUID,
	updateFn func(t *domain.Trade) (*domain.Trade, error),
) error

UpdateTrade updates data to a trade identified by any of its swap ids (request, accept, complete) passing an update function

type UnspentRepositoryImpl

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

UnspentRepositoryImpl represents an in memory storage

func (UnspentRepositoryImpl) AddUnspents

func (r UnspentRepositoryImpl) AddUnspents(_ context.Context, unspents []domain.Unspent) error

AddUnspents method is used by crawler to add unspent's to the memory, it assumes that all unspent's belongs to the same address, it assumes that each time it is invoked by crawler, it assumes that it will receive all unspent's for specific address it adds non exiting unspent's to the memory in case that unspent's, passed to the function, are not already in memory it will mark unspent in memory, as spent

func (UnspentRepositoryImpl) ConfirmUnspents added in v0.1.0

func (r UnspentRepositoryImpl) ConfirmUnspents(
	ctx context.Context,
	unspentKeys []domain.UnspentKey,
) error

func (UnspentRepositoryImpl) GetAllSpents

func (r UnspentRepositoryImpl) GetAllSpents(_ context.Context) []domain.Unspent

GetAllSpents returns all the unspents that have been spent

func (UnspentRepositoryImpl) GetAllUnspents

func (r UnspentRepositoryImpl) GetAllUnspents(_ context.Context) []domain.Unspent

GetAllUnspents returns all the unspents stored

func (UnspentRepositoryImpl) GetAllUnspentsForAddresses added in v0.1.0

func (r UnspentRepositoryImpl) GetAllUnspentsForAddresses(
	ctx context.Context,
	addresses []string,
) ([]domain.Unspent, error)

func (UnspentRepositoryImpl) GetAvailableUnspents

func (r UnspentRepositoryImpl) GetAvailableUnspents(_ context.Context) ([]domain.Unspent, error)

GetAvailableUnspents returns the list of unlocked unspents

func (UnspentRepositoryImpl) GetAvailableUnspentsForAddresses

func (r UnspentRepositoryImpl) GetAvailableUnspentsForAddresses(
	_ context.Context,
	addresses []string,
) ([]domain.Unspent, error)

GetAvailableUnspentsForAddresses returns the list of unlocked unspents for the given list of addresses

func (UnspentRepositoryImpl) GetBalance

func (r UnspentRepositoryImpl) GetBalance(
	_ context.Context,
	addresses []string,
	assetHash string,
) (uint64, error)

GetBalance returns the balance of the given asset for the given address

func (UnspentRepositoryImpl) GetUnlockedBalance

func (r UnspentRepositoryImpl) GetUnlockedBalance(
	_ context.Context,
	addresses []string,
	assetHash string,
) (uint64, error)

GetUnlockedBalance returns the total amount of unlocked unspents for the given asset and address

func (UnspentRepositoryImpl) GetUnspentForKey added in v0.1.0

func (r UnspentRepositoryImpl) GetUnspentForKey(
	_ context.Context,
	unspentKey domain.UnspentKey,
) (*domain.Unspent, error)

GetUnspentForKey return unspent for a given key.

func (UnspentRepositoryImpl) GetUnspentsForAddresses added in v0.1.0

func (r UnspentRepositoryImpl) GetUnspentsForAddresses(
	_ context.Context,
	addresses []string,
) ([]domain.Unspent, error)

GetUnspentsForAddresses returns unspents for a list of addresses.

func (UnspentRepositoryImpl) LockUnspents

func (r UnspentRepositoryImpl) LockUnspents(
	_ context.Context,
	unspentKeys []domain.UnspentKey,
	tradeID uuid.UUID,
) error

LockUnspents locks the given unspents associating them with the trade where they'are currently used as inputs

func (UnspentRepositoryImpl) SpendUnspents added in v0.1.0

func (r UnspentRepositoryImpl) SpendUnspents(
	ctx context.Context,
	unspentKeys []domain.UnspentKey,
) error

func (UnspentRepositoryImpl) UnlockUnspents

func (r UnspentRepositoryImpl) UnlockUnspents(
	_ context.Context,
	unspentKeys []domain.UnspentKey,
) error

UnlockUnspents unlocks the given locked unspents

func (UnspentRepositoryImpl) UpdateUnspent added in v0.1.0

func (r UnspentRepositoryImpl) UpdateUnspent(
	_ context.Context,
	unspentKey domain.UnspentKey,
	updateFn func(m *domain.Unspent) (*domain.Unspent, error),
) error

UpdateUnspent will update the Unspent model with the updateFn

type VaultRepositoryImpl

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

VaultRepositoryImpl represents an in memory storage

func (VaultRepositoryImpl) GetAccountByAddress

func (r VaultRepositoryImpl) GetAccountByAddress(ctx context.Context,
	addr string) (*domain.Account, int, error)

GetAccountByAddress returns the account with the given index if it exists

func (VaultRepositoryImpl) GetAccountByIndex

func (r VaultRepositoryImpl) GetAccountByIndex(ctx context.Context,
	accountIndex int) (*domain.Account, error)

GetAccountByIndex returns the account with the given index if it exists

func (VaultRepositoryImpl) GetAllDerivedAddressesAndBlindingKeysForAccount

func (r VaultRepositoryImpl) GetAllDerivedAddressesAndBlindingKeysForAccount(ctx context.Context, accountIndex int) ([]string, [][]byte, error)

GetAllDerivedAddressesAndBlindingKeysForAccount returns the list of all external and internal (change) addresses derived for the provided account along with the respective private blinding keys

func (VaultRepositoryImpl) GetAllDerivedExternalAddressesForAccount

func (r VaultRepositoryImpl) GetAllDerivedExternalAddressesForAccount(ctx context.Context, accountIndex int) ([]string, error)

func (VaultRepositoryImpl) GetDerivationPathByScript

func (r VaultRepositoryImpl) GetDerivationPathByScript(ctx context.Context, accountIndex int, scripts []string) (map[string]string, error)

GetDerivationPathByScript returns the derivation paths for the given account index and the given list of scripts. If some script of the list does not map to any known derivation path, an error is thrown

func (VaultRepositoryImpl) GetOrCreateVault

func (r VaultRepositoryImpl) GetOrCreateVault(ctx context.Context,
	mnemonic []string, passphrase string) (*domain.Vault, error)

GetOrCreateVault returns the current Vault. If not yet initialized, it creates a new Vault, initialized with the mnemonic encrypted with the passphrase

func (VaultRepositoryImpl) UpdateVault

func (r VaultRepositoryImpl) UpdateVault(
	ctx context.Context,
	mnemonic []string,
	passphrase string,
	updateFn func(*domain.Vault) (*domain.Vault, error),
) error

UpdateVault updates data to the Vault passing an update function

Jump to

Keyboard shortcuts

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