Skip to content

Commit

Permalink
Add release 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anon2020zzz committed Apr 13, 2022
1 parent beb2742 commit 937aee7
Show file tree
Hide file tree
Showing 83 changed files with 3,388 additions and 269 deletions.
2 changes: 2 additions & 0 deletions mixer/app/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ object Configs extends ConfigHelper {
lazy val mixOnlyAsBob: Boolean = readKey("mixOnlyAsBob", "false").toBoolean
lazy val stopMixingWhenReachedThreshold: Boolean = readKey("stopMixingWhenReachedThreshold", "true").toBoolean

lazy val hopRounds: Int = readKey("hopRounds", "0").toInt

}
6 changes: 5 additions & 1 deletion mixer/app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ class ApiController @Inject()(assets: Assets, controllerComponents: ControllerCo

/**
* A get endpoint which returns mix boxes of a specific group or covert request
* @param id mix group ID (covert ID in case of covert mixes)
* @param status mix withdraw status (all, active, withdrawn)
*/
def mixRequestList(id: String, status: String): Action[AnyContent] = Action {
try {
Expand All @@ -484,6 +486,7 @@ class ApiController @Inject()(assets: Assets, controllerComponents: ControllerCo
else if (mix.halfMix.isDefined) mix.halfMix.get.createdTime
else "None"
}
val lastHopRound = ergoMixer.getHopRound(mix.mixRequest.id)

s"""
|{
Expand All @@ -503,7 +506,8 @@ class ApiController @Inject()(assets: Assets, controllerComponents: ControllerCo
| "withdrawTxId": "$withdrawTxId",
| "lastMixTime": "$lastMixTime",
| "mixingTokenId": "${mix.mixRequest.tokenId}",
| "mixingTokenAmount": ${mix.mixRequest.mixingTokenAmount}
| "mixingTokenAmount": ${mix.mixRequest.mixingTokenAmount},
| "hopRounds": ${lastHopRound}
|}""".stripMargin
}).mkString(",") + "]"
Ok(res).as("application/json")
Expand Down
24 changes: 20 additions & 4 deletions mixer/app/dao/AllMixDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import slick.jdbc.JdbcProfile
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import models.Models.MixStatus.{Queued, Running}
import models.Models.{Deposit, FullMix, HalfMix, MixState, MixStatus}
import models.Models.MixWithdrawStatus.WithdrawRequested
import models.Models.{Deposit, FullMix, HalfMix, HopMix, MixState, MixStatus}
import models.Models.MixWithdrawStatus.{HopRequested, UnderHop, WithdrawRequested}
import network.BlockExplorer
import play.api.Logger

Expand All @@ -23,6 +23,7 @@ class AllMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider
with TokenEmissionComponent
with UnspentDepositsComponent
with SpentDepositsComponent
with HopMixComponent
with HasDatabaseConfigProvider[JdbcProfile] {

import profile.api._
Expand All @@ -48,6 +49,8 @@ class AllMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider

val spentDeposits = TableQuery[SpentDepositsTable]

val hopMixes = TableQuery[HopMixTable]

/**
* selects unspent halfBoxes
*
Expand All @@ -56,7 +59,7 @@ class AllMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider
val query = for {
((halfMix, state), request) <- halfMixes.filter(mix => mix.isSpent === false) join
mixes on((mix, state) => {mix.id === state.id && mix.round === state.round}) join
mixingRequests.filter(request => request.mixStatus === MixStatus.fromString(Running.value) || request.withdrawStatus === WithdrawRequested.value) on(_._1.id === _.id)
mixingRequests.filter(request => request.mixStatus === MixStatus.fromString(Running.value) || (request.withdrawStatus === WithdrawRequested.value || request.withdrawStatus === HopRequested.value)) on(_._1.id === _.id)
} yield (halfMix.id, state.round, halfMix.halfMixBoxId, request.masterKey, request.withdrawStatus, request.withdrawAddress)
db.run(query.result)
}
Expand All @@ -69,12 +72,25 @@ class AllMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider
val query = for {
((fullMix, state), request) <- fullMixes join
mixes on((mix, state) => {mix.id === state.id && mix.round === state.round}) join
mixingRequests.filter(request => request.mixStatus === MixStatus.fromString(Running.value) || request.withdrawStatus === WithdrawRequested.value) on(_._1.id === _.id)
mixingRequests.filter(request => request.mixStatus === MixStatus.fromString(Running.value) || (request.withdrawStatus === WithdrawRequested.value || request.withdrawStatus === HopRequested.value)) on(_._1.id === _.id)
} yield (fullMix.id, request.numRounds, request.withdrawAddress, request.masterKey, state.isAlice,
fullMix.fullMixBoxId, state.round, fullMix.halfMixBoxId, request.withdrawStatus, request.tokenId)
db.run(query.result)
}

/**
* selects unspent hopBoxes
*
*/
def groupHopMixesProgress: Future[Seq[HopMix]] = {
val lastHops = hopMixes.groupBy(hop => hop.id).map{ case (id, group) => (id, group.map(_.round).max) }
val lastHopMixes = (hopMixes join lastHops on((hopMix, lastHop) => hopMix.id === lastHop._1 && hopMix.round === lastHop._2)).map{ case(hopMix, lastHop) => hopMix}
val query = for {
(hopMix, request) <- lastHopMixes join mixingRequests.filter(request => request.withdrawStatus === UnderHop.value) on(_.id === _.id)
} yield hopMix
db.run(query.result)
}

/**
* Undos mix step for a deposits
*
Expand Down
32 changes: 32 additions & 0 deletions mixer/app/dao/CovertsDAO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dao

import models.Models.{CovertAsset, MixCovertRequest}
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}

@Singleton()
class CovertsDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit executionContext: ExecutionContext)
extends CovertAddressesComponent with CovertDefaultsComponent with MixingCovertRequestComponent
with HasDatabaseConfigProvider[JdbcProfile] {

import profile.api._

val covertAddresses = TableQuery[CovertAddressesTable]
val covertAssets = TableQuery[CovertDefaultsTable]
val covertRequests = TableQuery[MixCovertRequestTable]

/**
* selects unspent and spent deposits by address
*
* @param address String
*/
def createCovert(req: MixCovertRequest, addresses: Seq[(String, String)], asset: CovertAsset): Future[Unit] = {
val query = for {
_ <- DBIO.seq(covertRequests += req, covertAddresses ++= addresses, covertAssets += asset).transactionally
} yield { }
db.run(query)
}
}
6 changes: 6 additions & 0 deletions mixer/app/dao/FullMixDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class FullMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvide

val fullMixArchive = TableQuery[FullMixArchivedTable]

/**
* returns all mixes
*
*/
def all: Future[Seq[FullMix]] = db.run(fullMix.result)

/**
* inserts a mix state into MIX_STATE table
*
Expand Down
6 changes: 6 additions & 0 deletions mixer/app/dao/HalfMixDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class HalfMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvide

val halfMixArchive = TableQuery[HalfMixArchivedTable]

/**
* returns all mixes
*
*/
def all: Future[Seq[HalfMix]] = db.run(halfMix.result)

/**
* inserts a mix into table
*
Expand Down
90 changes: 90 additions & 0 deletions mixer/app/dao/HopMixDAO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package dao

import javax.inject.{Inject, Singleton}
import models.Models.HopMix
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.{ExecutionContext, Future}

trait HopMixComponent {
self: HasDatabaseConfigProvider[JdbcProfile] =>

import profile.api._

class HopMixTable(tag: Tag) extends Table[HopMix](tag, "HOP_MIX") {
def id = column[String]("MIX_ID")

def round = column[Int]("ROUND")

def createdTime = column[Long]("CREATED_TIME")

def boxId = column[String]("BOX_ID")

def * = (id, round, createdTime, boxId) <> (HopMix.tupled, HopMix.unapply)

def pk = primaryKey("pk_HOP_MIX", (id, round))
}

}

@Singleton()
class HopMixDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)(implicit executionContext: ExecutionContext)
extends HopMixComponent
with HasDatabaseConfigProvider[JdbcProfile] {

import profile.api._

val hopMixes = TableQuery[HopMixTable]

/**
* inserts a hop into table
*
* @param hop HopMix
*/
def insert(hop: HopMix): Future[Unit] = db.run(hopMixes += hop).map(_ => ())

/**
* returns all hops
*
*/
def all: Future[Seq[HopMix]] = db.run(hopMixes.result)

/**
* deletes all of hops
*
*/
def clear: Future[Unit] = db.run(hopMixes.delete).map(_ => ())

/**
* deletes future hops by mixId
*
* @param mixId String
* @param round Int
*/
def deleteFutureRounds(mixId: String, round: Int): Future[Unit] = db.run(hopMixes
.filter(hop => hop.id === mixId && hop.round > round).delete).map(_ => ())

/**
* updates hop by id
*
* @param hopMix HopMix
*/
def updateById(hopMix: HopMix): Future[Unit] = db.run(DBIO.seq(
hopMixes.filter(hop => hop.id === hopMix.mixId && hop.round === hopMix.round).delete,
hopMixes += hopMix
))

/**
* returns last hop round of mixId
*
* @param mixId String
*/
def getHopRound(mixId: String): Future[Option[Int]] = db.run(hopMixes
.filter(hop => hop.id === mixId)
.groupBy(hop => hop.id)
.map{ case (id, group) => group.map(_.round).max.get }
.result.headOption
)

}
6 changes: 6 additions & 0 deletions mixer/app/dao/MixStateDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class MixStateDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvid

val mixes = TableQuery[MixStateTable]

/**
* returns all mixes
*
*/
def all: Future[Seq[MixState]] = db.run(mixes.result)

/**
* deletes all of states
*
Expand Down
12 changes: 12 additions & 0 deletions mixer/app/dao/MixStateHistoryDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ class MixStateHistoryDAO @Inject()(protected val dbConfigProvider: DatabaseConfi

val mixStatesArchive = TableQuery[MixStateHistoryArchivedTable]

/**
* returns all mixes
*
*/
def all: Future[Seq[MixHistory]] = db.run(mixHistories.result)

/**
* deletes all of state histories
*
*/
def clear: Future[Unit] = db.run(mixHistories.delete).map(_ => ())

/**
* deletes future mixHistory by mixID
*
Expand Down
8 changes: 7 additions & 1 deletion mixer/app/dao/MixingGroupRequestDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class MixingGroupRequestDAO @Inject()(protected val dbConfigProvider: DatabaseCo
*/
def all: Future[Seq[MixGroupRequest]] = db.run(groupRequests.result)

/**
* selects id of all groupRequests
*
*/
def allIds: Future[Seq[String]] = db.run(groupRequests.map(_.id).result)

/**
* deletes all of requests
*
Expand Down Expand Up @@ -123,7 +129,7 @@ class MixingGroupRequestDAO @Inject()(protected val dbConfigProvider: DatabaseCo
}

/**
* updates deposit and tokenDeposit by mixGroupId
* updates status by mixGroupId
*
* @param mixGroupId String
* @param status String
Expand Down
21 changes: 17 additions & 4 deletions mixer/app/dao/MixingRequestsDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,22 @@ class MixingRequestsDAO @Inject()(protected val dbConfigProvider: DatabaseConfig
* counts number of withdrawn requests with mixGroupID
*
* @param groupId String
* @param withdrawnStatus String
*/
def countWithdrawn(groupId: String, withdrawnStatus: String): Future[Int] = db.run(mixingRequests.filter(req => req.groupId === groupId && req.withdrawStatus === withdrawnStatus).size.result)
def countWithdrawn(groupId: String): Future[Int] = db.run(mixingRequests.filter(req => req.groupId === groupId && req.withdrawStatus === Withdrawn.value).size.result)

/**
* counts number of requests in group that didn't withdrawn yet by mixGroupID
*
* @param groupId String
*/
def countNotWithdrawn(groupId: String): Future[Int] = db.run(mixingRequests.filter(req => req.groupId === groupId && req.withdrawStatus =!= Withdrawn.value).size.result)

/**
* counts number of finished requests with mixGroupID
*
* @param groupId String
* @param mixStatus String
*/
def countFinished(groupId: String, mixStatus: MixStatus): Future[Int] = db.run(mixingRequests.filter(req => req.groupId === groupId && req.mixStatus === mixStatus).size.result)
def countFinished(groupId: String): Future[Int] = db.run(mixingRequests.filter(req => req.groupId === groupId && req.mixStatus === MixStatus.fromString(Complete.value)).size.result)

/**
* counts number requests with mixGroupID
Expand Down Expand Up @@ -339,4 +344,12 @@ class MixingRequestsDAO @Inject()(protected val dbConfigProvider: DatabaseConfig
} yield req.depositCompleted
db.run(query.update(true)).map(_ => ())
}

/**
* checks if the mix request mixes erg or token
*
* @param mixId String
*/
def isMixingErg(mixId: String): Future[Boolean] = db.run(mixingRequests.filter(req => req.id === mixId && req.tokenId === "").exists.result)

}
12 changes: 6 additions & 6 deletions mixer/app/dao/RescanDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ trait RescanComponent {

def goBackward = column[Boolean]("GO_BACKWARD")

def isHalfMixTx = column[Boolean]("IS_HALF_MIX_TX")
def boxType = column[String]("BOX_TYPE")

def mixBoxId = column[String]("MIX_BOX_ID")

def * = (id, createdTime, round, goBackward, isHalfMixTx, mixBoxId) <> (PendingRescan.tupled, PendingRescan.unapply)
def * = (id, createdTime, round, goBackward, boxType, mixBoxId) <> (PendingRescan.tupled, PendingRescan.unapply)
}

class RescanArchivedTable(tag: Tag) extends Table[(String, Long, Int, Boolean, Boolean, String, String)](tag, "RESCAN_ARCHIVE") {
class RescanArchivedTable(tag: Tag) extends Table[(String, Long, Int, Boolean, String, String, String)](tag, "RESCAN_ARCHIVE") {
def id = column[String]("MIX_ID", O.PrimaryKey)

def createdTime = column[Long]("CREATED_TIME")
Expand All @@ -37,13 +37,13 @@ trait RescanComponent {

def goBackward = column[Boolean]("GO_BACKWARD")

def isHalfMixTx = column[Boolean]("IS_HALF_MIX_TX")
def boxType = column[String]("BOX_TYPE")

def mixBoxId = column[String]("MIX_BOX_ID")

def reason = column[String]("REASON")

def * = (id, createdTime, round, goBackward, isHalfMixTx, mixBoxId, reason)
def * = (id, createdTime, round, goBackward, boxType, mixBoxId, reason)
}

}
Expand Down Expand Up @@ -90,6 +90,6 @@ class RescanDAO @Inject()(protected val dbConfigProvider: DatabaseConfigProvider
def updateById(new_rescan: PendingRescan)(implicit insertReason: String): Future[Unit] = db.run(DBIO.seq(
rescans.filter(rescan => rescan.id === new_rescan.mixId).delete,
rescans += new_rescan,
rescansArchive += (new_rescan.mixId, new_rescan.time, new_rescan.round, new_rescan.goBackward, new_rescan.isHalfMixTx, new_rescan.mixBoxId, insertReason)
rescansArchive += (new_rescan.mixId, new_rescan.time, new_rescan.round, new_rescan.goBackward, new_rescan.boxType, new_rescan.mixBoxId, insertReason)
))
}
Loading

0 comments on commit 937aee7

Please sign in to comment.