Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 5600e7e

Browse files
committed
Separate ScorexEncoding and ScorexLogging. Fix /pull/25#pullrequestreview-83719938
1 parent 73fc369 commit 5600e7e

35 files changed

+98
-94
lines changed

examples/src/main/scala/examples/commons/PublicKey25519NoncedBox.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import io.circe.syntax._
66
import scorex.core.serialization.Serializer
77
import scorex.core.transaction.account.PublicKeyNoncedBox
88
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
9-
import scorex.core.utils.ScorexLogging
9+
import scorex.core.utils.{ScorexEncoding, ScorexLogging}
1010
import scorex.crypto.encode.Base16
1111
import scorex.crypto.hash.Blake2b256
1212
import scorex.crypto.signatures.{Curve25519, PublicKey}
@@ -25,7 +25,7 @@ case class PublicKey25519NoncedBox(override val proposition: PublicKey25519Propo
2525
s"PublicKey25519NoncedBox(id: ${Base16.encode(id)}, proposition: $proposition, nonce: $nonce, value: $value)"
2626
}
2727

28-
object PublicKey25519NoncedBox extends ScorexLogging {
28+
object PublicKey25519NoncedBox extends ScorexEncoding {
2929
val BoxKeyLength: Int = Blake2b256.DigestSize
3030
val BoxLength: Int = Curve25519.KeyLength + 2 * 8
3131

examples/src/main/scala/examples/commons/SimpleBoxTransaction.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scorex.core.transaction.box.BoxUnlocker
1313
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
1414
import scorex.core.transaction.proof.{Proof, Signature25519}
1515
import scorex.core.transaction.state.{PrivateKey25519, PrivateKey25519Companion}
16-
import scorex.core.utils.ScorexLogging
16+
import scorex.core.utils.ScorexEncoding
1717
import scorex.crypto.hash.Blake2b256
1818
import scorex.crypto.signatures.{Curve25519, PublicKey, Signature}
1919

@@ -73,7 +73,7 @@ case class SimpleBoxTransaction(from: IndexedSeq[(PublicKey25519Proposition, Non
7373
}
7474

7575

76-
object SimpleBoxTransaction extends ScorexLogging {
76+
object SimpleBoxTransaction extends ScorexEncoding {
7777

7878
implicit val simpleBoxEncoder: Encoder[SimpleBoxTransaction] = (sbe: SimpleBoxTransaction) =>
7979
Map(

examples/src/main/scala/examples/hybrid/HybridNodeViewHolder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scorex.core.settings.ScorexSettings
1212
import scorex.core.transaction.Transaction
1313
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
1414
import scorex.core.transaction.state.PrivateKey25519Companion
15-
import scorex.core.utils.{NetworkTimeProvider, ScorexLogging}
15+
import scorex.core.utils.{NetworkTimeProvider, ScorexEncoding, ScorexLogging}
1616
import scorex.core.{ModifierTypeId, NodeViewHolder, NodeViewModifier}
1717
import scorex.crypto.encode.Base58
1818
import scorex.crypto.signatures.PublicKey
@@ -65,7 +65,7 @@ class HybridNodeViewHolder(settings: ScorexSettings,
6565
}
6666
}
6767

68-
object HybridNodeViewHolder extends ScorexLogging {
68+
object HybridNodeViewHolder extends ScorexLogging with ScorexEncoding {
6969
def generateGenesisState(settings: ScorexSettings, minerSettings: HybridMiningSettings, timeProvider: NetworkTimeProvider):
7070
(HybridHistory, HBoxStoredState, HBoxWallet, SimpleBoxTransactionMemPool) = {
7171
val GenesisAccountsNum = 50

examples/src/main/scala/examples/hybrid/api/http/DebugApiRoute.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import io.circe.syntax._
1111
import scorex.core.ModifierId
1212
import scorex.core.api.http.{ApiResponse, ApiRouteWithFullView}
1313
import scorex.core.settings.RESTApiSettings
14-
import scorex.core.utils.ScorexLogging
14+
import scorex.core.utils.{ScorexEncoding, ScorexLogging}
1515

1616
import scala.util.Try
1717

1818

1919
case class DebugApiRoute(override val settings: RESTApiSettings, nodeViewHolderRef: ActorRef)
2020
(implicit val context: ActorRefFactory)
2121
extends ApiRouteWithFullView[HybridHistory, HBoxStoredState, HBoxWallet, SimpleBoxTransactionMemPool]
22-
with ScorexLogging {
22+
with ScorexEncoding {
2323

2424
override val route: Route = (pathPrefix("debug") & withCors) {
2525
infoRoute ~ chain ~ delay ~ myblocks ~ generators

examples/src/main/scala/examples/hybrid/api/http/StatsApiRoute.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import io.circe.syntax._
1010
import scorex.core.ModifierId
1111
import scorex.core.api.http.{ApiResponse, ApiRouteWithFullView, ApiTry}
1212
import scorex.core.settings.RESTApiSettings
13-
import scorex.core.utils.ScorexLogging
13+
import scorex.core.utils.{ScorexEncoding, ScorexLogging}
1414

1515
import scala.util.Try
1616

1717
case class StatsApiRoute(override val settings: RESTApiSettings, nodeViewHolderRef: ActorRef)
1818
(implicit val context: ActorRefFactory)
1919
extends ApiRouteWithFullView[HybridHistory, HBoxStoredState, HBoxWallet, SimpleBoxTransactionMemPool]
20-
with ScorexLogging {
20+
with ScorexEncoding {
2121

2222
override val route: Route = (pathPrefix("stats") & withCors) {
2323
tail ~ meanDifficulty

examples/src/main/scala/examples/hybrid/api/http/WalletApiRoute.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import io.circe.syntax._
1111
import scorex.core.api.http.{ApiError, ApiResponse, ApiRouteWithFullView}
1212
import scorex.core.settings.RESTApiSettings
1313
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
14-
import scorex.core.utils.ScorexLogging
15-
import scorex.crypto.encode.Base58
14+
import scorex.core.utils.ScorexEncoding
1615
import scorex.crypto.signatures.PublicKey
1716

1817
import scala.util.{Failure, Success, Try}
@@ -21,7 +20,7 @@ import scala.util.{Failure, Success, Try}
2120
case class WalletApiRoute(override val settings: RESTApiSettings, nodeViewHolderRef: ActorRef)
2221
(implicit val context: ActorRefFactory)
2322
extends ApiRouteWithFullView[HybridHistory, HBoxStoredState, HBoxWallet, SimpleBoxTransactionMemPool]
24-
with ScorexLogging {
23+
with ScorexEncoding {
2524

2625
import scorex.core.NodeViewHolder.ReceivableMessages.LocallyGeneratedTransaction
2726

examples/src/main/scala/examples/hybrid/blocks/PosBlock.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scorex.core.block.Block._
99
import scorex.core.serialization.Serializer
1010
import scorex.core.transaction.proof.Signature25519
1111
import scorex.core.transaction.state.PrivateKey25519
12-
import scorex.core.utils.ScorexLogging
12+
import scorex.core.utils.{ScorexEncoding, ScorexLogging}
1313
import scorex.core.{ModifierId, ModifierTypeId, TransactionsCarryingPersistentNodeViewModifier}
1414
import scorex.crypto.hash.Blake2b256
1515
import scorex.crypto.signatures.{Curve25519, Signature}
@@ -38,7 +38,7 @@ case class PosBlock(override val parentId: BlockId, //PoW block
3838
override def toString: String = s"PoSBlock(${this.asJson.noSpaces})"
3939
}
4040

41-
object PosBlockCompanion extends Serializer[PosBlock] with ScorexLogging {
41+
object PosBlockCompanion extends Serializer[PosBlock] with ScorexEncoding {
4242
override def toBytes(b: PosBlock): Array[Byte] = {
4343
val txsBytes = b.transactions.sortBy(t => encoder.encode(t.id)).foldLeft(Array[Byte]()) { (a, b) =>
4444
Bytes.concat(Ints.toByteArray(b.bytes.length), b.bytes, a)
@@ -77,7 +77,7 @@ object PosBlockCompanion extends Serializer[PosBlock] with ScorexLogging {
7777
}
7878
}
7979

80-
object PosBlock extends ScorexLogging {
80+
object PosBlock extends ScorexEncoding {
8181
val MaxBlockSize = 512 * 1024 //512K
8282
val ModifierTypeId: ModifierTypeId = scorex.core.ModifierTypeId @@ 4.toByte
8383

examples/src/main/scala/examples/hybrid/blocks/PowBlock.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import examples.commons.SimpleBoxTransaction
55
import examples.hybrid.mining.HybridMiningSettings
66
import io.circe.Encoder
77
import io.circe.syntax._
8-
import scorex.core.{ModifierId, _}
98
import scorex.core.block.Block
109
import scorex.core.block.Block._
1110
import scorex.core.serialization.Serializer
1211
import scorex.core.transaction.box.proposition.{PublicKey25519Proposition, PublicKey25519PropositionSerializer}
13-
import scorex.core.utils.ScorexLogging
12+
import scorex.core.utils.ScorexEncoding
13+
import scorex.core.{ModifierId, _}
1414
import scorex.crypto.hash.Blake2b256
1515
import scorex.crypto.signatures.{Curve25519, PublicKey}
1616

@@ -23,7 +23,7 @@ class PowBlockHeader(
2323
val nonce: Long,
2424
val brothersCount: Int,
2525
val brothersHash: Array[Byte],
26-
val generatorProposition: PublicKey25519Proposition) extends ScorexLogging {
26+
val generatorProposition: PublicKey25519Proposition) extends ScorexEncoding {
2727

2828

2929
import PowBlockHeader._
@@ -135,7 +135,7 @@ object PowBlockCompanion extends Serializer[PowBlock] {
135135
}
136136
}
137137

138-
object PowBlock extends ScorexLogging {
138+
object PowBlock extends ScorexEncoding {
139139
val ModifierTypeId: ModifierTypeId = scorex.core.ModifierTypeId @@ 3.toByte
140140

141141
implicit val powBlockEncoder: Encoder[PowBlock] = (pb: PowBlock) => {

examples/src/main/scala/examples/hybrid/history/HybridHistory.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import scorex.core.consensus.ModifierSemanticValidity._
1414
import scorex.core.consensus._
1515
import scorex.core.settings.ScorexSettings
1616
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
17-
import scorex.core.utils.{NetworkTimeProvider, ScorexLogging}
18-
import scorex.core.validation.{MalformedModifierError, RecoverableModifierError}
17+
import scorex.core.utils.{NetworkTimeProvider, ScorexEncoding, ScorexLogging}
18+
import scorex.core.validation.RecoverableModifierError
1919
import scorex.core.{ModifierId, ModifierTypeId, NodeViewModifier}
20-
import scorex.crypto.encode.Base58
2120
import scorex.crypto.hash.Blake2b256
2221

2322
import scala.annotation.tailrec
@@ -32,7 +31,7 @@ class HybridHistory(val storage: HistoryStorage,
3231
validators: Seq[BlockValidator[HybridBlock]],
3332
statsLogger: Option[FileLogger],
3433
timeProvider: NetworkTimeProvider)
35-
extends History[HybridBlock, HybridSyncInfo, HybridHistory] with ScorexLogging {
34+
extends History[HybridBlock, HybridSyncInfo, HybridHistory] with ScorexLogging with ScorexEncoding {
3635

3736
import HybridHistory._
3837

@@ -204,7 +203,7 @@ class HybridHistory(val storage: HistoryStorage,
204203

205204
val newSuffixValid = !newSuffix.drop(1).map(storage.semanticValidity).contains(Invalid)
206205

207-
if(newSuffixValid) {
206+
if (newSuffixValid) {
208207
// TODO: fixme, What should we do if `oldSuffix` is empty? and .get
209208
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps", "org.wartremover.warts.OptionPartial"))
210209
val throwBlocks = oldSuffix.tail.map(id => modifierById(id).get)
@@ -463,7 +462,7 @@ class HybridHistory(val storage: HistoryStorage,
463462
* Average delay in milliseconds between last $blockNum blocks starting from $block
464463
* Debug only
465464
*/
466-
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps","org.wartremover.warts.OptionPartial"))
465+
@SuppressWarnings(Array("org.wartremover.warts.TraversableOps", "org.wartremover.warts.OptionPartial"))
467466
def averageDelay(id: ModifierId, blockNum: Int): Try[Long] = Try {
468467
val block = modifierById(id).get
469468
val c = chainBack(block, isGenesis, blockNum).get.map(_._2)
@@ -486,7 +485,7 @@ class HybridHistory(val storage: HistoryStorage,
486485

487486
override def reportModifierIsInvalid(modifier: HybridBlock,
488487
progressInfo: ProgressInfo[HybridBlock]): (HybridHistory,
489-
ProgressInfo[HybridBlock]) = {
488+
ProgressInfo[HybridBlock]) = {
490489
storage.updateValidity(modifier, Invalid)
491490

492491
new HybridHistory(storage, settings, validators, statsLogger, timeProvider) ->

examples/src/main/scala/examples/hybrid/mining/PowMiner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scorex.core.ModifierId
1111
import scorex.core.NodeViewHolder.CurrentView
1212
import scorex.core.block.Block.BlockId
1313
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
14-
import scorex.core.utils.ScorexLogging
14+
import scorex.core.utils.{ScorexEncoding, ScorexLogging}
1515
import scorex.crypto.encode.Base58
1616
import scorex.crypto.hash.Blake2b256
1717

@@ -25,7 +25,7 @@ import scala.util.Random
2525
* and stops on a new PoW block found (when PoS ref is unknown)
2626
*/
2727
class PowMiner(viewHolderRef: ActorRef, settings: HybridMiningSettings)(implicit ec: ExecutionContext)
28-
extends Actor with ScorexLogging {
28+
extends Actor with ScorexLogging with ScorexEncoding {
2929

3030
import PowMiner.ReceivableMessages._
3131
import PowMiner._

0 commit comments

Comments
 (0)