Documentation ¶
Index ¶
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type AuthManager
- type Config
- type Storage
- type Swapper
- func (s *Swapper) AccountStats(acctAddr string, assetID uint32) (qty, swaps uint64, redeems int)
- func (s *Swapper) ChainsSynced(base, quote uint32) (bool, error)
- func (s *Swapper) CheckUnspent(ctx context.Context, assetID uint32, coinID []byte) error
- func (s *Swapper) LockCoins(asset uint32, coins map[order.OrderID][]order.CoinID)
- func (s *Swapper) LockOrdersCoins(orders []order.Order)
- func (s *Swapper) Negotiate(matchSets []*order.MatchSet)
- func (s *Swapper) Run(ctx context.Context)
- func (s *Swapper) UnsettledQuantity(user account.AccountID) map[[2]uint32]uint64
- type SwapperAsset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type AuthManager ¶
type AuthManager interface { Route(string, func(account.AccountID, *msgjson.Message) *msgjson.Error) Auth(user account.AccountID, msg, sig []byte) error Sign(...msgjson.Signable) Send(account.AccountID, *msgjson.Message) error Request(account.AccountID, *msgjson.Message, func(comms.Link, *msgjson.Message)) error RequestWithTimeout(user account.AccountID, req *msgjson.Message, handlerFunc func(comms.Link, *msgjson.Message), expireTimeout time.Duration, expireFunc func()) error SwapSuccess(user account.AccountID, mmid db.MarketMatchID, value uint64, refTime time.Time) Inaction(user account.AccountID, misstep auth.NoActionStep, mmid db.MarketMatchID, matchValue uint64, refTime time.Time, oid order.OrderID) }
AuthManager handles client-related actions, including authorization and communications.
type Config ¶
type Config struct { // Assets is a map to all the asset information, including the asset backends, // used by this Swapper. Assets map[uint32]*SwapperAsset // AuthManager is the auth manager for client messaging and authentication. AuthManager AuthManager // A database backend. Storage Storage // BroadcastTimeout is how long the Swapper will wait for expected swap // transactions following new blocks. BroadcastTimeout time.Duration // TxWaitExpiration is the longest the Swapper will wait for a coin waiter. // This could be thought of as the maximum allowable backend latency. TxWaitExpiration time.Duration // LockTimeTaker is the locktime Swapper will use for auditing taker swaps. LockTimeTaker time.Duration // LockTimeMaker is the locktime Swapper will use for auditing maker swaps. LockTimeMaker time.Duration // NoResume indicates that the swapper should not resume active swaps. NoResume bool // AllowPartialRestore indicates if it is acceptable to load only some of // the active swaps if the Swapper's asset configuration lacks assets // required to load them all. AllowPartialRestore bool // SwapDone registers a match with the DEX manager (or other consumer) for a // given order as being finished. SwapDone func(oid order.Order, match *order.Match, fail bool) }
Config is the swapper configuration settings. A Config instance is the only argument to the Swapper constructor.
type Storage ¶
type Storage interface { db.SwapArchiver LastErr() error Fatal() <-chan struct{} Order(oid order.OrderID, base, quote uint32) (order.Order, order.OrderStatus, error) CancelOrder(*order.LimitOrder) error InsertMatch(match *order.Match) error }
Storage updates match data in what is presumably a database.
type Swapper ¶
type Swapper struct {
// contains filtered or unexported fields
}
Swapper handles order matches by handling authentication and inter-party communications between clients, or 'users'. The Swapper authenticates users (vua AuthManager) and validates transactions as they are reported.
func NewSwapper ¶
NewSwapper is a constructor for a Swapper.
func (*Swapper) AccountStats ¶ added in v0.5.0
AccountStats is part of the MatchNegotiator interface to report in-process match information for a asset account address.
func (*Swapper) ChainsSynced ¶
ChainsSynced will return true if both specified asset's backends are synced.
func (*Swapper) CheckUnspent ¶
CheckUnspent attempts to verify a coin ID for a given asset by retrieving the corresponding asset.Coin. If the coin is not found or spent, an asset.CoinNotFoundError is returned. CheckUnspent returns immediately with no error if the requested asset is not a utxo-based asset.
func (*Swapper) LockCoins ¶
LockCoins locks coins of a given asset. The OrderID is used for tracking.
func (*Swapper) LockOrdersCoins ¶
LockOrdersCoins locks the backing coins for the provided orders.
func (*Swapper) Negotiate ¶
Negotiate takes ownership of the matches and begins swap negotiation. For reliable identification of completed orders when redeem acks are received and processed by processAck, BeginMatchAndNegotiate should be called prior to matching and order status/amount updates, and EndMatchAndNegotiate should be called after Negotiate. This locking sequence allows for orders that may already be involved in active swaps to remain unmodified by the Matcher/Market until new matches are recorded by the Swapper in Negotiate. If this is not done, it is possible that an order may be flagged as completed if a swap A completes after Matching and creation of swap B but before Negotiate has a chance to record the new swap.
type SwapperAsset ¶ added in v0.5.0
type SwapperAsset struct { *asset.BackedAsset Locker coinlock.CoinLocker // should be *coinlock.AssetCoinLocker }
SwapperAsset is a BackedAsset with an optional CoinLocker.