diff --git a/build.sbt b/build.sbt index 9f9752b..b461337 100644 --- a/build.sbt +++ b/build.sbt @@ -30,6 +30,8 @@ lazy val circeVersion = "0.14.2" lazy val http4sVersion = "0.23.25" lazy val http4sBlazeVersion = "0.23.16" lazy val logbackVersion = "1.4.14" +lazy val munitVersion = "1.0.0-M11" +lazy val munitCEVersion = "2.0.0-M4" lazy val pureconfigVersion = "0.17.5" lazy val scalaTestVersion = "3.2.18" lazy val slf4jVersion = "2.0.12" @@ -45,6 +47,7 @@ lazy val commonSettings = Seq( "releases" at "https://oss.sonatype.org/content/repositories/releases" ), libraryDependencies ++= Seq( + "xyz.didx" %% "castanet" % castanetVersion, "org.typelevel" %% "cats-effect" % catsEffectVersion, "io.circe" %% "circe-core" % circeVersion, "io.circe" %% "circe-parser" % circeVersion, @@ -54,7 +57,6 @@ lazy val commonSettings = Seq( "com.softwaremill.sttp.client3" %% "core" % sttpVersion, "com.softwaremill.sttp.client3" %% "circe" % sttpVersion, "com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpVersion, - "xyz.didx" %% "castanet" % castanetVersion, "com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % tapirVersion, "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion, "com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion, @@ -65,6 +67,7 @@ lazy val commonSettings = Seq( "org.http4s" %% "http4s-ember-server" % http4sVersion, "org.slf4j" % "slf4j-nop" % slf4jVersion ) ++ Seq( + "xyz.didx" %% "castanet" % castanetVersion % Test, "org.scalatest" %% "scalatest" % scalaTestVersion % Test, "org.typelevel" %% "cats-effect" % catsEffectVersion % Test, "io.circe" %% "circe-core" % circeVersion % Test, @@ -75,7 +78,6 @@ lazy val commonSettings = Seq( "com.softwaremill.sttp.client3" %% "circe" % sttpVersion % Test, "com.softwaremill.sttp.client3" %% "core" % sttpVersion % Test, "com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpVersion % Test, - "xyz.didx" %% "castanet" % castanetVersion % Test, "com.softwaremill.sttp.tapir" %% "tapir-http4s-server" % tapirVersion % Test, "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion % Test, "com.softwaremill.sttp.tapir" %% "tapir-sttp-stub-server" % tapirVersion % Test, @@ -85,7 +87,10 @@ lazy val commonSettings = Seq( "org.http4s" %% "http4s-blaze-server" % http4sBlazeVersion % Test, "org.http4s" %% "http4s-dsl" % http4sVersion % Test, "org.http4s" %% "http4s-ember-server" % http4sVersion % Test, - "org.slf4j" % "slf4j-nop" % slf4jVersion % Test + "org.slf4j" % "slf4j-nop" % slf4jVersion % Test, + "org.scalameta" %% "munit" % munitVersion % Test, + "org.scalameta" %% "munit-scalacheck" % munitVersion % Test, + "org.typelevel" %% "munit-cats-effect" % munitCEVersion % Test ) ) lazy val scalafixSettings = Seq(semanticdbEnabled := true) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf new file mode 100644 index 0000000..65ce8c8 --- /dev/null +++ b/src/main/resources/application.conf @@ -0,0 +1,14 @@ +purchase-proto { + places = ["start", "shopping-cart", "payment", "delivery", "end"] + transitions = ["order", "checkout", "deliver","done"] + + start = { place = "start", weight = 2, initial-params = ["did","location"]} + end = "end" + weights = [ + {start = "start", transition = "order", end = "shopping-cart", action = "create-order", action-params = ["order-date", "order-id", "order-name", "order-description", "order-amount"]}, + {start = "shopping-cart", transition = "order", end = "shopping-cart", action = "create-order", action-params = ["order-date", "order-id", "order-name", "order-description", "order-amount", "checkout"]}, + {start = "shopping-cart", transition = "checkout", end = "payment", action = "pay-order", action-params = ["order-id", "order-description", "order-amount"]}, + {start = "payment", transition = "deliver", end = "delivery", action = "receive-order", action-params = ["order-id", "location"]}, + {start = "delivery", transition = "done", end = "end", action = "complete-order", action-params = ["order-id", "order-amount"]}, + ] +} diff --git a/src/main/scala/xyz/didx/ConfigManager.scala b/src/main/scala/xyz/didx/ConfigManager.scala index f58f06b..4b68640 100644 --- a/src/main/scala/xyz/didx/ConfigManager.scala +++ b/src/main/scala/xyz/didx/ConfigManager.scala @@ -1,30 +1,18 @@ package xyz.didx import cats.effect.IO -import cats.effect._ +import cats.effect.* import cats.effect.kernel.Sync -import cats.implicits._ +import cats.implicits.* import org.typelevel.log4cats.Logger import org.typelevel.log4cats.slf4j.Slf4jLogger import pureconfig.* import pureconfig.generic.derivation.default.* object ConfigManager { - given Logger[IO] = Slf4jLogger.getLogger[IO] - def info[F[_]: Sync: Logger](value: String) = - for - _ <- Logger[F].info("Logging at start of passForEasierUse") - something <- Sync[F].delay(println("I could do anything")) - // .onError{case e => Logger[F].error(e)("Something Went Wrong in passForEasierUse")} - _ <- Logger[F].info(s"$value") - yield something - - // println(s"Main: $value") - // logger.info(s"$value" - - def err[T](value: T)(using logger: Logger[IO]): IO[Unit] = - println(s"Main: $value") - logger.error(s"$value") + given Logger[IO] = Slf4jLogger.getLogger[IO] + def info[T](value: T): IO[Unit] = Logger[IO].info(s"$value") + def err[T](value: T): IO[Unit] = Logger[IO].error(s"$value") case class WeightConf( start: String, @@ -71,11 +59,9 @@ object ConfigManager { |""".stripMargin def protocolConf(interfaceName: String): ProtocolConf = - // ConfigSource.default.at(s"$interfaceName-proto").load[ProtocolConf] match ConfigSource.file("src/main/resources/application.conf").at(s"$interfaceName-proto").load[ProtocolConf] match - case Left(error) => - err(s"Error: $error") + err(s"$error") ProtocolConf(List(), List(), StartConf("", 0, List()), "", List()) case Right(conf) => conf diff --git a/src/main/scala/xyz/didx/PetriCompiler.scala b/src/main/scala/xyz/didx/PetriCompiler.scala index eff9ce8..69fbe26 100644 --- a/src/main/scala/xyz/didx/PetriCompiler.scala +++ b/src/main/scala/xyz/didx/PetriCompiler.scala @@ -11,9 +11,9 @@ import org.http4s.server.Router import sttp.client3.HttpURLConnectionBackend import sttp.client3.SttpBackend import sttp.model.* -import sttp.tapir._ -import sttp.tapir.generic.auto._ -import sttp.tapir.json.circe._ +import sttp.tapir.* +import sttp.tapir.generic.auto.* +import sttp.tapir.json.circe.* import sttp.tapir.server.http4s.Http4sServerInterpreter import sttp.tapir.swagger.bundle.SwaggerInterpreter import xyz.didx.ConfigManager.ProtocolConf @@ -32,9 +32,6 @@ import scala.collection.immutable.ListSet case class PetriCompiler[F[_]](interfaceName: String)(using logger: org.log4s.Logger ): - - val x = this.getClass() - val protocolConf: ProtocolConf = ConfigManager.protocolConf(interfaceName) val pl1: ListSet[String] = @@ -47,8 +44,7 @@ case class PetriCompiler[F[_]](interfaceName: String)(using val colourMap: Map[Colour, String] = paramList.zipWithIndex.map { case (k, v) => (Colour.fromOrdinal(v), k) }.toMap - val paramMap: Map[String, Colour] = - colourMap.map(_.swap) // (m => m._2 -> m._1) + val paramMap: Map[String, Colour] = colourMap.map(_.swap) val paramValues = colourMap.map((k, v) => k -> "") val places: Map[String, Place] = protocolConf.places.map { p => @@ -70,7 +66,6 @@ case class PetriCompiler[F[_]](interfaceName: String)(using .flatMap(w => w.actionParams) p -> capacity }.toMap - // println(s"places -> $places") val transitions: Map[String, Transition] = protocolConf.transitions .map(t => t -> Transition(t, CastanetService(), RPC(t, "", ""))) diff --git a/src/main/scala/xyz/didx/PetriRunner.scala b/src/main/scala/xyz/didx/PetriRunner.scala index ae2dbd5..e2ca225 100644 --- a/src/main/scala/xyz/didx/PetriRunner.scala +++ b/src/main/scala/xyz/didx/PetriRunner.scala @@ -14,7 +14,6 @@ import scala.concurrent.ExecutionContext */ object PetriRunner extends IOApp: - // given logger[F[_]: Sync]: Logger[F] = Slf4jLogger.getLogger[F] given logger: org.log4s.Logger = org.log4s.getLogger given ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global diff --git a/src/main/scala/xyz/didx/StateManager.scala b/src/main/scala/xyz/didx/StateManager.scala index 155c643..ad2b2e6 100644 --- a/src/main/scala/xyz/didx/StateManager.scala +++ b/src/main/scala/xyz/didx/StateManager.scala @@ -25,7 +25,6 @@ import cats.effect.kernel.Ref import java.util.UUID import scala.collection.immutable.HashMap -//import didcomm.DIDTypes.* trait State case class Context(id: String) diff --git a/test/BuilderSpec.test.scala b/src/test/scala/xyz/didx/BuilderSpec.test.scala similarity index 100% rename from test/BuilderSpec.test.scala rename to src/test/scala/xyz/didx/BuilderSpec.test.scala