Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ADT for NodeType instead of booleans (#1901)
- Loading branch information
1 parent
a9ad927
commit c9c18fa
Showing
7 changed files
with
82 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.bitcoins.node | ||
|
||
import org.bitcoins.crypto.StringFactory | ||
|
||
sealed abstract class NodeType { | ||
def shortName: String | ||
} | ||
|
||
object NodeType extends StringFactory[NodeType] { | ||
|
||
final case object FullNode extends NodeType { | ||
override def shortName: String = "full" | ||
} | ||
|
||
final case object NeutrinoNode extends NodeType { | ||
override def shortName: String = "neutrino" | ||
} | ||
|
||
final case object SpvNode extends NodeType { | ||
override def shortName: String = "spv" | ||
} | ||
|
||
val all: Vector[NodeType] = Vector(FullNode, NeutrinoNode, SpvNode) | ||
|
||
override def fromStringOpt(str: String): Option[NodeType] = { | ||
all.find(state => str.toLowerCase() == state.toString.toLowerCase) match { | ||
case Some(value) => Some(value) | ||
case None => | ||
all.find(state => str.toLowerCase() == state.shortName.toLowerCase) | ||
} | ||
} | ||
|
||
override def fromString(string: String): NodeType = { | ||
fromStringOpt(string) match { | ||
case Some(state) => state | ||
case None => | ||
sys.error(s"Could not find a NodeType for string=$string") | ||
} | ||
} | ||
} |
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