inmemory

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 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")
)
View Source
var (
	// ErrMarketNotExist is thrown when a market is not found
	ErrMarketNotExist = errors.New("market does not exists")
)

Functions

func NewVaultRepositoryImpl

func NewVaultRepositoryImpl() domain.VaultRepository

NewVaultRepositoryImpl returns a new empty VaultRepositoryImpl

Types

type MarketRepositoryImpl

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

MarketRepositoryImpl represents an in memory storage

func NewMarketRepositoryImpl

func NewMarketRepositoryImpl() *MarketRepositoryImpl

NewMemoryMarketRepository returns a new empty MarketRepositoryImpl

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) (
	markets []domain.Market, err 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) 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

type TradeRepositoryImpl

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

TradeRepositoryImpl represents an in memory storage

func NewTradeRepositoryImpl

func NewTradeRepositoryImpl() *TradeRepositoryImpl

NewTradeRepositoryImpl returns a new empty TradeRepositoryImpl

func (TradeRepositoryImpl) Begin

func (r TradeRepositoryImpl) Begin() (uow.Tx, error)

Begin returns a new TradeRepositoryTx

func (TradeRepositoryImpl) ContextKey

func (r TradeRepositoryImpl) ContextKey() interface{}

ContextKey returns the context key shared between in-memory repositories

func (TradeRepositoryImpl) GetAllTrades

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

GetAllTrades returns all the trades processed by the daemon

func (TradeRepositoryImpl) GetAllTradesByMarket

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

GetAllTradesByMarket returns all the trades processed for the given market

func (TradeRepositoryImpl) GetAllTradesByTrader

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

GetAllTradesByTrader returns all the trades processed for the given trader

func (TradeRepositoryImpl) GetOrCreateTrade

func (r TradeRepositoryImpl) GetOrCreateTrade(ctx 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(ctx context.Context, swapAcceptID string) (*domain.Trade, error)

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

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 TradeRepositoryTx

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

TradeRepositoryTx allows to make transactional read/write operation on the in-memory repository

func (*TradeRepositoryTx) Commit

func (tx *TradeRepositoryTx) Commit() error

Commit applies the updates made to the state of the transaction to its root

func (*TradeRepositoryTx) Rollback

func (tx *TradeRepositoryTx) Rollback() error

Rollback resets the state of the transaction to the state of its root

type UnspentRepositoryImpl

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

UnspentRepositoryImpl represents an in memory storage

func NewUnspentRepositoryImpl

func NewUnspentRepositoryImpl() *UnspentRepositoryImpl

NewUnspentRepositoryImpl returns a new empty MarketRepositoryImpl

func (UnspentRepositoryImpl) AddUnspents

func (r UnspentRepositoryImpl) AddUnspents(ctx 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) Begin

func (r UnspentRepositoryImpl) Begin() (uow.Tx, error)

Begin returns a new UnspentRepositoryTxImpl

func (UnspentRepositoryImpl) ContextKey

func (r UnspentRepositoryImpl) ContextKey() interface{}

ContextKey returns the context key shared between in-memory repositories

func (UnspentRepositoryImpl) GetAllSpents

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

GetAllSpents returns all the unspents that have been spent

func (UnspentRepositoryImpl) GetAllUnspents

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

GetAllUnspents returns all the unspents stored

func (UnspentRepositoryImpl) GetAvailableUnspents

func (r UnspentRepositoryImpl) GetAvailableUnspents(ctx context.Context) []domain.Unspent

GetAvailableUnspents returns the list of unlocked unspents

func (UnspentRepositoryImpl) GetAvailableUnspentsForAddresses

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

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

func (UnspentRepositoryImpl) GetBalance

func (r UnspentRepositoryImpl) GetBalance(
	ctx context.Context,
	address, assetHash string,
) uint64

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

func (UnspentRepositoryImpl) GetUnlockedBalance

func (r UnspentRepositoryImpl) GetUnlockedBalance(
	ctx context.Context,
	address, assetHash string,
) uint64

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

func (UnspentRepositoryImpl) LockUnspents

func (r UnspentRepositoryImpl) LockUnspents(
	ctx 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) UnlockUnspents

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

UnlockUnspents unlocks the given locked unspents

type UnspentRepositoryTxImpl

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

UnspentRepositoryTxImpl allows to make transactional read/write operation on the in-memory repository

func (*UnspentRepositoryTxImpl) Commit

func (tx *UnspentRepositoryTxImpl) Commit() error

Commit applies the updates made to the state of the transaction to its root

func (*UnspentRepositoryTxImpl) Rollback

func (tx *UnspentRepositoryTxImpl) Rollback() error

Rollback resets the state of the transaction to the state of its root

type VaultRepositoryImpl

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

VaultRepositoryImpl represents an in memory storage

func (VaultRepositoryImpl) Begin

func (r VaultRepositoryImpl) Begin() (uow.Tx, error)

Begin returns a new VaultRepositoryTx

func (VaultRepositoryImpl) ContextKey

func (r VaultRepositoryImpl) ContextKey() interface{}

ContextKey returns the context key shared between in-memory repositories

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

type VaultRepositoryTx

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

VaultRepositoryTx allows to make transactional read/write operation on the in-memory repository

func (*VaultRepositoryTx) Commit

func (tx *VaultRepositoryTx) Commit() error

Commit applies the updates made to the state of the transaction to its root

func (*VaultRepositoryTx) Rollback

func (tx *VaultRepositoryTx) Rollback() error

Rollback resets the state of the transaction to the state of its root

Jump to

Keyboard shortcuts

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