-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
spew
committed
May 26, 2014
1 parent
958e6fd
commit f6c8142
Showing
6 changed files
with
90 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
target | ||
*.wallet | ||
*.spvchain |
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,13 @@ | ||
name := "bitcoin-scala" | ||
|
||
version := "1.0" | ||
|
||
scalaVersion := "2.10.4" | ||
|
||
libraryDependencies ++= Seq( | ||
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2", | ||
"ch.qos.logback" % "logback-classic" % "1.1.2", | ||
"com.github.scopt" %% "scopt" % "3.2.0", | ||
"com.google" % "bitcoinj" % "0.11.2" | ||
) | ||
|
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 @@ | ||
logLevel := Level.Warn |
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,35 @@ | ||
import com.google.bitcoin.core.ECKey | ||
import com.google.bitcoin.kits.WalletAppKit | ||
import com.google.bitcoin.params.{MainNetParams, RegTestParams, TestNet3Params} | ||
import java.io.File | ||
|
||
class BitcoinApplication(configuration: ProgramConfiguration) { | ||
def run() { | ||
val kit = createWalletAppKit() | ||
kit.startAndWait() | ||
kit.stopAndWait() | ||
} | ||
|
||
private def createWalletAppKit() = { | ||
val networkParams = this.networkParams | ||
val kit = new WalletAppKit(networkParams._1, new File("."), networkParams._2) { | ||
override def onSetupCompleted() = { | ||
if (wallet().getKeychainSize() < 1) | ||
wallet().addKey(new ECKey()); | ||
} | ||
} | ||
if (configuration.networkName == "regtest") { | ||
kit.connectToLocalHost() | ||
} | ||
kit | ||
} | ||
|
||
private def networkParams = { | ||
configuration.networkName match { | ||
case "testnet" => (TestNet3Params.get, "forwarding-service-testnet") | ||
case "regtest" => (RegTestParams.get, "forwarding-service-regtest") | ||
case "prod" => (MainNetParams.get, "forwarding-service") | ||
case _ => throw new Exception(s"Unknown network name: ${configuration.networkName}") | ||
} | ||
} | ||
} |
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,33 @@ | ||
import com.typesafe.scalalogging.slf4j.LazyLogging | ||
import scopt.OptionParser | ||
|
||
object Program extends LazyLogging { | ||
def main(args: Array[String]) { | ||
try { | ||
val parser = this.createParser(); | ||
parser.parse(args, createDefaultConfiguration()) map { configuration => | ||
val application = new BitcoinApplication(configuration) | ||
application.run() | ||
} getOrElse { | ||
logger.warn("Unable to properly parse arguments, exiting...") | ||
} | ||
} catch { | ||
case t: Throwable => | ||
logger.error("Uncaught exception in main thread", t) | ||
throw t | ||
} | ||
} | ||
|
||
private def createDefaultConfiguration(): ProgramConfiguration = { | ||
ProgramConfiguration() | ||
} | ||
|
||
private def createParser(): OptionParser[ProgramConfiguration] = { | ||
val parser = new OptionParser[ProgramConfiguration]("pokerbot") { | ||
head("bitcoin-scala", "1.0") | ||
opt[String]('n', "network-name") optional() action { (n, c) => c.copy(networkName = n) } text("the bitcoin network to connect to: { testnet, regtest, prod }") | ||
help("help") text("prints usage") | ||
} | ||
parser | ||
} | ||
} |
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,4 @@ | ||
|
||
case class ProgramConfiguration ( | ||
networkName: String = "testnet" | ||
) |