dex

package
v0.1.1-beta1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: BlueOak-1.0.0 Imports: 12 Imported by: 17

Documentation

Index

Constants

View Source
const (
	LevelTrace    = slog.LevelTrace
	LevelDebug    = slog.LevelDebug
	LevelInfo     = slog.LevelInfo
	LevelWarn     = slog.LevelWarn
	LevelError    = slog.LevelError
	LevelCritical = slog.LevelCritical
	LevelOff      = slog.LevelOff

	DefaultLogLevel = LevelDebug // TODO: back to LevelInfo at some point
)

Level constants.

View Source
const Simnet = Regtest

The DEX recognizes only three networks. Simnet is an alias of Regtest.

View Source
const (
	UnsupportedScriptError = ErrorKind("unsupported script type")
)

Variables

This section is empty.

Functions

func BipIDSymbol

func BipIDSymbol(id uint32) string

BipIDSymbol returns the BIP ID for a given symbol.

func BipSymbolID

func BipSymbolID(symbol string) (uint32, bool)

BipSymbolID returns the asset ID associated with a given ticker symbol. While there are a number of duplicate ticker symbols in the BIP ID list (cpc, cmt, xrd, dst, one, ask, ...), those are disambiguated in the bipIDs map here, so must be referenced with their bracketed suffix.

func LockTimeMaker

func LockTimeMaker(network Network) time.Duration

LockTimeMaker returns the maker locktime value that should be used by both client and server for the specified network. Mainnet uses a constant value while test networks support setting a custom value during build.

func LockTimeTaker

func LockTimeTaker(network Network) time.Duration

LockTimeTaker returns the taker locktime value that should be used by both client and server for the specified network. Mainnet uses a constant value while test networks support setting a custom value during build.

func MarketName

func MarketName(base, quote uint32) (string, error)

MarketName creates the string representation of a DEX market (e.g. "dcr_btc") given the base and quote asset indexes defined in BIP-0044. See also BipIDSymbol.

func SemverCompatible

func SemverCompatible(required, actual Semver) bool

SemverCompatible decides if the actual version is compatible with the required one.

Types

type Asset

type Asset struct {
	ID           uint32 `json:"id"`
	Symbol       string `json:"symbol"`
	LotSize      uint64 `json:"lotSize"`
	RateStep     uint64 `json:"rateStep"`
	MaxFeeRate   uint64 `json:"maxFeeRate"`
	SwapSize     uint64 `json:"swapSize"`
	SwapSizeBase uint64 `json:"swapSizeBase"`
	SwapConf     uint32 `json:"swapConf"`
}

Asset is the configurable asset variables.

type Bytes

type Bytes []byte

Bytes is a byte slice that marshals to and unmarshals from a hexadecimal string. The default go behavior is to marshal []byte to a base-64 string.

func (Bytes) MarshalJSON

func (b Bytes) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaller interface, and will marshal the bytes to a hex string.

func (*Bytes) Scan

func (b *Bytes) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (Bytes) String

func (b Bytes) String() string

String return the hex encoding of the Bytes.

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(encHex []byte) (err error)

UnmarshalJSON satisfies the json.Unmarshaler interface, and expects a UTF-8 encoding of a hex string in double quotes.

type ConnectionMaster

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

ConnectionMaster manages a Connector.

func NewConnectionMaster

func NewConnectionMaster(c Connector) *ConnectionMaster

NewConnectionMaster is the constructor for a new ConnectionMaster.

func (*ConnectionMaster) Connect

func (c *ConnectionMaster) Connect(ctx context.Context) (err error)

Connect connects the Connector, and returns any initial connection error. Use Disconnect to shut down the Connector.

func (*ConnectionMaster) Disconnect

func (c *ConnectionMaster) Disconnect()

Disconnect closes the connection and waits for shutdown.

func (*ConnectionMaster) On

func (cm *ConnectionMaster) On() bool

On will be true until the context is canceled.

func (*ConnectionMaster) Wait

func (c *ConnectionMaster) Wait()

Wait waits for the the WaitGroup returned by Connect.

type Connector

type Connector interface {
	Connect(ctx context.Context) (*sync.WaitGroup, error)
}

Connector is any type that implements the Connect method, which will return a connection error, and a WaitGroup that can be waited on at Disconnection.

type Error

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

Error pairs an error with details.

func NewError

func NewError(err error, detail string) Error

NewError wraps the provided Error with details in a Error, facilitating the use of errors.Is and errors.As via errors.Unwrap.

func (Error) Error

func (e Error) Error() string

Error satisfies the error interface, combining the wrapped error message with the details.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap returns the wrapped error, allowing errors.Is and errors.As to work.

type ErrorKind

type ErrorKind string

ErrorKind identifies a kind of error that can be used to define new errors via const SomeError = dex.ErrorKind("something").

func (ErrorKind) Error

func (e ErrorKind) Error() string

Error satisfies the error interface and prints human-readable errors.

type Logger

type Logger interface {
	slog.Logger
	SubLogger(name string) Logger
}

Logger is a logger. Many dcrdex types will take a logger as an argument.

var Disabled Logger = &logger{
	Logger:  slog.Disabled,
	level:   LevelOff,
	backend: slog.NewBackend(ioutil.Discard),
}

Disabled is a Logger that will never output anything.

func NewLogger

func NewLogger(name string, lvl slog.Level, writer io.Writer, utc ...bool) Logger

NewLogger creates a new Logger with the given name, log level, and io.Writer.

func StdOutLogger

func StdOutLogger(name string, lvl slog.Level, utc ...bool) Logger

StdOutLogger creates a Logger with the provided name with lvl as the log level and prints to standard out.

type LoggerMaker

type LoggerMaker struct {
	*slog.Backend
	DefaultLevel slog.Level
	Levels       map[string]slog.Level
}

LoggerMaker allows creation of new log subsystems with predefined levels.

func NewLoggerMaker

func NewLoggerMaker(writer io.Writer, debugLevel string, utc ...bool) (*LoggerMaker, error)

NewLoggerMaker creates a new LoggerMaker from the provided io.Writer and debug level string. See SetLevels for details on the debug level string.

func (*LoggerMaker) Level

func (lm *LoggerMaker) Level(name string) slog.Level

Level returns the log level for the named subsystem. If a level is not configured for this subsystem, the LoggerMaker's DefaultLevel is returned.

func (*LoggerMaker) Logger

func (lm *LoggerMaker) Logger(name string) Logger

Logger creates a logger with the provided name, using the log level for that name if it was set, otherwise the default log level. This differs from NewLogger, which does not look in the Level map for the name.

func (*LoggerMaker) NewLogger

func (lm *LoggerMaker) NewLogger(name string, level ...slog.Level) Logger

NewLogger creates a new Logger for the subsystem with the given name. If a log level is specified, it is used for the Logger. Otherwise the DefaultLevel is used.

func (*LoggerMaker) SetLevels

func (lm *LoggerMaker) SetLevels(debugLevel string) error

SetLevels either set the DefaultLevel or resets the Levels map for future subsystems created with the LoggerMaker.

The debugLevel string can specify a single verbosity for the entire system: "trace", "debug", "info", "warn", "error", "critical", "off". The Levels map is not modified with this syntax.

Or the verbosity can be specified for individual subsystems, separating subsystems by commas and assigning each specifically. Such a debugLevel string might look like `CORE=debug,SWAP=trace`. The DefaultLevel is not modified with this syntax.

type MarketInfo

type MarketInfo struct {
	Name                   string
	Base                   uint32
	Quote                  uint32
	LotSize                uint64
	EpochDuration          uint64 // msec
	MarketBuyBuffer        float64
	MaxUserCancelsPerEpoch uint32
}

MarketInfo specifies a market that the Archiver must support.

func NewMarketInfo

func NewMarketInfo(base, quote uint32, lotSize, epochDuration uint64, marketBuyBuffer float64) (*MarketInfo, error)

NewMarketInfo creates a new market configuration (MarketInfo) from the given base and quote asset indexes, order lot size, and epoch duration in milliseconds. See also MarketName.

func NewMarketInfoFromSymbols

func NewMarketInfoFromSymbols(base, quote string, lotSize, epochDuration uint64, marketBuyBuffer float64) (*MarketInfo, error)

NewMarketInfoFromSymbols is like NewMarketInfo, but the base and quote assets are identified by their symbols as defined in the decred.org/dcrdex/server/asset package.

type Network

type Network uint8

Network flags passed to asset backends to signify which network to use.

const (
	Mainnet Network = iota
	Testnet
	Regtest
)

func NetFromString

func NetFromString(net string) (Network, error)

NetFromString returns the Network for the given network name.

func (Network) String

func (n Network) String() string

String returns the string representation of a Network.

type Runner

type Runner interface {
	Run(ctx context.Context)
}

Runner is satisfied by DEX subsystems, which must start any of their goroutines via the Run method.

type Semver

type Semver struct {
	Major uint32
	Minor uint32
	Patch uint32
}

Semver models a semantic version major.minor.patch

func NewSemver

func NewSemver(major, minor, patch uint32) Semver

NewSemver returns a new Semver with the version major.minor.patch

func (Semver) String

func (s Semver) String() string

Semver formats the Semver as major.minor.patch (e.g. 1.2.3).

type StartStopWaiter

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

StartStopWaiter wraps a Runner, providing the non-blocking Start and Stop methods, and the blocking WaitForShutdown method.

func NewStartStopWaiter

func NewStartStopWaiter(runner Runner) *StartStopWaiter

NewStartStopWaiter creates a StartStopWaiter from a Runner.

func (*StartStopWaiter) On

func (cm *StartStopWaiter) On() bool

On will be true until the context is canceled.

func (*StartStopWaiter) Start

func (ssw *StartStopWaiter) Start(ctx context.Context)

Start launches the Runner in a goroutine. Start will return immediately. Use Stop to signal the Runner to stop, followed by WaitForShutdown to allow shutdown to complete.

func (*StartStopWaiter) Stop

func (ssw *StartStopWaiter) Stop()

Stop cancels the context.

func (*StartStopWaiter) WaitForShutdown

func (ssw *StartStopWaiter) WaitForShutdown()

WaitForShutdown blocks until the Runner has returned in response to Stop.

Directories

Path Synopsis
networks
btc
dcr
ltc
Package order defines the Order and Match types used throughout the DEX.
Package order defines the Order and Match types used throughout the DEX.
testing
loadbot Module

Jump to

Keyboard shortcuts

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