Documentation ¶
Index ¶
- Constants
- Variables
- func BipIDSymbol(id uint32) string
- func BipSymbolID(symbol string) (uint32, bool)
- func BondExpiry(net Network) int64
- func CleanAndExpandPath(path string) string
- func FileExists(name string) bool
- func IntDivUp(val, div int64) int64
- func LockTimeMaker(network Network) time.Duration
- func LockTimeTaker(network Network) time.Duration
- func LogRotator(dir, name string) (*rotator.Rotator, error)
- func MarketName(baseID, quoteID uint32) (string, error)
- func SemverCompatible(required, actual Semver) bool
- func SemverCompatibleAny(compatible []Semver, actual Semver) bool
- func TokenSymbol(symbol string) string
- type Asset
- type Bytes
- type ConnectionMaster
- func (c *ConnectionMaster) Connect(ctx context.Context) (err error)
- func (c *ConnectionMaster) ConnectOnce(ctx context.Context) (err error)
- func (c *ConnectionMaster) Disconnect()
- func (c *ConnectionMaster) Done() <-chan struct{}
- func (c *ConnectionMaster) On() bool
- func (c *ConnectionMaster) Wait()
- type Connector
- type Denomination
- type Error
- type ErrorCloser
- type ErrorKind
- type IPKey
- type Logger
- type LoggerMaker
- func (lm *LoggerMaker) Level(name string) slog.Level
- func (lm *LoggerMaker) Logger(name string) Logger
- func (lm *LoggerMaker) NewLogger(name string, level ...slog.Level) Logger
- func (lm *LoggerMaker) SetLevels(debugLevel string) error
- func (lm *LoggerMaker) SetLevelsFromMap(lvls map[string]slog.Level)
- type MarketInfo
- type Network
- type Runner
- type Semver
- type StartStopWaiter
- type Token
- type UnitInfo
Constants ¶
const ( UnsupportedScriptError = ErrorKind("unsupported script type") BondExpiryMainnet = 30 * secondsPerDay // 30 days BondExpiryTestnet = 180 * secondsPerMinute // 3 hours BondExpirySimnet = 4 * secondsPerMinute // 4 minutes )
const ( LevelTrace = slog.LevelTrace LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError LevelCritical = slog.LevelCritical LevelOff = slog.LevelOff DefaultLogLevel = LevelInfo )
Level constants.
const ( // PerTierBaseParcelLimit is the number of parcels users can trade per tier. PerTierBaseParcelLimit = 2 // ParcelLimitScoreMultiplier defines the maximum parcel limit multiplier // that a user achieves with max score. The users parcel limit ranges from // the starting value of tier*PerTierBaseParcelLimit to the maximum value of // tier*PerTierBaseParcelLimit*ParcelLimitScoreMultiplier. By default, // singly-tiered users have max lot limits limited to the range (8,24). ParcelLimitScoreMultiplier = 3 )
const Simnet = Regtest
Simnet is an alias of Regtest.
Variables ¶
var TokenChains = make(map[string][][2]uint32)
TokenChains is a map of token symbol to a list of [2]uint32, where the first element is the token's BIP ID and the second element is the chain's BIP ID.
Functions ¶
func BipIDSymbol ¶
BipIDSymbol returns the BIP ID for a given symbol.
func BipSymbolID ¶
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 BondExpiry ¶ added in v0.6.0
BondExpiry returns the bond expiry duration in seconds for a given network.
func CleanAndExpandPath ¶ added in v0.5.0
CleanAndExpandPath expands environment variables and leading ~ in the passed path, cleans the result, and returns it.
func FileExists ¶ added in v0.6.0
FilesExists reports whether the named file or directory exists.
func IntDivUp ¶ added in v0.5.0
IntDivUp divides two integers, rounding up, without using floating point conversion. This will panic if the denominator is zero, just like regular integer division. This function should be used instead of ad hoc solutions or being lazy with floating point math.
func LockTimeMaker ¶
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 ¶
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 LogRotator ¶ added in v1.0.0
LogRotator creates a file logger that rotates up to 8 files of 32 MiB each.
func MarketName ¶
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 ¶
SemverCompatible decides if the actual version is compatible with the required one.
func SemverCompatibleAny ¶ added in v0.6.0
SemverCompatibleAny checks if the version is compatible with any versions in a slice of versions.
func TokenSymbol ¶ added in v1.0.0
TokenSymbol returns the tokens raw symbol if this is compound symbol that encodes the blockchain, or else the input is returned unaltered. e.g. usdc.eth => usdc
Types ¶
type Asset ¶
type Asset struct { ID uint32 `json:"id"` Symbol string `json:"symbol"` Version uint32 `json:"version"` MaxFeeRate uint64 `json:"maxFeeRate"` SwapConf uint32 `json:"swapConf"` UnitInfo UnitInfo `json:"unitInfo"` }
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) Equal ¶ added in v0.2.0
Equal is true if otherB has identical []byte contents to the Bytes.
func (Bytes) MarshalBinary ¶ added in v1.0.0
func (Bytes) MarshalJSON ¶
MarshalJSON satisfies the json.Marshaller interface, and will marshal the bytes to a hex string.
func (*Bytes) UnmarshalJSON ¶
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 creates a new ConnectionMaster. The Connect method should be used before Disconnect. The On, Done, and Wait methods may be used at any time. However, prior to Connect, Wait and Done immediately return and signal completion, respectively.
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. Even if Connect returns a non-nil error, On may report true until Disconnect is called. You would use Connect if the wrapped Connector has a reconnect loop to continually attempt to establish a connection even if the initial attempt fails. Use ConnectOnce if the Connector should be given one chance to connect before being considered not to be "on". If the ConnectionMaster is discarded on error, it is not important which method is used.
func (*ConnectionMaster) ConnectOnce ¶ added in v0.5.0
func (c *ConnectionMaster) ConnectOnce(ctx context.Context) (err error)
ConnectOnce is like Connect, but on error the internal status is updated so that the On method returns false. This method may be used if an error from the Connector is terminal. The caller may also use Connect if they cancel the parent context or call Disconnect.
func (*ConnectionMaster) Disconnect ¶
func (c *ConnectionMaster) Disconnect()
Disconnect closes the connection and waits for shutdown. This must not be used before or concurrently with Connect.
func (*ConnectionMaster) Done ¶ added in v0.5.0
func (c *ConnectionMaster) Done() <-chan struct{}
Done returns a channel that is closed when the Connector's WaitGroup is done. If called before Connect, a closed channel is returned.
func (*ConnectionMaster) On ¶
func (c *ConnectionMaster) On() bool
On indicates if the Connector is running. This returns false if never connected, or if the Connector has completed shut down.
func (*ConnectionMaster) Wait ¶
func (c *ConnectionMaster) Wait()
Wait waits for the Connector to shut down. It returns immediately if Connect has not been called yet.
type Connector ¶
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 Denomination ¶ added in v0.4.0
type Denomination struct { Unit string `json:"unit"` ConversionFactor uint64 `json:"conversionFactor"` }
Denomination is a unit and its conversion factor.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error pairs an error with details.
func NewError ¶
NewError wraps the provided Error with details in a Error, facilitating the use of errors.Is and errors.As via errors.Unwrap.
type ErrorCloser ¶ added in v0.6.0
type ErrorCloser struct {
// contains filtered or unexported fields
}
ErrorCloser is used to synchronize shutdown when an error is encountered in a multi-step process. After each successful step, a shutdown routine can be scheduled with Add. If Success is not signaled before Done, the shutdown routines will be run in the reverse order that they are added.
func NewErrorCloser ¶ added in v0.6.0
func NewErrorCloser() *ErrorCloser
NewErrorCloser creates a new ErrorCloser.
func (*ErrorCloser) Add ¶ added in v0.6.0
func (e *ErrorCloser) Add(closer func() error)
Add adds a new function to the queue. If Success is not called before Done, the Add'ed functions will be run in the reverse order that they were added.
func (*ErrorCloser) Copy ¶ added in v0.6.0
func (e *ErrorCloser) Copy() *ErrorCloser
Copy creates a shallow copy of the ErrorCloser.
func (*ErrorCloser) Done ¶ added in v0.6.0
func (e *ErrorCloser) Done(log Logger)
Done signals that the ErrorClose can run its registered functions if success has not yet been flagged.
func (*ErrorCloser) Success ¶ added in v0.6.0
func (e *ErrorCloser) Success()
Success cancels the running of any Add'ed functions.
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").
type IPKey ¶ added in v0.2.0
IPKey is a IP address byte array.
func NewIPKey ¶ added in v0.2.0
NewIPKey parses an IP address string into an IPKey. For an IPV6 address, this drops the interface identifier, which is the second half of the address. The first half of the address comprises 48-bits for the prefix, which is the public topology of a network that is assigned by an ISP, and 16-bits for the Site-Level Aggregation Identifier (SLA). However, any number of the SLA bits may be assigned by a provider, potentially giving a single link the freedom to use multiple subnets, thus expanding the set of addresses they may use freely. As such, IPv6 addresses with just the interface bits masked may not be sufficient to identify a single remote uplink.
func (IPKey) IsLoopback ¶ added in v0.4.0
IsLoopback reports whether the IPKey represents a loopback address.
func (IPKey) IsUnspecified ¶ added in v0.4.0
IsUnspecified reports whether the IPKey is zero (unspecified).
func (IPKey) PrefixV6 ¶ added in v0.4.0
PrefixV6 returns the first 48-bits of an IPv6 address, or nil for an IPv4 address. This may be used to identify multiple remote hosts from the same public topology but different subnets. A heuristic may be defined to treat hosts with the same prefix as the same host if there are many such hosts.
type Logger ¶
type Logger interface { slog.Logger SubLogger(name string) Logger FileLogger(r *rotator.Rotator) Logger Meter(callerID string, delay time.Duration) 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(io.Discard), }
Disabled is a Logger that will never output anything.
type LoggerMaker ¶
LoggerMaker allows creation of new log subsystems with predefined levels.
func NewLoggerMaker ¶
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.
func (*LoggerMaker) SetLevelsFromMap ¶ added in v0.5.0
func (lm *LoggerMaker) SetLevelsFromMap(lvls map[string]slog.Level)
SetLevelsFromMap sets all logs for certain subsystems with the same name to the corresponding log level in the map.
type MarketInfo ¶
type MarketInfo struct { Name string Base uint32 Quote uint32 LotSize uint64 ParcelSize uint32 // number of lots in the base trading limit. RateStep 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, rateStep, 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. TODO: Only used in tests. Should just use NewMarketInfoFromSymbols instead.
func NewMarketInfoFromSymbols ¶
func NewMarketInfoFromSymbols(base, quote string, lotSize, rateStep, epochDuration uint64, parcelSize uint32, 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.
func (*MarketInfo) String ¶ added in v0.2.0
func (mi *MarketInfo) String() string
String returns the market's Name.
type Network ¶
type Network uint8
Network flags passed to asset backends to signify which network to use.
func NetFromString ¶
NetFromString returns the Network for the given network name.
type Runner ¶
Runner is satisfied by DEX subsystems, which must start any of their goroutines via the Run method.
type Semver ¶
Semver models a semantic version major.minor.patch
func SemverFromString ¶ added in v1.0.0
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) WaitForShutdown ¶
func (ssw *StartStopWaiter) WaitForShutdown()
WaitForShutdown blocks until the Runner has returned in response to Stop.
type Token ¶ added in v0.5.0
type Token struct { // ParentID is the asset ID of the token's parent asset. ParentID uint32 `json:"parentID"` // Name is the display name of the token asset. Name string `json:"name"` // UnitInfo is the UnitInfo for the token. UnitInfo UnitInfo `json:"unitInfo"` }
Token is a generic representation of a token-type asset.
type UnitInfo ¶ added in v0.4.0
type UnitInfo struct { // AtomicUnit is the name associated with the asset's integral unit of // measure, e.g. satoshis, atoms, gwei (for DEX purposes). AtomicUnit string `json:"atomicUnit"` // Conventional is the conventionally-used denomination. Conventional Denomination `json:"conventional"` // Alternatives lists additionally available Denominations, and can be // empty. Alternatives []Denomination `json:"denominations"` // FeeRateDenom is the denominator used for fee rates. FeeRateDenom string `json:"feeRateDenom"` }
UnitInfo conveys information about the units and available denominations for an asset.
func (*UnitInfo) ConventionalString ¶ added in v0.4.0
ConventionalString converts the quantity to conventional units, and returns the formatted float string.
func (*UnitInfo) FormatAtoms ¶ added in v1.0.0
FormatAtoms formats the atomic value as a string with units. The number is formatted with full precision. For small values, the value is formatted in atomic units, while for larger values the value is formatted in conventional units.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
networks
|
|
eth
This file lifted from go-ethereum/signer/fourbyte at v1.10.6 commit 576681f29b895dd39e559b7ba17fcd89b42e4833 and modified to make parseCalldata take an abi instead of a string.
|
This file lifted from go-ethereum/signer/fourbyte at v1.10.6 commit 576681f29b895dd39e559b7ba17fcd89b42e4833 and modified to make parseCalldata take an abi instead of a string. |
eth/contracts/v0
Package v0 contains pre-generated code that should not be directly edited.
|
Package v0 contains pre-generated code that should not be directly edited. |
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
|
|