-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2111 from ergoplatform/v5.0.21
Candidate for 5.0.21 release
- Loading branch information
Showing
230 changed files
with
34,389 additions
and
3,130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
ergo-core/src/main/scala/org/ergoplatform/network/message/MessageBase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.ergoplatform.network.message | ||
|
||
import org.ergoplatform.network.message.MessageConstants._ | ||
|
||
import scala.util.{Success, Try} | ||
|
||
/** | ||
* Trait for a ergo network message | ||
* | ||
* @param spec - message specification | ||
* @param input - message being wrapped, whether in byte-array form (if from outside), | ||
* or structured data (if formed locally) | ||
* @tparam Content - message data type | ||
*/ | ||
trait MessageBase[Content] { | ||
val spec: MessageSpec[Content] | ||
val input: Either[Array[Byte], Content] | ||
|
||
/** | ||
* Message data bytes | ||
*/ | ||
lazy val dataBytes: Array[Byte] = input match { | ||
case Left(db) => db | ||
case Right(d) => spec.toBytes(d) | ||
} | ||
|
||
/** | ||
* Structured message content | ||
*/ | ||
lazy val data: Try[Content] = input match { | ||
case Left(db) => spec.parseBytesTry(db) | ||
case Right(d) => Success(d) | ||
} | ||
|
||
lazy val dataLength: Int = dataBytes.length | ||
|
||
/** | ||
* @return serialized message length in bytes | ||
*/ | ||
def messageLength: Int = { | ||
if (dataLength > 0) { | ||
HeaderLength + ChecksumLength + dataLength | ||
} else { | ||
HeaderLength | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
ergo-core/src/main/scala/org/ergoplatform/settings/ChainSettingsReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.ergoplatform.settings | ||
|
||
import com.typesafe.config.ConfigFactory | ||
import net.ceedubs.ficus.Ficus._ | ||
import net.ceedubs.ficus.readers.ArbitraryTypeReader._ | ||
import java.io.File | ||
|
||
object ChainSettingsReader extends PowSchemeReaders with ModifierIdReader with SettingsReaders{ | ||
def read(path: String): Option[ChainSettings] = { | ||
val file = new File(path) | ||
if (file.exists) { | ||
val cfg = ConfigFactory.parseFile(file) | ||
val fallback = ConfigFactory.parseFile(new File("src/main/resources/application.conf")) | ||
val network = ConfigFactory.parseFile(new File("src/main/resources/testnet.conf")) | ||
val fullConfig = ConfigFactory | ||
.defaultOverrides() | ||
.withFallback(cfg) //order | ||
.withFallback(network) //matters | ||
.withFallback(fallback) //here | ||
.resolve() | ||
|
||
val chainSettings = fullConfig.as[ChainSettings]("ergo.chain") | ||
Some(chainSettings) | ||
} else None | ||
} | ||
} |
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
ergo-core/src/main/scala/org/ergoplatform/settings/ModifierIdReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.ergoplatform.settings | ||
|
||
import com.typesafe.config.Config | ||
import net.ceedubs.ficus.readers.ValueReader | ||
import scorex.util.ModifierId | ||
|
||
trait ModifierIdReader { | ||
|
||
implicit val modifierIdReader: ValueReader[ModifierId] = new ValueReader[ModifierId] { | ||
override def read(cfg: Config, path: String): ModifierId = { | ||
ModifierId @@ cfg.getString(path) | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
ergo-core/src/main/scala/org/ergoplatform/settings/PowSchemeReaders.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.ergoplatform.settings | ||
|
||
import com.typesafe.config.{Config, ConfigException} | ||
import net.ceedubs.ficus.Ficus._ | ||
import net.ceedubs.ficus.readers.ValueReader | ||
import org.ergoplatform.mining._ | ||
|
||
trait PowSchemeReaders { | ||
|
||
implicit val powSchemeReader: ValueReader[AutolykosPowScheme] = new ValueReader[AutolykosPowScheme] { | ||
override def read(cfg: Config, path: String): AutolykosPowScheme = { | ||
val schemeNameKey = s"$path.powType" | ||
val schemeName = cfg.getString(schemeNameKey) | ||
val n = cfg.as[Int](s"$path.n") | ||
val k = cfg.as[Int](s"$path.k") | ||
if (schemeName == "autolykos") { | ||
new AutolykosPowScheme(k, n) | ||
} else if (schemeName == "fake") { | ||
new DefaultFakePowScheme(k, n) | ||
} else { | ||
throw new ConfigException.BadValue(schemeNameKey, schemeName) | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.