Skip to content

Commit

Permalink
fix PeerSimple cannot be treated as entity
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed Apr 29, 2018
1 parent 5e1a315 commit 3043e68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/main/scala/com/fluency03/blockchain/core/Peer.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package com.fluency03.blockchain.core

trait PeerSimple {
def name: String
}

case class Peer(name: String, publicKeys: Set[String]) extends PeerSimple
case class PeerSimple(name: String)
case class Peer(name: String, publicKeys: Set[String])
5 changes: 5 additions & 0 deletions src/main/scala/com/fluency03/blockchain/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.security.{MessageDigest, PrivateKey, PublicKey}
import java.time.Instant

import com.fluency03.blockchain.Crypto.{privateKeyToHex, publicKeyToHex}
import com.fluency03.blockchain.core.{Peer, PeerSimple}
import org.bouncycastle.util.encoders.{Base64, Hex}
import org.json4s.{Formats, NoTypeHints}
import org.json4s.native.Serialization
Expand Down Expand Up @@ -50,6 +51,10 @@ package object blockchain {
def toHex: String = privateKeyToHex(privateKey)
}

implicit class PeerImplicit(val peer: Peer) {
def toSimple: PeerSimple = PeerSimple(peer.name)
}


/**
* Generate SHA256 Hash from a input String.
Expand Down
5 changes: 4 additions & 1 deletion src/test/scala/com/fluency03/blockchain/core/PeerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ class PeerTest extends FlatSpec with Matchers {
val p = Peer("peer", Set("abcd"))
p.name shouldEqual "peer"
p.publicKeys shouldEqual Set("abcd")
p shouldBe a[PeerSimple]
p shouldBe a[Peer]
p should not be a[PeerSimple]
val ps = p.toSimple
ps shouldBe a[PeerSimple]
ps.name shouldEqual "peer"
}

}

0 comments on commit 3043e68

Please sign in to comment.