Skip to content

Commit

Permalink
ergotree-version: abstract classes for BlockchainParameters and Block…
Browse files Browse the repository at this point in the history
…chainStateContext
  • Loading branch information
aslesarenko committed Sep 26, 2023
1 parent a61c9ef commit d98325e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
4 changes: 2 additions & 2 deletions sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ object Isos {

val isoBlockchainParameters: Iso[BlockchainParameters, sdk.BlockchainParameters] = new Iso[BlockchainParameters, sdk.BlockchainParameters] {
override def to(a: BlockchainParameters): sdk.BlockchainParameters = {
sdk.BlockchainParameters(
sdk.CBlockchainParameters(
storageFeeFactor = a.storageFeeFactor,
minValuePerByte = a.minValuePerByte,
maxBlockSize = a.maxBlockSize,
Expand Down Expand Up @@ -222,7 +222,7 @@ object Isos {

implicit val isoBlockchainStateContext: Iso[BlockchainStateContext, context.BlockchainStateContext] = new Iso[BlockchainStateContext, context.BlockchainStateContext] {
override def to(a: BlockchainStateContext): context.BlockchainStateContext = {
context.BlockchainStateContext(
context.CBlockchainStateContext(
sigmaLastHeaders = isoArrayToColl(isoHeader).to(a.sigmaLastHeaders),
previousStateDigest = isoStringToColl.to(a.previousStateDigest),
sigmaPreHeader = isoPreHeader.to(a.sigmaPreHeader)
Expand Down
4 changes: 2 additions & 2 deletions sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.ergoplatform.sdk.js

import org.ergoplatform.ErgoBox.{AdditionalRegisters, BoxId, TokenId}
import org.ergoplatform._
import org.ergoplatform.sdk.wallet.protocol.context.BlockchainStateContext
import org.ergoplatform.sdk.wallet.protocol.context.{BlockchainStateContext, CBlockchainStateContext}
import org.ergoplatform.sdk.{ExtendedInputBox, Iso}
import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.matchers.should.Matchers
Expand Down Expand Up @@ -30,7 +30,7 @@ class IsosSpec extends AnyPropSpec with Matchers with ObjectGenerators with Sca
stateRoot <- avlTreeGen
headers <- headersGen(stateRoot)
preHeader <- preHeaderGen(headers.headOption.map(_.id).getOrElse(modifierIdBytesGen.sample.get))
} yield BlockchainStateContext(
} yield CBlockchainStateContext(
sigmaLastHeaders = Colls.fromItems(headers:_*),
previousStateDigest = stateRoot.digest,
sigmaPreHeader = preHeader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package org.ergoplatform.sdk

/** Blockchain parameters re-adjustable via miners voting and voting-related data.
* All these fields are included into extension section of a first block of a voting epoch.
*
* @param storageFeeFactor cost of storing 1 byte in UTXO for four years, in nanoErgs
* @param minValuePerByte cost of a transaction output, in computation unit
* @param maxBlockSize max block size, in bytes
* @param tokenAccessCost cost of a token contained in a transaction, in computation unit
* @param inputCost cost of a transaction input, in computation unit
* @param dataInputCost cost of a transaction data input, in computation unit
* @param outputCost cost of a transaction output, in computation unit
* @param maxBlockCost computation units limit per block
* @param softForkStartingHeight height when voting for a soft-fork had been started
* @param softForkVotesCollected votes for soft-fork collected in previous epochs
* @param blockVersion Protocol version activated on the network
* All these parameters are included into extension section of a first block of a voting epoch.
*/
case class BlockchainParameters(
abstract class BlockchainParameters {
/** Cost of storing 1 byte in UTXO for four years, in nanoErgs. */
def storageFeeFactor: Int
/** Cost of a transaction output, in computation unit. */
def minValuePerByte: Int
/** Max block size, in bytes. */
def maxBlockSize: Int
/** Cost of a token contained in a transaction, in computation unit. */
def tokenAccessCost: Int
/** Cost of a transaction input, in computation unit. */
def inputCost: Int
/** Cost of a transaction data input, in computation unit. */
def dataInputCost: Int
/** Cost of a transaction output, in computation unit. */
def outputCost: Int
/** Computation units limit per block. */
def maxBlockCost: Int
/** Height when voting for a soft-fork had been started. */
def softForkStartingHeight: Option[Int]
/** Votes for soft-fork collected in previous epochs. */
def softForkVotesCollected: Option[Int]
/** Protocol version activated on the network. */
def blockVersion: Byte
}

/** Concete implementation of blockchain parameters. */
case class CBlockchainParameters(
storageFeeFactor: Int,
minValuePerByte: Int,
maxBlockSize: Int,
Expand All @@ -27,7 +41,7 @@ case class BlockchainParameters(
softForkStartingHeight: Option[Int],
softForkVotesCollected: Option[Int],
blockVersion: Byte
)
) extends BlockchainParameters

/** Global parameters used by SDK */
object BlockchainParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package org.ergoplatform.sdk.wallet.protocol.context

import special.collection.Coll

/** Blockchain context used in tx signing.
*
* @param sigmaLastHeaders fixed number (10 in Ergo) of last block headers
* @param previousStateDigest UTXO set digest from a last header (of sigmaLastHeaders)
* @param sigmaPreHeader returns pre-header (header without certain fields) of the current block
*/
case class BlockchainStateContext(
sigmaLastHeaders: Coll[special.sigma.Header],
/** Blockchain context used in tx signing. */
abstract class BlockchainStateContext {
/** Fixed number (10 in Ergo) of last block headers. */
def sigmaLastHeaders: Coll[sigma.Header]
/** UTXO set digest from a last header (of sigmaLastHeaders). */
def previousStateDigest: Coll[Byte]
/** Returns pre-header (header without certain fields) of the current block. */
def sigmaPreHeader: sigma.PreHeader
}

/** Blockchain context used in tx signing. */
case class CBlockchainStateContext(
sigmaLastHeaders: Coll[sigma.Header],
previousStateDigest: Coll[Byte],
sigmaPreHeader: special.sigma.PreHeader
)
sigmaPreHeader: sigma.PreHeader
) extends BlockchainStateContext

0 comments on commit d98325e

Please sign in to comment.