Skip to content

Commit

Permalink
Move classes into ergo-core to satisfy NipopowProof and NipopowVerifi…
Browse files Browse the repository at this point in the history
…er requirements
  • Loading branch information
ccellado committed Nov 17, 2023
1 parent 00fa2a3 commit 47938e2
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 209 deletions.
75 changes: 0 additions & 75 deletions ergo-core/src/main/scala/org/ergoplatform/http/api/ApiCodecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ trait ApiCodecs extends JsonCodecs {

implicit val proveDlogEncoder: Encoder[ProveDlog] = _.pkBytes.asJson

implicit val balancesSnapshotEncoder: Encoder[WalletDigest] = { v =>
import v._
Json.obj(
"height" -> height.asJson,
"balance" -> walletBalance.asJson,
"assets" -> walletAssetBalances.toMap.map(x => (x._1: String, x._2)).asJson //toMap to have assets as JSON map
)
}

// this val is named "anyRegisterIdEncoder" because parent trait already contains
// "registerIdEncoder" which is actually a KeyEncoder for NonMandatoryRegisterId
// todo: rename "registerIdEncoder" into "nonMandatoryRegisterId" in parent trait in sigma repo
Expand Down Expand Up @@ -398,72 +389,6 @@ trait ApiCodecs extends JsonCodecs {
publicHints <- Decoder.decodeMap[Int, Seq[Hint]].tryDecode(cursor.downField("publicHints"))
} yield TransactionHintsBag(secretHints.mapValues(HintsBag.apply), publicHints.mapValues(HintsBag.apply))
}

implicit val SnapshotInfoEncoder: Encoder[SnapshotsInfo] = { si =>
Json.obj(
"availableManifests" -> si.availableManifests.map { case (height, manifest) =>
height -> manifest
}.asJson
)
}

implicit val SnapshotInfoDecoder: Decoder[SnapshotsInfo] = { cursor =>
for {
availableManifests <- Decoder.decodeMap[Int, ManifestId].tryDecode(cursor.downField("availableManifests"))
} yield new SnapshotsInfo(availableManifests)
}

implicit val transactionSigningRequestEncoder: Encoder[TransactionSigningRequest] = { tsr =>
Json.obj(
"tx" -> tsr.unsignedTx.asJson,
"secrets" -> Json.obj(
"dlog" -> tsr.dlogs.asJson,
"dht" -> tsr.dhts.asJson
),
"hints" -> tsr.hints.asJson,
"inputsRaw" -> tsr.inputs.asJson,
"dataInputsRaw" -> tsr.dataInputs.asJson
)
}

implicit val transactionSigningRequestDecoder: Decoder[TransactionSigningRequest] = { cursor =>
for {
tx <- cursor.downField("tx").as[UnsignedErgoTransaction]
dlogs <- cursor.downField("secrets").downField("dlog").as[Option[Seq[DlogSecretKey]]]
dhts <- cursor.downField("secrets").downField("dht").as[Option[Seq[DhtSecretKey]]]
hints <- cursor.downField("hints").as[Option[TransactionHintsBag]]
inputs <- cursor.downField("inputsRaw").as[Option[Seq[String]]]
dataInputs <- cursor.downField("dataInputsRaw").as[Option[Seq[String]]]
secrets = (dlogs.getOrElse(Seq.empty) ++ dhts.getOrElse(Seq.empty)).map(ExternalSecret.apply)
} yield TransactionSigningRequest(tx, hints.getOrElse(TransactionHintsBag.empty), secrets, inputs, dataInputs)
}

implicit val generateCommitmentsRequestEncoder: Encoder[GenerateCommitmentsRequest] = { gcr =>
Json.obj(
"tx" -> gcr.unsignedTx.asJson,
"secrets" -> Json.obj(
"dlog" -> gcr.dlogs.asJson,
"dht" -> gcr.dhts.asJson,
"inputsRaw" -> gcr.inputs.asJson,
"dataInputsRaw" -> gcr.dataInputs.asJson
)
)
}

implicit val generateCommitmentsRequestDecoder: Decoder[GenerateCommitmentsRequest] = { cursor =>
for {
tx <- cursor.downField("tx").as[UnsignedErgoTransaction]
dlogs <- cursor.downField("secrets").downField("dlog").as[Option[Seq[DlogSecretKey]]]
dhts <- cursor.downField("secrets").downField("dht").as[Option[Seq[DhtSecretKey]]]
secrets = (dlogs.getOrElse(Seq.empty) ++ dhts.getOrElse(Seq.empty)).map(ExternalSecret.apply)
secretsOpt = if(secrets.isEmpty) None else Some(secrets)
inputs <- cursor.downField("inputsRaw").as[Option[Seq[String]]]
dataInputs <- cursor.downField("dataInputsRaw").as[Option[Seq[String]]]
} yield GenerateCommitmentsRequest(tx, secretsOpt, inputs, dataInputs)
}



}

trait ApiEncoderOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class AutolykosPowScheme(val k: Int, val n: Int) extends ScorexLogging {
def deriveExternalCandidate(blockCandidate: CandidateBlock,
pk: ProveDlog,
mandatoryTxIds: Seq[ModifierId]): WorkMessage = {
val headerCandidate = CandidateGenerator.deriveUnprovenHeader(blockCandidate)
val headerCandidate = CandidateUtils.deriveUnprovenHeader(blockCandidate)
val msg = msgByHeader(headerCandidate)
val b = getB(blockCandidate.nBits)
val hOpt = if (blockCandidate.version == 1) {
Expand Down Expand Up @@ -417,7 +417,7 @@ object AutolykosPowScheme {
*/
def derivedHeaderFields(parentOpt: Option[Header]): (ModifierId, Int) = {

val height = parentOpt.map(parent => parent.height + 1).getOrElse(ErgoHistory.GenesisHeight)
val height = parentOpt.map(parent => parent.height + 1).getOrElse(GenesisHeight)

val parentId: ModifierId = parentOpt.map(_.id).getOrElse(Header.GenesisParentId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package org.ergoplatform.modifiers.history.header

import io.circe.syntax._
import io.circe.{Decoder, Encoder, HCursor}
import org.ergoplatform.nodeView.history.ErgoHistoryConstants.{GenesisHeight, Difficulty}
import org.ergoplatform.http.api.ApiCodecs
import org.ergoplatform.mining.AutolykosSolution
import org.ergoplatform.mining.difficulty.DifficultySerializer
import org.ergoplatform.modifiers.history.extension.Extension
import org.ergoplatform.modifiers.history.{ADProofs, BlockTransactions, PreHeader}
import org.ergoplatform.modifiers.{BlockSection, HeaderTypeId, NetworkObjectTypeId, NonHeaderBlockSection}
import org.ergoplatform.nodeView.history.ErgoHistory
import org.ergoplatform.nodeView.history.ErgoHistory.Difficulty
import org.ergoplatform.nodeView.history.ErgoHistoryConstants._
import org.ergoplatform.settings.{Algos, Constants}
import org.ergoplatform.wallet.interpreter.ErgoInterpreter
import scorex.core.serialization.ErgoSerializer
Expand Down Expand Up @@ -91,7 +89,7 @@ case class Header(override val version: Header.Version,

override lazy val serializer: ErgoSerializer[Header] = HeaderSerializer

lazy val isGenesis: Boolean = height == ErgoHistory.GenesisHeight
lazy val isGenesis: Boolean = height == GenesisHeight

/**
* Checks that modifier m corresponds to this header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object PreGenesisHeader extends Header(
transactionsRoot = null,
timestamp = 0L,
nBits = 0L,
height = ErgoHistory.EmptyHistoryHeight,
height = EmptyHistoryHeight,
extensionRoot = null,
powSolution = null,
votes = null,
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions ergo-core/src/main/scala/org/ergoplatform/settings/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ object Constants {
// Number of last block headers available is scripts from ErgoStateContext
val LastHeadersInContext = 10

/**
* Serializers for block sections and transactions
*
* // todo: move to NodeViewSynchronizer, used only there
*/
val modifierSerializers: Map[NetworkObjectTypeId.Value, ErgoSerializer[_ <: NodeViewModifier]] =
Map(Header.modifierTypeId -> HeaderSerializer,
Extension.modifierTypeId -> ExtensionSerializer,
BlockTransactions.modifierTypeId -> BlockTransactionsSerializer,
ADProofs.modifierTypeId -> ADProofsSerializer,
ErgoTransaction.modifierTypeId -> ErgoTransactionSerializer)

val SoftForkEpochs = 32 //about 45.5 days

def TrueLeaf: ErgoTree = Values.TrueLeaf.toSigmaProp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object ValidationRules {
hdrGenesisFromConfig -> RuleStatus(im => fatal(s"Genesis header id should be equal to id from the config. ${im.error}", im.modifierId, im.modifierTypeId),
Seq(classOf[Header]),
mayBeDisabled = false),
hdrGenesisHeight -> RuleStatus(im => fatal(s"Genesis height should be ${ErgoHistory.GenesisHeight}. ${im.error}", im.modifierId, im.modifierTypeId),
hdrGenesisHeight -> RuleStatus(im => fatal(s"Genesis height should be ${GenesisHeight}. ${im.error}", im.modifierId, im.modifierTypeId),
Seq(classOf[Header]),
mayBeDisabled = false),
hdrParent -> RuleStatus(im => recoverable(s"Parent header with id ${im.error} is not defined", im.modifierId, im.modifierTypeId),
Expand Down

0 comments on commit 47938e2

Please sign in to comment.