Documentation ¶
Index ¶
- func DisableLog()
- func UseLogger(logger slog.Logger)
- type AuthManager
- type BackupFile
- type Config
- type LockableAsset
- type State
- type Storage
- type Swapper
- func (s *Swapper) CheckUnspent(asset 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, finalSwap map[order.OrderID]bool)
- func (s *Swapper) Run(ctx context.Context)
- func (s *Swapper) UserSwappingAmt(user account.AccountID, base, quote uint32) (amt, count uint64)
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) error 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) RecordCancel(user account.AccountID, oid, target order.OrderID, t time.Time) RecordCompletedOrder(user account.AccountID, oid order.OrderID, t time.Time) }
AuthManager handles client-related actions, including authorization and communications.
type BackupFile ¶
type BackupFile struct { // Name is the full path to the backup file. Name string // Stamp is the millisecond unix epoch time stamp of the state. Stamp int64 }
BackupFile is a located swap state file path and it's millisecond time stamp.
func LatestStateFile ¶
func LatestStateFile(dir string) (*BackupFile, error)
LatestStateFile attempts to locate the swap state file with the most recent time stamp (in the file name) from the given directory. The *BackupFile return will be nil if the directory was read successfully but no matching files were found.
type Config ¶
type Config struct { // DataDir is the folder where swap state is stored. DataDir string // AllowPartialRestore indicates if it is acceptable to load only part of // the State if the Swapper's asset configuration lacks assets required to // load all elements of State. AllowPartialRestore bool // Assets is a map to all the asset information, including the asset backends, // used by this Swapper. Assets map[uint32]*LockableAsset // 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 // LockTimeTaker is the locktime Swapper will use for auditing taker swaps. LockTimeTaker time.Duration // LockTimeTaker is the locktime Swapper will use for auditing maker swaps. LockTimeMaker time.Duration // IgnoreState indicates that the swapper should not load the latest state // from file. IgnoreState bool // StatePath is a path to a swap state file from which the swapper state // will be loaded. If StatePath is not set, and IgnoreState if false, the // most recent stored state file will be loaded. StatePath supercedes // IgnoreState. StatePath string // UnbookHook informs the DEX manager that the specified order should be // removed from the order book. UnbookHook func(lo *order.LimitOrder) bool }
Config is the swapper configuration settings. A Config instance is the only argument to the Swapper constructor.
type LockableAsset ¶
type LockableAsset struct { *asset.BackedAsset coinlock.CoinLocker // should be *coinlock.AssetCoinLocker }
LockableAsset pairs an Asset with a CoinLocker.
type State ¶
type State struct { // Version is State format's binary version. This field should be present in // any revision of the State struct. Version byte // Assets lists the IDs of the assets required to fully restore the the data // for all of the active matches. Assets []uint32 // Swapper.matches MatchTrackers map[order.MatchID]*matchTrackerData // Swapper.orders.orderMatches OrderMatches map[order.OrderID]*orderSwapStat // Swapper.liveWaiters LiveWaiters map[waiterKey]*handlerArgs }
State contains the Swapper's state data, which is used to restart the Swapper without interrupting active swaps or waiting for long duration operations to complete before stopping.
func LoadStateFile ¶
LoadStateFile attempts to load and decode a swap state file.
type Storage ¶
type Storage interface { db.SwapArchiver LastErr() error Fatal() <-chan struct{} InsertMatch(match *order.Match) error CancelOrder(*order.LimitOrder) error RevokeOrder(order.Order) (cancelID order.OrderID, t time.Time, err error) SetOrderCompleteTime(ord order.Order, compTimeMs int64) error GetStateHash() ([]byte, error) SetStateHash([]byte) 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) 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.
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.