diff --git a/worker/swap.go b/worker/swap.go index 8cfb7fd9..3b37139e 100644 --- a/worker/swap.go +++ b/worker/swap.go @@ -37,11 +37,13 @@ func StartSwapJob() { for _, pairCfg := range tokens.GetTokenPairsConfig() { AddSwapJob(pairCfg) } + + go startSwapinSwapJob() + go startSwapoutSwapJob() } // AddSwapJob add swap job func AddSwapJob(pairCfg *tokens.TokenPairConfig) { - pairID := strings.ToLower(pairCfg.PairID) swapinDcrmAddr := strings.ToLower(pairCfg.DestToken.DcrmAddress) if _, exist := swapinTaskChanMap[swapinDcrmAddr]; !exist { swapinTaskChanMap[swapinDcrmAddr] = make(chan *tokens.BuildTxArgs, swapChanSize) @@ -52,15 +54,12 @@ func AddSwapJob(pairCfg *tokens.TokenPairConfig) { swapoutTaskChanMap[swapoutDcrmAddr] = make(chan *tokens.BuildTxArgs, swapChanSize) go processSwapTask(swapoutTaskChanMap[swapoutDcrmAddr]) } - - go startSwapinSwapJob(pairID) - go startSwapoutSwapJob(pairID) } -func startSwapinSwapJob(pairID string) { +func startSwapinSwapJob() { logWorker("swap", "start swapin swap job") for { - res, err := findSwapinsToSwap(pairID) + res, err := findSwapinsToSwap() if err != nil { logWorkerError("swapin", "find swapins error", err) } @@ -79,10 +78,10 @@ func startSwapinSwapJob(pairID string) { } } -func startSwapoutSwapJob(pairID string) { +func startSwapoutSwapJob() { logWorker("swapout", "start swapout swap job") for { - res, err := findSwapoutsToSwap(pairID) + res, err := findSwapoutsToSwap() if err != nil { logWorkerError("swapout", "find swapouts error", err) } @@ -101,16 +100,16 @@ func startSwapoutSwapJob(pairID string) { } } -func findSwapinsToSwap(pairID string) ([]*mongodb.MgoSwap, error) { +func findSwapinsToSwap() ([]*mongodb.MgoSwap, error) { status := mongodb.TxNotSwapped septime := getSepTimeInFind(maxDoSwapLifetime) - return mongodb.FindSwapinsWithPairIDAndStatus(pairID, status, septime) + return mongodb.FindSwapinsWithStatus(status, septime) } -func findSwapoutsToSwap(pairID string) ([]*mongodb.MgoSwap, error) { +func findSwapoutsToSwap() ([]*mongodb.MgoSwap, error) { status := mongodb.TxNotSwapped septime := getSepTimeInFind(maxDoSwapLifetime) - return mongodb.FindSwapoutsWithPairIDAndStatus(pairID, status, septime) + return mongodb.FindSwapoutsWithStatus(status, septime) } func isSwapInBlacklist(swap *mongodb.MgoSwapResult) (isBlacked bool, err error) {