application

package
v0.2.0-rc.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TradeBuy = iota
	TradeSell
)
View Source
const RegtestExplorerAPI = "http://127.0.0.1:3001"

RegtestExplorerAPI ...

Variables

View Source
var (
	// ErrFeeAccountNotFunded ...
	ErrFeeAccountNotFunded = errors.New(
		"fee account must be funded to perform the requested operation",
	)
	// ErrUnknownStrategy ...
	ErrUnknownStrategy = errors.New("strategy not supported")
)
View Source
var (
	// ErrWalletNotFunded ...
	ErrWalletNotFunded = fmt.Errorf("wallet not funded")
	// ErrWalletIsSyncing ...
	ErrWalletIsSyncing = fmt.Errorf(
		"wallet is syncing data from blockchain. All functionalities are " +
			"disabled until this operation is completed",
	)
	// ErrWalletNotInitialized ...
	ErrWalletNotInitialized = fmt.Errorf("wallet not initialized")
)

Functions

This section is empty.

Types

type AddressAndBlindingKey added in v0.1.2

type AddressAndBlindingKey struct {
	Address     string
	BlindingKey string
}

type Balance

type Balance struct {
	BaseAmount  int64
	QuoteAmount int64
}

type BalanceWithFee

type BalanceWithFee struct {
	Balance
	Fee
}

type BlockchainListener

type BlockchainListener interface {
	StartObservation()
	StopObservation()

	StartObserveAddress(accountIndex int, addr string, blindKey []byte)
	StopObserveAddress(addr string)

	StartObserveTx(txid string)
	StopObserveTx(txid string)
}

BlockchainListener defines the needed method sto start and stop a blockchain listener

func NewBlockchainListener

func NewBlockchainListener(
	unspentRepository domain.UnspentRepository,
	marketRepository domain.MarketRepository,
	vaultRepository domain.VaultRepository,
	tradeRepository domain.TradeRepository,
	crawlerSvc crawler.Service,
	explorerSvc explorer.Service,
	dbManager ports.DbManager,
) BlockchainListener

NewBlockchainListener returns a BlockchainListener with all the needed services

type Fee

type Fee struct {
	BasisPoint int64
}

Fee is the market fee percentage in basis point:

  • 0,01% -> 1 bp
  • 1,00% -> 100 bp
  • 99,99% -> 9999 bp

type FeeInfo added in v0.2.0

type FeeInfo struct {
	TradeID     string
	BasisPoint  int64
	Asset       string
	Amount      uint64
	MarketPrice decimal.Decimal
}

type Market

type Market struct {
	BaseAsset  string
	QuoteAsset string
}

type MarketInfo

type MarketInfo struct {
	Market       Market
	Fee          Fee
	Tradable     bool
	StrategyType int
}

MarketInfo is the data struct returned by ListMarket RPC.

type MarketStrategy

type MarketStrategy struct {
	Market
	Strategy domain.StrategyType
}

type MarketWithFee

type MarketWithFee struct {
	Market
	Fee
}

type MarketWithPrice

type MarketWithPrice struct {
	Market
	Price
}

type OperatorService

type OperatorService interface {
	DepositMarket(
		ctx context.Context,
		baseAsset string,
		quoteAsset string,
		numOfAddresses int,
	) ([]string, error)
	DepositFeeAccount(
		ctx context.Context,
		numOfAddresses int,
	) ([]AddressAndBlindingKey, error)
	OpenMarket(
		ctx context.Context,
		baseAsset string,
		quoteAsset string,
	) error
	CloseMarket(
		ctx context.Context,
		baseAsset string,
		quoteAsset string,
	) error
	UpdateMarketFee(
		ctx context.Context,
		req MarketWithFee,
	) (*MarketWithFee, error)
	UpdateMarketPrice(
		ctx context.Context,
		req MarketWithPrice,
	) error
	UpdateMarketStrategy(
		ctx context.Context,
		req MarketStrategy,
	) error
	ListSwaps(
		ctx context.Context,
	) ([]SwapInfo, error)
	ListMarketExternalAddresses(
		ctx context.Context,
		req Market,
	) ([]string, error)
	WithdrawMarketFunds(
		ctx context.Context,
		req WithdrawMarketReq,
	) (
		[]byte,
		error,
	)
	FeeAccountBalance(ctx context.Context) (
		int64,
		error,
	)
	ListMarket(
		ctx context.Context,
	) ([]MarketInfo, error)
	GetCollectedMarketFee(
		ctx context.Context,
		market Market,
	) (*ReportMarketFee, error)
}

OperatorService defines the methods of the application layer for the operator service.

func NewOperatorService

func NewOperatorService(
	marketRepository domain.MarketRepository,
	vaultRepository domain.VaultRepository,
	tradeRepository domain.TradeRepository,
	unspentRepository domain.UnspentRepository,
	explorerSvc explorer.Service,
	bcListener BlockchainListener,
) OperatorService

NewOperatorService is a constructor function for OperatorService.

type Price

type Price struct {
	BasePrice  decimal.Decimal
	QuotePrice decimal.Decimal
}

type PriceWithFee

type PriceWithFee struct {
	Price
	Fee
	Amount uint64
	Asset  string
}

type ReportMarketFee

type ReportMarketFee struct {
	CollectedFees              []FeeInfo
	TotalCollectedFeesPerAsset map[string]int64
}

type SendToManyRequest

type SendToManyRequest struct {
	Outputs         []TxOut
	MillisatPerByte int64
	Push            bool
}

type SwapInfo

type SwapInfo struct {
	Status           int32
	AmountP          uint64
	AssetP           string
	AmountR          uint64
	AssetR           string
	MarketFee        Fee
	RequestTimeUnix  uint64
	AcceptTimeUnix   uint64
	CompleteTimeUnix uint64
	ExpiryTimeUnix   uint64
}

SwapInfo is the data struct returned by ListSwap RPC.

type TradeService

type TradeService interface {
	GetTradableMarkets(ctx context.Context) ([]MarketWithFee, error)
	GetMarketPrice(
		ctx context.Context,
		market Market,
		tradeType int,
		amount uint64,
		asset string,
	) (*PriceWithFee, error)
	TradePropose(
		ctx context.Context,
		market Market,
		tradeType int,
		swapRequest *pb.SwapRequest,
	) (*pb.SwapAccept, *pb.SwapFail, uint64, error)
	TradeComplete(
		ctx context.Context,
		swapComplete *pb.SwapComplete,
		swapFail *pb.SwapFail,
	) (string, *pb.SwapFail, error)
	GetMarketBalance(
		ctx context.Context,
		market Market,
	) (*BalanceWithFee, error)
}

func NewTradeService

func NewTradeService(
	marketRepository domain.MarketRepository,
	tradeRepository domain.TradeRepository,
	vaultRepository domain.VaultRepository,
	unspentRepository domain.UnspentRepository,
	explorerSvc explorer.Service,
	bcListener BlockchainListener,
) TradeService

type TxOut

type TxOut struct {
	Asset   string
	Value   int64
	Address string
}

type WalletService

type WalletService interface {
	GenSeed(ctx context.Context) ([]string, error)
	InitWallet(
		ctx context.Context,
		mnemonic []string,
		passphrase string,
		restore bool,
	) error
	UnlockWallet(
		ctx context.Context,
		passphrase string,
	) error
	ChangePassword(
		ctx context.Context,
		currentPassphrase string,
		newPassphrase string) error
	GenerateAddressAndBlindingKey(
		ctx context.Context,
	) (address string, blindingKey string, err error)
	GetWalletBalance(
		ctx context.Context,
	) (map[string]domain.BalanceInfo, error)
	SendToMany(
		ctx context.Context,
		req SendToManyRequest,
	) ([]byte, error)
}

func NewWalletService

func NewWalletService(
	vaultRepository domain.VaultRepository,
	unspentRepository domain.UnspentRepository,
	explorerService explorer.Service,
	blockchainListener BlockchainListener,
) WalletService

type WithdrawMarketReq

type WithdrawMarketReq struct {
	Market
	BalanceToWithdraw Balance
	MillisatPerByte   int64
	Address           string
	Push              bool
}

Jump to

Keyboard shortcuts

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