Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
40f91ca
update bitcoinj
Dec 18, 2017
20af5a3
make network configurable (main, testnet, regtest)
Dec 18, 2017
65a1b0c
fix new configuration to get testnet bge
JorgeMartinezPizarro Dec 18, 2017
6818c03
use custom fileLoader for block reading in testnet3
JorgeMartinezPizarro Dec 19, 2017
bf1219e
revert default value of reference.conf and add try catch to stop popu…
Dec 19, 2017
829b042
remove debug code
JorgeMartinezPizarro Dec 19, 2017
a02c3a7
fix compilation issues
JorgeMartinezPizarro Dec 19, 2017
5d44c51
fix compilation error
JorgeMartinezPizarro Dec 19, 2017
8ca8383
enable use other networks than the main one
JorgeMartinezPizarro Dec 19, 2017
7d7630b
use address prefix depending on network configuration
JorgeMartinezPizarro Dec 19, 2017
cea6e86
Merge branch 'development' into test/bitcoinjSNAPSHOT
JorgeMartinezPizarro Dec 19, 2017
a9984c5
Merge pull request #50 from bitcoinprivacy/test/bitcoinjSNAPSHOT
JorgeMartinezPizarro Dec 19, 2017
10951e3
catch address parse errors
JorgeMartinezPizarro Dec 21, 2017
5d21c59
use correct address version depending on the network
JorgeMartinezPizarro Dec 21, 2017
000fe64
add parameters to configure bge
JorgeMartinezPizarro Dec 28, 2017
3698918
move magic numbers into configuration
JorgeMartinezPizarro Dec 28, 2017
f9b1cbd
add config params to stats endpoint
Jan 4, 2018
854e88f
remove duplicated index
Jan 5, 2018
0b79271
add update balance limit in conf
Jan 5, 2018
01785d6
have you saved the files? No
Jan 5, 2018
7e90de2
change rollBack strategy to potentially allow for rolling back multip…
Jan 5, 2018
dfd8499
fix error obtaining address from hash
Jan 10, 2018
3e39272
add --newstats flag to resume command
Mar 22, 2018
889c9cd
update everything to scala 2.12.4 and sbt 1.1.0
Mar 23, 2018
2ebf3d4
fixed tests after upgrade to scala 2.12
Mar 23, 2018
42b1fc7
trying to find the unmatched input problem
Apr 10, 2018
7f5dc6c
enable docker:publish and postgres-jdbc upgrade
Apr 12, 2018
0806f0b
several fixes
May 16, 2018
ac09d45
another fix in updateBalances.
May 17, 2018
d3d62c5
fix updateBalances
May 17, 2018
d0f3265
Added bge integration tests (required of docker environment, this nee…
May 19, 2018
7873486
move test script to test folder. rename old spec to bge spec
May 19, 2018
30a4f3c
add docker environment for testing
May 20, 2018
340078b
gitignore
May 20, 2018
250d120
add test data default folder structure
May 20, 2018
10eb9ea
change folders
May 20, 2018
539fe26
fix postgres docker init and add proper waiting conditions
May 20, 2018
88fb1df
remove unused file
May 20, 2018
51c8193
final version of testing
May 20, 2018
f489f6c
use ports forward to avoid postgres docker collisions ...
May 20, 2018
77e300d
remove redundant log - debug
May 20, 2018
bff2ec0
convert updateBalances variables to mutable maps. Rewrite closure bal…
May 27, 2018
3d6e70a
improve asserts on balances. create first time if sums are wrong.
May 27, 2018
0b9124d
use DisjointSets for save resume partial tree instead of simulate it …
May 28, 2018
4f93935
Refactor updateBalances: functional. Isolated DB calls to make code m…
May 28, 2018
c4a7735
Fix asserts and improve code readability
May 29, 2018
0bb988c
move asserts to tests
May 31, 2018
7d1c67c
changes
May 31, 2018
8c954c3
move explorer logic to testExplorer tools class. add missing bitcoin …
May 31, 2018
1f0ce73
update balances errors are catched by test suite
May 31, 2018
9741baa
Delete useless info log
Jun 1, 2018
745ab03
Remove support for bitcoinJ raw file reader: peer reader is fast enou…
Jun 1, 2018
76e2b3a
Extend checks to find all bugs
Jun 2, 2018
383b67f
Make up tests
JorgeMartinezPizarro Jun 2, 2018
079dd4c
Add missing checks
JorgeMartinezPizarro Jun 2, 2018
254289c
Fix wrong type in should call
JorgeMartinezPizarro Jun 2, 2018
11f4efb
Fix wrong assert return
JorgeMartinezPizarro Jun 2, 2018
b2989f8
Minor improvements
JorgeMartinezPizarro Jun 2, 2018
1fb8ec5
Improve test more
JorgeMartinezPizarro Jun 2, 2018
9839690
Fix update balances
JorgeMartinezPizarro Jun 3, 2018
baf2947
Clean up unused files
JorgeMartinezPizarro Jun 3, 2018
dc9d1e2
Minor changes - comments
JorgeMartinezPizarro Jun 3, 2018
1273947
update sbt-native-packager plugin
JorgeMartinezPizarro Jun 4, 2018
e99eeaf
add ensime.sbt file outside git for random ensime/sbt fixes
JorgeMartinezPizarro Jun 4, 2018
b57000c
fix method names
JorgeMartinezPizarro Jun 4, 2018
052e3b7
fix broken asSet function
JorgeMartinezPizarro Jun 4, 2018
26d4a21
Improve test suite. SoRestructure updateBalances. Please squash befor…
JorgeMartinezPizarro Jun 23, 2018
889f46e
Reconstruct stats after one or several rollbacks
JorgeMartinezPizarro Jul 2, 2018
974b4dc
Speed up get wrong block
JorgeMartinezPizarro Jul 2, 2018
5539b70
fix several bugs
JorgeMartinezPizarro Oct 9, 2018
6338389
add missing script
JorgeMartinezPizarro Oct 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ project/target/
project/plugins/
.idea/
*.log
neodb/
.ensime
.ensime_cache/
src/main/resources/application.conf
.history
.history
blockchain
ensime.sbt
1 change: 1 addition & 0 deletions api/ensime.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ensimeScalaVersion in ThisBuild := "2.11.8"
3 changes: 2 additions & 1 deletion api/project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.earldouglas.xwp.ContainerPlugin.autoImport._
object BgeapiBuild extends Build {
val Organization = "net.bitcoinprivacy"
val Name = "bgeapi"
val Version = "3.3"
val Version = "3.3-SNAPSHOT"
val ScalaVersion = "2.11.8"
val ScalatraVersion = "2.4.0"

Expand All @@ -24,6 +24,7 @@ object BgeapiBuild extends Build {
version := Version,
scalaVersion := ScalaVersion,
resolvers += Classpaths.typesafeReleases,
resolvers += "Local Maven Repository" at "file:///root/.m2/repository",
resolvers += "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases",
libraryDependencies ++= Seq(
"net.bitcoinprivacy" %% "bge" % Version,
Expand Down
4 changes: 2 additions & 2 deletions api/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.3")

addSbtPlugin("com.mojolly.scalate" % "xsbt-scalate-generator" % "0.5.0")

Expand Down
39 changes: 34 additions & 5 deletions api/src/main/scala/api/MyScalatraServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,41 @@ import org.json4s.{DefaultFormats, Formats}
import org.scalatra.json._
import net.bitcoinprivacy.bge.models._
import org.bitcoinj.core.{Address => BitcoinJAddress}
import org.bitcoinj.params.MainNetParams
import org.bitcoinj.params._
import org.scalatra.CorsSupport
import com.typesafe.config.ConfigFactory

class MyScalatraServlet extends BgeapiStack with db.BitcoinDB with JacksonJsonSupport with CorsSupport {

// Sets up automatic case class to JSON output serialization, required by
lazy val conf = ConfigFactory.load()
lazy val network = conf.getString("network")

lazy val networkParams = network match {
case "main" =>
MainNetParams.get
case "regtest" =>
RegTestParams.get
case "testnet" =>
TestNet3Params.get
case _ =>
throw new Exception("Unknow params for network"+network)

}

case class AddressPrefixes(p2pAddress: String, normalAddress: String)
lazy val prefix = network match {
case "main" =>
AddressPrefixes("05", "00")
case "regtest" =>
AddressPrefixes("C4", "6F")
case "testnet" =>
AddressPrefixes("C4", "6F")
case _ =>
throw new Exception("Unknow params for network"+network)

}

// Sets up automatic case class to JSON output serialization, required by
// the JValueResult trait.
protected implicit lazy val jsonFormats: Formats = DefaultFormats

Expand Down Expand Up @@ -144,13 +173,13 @@ class MyScalatraServlet extends BgeapiStack with db.BitcoinDB with JacksonJsonSu
def hexAddress(stringAddress: String): String = {
val arrayAddress = stringAddress.split(",")
if (arrayAddress.length == 1) {
val address = new BitcoinJAddress(MainNetParams.get, stringAddress)
(if(address.isP2SHAddress) "05" else "00")+valueOf(address.getHash160)
val address = new BitcoinJAddress(networkParams, stringAddress)
(if(address.isP2SHAddress) prefix.p2pAddress else prefix.normalAddress)+valueOf(address.getHash160)
}
else{
"0" + arrayAddress.length +
(for (i <- 0 until arrayAddress.length)
yield valueOf(new BitcoinJAddress(MainNetParams.get, arrayAddress(i)).getHash160) ).mkString("")
yield valueOf(new BitcoinJAddress(networkParams, arrayAddress(i)).getHash160) ).mkString("")
}
}

Expand Down
32 changes: 23 additions & 9 deletions api/src/main/scala/api/models/Address.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ package net.bitcoinprivacy.bge.models

import db._
import org.bitcoinj.core.{Address => Add}
import org.bitcoinj.params.MainNetParams
import org.bitcoinj.params._
import scala.slick.driver.PostgresDriver.simple._

import com.typesafe.config.ConfigFactory

case class Address(address: String, balance: Long)
case class AddressesSummary(count: Int, sum: Long)

object Address extends db.BitcoinDB {

lazy val conf = ConfigFactory.load()
lazy val network = conf.getString("network")

lazy val params = network match {
case "main" =>
MainNetParams.get
case "regtest" =>
RegTestParams.get
case "testnet" =>
TestNet3Params.get
case _ =>
throw new Exception(s"Unknow params for network $network")
}

def getWallet(hash: Array[Byte], from: Int, until: Int) = DB withSession { implicit session =>

val repOpt = addresses.filter(_.hash === hash).map(_.representant).firstOption
Expand Down Expand Up @@ -80,20 +93,21 @@ object Address extends db.BitcoinDB {

}

def hashToAddress(hash: Array[Byte]): String = hash.length match {
def hashToAddress(hash: Array[Byte]): String = try {hash.length match {

case 20 => new Add(MainNetParams.get,0,hash).toString
case 20 => new Add(params,params.getAddressHeader,hash).toString

case 21 => new Add(MainNetParams.get,hash.head.toInt,hash.tail).toString
case 21 => new Add(params,hash.head.toInt,hash.tail).toString

case 0 => "No decodable address found"

case x if (x%20==1) =>

try {
(for (i <- 1 to hash.length-20 by 20)
yield hashToAddress(hash.slice(i,i+20)) ).mkString(",")

} catch { case e:Exception => hash.toString }
case _ => hash.length + " undefined"
}
}} catch { case _ => "Bitcoinj failed decoding address" }


}
14 changes: 9 additions & 5 deletions api/src/main/scala/api/models/Stats.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package net.bitcoinprivacy.bge.models

import scala.slick.driver.PostgresDriver.simple._
import com.typesafe.config.ConfigFactory


case class Stats(block_height:Int, total_bitcoins_in_addresses:Long, total_transactions:Long, total_addresses:Long, total_closures:Long, total_addresses_with_balance:Long, total_closures_with_balance:Long, total_addresses_no_dust:Long, total_closures_no_dust:Long, gini_closure:Double,gini_address:Double, tstamp:Long)
case class Stats(block_height:Int, total_bitcoins_in_addresses:Long, total_transactions:Long, total_addresses:Long, total_closures:Long, total_addresses_with_balance:Long, total_closures_with_balance:Long, total_addresses_no_dust:Long, total_closures_no_dust:Long, gini_closure:Double,gini_address:Double, tstamp:Long, network:String, dust: Int)


object Stats extends db.BitcoinDB
{
{
lazy val conf = ConfigFactory.load()
lazy val dustLimit = conf.getInt("dustLimit")
lazy val network= conf.getString("network")

def getStats =
DB withSession { implicit session =>
val o = stats.sortBy(_.block_height.desc).firstOption

for (p <- o)
yield Stats(p._1,p._2,p._3,p._4,p._5,p._6,p._7,p._8,p._9,p._10,p._11,p._12)
yield Stats(p._1,p._2,p._3,p._4,p._5,p._6,p._7,p._8,p._9,p._10,p._11,p._12, network, dustLimit)
}

def getAllStats =
Expand All @@ -22,7 +26,7 @@ object Stats extends db.BitcoinDB
val p1 = stats.sortBy(_.block_height.desc).run.toList

p1 map {
p => Stats(p._1,p._2,p._3,p._4,p._5,p._6,p._7,p._8,p._9,p._10,p._11,p._12)
p => Stats(p._1,p._2,p._3,p._4,p._5,p._6,p._7,p._8,p._9,p._10,p._11,p._12, network, dustLimit)
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ organization := "net.bitcoinprivacy"

name := "bge"

version := "3.3"
version := "3.3-SNAPSHOT"

scalaVersion := "2.11.8"
scalaVersion := "2.12.4"

maintainer := "Bitcoinprivacy <info@bitcoinprivacy.net>"

// additional libraries
libraryDependencies ++= Seq(
"org.bitcoinj" % "bitcoinj-core" % "0.13.6",
"org.bitcoinj" % "bitcoinj-core" % "0.15-SNAPSHOT",
"org.xerial.snappy"%"snappy-java"%"1.1.2.4",
"org.iq80.leveldb"%"leveldb"%"0.7",
"org.fusesource.leveldbjni"%"leveldbjni-all"%"1.8",
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41",
"org.postgresql" % "postgresql" % "42.2.2",
"com.typesafe.slick" %% "slick" % "2.1.0",
"com.typesafe" % "config" % "1.2.1",
"org.scalacheck" %% "scalacheck" % "1.12.4" % "test",
"org.scalatest" %% "scalatest" % "2.1.5" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test",
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % "test",
"org.deephacks.lmdbjni" % "lmdbjni" % "0.4.6",
"com.typesafe.scala-logging" %% "scala-logging" % "3.4.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.5.0",
"ch.qos.logback" % "logback-classic" % "1.1.7",
////////////////////////////////////////////////////////////////////
// select one of the following depending on your architecture
Expand All @@ -31,10 +31,15 @@ libraryDependencies ++= Seq(
)

enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)

dockerEntrypoint := Seq("bin/bge", "-Dlogback.configurationFile=/conf/logback.xml", "-Dconfig.file=/conf/bge.conf", "--", "start")
dockerUsername := Some("jorgemartinezpizarro")
daemonUser in Docker := "root"

libraryDependencies ~= { _.map(_.exclude("org.slf4j", "slf4j-simple")) }

resolvers += "Local Maven Repository" at "file:///"+Path.userHome.absolutePath+"/.m2/repository"
resolvers += "Local Maven Repository" at "file:///root/.m2/repository"

resolvers += "Fakod Snapshots" at "https://raw.github.com/FaKod/fakod-mvn-repo/master/snapshots"

Expand All @@ -57,6 +62,7 @@ case x if Assembly.isConfigFile(x) =>
MergeStrategy.rename
case PathList("META-INF", xs @ _*) =>
(xs map {_.toLowerCase}) match {

case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) =>
MergeStrategy.discard
case ps @ (x :: xs) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
Expand Down Expand Up @@ -91,3 +97,5 @@ javaOptions in run += "-Xmx16G"
javaOptions in run += "-Xms1G"

fork := true

testOptions in Test += Tests.Argument("-oD")
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.11
sbt.version=1.1.0
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.4")
15 changes: 10 additions & 5 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ levelDBFile = ${dataDir}"level.db"
lockFile = ${dataDir}"lock"
dustLimit=546
databaseName="postgres"
username = "root"
password = "trivial"
host = "localhost"
username = "user"
password = "pass"
host = "localhost:1234"
jdbcOptions = "?useServerPrepStmts=false&rewriteBatchedStatements=true&maxWait=-1"
mdb.path = ${dataDir}"mdb/"
mdb.transactionSize = 100000

logger.scala.slick=ERROR
network=main # accepts main, testnet, regtest
logger.scala.slick=ERROR
resumeBlockSize=1000000 # depending on the available ram
bitcoin.ip=localhost
bitcoin.maxPopulate=0 # 0 all,m number block until stop first populate. To rest partial blockchains without running all!
balanceUpdateLimit=50000 # for balance changes beyond this size, create new balance tables
checkUTXOsSize=100000
Loading