Bitcoin Implementation in Scala
Go to file
Torkel Rogstad 2723ef6f5d Move Logback config into test resources (#509)
I though I had solved our logging problem:
    We want projects to pick up logging config
    in core, without it being published.

The previous attempt was filtering out XML files
from unmanagedResources. That caused the XML
files to not get published, and when running
tests through Bloop everything worked fine.
However, when running them through sbt the
config did not get picked up. I suspect this
is because of a bug in how Bloop exports sbt
builds.

In this attempt we instead move the XML files
to test resources in core, and then make the
test projects depend on test sources in core,
with the awkward syntax 'core % "test->test"'.
2019-06-11 06:38:42 -05:00
bench Creates a package for the bench project, moves BlockBench into that package (#472) 2019-05-14 09:21:50 -05:00
bitcoind-rpc Add debug prints to bitcoindCall when not on mainnet 2019-06-06 13:25:09 +02:00
bitcoind-rpc-test/src/test Node (#490) 2019-06-04 09:53:00 -05:00
chain Fix bug when overriding configurations 2019-06-05 18:37:38 +02:00
chain-test/src/test Multi module configuration (#494) 2019-06-05 10:48:15 -05:00
core Move Logback config into test resources (#509) 2019-06-11 06:38:42 -05:00
core-test Reshuffle package location of P2P messages (#495) 2019-06-06 09:13:32 -05:00
db-commons Fix bug when overriding configurations 2019-06-05 18:37:38 +02:00
docs Docs: conditional Travis based on commit message 2019-06-03 11:18:19 +02:00
eclair-rpc Give sbt-api-mappings plugin a concrete version, fix compiler warnings with unused imports (#485) 2019-05-30 09:47:21 -05:00
eclair-rpc-test/src/test/scala/org/bitcoins/eclair Node (#490) 2019-06-04 09:53:00 -05:00
node Reshuffle package location of P2P messages (#495) 2019-06-06 09:13:32 -05:00
node-test/src/test/scala/org/bitcoins/node Reshuffle package location of P2P messages (#495) 2019-06-06 09:13:32 -05:00
project Multi module configuration (#494) 2019-06-05 10:48:15 -05:00
secp256k1@2e16ac7d6c Changing TxSigComponent to take a TransactionOutput instead of a ScriptPubKey, refactoring ScriptProgram into 3 companion objects PreExecutionScriptProgram, ExecutionInProgressScriptProgram, ExecutedScriptProgram 2018-05-19 09:25:32 -05:00
secp256k1jni Node (#490) 2019-06-04 09:53:00 -05:00
testkit Refactor logback configuration to reduce repetition (#499) 2019-06-07 07:29:40 -05:00
wallet Respond to code review on legacy address generation 2019-06-06 15:10:20 +02:00
wallet-test/src/test/scala/org/bitcoins/wallet Respond to code review on legacy address generation 2019-06-06 15:10:20 +02:00
website Docs: removes blog from website 2019-06-11 12:59:58 +02:00
zmq Node (#490) 2019-06-04 09:53:00 -05:00
.dockerignore WIP: Docusaurus website (#465) 2019-05-14 18:05:14 -05:00
.gitignore WIP: Docusaurus website (#465) 2019-05-14 18:05:14 -05:00
.gitmodules Adding specific commit for secp256k1 2018-04-25 16:44:48 -05:00
.jvmopts Reduce number of requests we send to eclair in testkits, add commandN… (#343) 2019-02-19 14:18:37 -06:00
.scalafmt.conf Add access modifier sort rewrite rule (#468) 2019-05-22 05:54:41 -05:00
build.sbt Move Logback config into test resources (#509) 2019-06-11 06:38:42 -05:00
CONTRIBUTING.md WIP: Docusaurus website (#465) 2019-05-14 18:05:14 -05:00
docker-compose.yml Docs: removes blog from website 2019-06-11 12:59:58 +02:00
Dockerfile WIP: Docusaurus website (#465) 2019-05-14 18:05:14 -05:00
inThisBuild.sbt Bump scalac to 2.12.8 (#340) 2019-02-16 14:52:04 -06:00
LICENSE updating license 2018-01-17 17:15:18 -06:00
README.md Adds Ammonite REPL in test scope (#323) 2019-02-26 06:16:12 -06:00
try-bitcoin-s.sh Doc: Add stable and unstable version, try bitcoin-s script 2019-05-31 17:14:15 +02:00

Build Status Coverage Status IRC NetworkGitter chat

Bitcoin-S

Design Principles

  • Immutable data structures everywhere
  • Algebraic Data Types to allow the compiler to check for exhaustiveness on match statements
  • Using property based testing to test robustness of code
  • Minimize dependencies to reduce attack surface

Projects

  1. core - this is where protocol data structures live, like Transactions, Blocks, or PrivateKeys. For more info read core/README.md

  2. core-test - this is where all test cases for the core project live

  3. bitcoind-rpc - this is a RPC client implementation for bitcoind. For more info read bitcoind-rpc/README.md

  4. bitcoind-rpc-test - this is where all test cases for the bitcoind-rpc project live

  5. eclair-rpc - this is a RPC client implementation for Eclair, which is a Lightning Network implementation. For more information please read eclair-rpc/README.md

  6. eclair-rpc-test - this is where all test cases for the eclair-rpc project live

  7. bench - benchmarks for Bitcoin-S. For more information please read bench/README.md

  8. testkit - This is a useful testkit for testing Bitcoin related applications. You can spin up Bitcoin and Lightning nodes arbitrarily and set them in specific states. For more information please read testkit/README.md

  9. zmq - bitcoind has a setting that publishes information about the state of the network over ZMQ. This project implements a subscriber that allows you to read and parse that information. For more information see zmq/README.md as well as the official Bitcoin Core ZMQ documentation

  10. secp256k1jni - JNI (Java Native Interface) for secp256k1, a optimized C library for EC operations on curve secp256k1. It has support for a wide range of cryptographic operations used in the Bitcoin protocol. Fore more information please read secp256k1jni/README.md

REPL

In any given sub project, it's possible to open a REPL session. This session has both main and test sources from Bitcoin-S available, as well as all dependencies for the given sub project. To do this:

// core project 
$ sbt coreTest/test:run // we do coreTest instead of core to have all test sources available

// this works as well
$ sbt
> project coreTest
> amm
...
Loading...
Compiling (synthetic)/ammonite/predef/interpBridge.sc
Compiling (synthetic)/ammonite/predef/replBridge.sc
Compiling (synthetic)/ammonite/predef/DefaultPredef.sc
Welcome to the Ammonite Repl 1.6.2
(Scala 2.12.7 Java 1.8.0_191)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import org.bitcoins.core.protocol.ln.currency.MilliSatoshis 
import org.bitcoins.core.protocol.ln.currency.MilliSatoshis

@ MilliSatoshis(100) 
res1: MilliSatoshis = MilliSatoshisImpl(100)


// Bitcoind RPC project
$ sbt bitcoindRpcTest/test:run

// this works as well
$ sbt
> project bitcoindRpcTest
> amm

// Similarly for other projects

Artifacts

You need to add the Bitcoin-S Bintray to your resolvers to be able to access published artifacts.

sbt

With sbt, this can be done like this:

resolvers += Resolver.bintrayRepo("bitcoin-s", "bitcoin-s-core"),

Now you should be able to add Bitcoin-S artifacts like this:


"org.bitcoins" % "bitcoin-s-secp256k1jni" % "0.0.4"

"org.bitcoins" %% "bitcoin-s-core" % "0.0.4" withSources() withJavadoc()

"org.bitcoins" %% "bitcoin-s-bitcoind-rpc" % "0.0.4" withSources() withJavadoc()

"org.bitcoins" %% "bitcoin-s-eclair-rpc" % "0.0.4" withSources() withJavadoc()

"org.bitcoins" %% "bitcoin-s-testkit" % "0.0.4" withSources() withJavadoc()

"org.bitcoins" %% "bitcoin-s-zmq" % "0.0.4" withSources() withJavadoc()

Ammonite

Ammonite is (among other things) a modernized Scala REPL with syntax highlighting, multi-line editing, the ability to load artifacts directly in the REPL, and many other quality-of-life improvements missing in the default Scala REPL.

Ammonite is a project by Li Haoyi, and you can get it at ammonite.io

With Ammonite, this can be done like this:

@ import coursier.MavenRepository
import coursier.MavenRepository

@ interp.repositories() ++= Seq(MavenRepository("https://dl.bintray.com/bitcoin-s/bitcoin-s-core"))

@ import $ivy.`org.bitcoins::bitcoin-s-core:0.0.4`
import $ivy.$

@ import org.bitcoins.core.currency.Bitcoins
import org.bitcoins.core.currency.Bitcoins

@ Bitcoins(10)
res0: Bitcoins = BitcoinsImpl(10) // 🎉

This is only necessary one time, Ammonite remembers your resolvers across sessions.

Published artifacts

Versioned artifacts are available online.

Snapshots (not necessarily stable, use for local development) are available at JFrog.

Tagged versions are available at Bintray.